aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-10-25 23:10:41 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-10-25 23:10:41 -0400
commit5f28a9d23851d94edc2b24e549b7c5abbbf23f68 (patch)
tree35900fc47e346ef3161279f3c38bb91079596eca /std
parent6764a4522391d82c40fc54bae448b32366e3e6d8 (diff)
downloadzig-5f28a9d23851d94edc2b24e549b7c5abbbf23f68.tar.gz
zig-5f28a9d23851d94edc2b24e549b7c5abbbf23f68.zip
cleaner verbose flags and zig build prints failed command
Diffstat (limited to 'std')
-rw-r--r--std/build.zig39
-rw-r--r--std/special/build_runner.zig39
2 files changed, 64 insertions, 14 deletions
diff --git a/std/build.zig b/std/build.zig
index 84eba6d33b..7cf2ac5987 100644
--- a/std/build.zig
+++ b/std/build.zig
@@ -33,6 +33,12 @@ pub const Builder = struct {
available_options_map: AvailableOptionsMap,
available_options_list: ArrayList(AvailableOption),
verbose: bool,
+ verbose_tokenize: bool,
+ verbose_ast: bool,
+ verbose_link: bool,
+ verbose_ir: bool,
+ verbose_llvm_ir: bool,
+ verbose_cimport: bool,
invalid_user_input: bool,
zig_exe: []const u8,
default_step: &Step,
@@ -88,6 +94,12 @@ pub const Builder = struct {
.build_root = build_root,
.cache_root = %%os.path.relative(allocator, build_root, cache_root),
.verbose = false,
+ .verbose_tokenize = false,
+ .verbose_ast = false,
+ .verbose_link = false,
+ .verbose_ir = false,
+ .verbose_llvm_ir = false,
+ .verbose_cimport = false,
.invalid_user_input = false,
.allocator = allocator,
.lib_paths = ArrayList([]const u8).init(allocator),
@@ -536,15 +548,19 @@ pub const Builder = struct {
return self.spawnChildEnvMap(null, &self.env_map, argv);
}
+ fn printCmd(cwd: ?[]const u8, argv: []const []const u8) {
+ if (cwd) |yes_cwd| %%io.stderr.print("cd {} && ", yes_cwd);
+ for (argv) |arg| {
+ %%io.stderr.print("{} ", arg);
+ }
+ %%io.stderr.printf("\n");
+ }
+
fn spawnChildEnvMap(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap,
argv: []const []const u8) -> %void
{
if (self.verbose) {
- if (cwd) |yes_cwd| %%io.stderr.print("cd {}; ", yes_cwd);
- for (argv) |arg| {
- %%io.stderr.print("{} ", arg);
- }
- %%io.stderr.printf("\n");
+ printCmd(cwd, argv);
}
const child = %%os.ChildProcess.init(argv, self.allocator);
@@ -561,12 +577,15 @@ pub const Builder = struct {
switch (term) {
Term.Exited => |code| {
if (code != 0) {
- %%io.stderr.printf("Process {} exited with error code {}\n", argv[0], code);
+ %%io.stderr.printf("The following command exited with error code {}:\n", code);
+ printCmd(cwd, argv);
return error.UncleanExit;
}
},
else => {
- %%io.stderr.printf("Process {} terminated unexpectedly\n", argv[0]);
+ %%io.stderr.printf("The following command terminated unexpectedly:\n");
+ printCmd(cwd, argv);
+
return error.UncleanExit;
},
};
@@ -1117,6 +1136,12 @@ pub const LibExeObjStep = struct {
if (self.verbose) {
%%zig_args.append("--verbose");
}
+ if (builder.verbose_tokenize) %%zig_args.append("--verbose-tokenize");
+ if (builder.verbose_ast) %%zig_args.append("--verbose-ast");
+ if (builder.verbose_cimport) %%zig_args.append("--verbose-cimport");
+ if (builder.verbose_ir) %%zig_args.append("--verbose-ir");
+ if (builder.verbose_llvm_ir) %%zig_args.append("--verbose-llvm-ir");
+ if (builder.verbose_link) %%zig_args.append("--verbose-link");
if (self.strip) {
%%zig_args.append("--strip");
diff --git a/std/special/build_runner.zig b/std/special/build_runner.zig
index b1fbfc6c2b..089137c923 100644
--- a/std/special/build_runner.zig
+++ b/std/special/build_runner.zig
@@ -69,6 +69,18 @@ pub fn main() -> %void {
%%io.stderr.printf("Expected argument after --prefix\n\n");
return usage(&builder, false, &io.stderr);
});
+ } else if (mem.eql(u8, arg, "--verbose-tokenize")) {
+ builder.verbose_tokenize = true;
+ } else if (mem.eql(u8, arg, "--verbose-ast")) {
+ builder.verbose_ast = true;
+ } else if (mem.eql(u8, arg, "--verbose-link")) {
+ builder.verbose_link = true;
+ } else if (mem.eql(u8, arg, "--verbose-ir")) {
+ builder.verbose_ir = true;
+ } else if (mem.eql(u8, arg, "--verbose-llvm-ir")) {
+ builder.verbose_llvm_ir = true;
+ } else if (mem.eql(u8, arg, "--verbose-cimport")) {
+ builder.verbose_cimport = true;
} else {
%%io.stderr.printf("Unrecognized argument: {}\n\n", arg);
return usage(&builder, false, &io.stderr);
@@ -116,27 +128,40 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream)
\\
\\General Options:
\\ --help Print this help and exit
- \\ --build-file [file] Override path to build.zig
- \\ --cache-dir [path] Override path to cache directory
\\ --verbose Print commands before executing them
- \\ --debug-build-verbose Print verbose debugging information for the build system itself
- \\ --prefix [prefix] Override default install prefix
+ \\ --prefix $path Override default install prefix
\\
\\Project-Specific Options:
\\
);
if (builder.available_options_list.len == 0) {
- %%out_stream.printf(" (none)\n");
+ %%out_stream.print(" (none)\n");
} else {
for (builder.available_options_list.toSliceConst()) |option| {
const name = %%fmt.allocPrint(allocator,
- " -D{}=({})", option.name, Builder.typeIdName(option.type_id));
+ " -D{}=${}", option.name, Builder.typeIdName(option.type_id));
defer allocator.free(name);
- %%out_stream.printf("{s24} {}\n", name, option.description);
+ %%out_stream.print("{s24} {}\n", name, option.description);
}
}
+ %%out_stream.write(
+ \\
+ \\Advanced Options:
+ \\ --build-file $file Override path to build.zig
+ \\ --cache-dir $path Override path to zig cache directory
+ \\ --verbose-tokenize Enable compiler debug output for tokenization
+ \\ --verbose-ast Enable compiler debug output for parsing into an AST
+ \\ --verbose-link Enable compiler debug output for linking
+ \\ --verbose-ir Enable compiler debug output for Zig IR
+ \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR
+ \\ --verbose-cimport Enable compiler debug output for C imports
+ \\
+ );
+
+ %%out_stream.flush();
+
if (out_stream == &io.stderr)
return error.InvalidArgs;
}