zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 3bfacf071e0d208d445292c62f6e19b3f5c607d7 (tree)
parent 14ca0fd4937b7a4ab2a7c4c704066179d443bfdf
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Wed, 27 Feb 2019 16:02:07 -0500

print the command that failed when C source code fails to build

also respect the --color arg when building C code

Diffstat:
Msrc/codegen.cpp | 31++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/src/codegen.cpp b/src/codegen.cpp @@ -8164,6 +8164,14 @@ static void gen_global_asm(CodeGen *g) { } } +static void print_zig_cc_cmd(const char *zig_exe, ZigList<const char *> *args) { + fprintf(stderr, zig_exe); + for (size_t arg_i = 0; arg_i < args->length; arg_i += 1) { + fprintf(stderr, " %s", args->at(arg_i)); + } + fprintf(stderr, "\n"); +} + static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { Error err; @@ -8190,6 +8198,19 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { args.append("-nostdinc"); args.append("-fno-spell-checking"); + switch (g->err_color) { + case ErrColorAuto: + break; + case ErrColorOff: + args.append("-fno-color-diagnostics"); + args.append("-fno-caret-diagnostics"); + break; + case ErrColorOn: + args.append("-fcolor-diagnostics"); + args.append("-fcaret-diagnostics"); + break; + } + args.append("-isystem"); args.append(buf_ptr(g->zig_c_headers_dir)); @@ -8263,16 +8284,12 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { } if (g->verbose_cc) { - fprintf(stderr, "zig"); - for (size_t arg_i = 0; arg_i < args.length; arg_i += 1) { - fprintf(stderr, " %s", args.at(arg_i)); - } - fprintf(stderr, "\n"); + print_zig_cc_cmd("zig", &args); } - os_spawn_process(buf_ptr(self_exe_path), args, &term); if (term.how != TerminationIdClean || term.code != 0) { - fprintf(stderr, "`zig cc` failed\n"); + fprintf(stderr, "\nThe following command failed:\n"); + print_zig_cc_cmd(buf_ptr(self_exe_path), &args); exit(1); }