aboutsummaryrefslogtreecommitdiff
path: root/src/Cache.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-09-22 22:18:19 -0700
committerAndrew Kelley <andrew@ziglang.org>2020-09-22 22:18:19 -0700
commitc2b1cd7c456e274c7ead96e597d147e2df7d317e (patch)
treebf924cc095e8bb77dfee6484d6bdc2fb0f7aa2e3 /src/Cache.zig
parent250664bea41cc5dde66e3054ca0c1b6e0feab9be (diff)
downloadzig-c2b1cd7c456e274c7ead96e597d147e2df7d317e.tar.gz
zig-c2b1cd7c456e274c7ead96e597d147e2df7d317e.zip
stage2: implement zig build
As part of this: * add std.process.cleanExit. closes #6395 - use it in several places * adjust the alignment of text in `zig build --help` menu * Cache: support the concept of "unhit" so that we properly keep track of the cache when we find out using the secondary hash that the cache "hit" was actually a miss. Use this to fix false negatives of caching of stage1 build artifacts. * fix not deleting the symlink hash for stage1 build artifacts causing false positives. * implement support for Package arguments in stage1 build artifacts * update and add missing usage text * add --override-lib-dir and --enable-cache CLI options - `--enable-cache` takes the place of `--cache on` * CLI supports -femit-bin=foo combined with --enable-cache to do an "update file" operation. --enable-cache without that argument will build the output into a cache directory and then print the path to stdout (matching master branch behavior). * errors surfacing from main() now print "error: Foo" instead of "error: error.Foo".
Diffstat (limited to 'src/Cache.zig')
-rw-r--r--src/Cache.zig37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/Cache.zig b/src/Cache.zig
index 24c6ae3ac4..7a0c78a1d9 100644
--- a/src/Cache.zig
+++ b/src/Cache.zig
@@ -120,6 +120,13 @@ pub const HashHelper = struct {
return copy.final();
}
+ pub fn peekBin(hh: HashHelper) [bin_digest_len]u8 {
+ var copy = hh;
+ var bin_digest: [bin_digest_len]u8 = undefined;
+ copy.hasher.final(&bin_digest);
+ return bin_digest;
+ }
+
/// Returns a hex encoded hash of the inputs, mutating the state of the hasher.
pub fn final(hh: *HashHelper) [hex_digest_len]u8 {
var bin_digest: [bin_digest_len]u8 = undefined;
@@ -338,19 +345,7 @@ pub const CacheHash = struct {
if (any_file_changed) {
// cache miss
// keep the manifest file open
- // reset the hash
- self.hash.hasher = hasher_init;
- self.hash.hasher.update(&bin_digest);
-
- // Remove files not in the initial hash
- for (self.files.items[input_file_count..]) |*file| {
- file.deinit(self.cache.gpa);
- }
- self.files.shrinkRetainingCapacity(input_file_count);
-
- for (self.files.items) |file| {
- self.hash.hasher.update(&file.bin_digest);
- }
+ self.unhit(bin_digest, input_file_count);
return false;
}
@@ -366,6 +361,22 @@ pub const CacheHash = struct {
return true;
}
+ pub fn unhit(self: *CacheHash, bin_digest: [bin_digest_len]u8, input_file_count: usize) void {
+ // Reset the hash.
+ self.hash.hasher = hasher_init;
+ self.hash.hasher.update(&bin_digest);
+
+ // Remove files not in the initial hash.
+ for (self.files.items[input_file_count..]) |*file| {
+ file.deinit(self.cache.gpa);
+ }
+ self.files.shrinkRetainingCapacity(input_file_count);
+
+ for (self.files.items) |file| {
+ self.hash.hasher.update(&file.bin_digest);
+ }
+ }
+
fn populateFileHash(self: *CacheHash, ch_file: *File) !void {
const file = try fs.cwd().openFile(ch_file.path.?, .{});
defer file.close();