fix .d file processing and use -MV to quote spaces
This commit is contained in:
@@ -426,7 +426,7 @@ Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) {
|
||||
}
|
||||
return ErrorReadingDepFile;
|
||||
}
|
||||
SplitIterator it = memSplit(buf_to_slice(contents), str("\n"));
|
||||
SplitIterator it = memSplit(buf_to_slice(contents), str("\r\n"));
|
||||
// skip first line
|
||||
SplitIterator_next(&it);
|
||||
for (;;) {
|
||||
@@ -435,14 +435,44 @@ Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) {
|
||||
break;
|
||||
if (opt_line.value.len == 0)
|
||||
continue;
|
||||
SplitIterator line_it = memSplit(opt_line.value, str(" \t"));
|
||||
Slice<uint8_t> filename;
|
||||
if (!SplitIterator_next(&line_it).unwrap(&filename))
|
||||
// skip over indentation
|
||||
while (opt_line.value.len != 0 && (opt_line.value.ptr[0] == ' ' || opt_line.value.ptr[0] == '\t')) {
|
||||
opt_line.value.ptr += 1;
|
||||
opt_line.value.len -= 1;
|
||||
}
|
||||
if (opt_line.value.len == 0)
|
||||
continue;
|
||||
Buf *filename_buf = buf_create_from_slice(filename);
|
||||
if (opt_line.value.ptr[0] == '"') {
|
||||
if (opt_line.value.len < 2) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "unable to process invalid .d file %s: line too short\n", buf_ptr(dep_file_path));
|
||||
}
|
||||
return ErrorInvalidDepFile;
|
||||
}
|
||||
opt_line.value.ptr += 1;
|
||||
opt_line.value.len -= 2;
|
||||
while (opt_line.value.len != 0 && opt_line.value.ptr[opt_line.value.len] != '"') {
|
||||
opt_line.value.len -= 1;
|
||||
}
|
||||
if (opt_line.value.len == 0) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "unable to process invalid .d file %s: missing double quote\n", buf_ptr(dep_file_path));
|
||||
}
|
||||
return ErrorInvalidDepFile;
|
||||
}
|
||||
} else {
|
||||
if (opt_line.value.ptr[opt_line.value.len - 1] == '\\') {
|
||||
opt_line.value.len -= 2; // cut off ` \`
|
||||
}
|
||||
if (opt_line.value.len == 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
Buf *filename_buf = buf_create_from_slice(opt_line.value);
|
||||
if ((err = cache_add_file(ch, filename_buf))) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "unable to add %s to cache: %s\n", buf_ptr(filename_buf), err_str(err));
|
||||
fprintf(stderr, "when processing .d file: %s\n", buf_ptr(dep_file_path));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user