stage2: support environment variables for verbose options

The presence of ZIG_VERBOSE_LINK now enables --verbose-link.
The presence of ZIG_VERBOSE_CC now enables --verbose-cc.

These are useful when debugging usage of `zig cc` which does not have
CLI flags for these options, since they are not valid C compiler flags.
This commit is contained in:
Andrew Kelley
2021-03-04 17:37:53 -07:00
parent ffb2568a9f
commit 98b24aa47f

View File

@@ -448,6 +448,15 @@ const Emit = union(enum) {
}
};
fn optionalBoolEnvVar(arena: *Allocator, name: []const u8) !bool {
if (std.process.getEnvVarOwned(arena, name)) |value| {
return true;
} else |err| switch (err) {
error.EnvironmentVariableNotFound => return false,
else => |e| return e,
}
}
fn optionalStringEnvVar(arena: *Allocator, name: []const u8) !?[]const u8 {
if (std.process.getEnvVarOwned(arena, name)) |value| {
return value;
@@ -482,8 +491,8 @@ fn buildOutputType(
var single_threaded = false;
var function_sections = false;
var watch = false;
var verbose_link = false;
var verbose_cc = false;
var verbose_link = try optionalBoolEnvVar(arena, "ZIG_VERBOSE_LINK");
var verbose_cc = try optionalBoolEnvVar(arena, "ZIG_VERBOSE_CC");
var verbose_tokenize = false;
var verbose_ast = false;
var verbose_ir = false;