Skip to content

Commit

Permalink
Fixes ziglang#12685.
Browse files Browse the repository at this point in the history
The problem was that paths in the cache are assumed to endwithout the path separator, but are added verbatim from the command line
in several places. The solution here is to make sure that all prefixes are without path separator by cutting it off when it is passed
to Cache.addPrefix. This way, the assumption is met.
  • Loading branch information
Felix "xq" Queißner authored and andrewrk committed Jan 27, 2023
1 parent 97b1a9b commit 576401f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Cache.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,21 @@ const Compilation = @import("Compilation.zig");
const log = std.log.scoped(.cache);

pub fn addPrefix(cache: *Cache, directory: Compilation.Directory) void {
if (directory.path) |p| {
var patched_dir = directory;
if (patched_dir.path) |*path| {
if (std.mem.endsWith(u8, path.*, std.fs.path.sep_str)) {
// remove the path separator at the end. This might remove the "/" from an
// absolute path, and push "" into the cache, but this is acceptible,
// as both "/" and "" are semantically the same prefix of a unix path.
path.* = path.*[0 .. path.*.len - 1];
}
}

if (patched_dir.path) |p| {
log.debug("Cache.addPrefix {d} {s}", .{ cache.prefixes_len, p });
}
cache.prefixes_buffer[cache.prefixes_len] = directory;

cache.prefixes_buffer[cache.prefixes_len] = patched_dir;
cache.prefixes_len += 1;
}

Expand Down

0 comments on commit 576401f

Please sign in to comment.