CLI: resolve zig lib directory before using it

Fixes issues with trailing slashes and things like this.
This commit is contained in:
Andrew Kelley 2022-11-21 16:46:45 -07:00
parent 58d3ee2a08
commit 7717cacacb
2 changed files with 11 additions and 5 deletions

View File

@ -31,6 +31,9 @@ const Compilation = @import("Compilation.zig");
const log = std.log.scoped(.cache);
pub fn addPrefix(cache: *Cache, directory: Compilation.Directory) void {
if (directory.path) |p| {
log.debug("Cache.addPrefix {d} {s}", .{ cache.prefixes_len, p });
}
cache.prefixes_buffer[cache.prefixes_len] = directory;
cache.prefixes_len += 1;
}

View File

@ -2744,11 +2744,14 @@ fn buildOutputType(
}
const self_exe_path = try introspect.findZigExePath(arena);
var zig_lib_directory: Compilation.Directory = if (override_lib_dir) |lib_dir| .{
.path = lib_dir,
.handle = fs.cwd().openDir(lib_dir, .{}) catch |err| {
fatal("unable to open zig lib directory '{s}': {s}", .{ lib_dir, @errorName(err) });
},
var zig_lib_directory: Compilation.Directory = if (override_lib_dir) |unresolved_lib_dir| l: {
const lib_dir = try fs.path.resolve(arena, &.{unresolved_lib_dir});
break :l .{
.path = lib_dir,
.handle = fs.cwd().openDir(lib_dir, .{}) catch |err| {
fatal("unable to open zig lib directory '{s}': {s}", .{ lib_dir, @errorName(err) });
},
};
} else introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {
fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});
};