diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-03-10 13:48:06 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-03-10 13:48:06 -0400 |
| commit | 3cdd2c0bddebf82a3ec7b187014acf2e7507a79c (patch) | |
| tree | 4f38ce2307e32b518c8c65b12a186d054876f8dc /src/cache_hash.cpp | |
| parent | 0714e19598e91f457d3d0119856fd7a24dd4f150 (diff) | |
| parent | 0a8a7a57e7a6b4b5a0d1523bde57b2a4b93fa50a (diff) | |
| download | zig-3cdd2c0bddebf82a3ec7b187014acf2e7507a79c.tar.gz zig-3cdd2c0bddebf82a3ec7b187014acf2e7507a79c.zip | |
Merge remote-tracking branch 'origin/master' into llvm8
Diffstat (limited to 'src/cache_hash.cpp')
| -rw-r--r-- | src/cache_hash.cpp | 79 |
1 files changed, 61 insertions, 18 deletions
diff --git a/src/cache_hash.cpp b/src/cache_hash.cpp index 85bad3dd2d..6c9cf12962 100644 --- a/src/cache_hash.cpp +++ b/src/cache_hash.cpp @@ -19,6 +19,8 @@ void cache_init(CacheHash *ch, Buf *manifest_dir) { ch->manifest_dir = manifest_dir; ch->manifest_file_path = nullptr; ch->manifest_dirty = false; + ch->force_check_manifest = false; + ch->b64_digest = BUF_INIT; } void cache_str(CacheHash *ch, const char *ptr) { @@ -243,22 +245,21 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) { int rc = blake2b_final(&ch->blake, bin_digest, 48); assert(rc == 0); - if (ch->files.length == 0) { + buf_resize(&ch->b64_digest, 64); + base64_encode(buf_to_slice(&ch->b64_digest), {bin_digest, 48}); + + if (ch->files.length == 0 && !ch->force_check_manifest) { buf_resize(out_digest, 64); base64_encode(buf_to_slice(out_digest), {bin_digest, 48}); return ErrorNone; } - Buf b64_digest = BUF_INIT; - buf_resize(&b64_digest, 64); - base64_encode(buf_to_slice(&b64_digest), {bin_digest, 48}); - rc = blake2b_init(&ch->blake, 48); assert(rc == 0); blake2b_update(&ch->blake, bin_digest, 48); ch->manifest_file_path = buf_alloc(); - os_path_join(ch->manifest_dir, &b64_digest, ch->manifest_file_path); + os_path_join(ch->manifest_dir, &ch->b64_digest, ch->manifest_file_path); buf_append_str(ch->manifest_file_path, ".txt"); @@ -281,8 +282,6 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) { SplitIterator line_it = memSplit(buf_to_slice(&line_buf), str("\n")); for (;; file_i += 1) { Optional<Slice<uint8_t>> opt_line = SplitIterator_next(&line_it); - if (!opt_line.is_some) - break; CacheHashFile *chf; if (file_i < input_file_count) { @@ -301,11 +300,16 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) { } // caller can notice that out_digest is unmodified. return ErrorNone; + } else if (!opt_line.is_some) { + break; } else { chf = ch->files.add_one(); chf->path = nullptr; } + if (!opt_line.is_some) + break; + SplitIterator it = memSplit(opt_line.value, str(" ")); Optional<Slice<uint8_t>> opt_mtime_sec = SplitIterator_next(&it); @@ -377,7 +381,7 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) { blake2b_update(&ch->blake, chf->bin_digest, 48); } } - if (file_i < input_file_count) { + if (file_i < input_file_count || file_i == 0) { // manifest file is empty or missing entries, so this is a cache miss ch->manifest_dirty = true; for (; file_i < input_file_count; file_i += 1) { @@ -423,7 +427,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 (;;) { @@ -432,16 +436,55 @@ 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 ((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)); + + 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; + } + 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; + } + } else { + // sometimes there are multiple files on the same line; we actually need space tokenization. + SplitIterator line_it = memSplit(opt_line.value, str(" \t")); + Slice<uint8_t> filename; + while (SplitIterator_next(&line_it).unwrap(&filename)) { + Buf *filename_buf = buf_create_from_slice(filename); + if (buf_eql_str(filename_buf, "\\")) continue; + 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; + } } - return err; } } return ErrorNone; |
