authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-25 23:10:41-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-25 23:10:41-04:00
log5f28a9d23851d94edc2b24e549b7c5abbbf23f68
tree35900fc47e346ef3161279f3c38bb91079596eca
parent6764a4522391d82c40fc54bae448b32366e3e6d8

cleaner verbose flags and zig build prints failed command


10 files changed, 171 insertions(+), 112 deletions(-)

src/all_types.hpp+4-1
......@@ -1515,9 +1515,12 @@ struct CodeGen {
15151515 size_t version_major;
15161516 size_t version_minor;
15171517 size_t version_patch;
1518 bool verbose;
1518 bool verbose_tokenize;
1519 bool verbose_ast;
15191520 bool verbose_link;
15201521 bool verbose_ir;
1522 bool verbose_llvm_ir;
1523 bool verbose_cimport;
15211524 ErrColor err_color;
15221525 ImportTableEntry *root_import;
15231526 ImportTableEntry *bootstrap_import;
src/analyze.cpp+5-5
......@@ -2982,7 +2982,7 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ
29822982 return;
29832983 }
29842984
2985 if (g->verbose) {
2985 if (g->verbose_ir) {
29862986 fprintf(stderr, "{ // (analyzed)\n");
29872987 ir_print(g, stderr, &fn_table_entry->analyzed_executable, 4);
29882988 fprintf(stderr, "}\n");
......@@ -3015,7 +3015,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
30153015 fn_table_entry->anal_state = FnAnalStateInvalid;
30163016 return;
30173017 }
3018 if (g->verbose) {
3018 if (g->verbose_ir) {
30193019 fprintf(stderr, "\n");
30203020 ast_render(g, stderr, fn_table_entry->body_node, 4);
30213021 fprintf(stderr, "\n{ // (IR)\n");
......@@ -3115,7 +3115,7 @@ void preview_use_decl(CodeGen *g, AstNode *node) {
31153115}
31163116
31173117ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code) {
3118 if (g->verbose) {
3118 if (g->verbose_tokenize) {
31193119 fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(abs_full_path));
31203120 fprintf(stderr, "----------------\n");
31213121 fprintf(stderr, "%s\n", buf_ptr(source_code));
......@@ -3135,7 +3135,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a
31353135 exit(1);
31363136 }
31373137
3138 if (g->verbose) {
3138 if (g->verbose_tokenize) {
31393139 print_tokens(source_code, tokenization.tokens);
31403140
31413141 fprintf(stderr, "\nAST:\n");
......@@ -3150,7 +3150,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a
31503150
31513151 import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color);
31523152 assert(import_entry->root);
3153 if (g->verbose) {
3153 if (g->verbose_ast) {
31543154 ast_print(stderr, import_entry->root, 0);
31553155 }
31563156
src/codegen.cpp+2-16
......@@ -196,10 +196,6 @@ void codegen_set_is_static(CodeGen *g, bool is_static) {
196196 g->is_static = is_static;
197197}
198198
199void codegen_set_verbose(CodeGen *g, bool verbose) {
200 g->verbose = verbose;
201}
202
203199void codegen_set_each_lib_rpath(CodeGen *g, bool each_lib_rpath) {
204200 g->each_lib_rpath = each_lib_rpath;
205201}
......@@ -4163,10 +4159,6 @@ static void validate_inline_fns(CodeGen *g) {
41634159}
41644160
41654161static void do_code_gen(CodeGen *g) {
4166 if (g->verbose) {
4167 fprintf(stderr, "\nCode Generation:\n");
4168 fprintf(stderr, "------------------\n");
4169 }
41704162 assert(!g->errors.length);
41714163
41724164 codegen_add_time_event(g, "Code Generation");
......@@ -4443,7 +4435,8 @@ static void do_code_gen(CodeGen *g) {
44434435
44444436 ZigLLVMDIBuilderFinalize(g->dbuilder);
44454437
4446 if (g->verbose || g->verbose_ir) {
4438 if (g->verbose_llvm_ir) {
4439 fflush(stderr);
44474440 LLVMDumpModule(g->module);
44484441 }
44494442
......@@ -5273,10 +5266,6 @@ static void gen_root_source(CodeGen *g) {
52735266 resolve_top_level_decl(g, panic_tld, false, nullptr);
52745267 }
52755268
5276 if (g->verbose) {
5277 fprintf(stderr, "\nIR Generation and Semantic Analysis:\n");
5278 fprintf(stderr, "--------------------------------------\n");
5279 }
52805269 if (!g->error_during_imports) {
52815270 semantic_analyze(g);
52825271 }
......@@ -5290,9 +5279,6 @@ static void gen_root_source(CodeGen *g) {
52905279 }
52915280
52925281 report_errors_and_maybe_exit(g);
5293 if (g->verbose) {
5294 fprintf(stderr, "OK\n");
5295 }
52965282
52975283}
52985284
src/codegen.hpp-1
......@@ -25,7 +25,6 @@ void codegen_set_each_lib_rpath(CodeGen *codegen, bool each_lib_rpath);
2525
2626void codegen_set_is_static(CodeGen *codegen, bool is_static);
2727void codegen_set_strip(CodeGen *codegen, bool strip);
28void codegen_set_verbose(CodeGen *codegen, bool verbose);
2928void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color);
3029void codegen_set_out_name(CodeGen *codegen, Buf *out_name);
3130void codegen_set_libc_lib_dir(CodeGen *codegen, Buf *libc_lib_dir);
src/ir.cpp+3-3
......@@ -7849,7 +7849,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
78497849 if (ir_executable.invalid)
78507850 return codegen->invalid_instruction;
78517851
7852 if (codegen->verbose) {
7852 if (codegen->verbose_ir) {
78537853 fprintf(stderr, "\nSource: ");
78547854 ast_render(codegen, stderr, node, 4);
78557855 fprintf(stderr, "\n{ // (IR)\n");
......@@ -7870,7 +7870,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
78707870 if (type_is_invalid(result_type))
78717871 return codegen->invalid_instruction;
78727872
7873 if (codegen->verbose) {
7873 if (codegen->verbose_ir) {
78747874 fprintf(stderr, "{ // (analyzed)\n");
78757875 ir_print(codegen, stderr, &analyzed_executable, 4);
78767876 fprintf(stderr, "}\n");
......@@ -13514,7 +13514,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
1351413514 return ira->codegen->builtin_types.entry_invalid;
1351513515 }
1351613516
13517 if (ira->codegen->verbose) {
13517 if (ira->codegen->verbose_cimport) {
1351813518 fprintf(stderr, "\nC imports:\n");
1351913519 fprintf(stderr, "-----------\n");
1352013520 ast_render(ira->codegen, stderr, child_import->root, 4);
src/link.cpp+7-14
......@@ -37,8 +37,12 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path)
3737 parent_gen->zig_lib_dir);
3838
3939 child_gen->want_h_file = false;
40 child_gen->verbose_tokenize = parent_gen->verbose_tokenize;
41 child_gen->verbose_ast = parent_gen->verbose_ast;
4042 child_gen->verbose_link = parent_gen->verbose_link;
4143 child_gen->verbose_ir = parent_gen->verbose_ir;
44 child_gen->verbose_llvm_ir = parent_gen->verbose_llvm_ir;
45 child_gen->verbose_cimport = parent_gen->verbose_cimport;
4246
4347 codegen_set_cache_dir(child_gen, parent_gen->cache_dir);
4448
......@@ -47,7 +51,6 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path)
4751
4852 codegen_set_out_name(child_gen, buf_create_from_str(oname));
4953
50 codegen_set_verbose(child_gen, parent_gen->verbose);
5154 codegen_set_errmsg_color(child_gen, parent_gen->err_color);
5255
5356 codegen_set_mmacosx_version_min(child_gen, parent_gen->mmacosx_version_min);
......@@ -859,15 +862,12 @@ void codegen_link(CodeGen *g, const char *out_file) {
859862 buf_resize(&lj.out_file, 0);
860863 }
861864
862 if (g->verbose || g->verbose_ir) {
865 if (g->verbose_llvm_ir) {
863866 fprintf(stderr, "\nOptimization:\n");
864867 fprintf(stderr, "---------------\n");
868 fflush(stderr);
865869 LLVMDumpModule(g->module);
866870 }
867 if (g->verbose || g->verbose_link) {
868 fprintf(stderr, "\nLink:\n");
869 fprintf(stderr, "-------\n");
870 }
871871
872872 bool override_out_file = (buf_len(&lj.out_file) != 0);
873873 if (!override_out_file) {
......@@ -888,9 +888,6 @@ void codegen_link(CodeGen *g, const char *out_file) {
888888 zig_panic("unable to rename object file into final output: %s", err_str(err));
889889 }
890890 }
891 if (g->verbose || g->verbose_link) {
892 fprintf(stderr, "OK\n");
893 }
894891 return;
895892 }
896893
......@@ -908,7 +905,7 @@ void codegen_link(CodeGen *g, const char *out_file) {
908905 construct_linker_job(&lj);
909906
910907
911 if (g->verbose || g->verbose_link) {
908 if (g->verbose_link) {
912909 for (size_t i = 0; i < lj.args.length; i += 1) {
913910 const char *space = (i != 0) ? " " : "";
914911 fprintf(stderr, "%s%s", space, lj.args.at(i));
......@@ -925,8 +922,4 @@ void codegen_link(CodeGen *g, const char *out_file) {
925922 }
926923
927924 codegen_add_time_event(g, "Done");
928
929 if (g->verbose || g->verbose_link) {
930 fprintf(stderr, "OK\n");
931 }
932925}
src/main.cpp+85-57
......@@ -20,67 +20,70 @@ static int usage(const char *arg0) {
2020 fprintf(stderr, "Usage: %s [command] [options]\n"
2121 "Commands:\n"
2222 " build build project from build.zig\n"
23 " build-exe [source] create executable from source or object files\n"
24 " build-lib [source] create library from source or object files\n"
25 " build-obj [source] create object from source or assembly\n"
26 " parsec [source] convert c code to zig code\n"
23 " build-exe $source create executable from source or object files\n"
24 " build-lib $source create library from source or object files\n"
25 " build-obj $source create object from source or assembly\n"
26 " parsec $source convert c code to zig code\n"
2727 " targets list available compilation targets\n"
28 " test [source] create and run a test build\n"
28 " test $source create and run a test build\n"
2929 " version print version number and exit\n"
3030 " zen print zen of zig and exit\n"
3131 "Compile Options:\n"
32 " --assembly [source] add assembly file to build\n"
33 " --cache-dir [path] override the cache directory\n"
34 " --color [auto|off|on] enable or disable colored error messages\n"
32 " --assembly $source add assembly file to build\n"
33 " --cache-dir $path override the cache directory\n"
34 " --color $auto|off|on enable or disable colored error messages\n"
3535 " --enable-timing-info print timing diagnostics\n"
36 " --libc-include-dir [path] directory where libc stdlib.h resides\n"
37 " --name [name] override output name\n"
38 " --output [file] override destination path\n"
39 " --output-h [file] override generated header file path\n"
40 " --pkg-begin [name] [path] make package available to import and push current pkg\n"
36 " --libc-include-dir $path directory where libc stdlib.h resides\n"
37 " --name $name override output name\n"
38 " --output $file override destination path\n"
39 " --output-h $file override generated header file path\n"
40 " --pkg-begin $name $path make package available to import and push current pkg\n"
4141 " --pkg-end pop current pkg\n"
4242 " --release-fast build with optimizations on and safety off\n"
4343 " --release-safe build with optimizations on and safety on\n"
4444 " --static output will be statically linked\n"
4545 " --strip exclude debug symbols\n"
46 " --target-arch [name] specify target architecture\n"
47 " --target-environ [name] specify target environment\n"
48 " --target-os [name] specify target operating system\n"
49 " --verbose turn on compiler debug output\n"
50 " --verbose-link turn on compiler debug output for linking only\n"
51 " --verbose-ir turn on compiler debug output for IR only\n"
52 " --zig-install-prefix [path] override directory where zig thinks it is installed\n"
53 " -dirafter [dir] same as -isystem but do it last\n"
54 " -isystem [dir] add additional search path for other .h files\n"
55 " -mllvm [arg] additional arguments to forward to LLVM's option processing\n"
46 " --target-arch $name specify target architecture\n"
47 " --target-environ $name specify target environment\n"
48 " --target-os $name specify target operating system\n"
49 " --verbose-tokenize turn on compiler debug output for tokenization\n"
50 " --verbose-ast turn on compiler debug output for parsing into an AST\n"
51 " --verbose-link turn on compiler debug output for linking\n"
52 " --verbose-ir turn on compiler debug output for Zig IR\n"
53 " --verbose-llvm-ir turn on compiler debug output for LLVM IR\n"
54 " --verbose-cimport turn on compiler debug output for C imports\n"
55 " --zig-install-prefix $path override directory where zig thinks it is installed\n"
56 " -dirafter $dir same as -isystem but do it last\n"
57 " -isystem $dir add additional search path for other .h files\n"
58 " -mllvm $arg additional arguments to forward to LLVM's option processing\n"
5659 "Link Options:\n"
57 " --ar-path [path] set the path to ar\n"
58 " --dynamic-linker [path] set the path to ld.so\n"
60 " --ar-path $path set the path to ar\n"
61 " --dynamic-linker $path set the path to ld.so\n"
5962 " --each-lib-rpath add rpath for each used dynamic library\n"
60 " --libc-lib-dir [path] directory where libc crt1.o resides\n"
61 " --libc-static-lib-dir [path] directory where libc crtbegin.o resides\n"
62 " --msvc-lib-dir [path] (windows) directory where vcruntime.lib resides\n"
63 " --kernel32-lib-dir [path] (windows) directory where kernel32.lib resides\n"
64 " --library [lib] link against lib\n"
65 " --library-path [dir] add a directory to the library search path\n"
66 " --linker-script [path] use a custom linker script\n"
67 " --object [obj] add object file to build\n"
68 " -L[dir] alias for --library-path\n"
63 " --libc-lib-dir $path directory where libc crt1.o resides\n"
64 " --libc-static-lib-dir $path directory where libc crtbegin.o resides\n"
65 " --msvc-lib-dir $path (windows) directory where vcruntime.lib resides\n"
66 " --kernel32-lib-dir $path (windows) directory where kernel32.lib resides\n"
67 " --library $lib link against lib\n"
68 " --library-path $dir add a directory to the library search path\n"
69 " --linker-script $path use a custom linker script\n"
70 " --object $obj add object file to build\n"
71 " -L$dir alias for --library-path\n"
6972 " -rdynamic add all symbols to the dynamic symbol table\n"
70 " -rpath [path] add directory to the runtime library search path\n"
73 " -rpath $path add directory to the runtime library search path\n"
7174 " -mconsole (windows) --subsystem console to the linker\n"
7275 " -mwindows (windows) --subsystem windows to the linker\n"
7376 " -municode (windows) link with unicode\n"
74 " -framework [name] (darwin) link against framework\n"
75 " -mios-version-min [ver] (darwin) set iOS deployment target\n"
76 " -mmacosx-version-min [ver] (darwin) set Mac OS X deployment target\n"
77 " --ver-major [ver] dynamic library semver major version\n"
78 " --ver-minor [ver] dynamic library semver minor version\n"
79 " --ver-patch [ver] dynamic library semver patch version\n"
77 " -framework $name (darwin) link against framework\n"
78 " -mios-version-min $ver (darwin) set iOS deployment target\n"
79 " -mmacosx-version-min $ver (darwin) set Mac OS X deployment target\n"
80 " --ver-major $ver dynamic library semver major version\n"
81 " --ver-minor $ver dynamic library semver minor version\n"
82 " --ver-patch $ver dynamic library semver patch version\n"
8083 "Test Options:\n"
81 " --test-filter [text] skip tests that do not match filter\n"
82 " --test-name-prefix [text] add prefix to all tests\n"
83 " --test-cmd [arg] specify test execution command one arg at a time\n"
84 " --test-filter $text skip tests that do not match filter\n"
85 " --test-name-prefix $text add prefix to all tests\n"
86 " --test-cmd $arg specify test execution command one arg at a time\n"
8487 " --test-cmd-bin appends test binary path to test cmd args\n"
8588 , arg0);
8689 return EXIT_FAILURE;
......@@ -274,9 +277,12 @@ int main(int argc, char **argv) {
274277 bool is_static = false;
275278 OutType out_type = OutTypeUnknown;
276279 const char *out_name = nullptr;
277 bool verbose = false;
280 bool verbose_tokenize = false;
281 bool verbose_ast = false;
278282 bool verbose_link = false;
279283 bool verbose_ir = false;
284 bool verbose_llvm_ir = false;
285 bool verbose_cimport = false;
280286 ErrColor color = ErrColorAuto;
281287 const char *libc_lib_dir = nullptr;
282288 const char *libc_static_lib_dir = nullptr;
......@@ -328,9 +334,7 @@ int main(int argc, char **argv) {
328334 args.append(NULL); // placeholder
329335 args.append(NULL); // placeholder
330336 for (int i = 2; i < argc; i += 1) {
331 if (strcmp(argv[i], "--debug-build-verbose") == 0) {
332 verbose = true;
333 } else if (strcmp(argv[i], "--help") == 0) {
337 if (strcmp(argv[i], "--help") == 0) {
334338 asked_for_help = true;
335339 args.append(argv[i]);
336340 } else if (i + 1 < argc && strcmp(argv[i], "--build-file") == 0) {
......@@ -363,7 +367,6 @@ int main(int argc, char **argv) {
363367
364368 CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf);
365369 codegen_set_out_name(g, buf_create_from_str("build"));
366 codegen_set_verbose(g, verbose);
367370
368371 Buf build_file_abs = BUF_INIT;
369372 os_path_resolve(buf_create_from_str("."), buf_create_from_str(build_file), &build_file_abs);
......@@ -398,14 +401,30 @@ int main(int argc, char **argv) {
398401 "\n"
399402 "General Options:\n"
400403 " --help Print this help and exit\n"
401 " --build-file [file] Override path to build.zig\n"
402 " --cache-dir [path] Override path to cache directory\n"
404 " --build-file $file Override path to build.zig\n"
405 " --cache-dir $path Override path to cache directory\n"
403406 " --verbose Print commands before executing them\n"
404 " --debug-build-verbose Print verbose debugging information for the build system itself\n"
405 " --prefix [prefix] Override default install prefix\n"
407 " --verbose-tokenize Enable compiler debug output for tokenization\n"
408 " --verbose-ast Enable compiler debug output for parsing into an AST\n"
409 " --verbose-link Enable compiler debug output for linking\n"
410 " --verbose-ir Enable compiler debug output for Zig IR\n"
411 " --verbose-llvm-ir Enable compiler debug output for LLVM IR\n"
412 " --verbose-cimport Enable compiler debug output for C imports\n"
413 " --prefix $path Override default install prefix\n"
406414 "\n"
407 "More options become available when the build file is found.\n"
415 "Project-specific options become available when the build file is found.\n"
408416 "Run this command with no options to generate a build.zig template.\n"
417 "\n"
418 "Advanced Options:\n"
419 " --build-file $file Override path to build.zig\n"
420 " --cache-dir $path Override path to cache directory\n"
421 " --verbose-tokenize Enable compiler debug output for tokenization\n"
422 " --verbose-ast Enable compiler debug output for parsing into an AST\n"
423 " --verbose-link Enable compiler debug output for linking\n"
424 " --verbose-ir Enable compiler debug output for Zig IR\n"
425 " --verbose-llvm-ir Enable compiler debug output for LLVM IR\n"
426 " --verbose-cimport Enable compiler debug output for C imports\n"
427 "\n"
409428 , zig_exe_path);
410429 return 0;
411430 }
......@@ -452,12 +471,18 @@ int main(int argc, char **argv) {
452471 strip = true;
453472 } else if (strcmp(arg, "--static") == 0) {
454473 is_static = true;
455 } else if (strcmp(arg, "--verbose") == 0) {
456 verbose = true;
474 } else if (strcmp(arg, "--verbose-tokenize") == 0) {
475 verbose_tokenize = true;
476 } else if (strcmp(arg, "--verbose-ast") == 0) {
477 verbose_ast = true;
457478 } else if (strcmp(arg, "--verbose-link") == 0) {
458479 verbose_link = true;
459480 } else if (strcmp(arg, "--verbose-ir") == 0) {
460481 verbose_ir = true;
482 } else if (strcmp(arg, "--verbose-llvm-ir") == 0) {
483 verbose_llvm_ir = true;
484 } else if (strcmp(arg, "--verbose-cimport") == 0) {
485 verbose_cimport = true;
461486 } else if (strcmp(arg, "-mwindows") == 0) {
462487 mwindows = true;
463488 } else if (strcmp(arg, "-mconsole") == 0) {
......@@ -742,9 +767,12 @@ int main(int argc, char **argv) {
742767 codegen_set_kernel32_lib_dir(g, buf_create_from_str(kernel32_lib_dir));
743768 if (dynamic_linker)
744769 codegen_set_dynamic_linker(g, buf_create_from_str(dynamic_linker));
745 codegen_set_verbose(g, verbose);
770 g->verbose_tokenize = verbose_tokenize;
771 g->verbose_ast = verbose_ast;
746772 g->verbose_link = verbose_link;
747773 g->verbose_ir = verbose_ir;
774 g->verbose_llvm_ir = verbose_llvm_ir;
775 g->verbose_cimport = verbose_cimport;
748776 codegen_set_errmsg_color(g, color);
749777
750778 for (size_t i = 0; i < lib_dirs.length; i += 1) {
src/parsec.cpp+1-1
......@@ -3167,7 +3167,7 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch
31673167{
31683168 Context context = {0};
31693169 Context *c = &context;
3170 c->warnings_on = codegen->verbose;
3170 c->warnings_on = codegen->verbose_cimport;
31713171 c->import = import;
31723172 c->errors = errors;
31733173 if (buf_ends_with_str(buf_create_from_str(target_file), ".h")) {
std/build.zig+32-7
......@@ -33,6 +33,12 @@ pub const Builder = struct {
3333 available_options_map: AvailableOptionsMap,
3434 available_options_list: ArrayList(AvailableOption),
3535 verbose: bool,
36 verbose_tokenize: bool,
37 verbose_ast: bool,
38 verbose_link: bool,
39 verbose_ir: bool,
40 verbose_llvm_ir: bool,
41 verbose_cimport: bool,
3642 invalid_user_input: bool,
3743 zig_exe: []const u8,
3844 default_step: &Step,
......@@ -88,6 +94,12 @@ pub const Builder = struct {
8894 .build_root = build_root,
8995 .cache_root = %%os.path.relative(allocator, build_root, cache_root),
9096 .verbose = false,
97 .verbose_tokenize = false,
98 .verbose_ast = false,
99 .verbose_link = false,
100 .verbose_ir = false,
101 .verbose_llvm_ir = false,
102 .verbose_cimport = false,
91103 .invalid_user_input = false,
92104 .allocator = allocator,
93105 .lib_paths = ArrayList([]const u8).init(allocator),
......@@ -536,15 +548,19 @@ pub const Builder = struct {
536548 return self.spawnChildEnvMap(null, &self.env_map, argv);
537549 }
538550
551 fn printCmd(cwd: ?[]const u8, argv: []const []const u8) {
552 if (cwd) |yes_cwd| %%io.stderr.print("cd {} && ", yes_cwd);
553 for (argv) |arg| {
554 %%io.stderr.print("{} ", arg);
555 }
556 %%io.stderr.printf("\n");
557 }
558
539559 fn spawnChildEnvMap(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap,
540560 argv: []const []const u8) -> %void
541561 {
542562 if (self.verbose) {
543 if (cwd) |yes_cwd| %%io.stderr.print("cd {}; ", yes_cwd);
544 for (argv) |arg| {
545 %%io.stderr.print("{} ", arg);
546 }
547 %%io.stderr.printf("\n");
563 printCmd(cwd, argv);
548564 }
549565
550566 const child = %%os.ChildProcess.init(argv, self.allocator);
......@@ -561,12 +577,15 @@ pub const Builder = struct {
561577 switch (term) {
562578 Term.Exited => |code| {
563579 if (code != 0) {
564 %%io.stderr.printf("Process {} exited with error code {}\n", argv[0], code);
580 %%io.stderr.printf("The following command exited with error code {}:\n", code);
581 printCmd(cwd, argv);
565582 return error.UncleanExit;
566583 }
567584 },
568585 else => {
569 %%io.stderr.printf("Process {} terminated unexpectedly\n", argv[0]);
586 %%io.stderr.printf("The following command terminated unexpectedly:\n");
587 printCmd(cwd, argv);
588
570589 return error.UncleanExit;
571590 },
572591 };
......@@ -1117,6 +1136,12 @@ pub const LibExeObjStep = struct {
11171136 if (self.verbose) {
11181137 %%zig_args.append("--verbose");
11191138 }
1139 if (builder.verbose_tokenize) %%zig_args.append("--verbose-tokenize");
1140 if (builder.verbose_ast) %%zig_args.append("--verbose-ast");
1141 if (builder.verbose_cimport) %%zig_args.append("--verbose-cimport");
1142 if (builder.verbose_ir) %%zig_args.append("--verbose-ir");
1143 if (builder.verbose_llvm_ir) %%zig_args.append("--verbose-llvm-ir");
1144 if (builder.verbose_link) %%zig_args.append("--verbose-link");
11201145
11211146 if (self.strip) {
11221147 %%zig_args.append("--strip");
std/special/build_runner.zig+32-7
......@@ -69,6 +69,18 @@ pub fn main() -> %void {
6969 %%io.stderr.printf("Expected argument after --prefix\n\n");
7070 return usage(&builder, false, &io.stderr);
7171 });
72 } else if (mem.eql(u8, arg, "--verbose-tokenize")) {
73 builder.verbose_tokenize = true;
74 } else if (mem.eql(u8, arg, "--verbose-ast")) {
75 builder.verbose_ast = true;
76 } else if (mem.eql(u8, arg, "--verbose-link")) {
77 builder.verbose_link = true;
78 } else if (mem.eql(u8, arg, "--verbose-ir")) {
79 builder.verbose_ir = true;
80 } else if (mem.eql(u8, arg, "--verbose-llvm-ir")) {
81 builder.verbose_llvm_ir = true;
82 } else if (mem.eql(u8, arg, "--verbose-cimport")) {
83 builder.verbose_cimport = true;
7284 } else {
7385 %%io.stderr.printf("Unrecognized argument: {}\n\n", arg);
7486 return usage(&builder, false, &io.stderr);
......@@ -116,27 +128,40 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream)
116128 \\
117129 \\General Options:
118130 \\ --help Print this help and exit
119 \\ --build-file [file] Override path to build.zig
120 \\ --cache-dir [path] Override path to cache directory
121131 \\ --verbose Print commands before executing them
122 \\ --debug-build-verbose Print verbose debugging information for the build system itself
123 \\ --prefix [prefix] Override default install prefix
132 \\ --prefix $path Override default install prefix
124133 \\
125134 \\Project-Specific Options:
126135 \\
127136 );
128137
129138 if (builder.available_options_list.len == 0) {
130 %%out_stream.printf(" (none)\n");
139 %%out_stream.print(" (none)\n");
131140 } else {
132141 for (builder.available_options_list.toSliceConst()) |option| {
133142 const name = %%fmt.allocPrint(allocator,
134 " -D{}=({})", option.name, Builder.typeIdName(option.type_id));
143 " -D{}=${}", option.name, Builder.typeIdName(option.type_id));
135144 defer allocator.free(name);
136 %%out_stream.printf("{s24} {}\n", name, option.description);
145 %%out_stream.print("{s24} {}\n", name, option.description);
137146 }
138147 }
139148
149 %%out_stream.write(
150 \\
151 \\Advanced Options:
152 \\ --build-file $file Override path to build.zig
153 \\ --cache-dir $path Override path to zig cache directory
154 \\ --verbose-tokenize Enable compiler debug output for tokenization
155 \\ --verbose-ast Enable compiler debug output for parsing into an AST
156 \\ --verbose-link Enable compiler debug output for linking
157 \\ --verbose-ir Enable compiler debug output for Zig IR
158 \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR
159 \\ --verbose-cimport Enable compiler debug output for C imports
160 \\
161 );
162
163 %%out_stream.flush();
164
140165 if (out_stream == &io.stderr)
141166 return error.InvalidArgs;
142167}