authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-07 14:30:50-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-07 14:30:50-05:00
log2caf39c96169be8eede11f2ec9887923b650315f
treea1b32a1fb4eff85406852bd377e8926cecc02229
parent431b3b245959830ac385dd162b779a78c93b1c2d

fix .d file processing and use -MV to quote spaces


5 files changed, 39 insertions(+), 5 deletions(-)

src/cache_hash.cpp+35-5
......@@ -426,7 +426,7 @@ Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) {
426426 }
427427 return ErrorReadingDepFile;
428428 }
429 SplitIterator it = memSplit(buf_to_slice(contents), str("\n"));
429 SplitIterator it = memSplit(buf_to_slice(contents), str("\r\n"));
430430 // skip first line
431431 SplitIterator_next(&it);
432432 for (;;) {
......@@ -435,14 +435,44 @@ Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) {
435435 break;
436436 if (opt_line.value.len == 0)
437437 continue;
438 SplitIterator line_it = memSplit(opt_line.value, str(" \t"));
439 Slice<uint8_t> filename;
440 if (!SplitIterator_next(&line_it).unwrap(&filename))
438 // skip over indentation
439 while (opt_line.value.len != 0 && (opt_line.value.ptr[0] == ' ' || opt_line.value.ptr[0] == '\t')) {
440 opt_line.value.ptr += 1;
441 opt_line.value.len -= 1;
442 }
443 if (opt_line.value.len == 0)
441444 continue;
442 Buf *filename_buf = buf_create_from_slice(filename);
445 if (opt_line.value.ptr[0] == '"') {
446 if (opt_line.value.len < 2) {
447 if (verbose) {
448 fprintf(stderr, "unable to process invalid .d file %s: line too short\n", buf_ptr(dep_file_path));
449 }
450 return ErrorInvalidDepFile;
451 }
452 opt_line.value.ptr += 1;
453 opt_line.value.len -= 2;
454 while (opt_line.value.len != 0 && opt_line.value.ptr[opt_line.value.len] != '"') {
455 opt_line.value.len -= 1;
456 }
457 if (opt_line.value.len == 0) {
458 if (verbose) {
459 fprintf(stderr, "unable to process invalid .d file %s: missing double quote\n", buf_ptr(dep_file_path));
460 }
461 return ErrorInvalidDepFile;
462 }
463 } else {
464 if (opt_line.value.ptr[opt_line.value.len - 1] == '\\') {
465 opt_line.value.len -= 2; // cut off ` \`
466 }
467 if (opt_line.value.len == 0)
468 continue;
469 }
470
471 Buf *filename_buf = buf_create_from_slice(opt_line.value);
443472 if ((err = cache_add_file(ch, filename_buf))) {
444473 if (verbose) {
445474 fprintf(stderr, "unable to add %s to cache: %s\n", buf_ptr(filename_buf), err_str(err));
475 fprintf(stderr, "when processing .d file: %s\n", buf_ptr(dep_file_path));
446476 }
447477 return err;
448478 }
src/codegen.cpp+1
......@@ -8367,6 +8367,7 @@ static bool gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
83678367
83688368 Buf *out_dep_path = buf_sprintf("%s.d", buf_ptr(out_obj_path));
83698369 args.append("-MD");
8370 args.append("-MV");
83708371 args.append("-MF");
83718372 args.append(buf_ptr(out_dep_path));
83728373
src/error.cpp+1
......@@ -38,6 +38,7 @@ const char *err_str(Error err) {
3838 case ErrorPathTooLong: return "path too long";
3939 case ErrorCCompilerCannotFindFile: return "C compiler cannot find file";
4040 case ErrorReadingDepFile: return "failed to read .d file";
41 case ErrorInvalidDepFile: return "invalid .d file";
4142 case ErrorMissingArchitecture: return "missing architecture";
4243 case ErrorMissingOperatingSystem: return "missing operating system";
4344 case ErrorUnknownArchitecture: return "unrecognized architecture";
src/error.hpp+1
......@@ -40,6 +40,7 @@ enum Error {
4040 ErrorPathTooLong,
4141 ErrorCCompilerCannotFindFile,
4242 ErrorReadingDepFile,
43 ErrorInvalidDepFile,
4344 ErrorMissingArchitecture,
4445 ErrorMissingOperatingSystem,
4546 ErrorUnknownArchitecture,
src/translate_c.cpp+1
......@@ -4781,6 +4781,7 @@ Error parse_h_file(ZigType *import, ZigList<ErrorMsg *> *errors, const char *tar
47814781 Buf *prefix = buf_sprintf("%s" OS_SEP, buf_ptr(codegen->cache_dir));
47824782 out_dep_path = os_tmp_filename(prefix, buf_create_from_str(".d"));
47834783 clang_argv.append("-MD");
4784 clang_argv.append("-MV");
47844785 clang_argv.append("-MF");
47854786 clang_argv.append(buf_ptr(out_dep_path));
47864787 }