diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2021-05-13 08:24:21 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2021-05-13 08:24:21 +0200 |
| commit | 1aee896cae0747263e607de125a93023b5a9b320 (patch) | |
| tree | 49841fe55b55de0058176b025ec015ba990c1b61 /src/Cache.zig | |
| parent | 6c3050e3c3eee19a9de2c912dc653062e5597b67 (diff) | |
| parent | 4b59f564344598b4d1f1a51839a4dc5cbf357012 (diff) | |
| download | zig-1aee896cae0747263e607de125a93023b5a9b320.tar.gz zig-1aee896cae0747263e607de125a93023b5a9b320.zip | |
Merge branch 'master' into streamline-stage2-build-script
Diffstat (limited to 'src/Cache.zig')
| -rw-r--r-- | src/Cache.zig | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/Cache.zig b/src/Cache.zig index 5bc32b4b68..6c17f52d69 100644 --- a/src/Cache.zig +++ b/src/Cache.zig @@ -11,6 +11,7 @@ const testing = std.testing; const mem = std.mem; const fmt = std.fmt; const Allocator = std.mem.Allocator; +const Compilation = @import("Compilation.zig"); /// Be sure to call `Manifest.deinit` after successful initialization. pub fn obtain(cache: *const Cache) Manifest { @@ -61,7 +62,7 @@ pub const File = struct { pub const HashHelper = struct { hasher: Hasher = hasher_init, - const EmitLoc = @import("Compilation.zig").EmitLoc; + const EmitLoc = Compilation.EmitLoc; /// Record a slice of bytes as an dependency of the process being cached pub fn addBytes(hh: *HashHelper, bytes: []const u8) void { @@ -220,6 +221,24 @@ pub const Manifest = struct { return idx; } + pub fn hashCSource(self: *Manifest, c_source: Compilation.CSourceFile) !void { + _ = try self.addFile(c_source.src_path, null); + // Hash the extra flags, with special care to call addFile for file parameters. + // TODO this logic can likely be improved by utilizing clang_options_data.zig. + const file_args = [_][]const u8{"-include"}; + var arg_i: usize = 0; + while (arg_i < c_source.extra_flags.len) : (arg_i += 1) { + const arg = c_source.extra_flags[arg_i]; + self.hash.addBytes(arg); + for (file_args) |file_arg| { + if (mem.eql(u8, file_arg, arg) and arg_i + 1 < c_source.extra_flags.len) { + arg_i += 1; + _ = try self.addFile(c_source.extra_flags[arg_i], null); + } + } + } + } + pub fn addOptionalFile(self: *Manifest, optional_file_path: ?[]const u8) !void { self.hash.add(optional_file_path != null); const file_path = optional_file_path orelse return; |
