| ... | ... | @@ -426,7 +426,7 @@ Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) { |
| 426 | 426 | } |
| 427 | 427 | return ErrorReadingDepFile; |
| 428 | 428 | } |
| 429 | | SplitIterator it = memSplit(buf_to_slice(contents), str("\n")); |
| 429 | SplitIterator it = memSplit(buf_to_slice(contents), str("\r\n")); |
| 430 | 430 | // skip first line |
| 431 | 431 | SplitIterator_next(&it); |
| 432 | 432 | for (;;) { |
| ... | ... | @@ -435,14 +435,44 @@ Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) { |
| 435 | 435 | break; |
| 436 | 436 | if (opt_line.value.len == 0) |
| 437 | 437 | 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) |
| 441 | 444 | 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); |
| 443 | 472 | if ((err = cache_add_file(ch, filename_buf))) { |
| 444 | 473 | if (verbose) { |
| 445 | 474 | 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)); |
| 446 | 476 | } |
| 447 | 477 | return err; |
| 448 | 478 | } |