aboutsummaryrefslogtreecommitdiff
path: root/src/cache_hash.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-03-09 01:17:36 -0500
committerGitHub <noreply@github.com>2019-03-09 01:17:36 -0500
commit8624379c71d79f67032d7ff2fd71642c84c79621 (patch)
treefb34094e6738e469808cfd4318c751af759f5555 /src/cache_hash.cpp
parentdd34c217791a0949ef2b0531ce8e8d4691239c45 (diff)
parenta45807db22cf92167734d2055b836fa0aba8cf30 (diff)
downloadzig-8624379c71d79f67032d7ff2fd71642c84c79621.tar.gz
zig-8624379c71d79f67032d7ff2fd71642c84c79621.zip
Merge pull request #2038 from ziglang/caching
breaking changes to zig build API and improved caching
Diffstat (limited to 'src/cache_hash.cpp')
-rw-r--r--src/cache_hash.cpp50
1 files changed, 30 insertions, 20 deletions
diff --git a/src/cache_hash.cpp b/src/cache_hash.cpp
index e9d4bdc671..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");
@@ -380,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) {
@@ -442,6 +443,7 @@ Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) {
}
if (opt_line.value.len == 0)
continue;
+
if (opt_line.value.ptr[0] == '"') {
if (opt_line.value.len < 2) {
if (verbose) {
@@ -460,21 +462,29 @@ Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) {
}
return ErrorInvalidDepFile;
}
- } else {
- if (opt_line.value.ptr[opt_line.value.len - 1] == '\\') {
- opt_line.value.len -= 2; // cut off ` \`
+ 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;
}
- 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));
+ } 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;