aboutsummaryrefslogtreecommitdiff
path: root/src-self-hosted/Cache.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-09-15 18:02:42 -0700
committerAndrew Kelley <andrew@ziglang.org>2020-09-15 18:02:42 -0700
commit99a2fc2cde4c193d11322b2b22086fb4bc99f9fc (patch)
tree0a23520aa45f2e15c8130e9b59caa3bb59255bd0 /src-self-hosted/Cache.zig
parenta0b43ff3b3c22cb5c57e6728d6cb35d722f22a3b (diff)
downloadzig-99a2fc2cde4c193d11322b2b22086fb4bc99f9fc.tar.gz
zig-99a2fc2cde4c193d11322b2b22086fb4bc99f9fc.zip
stage2: implement .d file parsing for C objects
Diffstat (limited to 'src-self-hosted/Cache.zig')
-rw-r--r--src-self-hosted/Cache.zig39
1 files changed, 39 insertions, 0 deletions
diff --git a/src-self-hosted/Cache.zig b/src-self-hosted/Cache.zig
index b41c0a312f..8ad26a8f05 100644
--- a/src-self-hosted/Cache.zig
+++ b/src-self-hosted/Cache.zig
@@ -444,6 +444,45 @@ pub const CacheHash = struct {
try self.populateFileHash(new_ch_file);
}
+ pub fn addDepFilePost(self: *CacheHash, dir: fs.Dir, dep_file_basename: []const u8) !void {
+ assert(self.manifest_file != null);
+
+ const dep_file_contents = try dir.readFileAlloc(self.cache.gpa, dep_file_basename, MANIFEST_FILE_SIZE_MAX);
+ defer self.cache.gpa.free(dep_file_contents);
+
+ const DepTokenizer = @import("DepTokenizer.zig");
+ var it = DepTokenizer.init(self.cache.gpa, dep_file_contents);
+ defer it.deinit();
+
+ // Skip first token: target.
+ {
+ const opt_result = it.next() catch |err| switch (err) {
+ error.OutOfMemory => return error.OutOfMemory,
+ error.InvalidInput => {
+ std.log.err("failed parsing {}: {}: {}", .{ dep_file_basename, @errorName(err), it.error_text });
+ return error.InvalidDepFile;
+ },
+ };
+ _ = opt_result orelse return; // Empty dep file OK.
+ }
+ // Process 0+ preqreqs.
+ // Clang is invoked in single-source mode so we never get more targets.
+ while (true) {
+ const opt_result = it.next() catch |err| switch (err) {
+ error.OutOfMemory => return error.OutOfMemory,
+ error.InvalidInput => {
+ std.log.err("failed parsing {}: {}: {}", .{ dep_file_basename, @errorName(err), it.error_text });
+ return error.InvalidDepFile;
+ },
+ };
+ const result = opt_result orelse return;
+ switch (result.id) {
+ .target => return,
+ .prereq => try self.addFilePost(result.bytes),
+ }
+ }
+ }
+
/// Returns a base64 encoded hash of the inputs.
pub fn final(self: *CacheHash) [BASE64_DIGEST_LEN]u8 {
assert(self.manifest_file != null);