diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-02-25 14:11:54 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-25 14:11:54 -0500 |
| commit | 6003b1ea7018fe6a7aa87622d1178e444e6d8abb (patch) | |
| tree | f87768be86d630511e694ebd09173057c7b88a58 /src/cache_hash.cpp | |
| parent | e5d4862e145c38ffc1111ee578ddcafc1e35ad57 (diff) | |
| parent | 0d4db8828a9efc05b5c3622098a8337de0b62d1e (diff) | |
| download | zig-6003b1ea7018fe6a7aa87622d1178e444e6d8abb.tar.gz zig-6003b1ea7018fe6a7aa87622d1178e444e6d8abb.zip | |
Merge pull request #2005 from ziglang/c-source
first class support for compiling C code
Diffstat (limited to 'src/cache_hash.cpp')
| -rw-r--r-- | src/cache_hash.cpp | 34 |
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); } + |
