authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-27 16:02:07-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-27 16:02:07-05:00
log3bfacf071e0d208d445292c62f6e19b3f5c607d7
tree037aa9f29c4a6285b64d5167d3215536f77cb564
parent14ca0fd4937b7a4ab2a7c4c704066179d443bfdf
signaturelock-open Commit is signed but in an unrecognized format.

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

also respect the --color arg when building C code

1 files changed, 24 insertions(+), 7 deletions(-)

src/codegen.cpp+24-7
......@@ -8164,6 +8164,14 @@ static void gen_global_asm(CodeGen *g) {
81648164 }
81658165}
81668166
8167static void print_zig_cc_cmd(const char *zig_exe, ZigList<const char *> *args) {
8168 fprintf(stderr, zig_exe);
8169 for (size_t arg_i = 0; arg_i < args->length; arg_i += 1) {
8170 fprintf(stderr, " %s", args->at(arg_i));
8171 }
8172 fprintf(stderr, "\n");
8173}
8174
81678175static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
81688176 Error err;
81698177
......@@ -8190,6 +8198,19 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
81908198 args.append("-nostdinc");
81918199 args.append("-fno-spell-checking");
81928200
8201 switch (g->err_color) {
8202 case ErrColorAuto:
8203 break;
8204 case ErrColorOff:
8205 args.append("-fno-color-diagnostics");
8206 args.append("-fno-caret-diagnostics");
8207 break;
8208 case ErrColorOn:
8209 args.append("-fcolor-diagnostics");
8210 args.append("-fcaret-diagnostics");
8211 break;
8212 }
8213
81938214 args.append("-isystem");
81948215 args.append(buf_ptr(g->zig_c_headers_dir));
81958216
......@@ -8263,16 +8284,12 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
82638284 }
82648285
82658286 if (g->verbose_cc) {
8266 fprintf(stderr, "zig");
8267 for (size_t arg_i = 0; arg_i < args.length; arg_i += 1) {
8268 fprintf(stderr, " %s", args.at(arg_i));
8269 }
8270 fprintf(stderr, "\n");
8287 print_zig_cc_cmd("zig", &args);
82718288 }
8272
82738289 os_spawn_process(buf_ptr(self_exe_path), args, &term);
82748290 if (term.how != TerminationIdClean || term.code != 0) {
8275 fprintf(stderr, "`zig cc` failed\n");
8291 fprintf(stderr, "\nThe following command failed:\n");
8292 print_zig_cc_cmd(buf_ptr(self_exe_path), &args);
82768293 exit(1);
82778294 }
82788295