aboutsummaryrefslogtreecommitdiff
path: root/src/cache_hash.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-02-25 14:03:36 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-02-25 14:03:36 -0500
commit0d4db8828a9efc05b5c3622098a8337de0b62d1e (patch)
treef87768be86d630511e694ebd09173057c7b88a58 /src/cache_hash.cpp
parent525c2eaf5d49f537d4ccd48ab0c5bc1f52cc3204 (diff)
downloadzig-0d4db8828a9efc05b5c3622098a8337de0b62d1e.tar.gz
zig-0d4db8828a9efc05b5c3622098a8337de0b62d1e.zip
`@cImport` works with `--cache on`
We pass -MD -MF args to clang when doing `@cImport`, which gives us a complete list of files that the C code read from. Then we add these to the cache. So even when using `@cImport` Zig's caching system remains perfect. This is a proof of concept for the mechanism that the self-hosted compiler will use to watch and rebuild files.
Diffstat (limited to 'src/cache_hash.cpp')
-rw-r--r--src/cache_hash.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/cache_hash.cpp b/src/cache_hash.cpp
index 4526a83c27..85bad3dd2d 100644
--- a/src/cache_hash.cpp
+++ b/src/cache_hash.cpp
@@ -414,6 +414,39 @@ Error cache_add_file(CacheHash *ch, Buf *path) {
return cache_add_file_fetch(ch, resolved_path, nullptr);
}
+Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) {
+ Error err;
+ Buf *contents = buf_alloc();
+ if ((err = os_fetch_file_path(dep_file_path, contents, false))) {
+ if (verbose) {
+ fprintf(stderr, "unable to read .d file: %s\n", err_str(err));
+ }
+ return ErrorReadingDepFile;
+ }
+ SplitIterator it = memSplit(buf_to_slice(contents), str("\n"));
+ // skip first line
+ SplitIterator_next(&it);
+ for (;;) {
+ Optional<Slice<uint8_t>> opt_line = SplitIterator_next(&it);
+ if (!opt_line.is_some)
+ 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))
+ 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));
+ }
+ return err;
+ }
+ }
+ return ErrorNone;
+}
+
static Error write_manifest_file(CacheHash *ch) {
Error err;
Buf contents = BUF_INIT;
@@ -464,3 +497,4 @@ void cache_release(CacheHash *ch) {
os_file_close(ch->manifest_file);
}
+