authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-11-21 16:46:45-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-11-22 20:58:13-07:00
log7717cacacbf86e069ff3ffebf4a1a24f1a74903f
tree4d585d073c282ac658189860a31a9439b32e4111
parent58d3ee2a08f5a1f1c66d5e3b4f215361073c6372

CLI: resolve zig lib directory before using it

Fixes issues with trailing slashes and things like this.

2 files changed, 11 insertions(+), 5 deletions(-)

src/Cache.zig+3
...@@ -31,6 +31,9 @@ const Compilation = @import("Compilation.zig");...@@ -31,6 +31,9 @@ const Compilation = @import("Compilation.zig");
31const log = std.log.scoped(.cache);31const log = std.log.scoped(.cache);
3232
33pub fn addPrefix(cache: *Cache, directory: Compilation.Directory) void {33pub fn addPrefix(cache: *Cache, directory: Compilation.Directory) void {
34 if (directory.path) |p| {
35 log.debug("Cache.addPrefix {d} {s}", .{ cache.prefixes_len, p });
36 }
34 cache.prefixes_buffer[cache.prefixes_len] = directory;37 cache.prefixes_buffer[cache.prefixes_len] = directory;
35 cache.prefixes_len += 1;38 cache.prefixes_len += 1;
36}39}
src/main.zig+8-5
...@@ -2744,11 +2744,14 @@ fn buildOutputType(...@@ -2744,11 +2744,14 @@ fn buildOutputType(
2744 }2744 }
27452745
2746 const self_exe_path = try introspect.findZigExePath(arena);2746 const self_exe_path = try introspect.findZigExePath(arena);
2747 var zig_lib_directory: Compilation.Directory = if (override_lib_dir) |lib_dir| .{2747 var zig_lib_directory: Compilation.Directory = if (override_lib_dir) |unresolved_lib_dir| l: {
2748 .path = lib_dir,2748 const lib_dir = try fs.path.resolve(arena, &.{unresolved_lib_dir});
2749 .handle = fs.cwd().openDir(lib_dir, .{}) catch |err| {2749 break :l .{
2750 fatal("unable to open zig lib directory '{s}': {s}", .{ lib_dir, @errorName(err) });2750 .path = lib_dir,
2751 },2751 .handle = fs.cwd().openDir(lib_dir, .{}) catch |err| {
2752 fatal("unable to open zig lib directory '{s}': {s}", .{ lib_dir, @errorName(err) });
2753 },
2754 };
2752 } else introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {2755 } else introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {
2753 fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});2756 fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});
2754 };2757 };