From 7717cacacbf86e069ff3ffebf4a1a24f1a74903f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 21 Nov 2022 16:46:45 -0700 Subject: [PATCH] CLI: resolve zig lib directory before using it Fixes issues with trailing slashes and things like this. --- src/Cache.zig | 3 +++ src/main.zig | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Cache.zig b/src/Cache.zig index 2c32131845..a645e06594 100644 --- a/src/Cache.zig +++ b/src/Cache.zig @@ -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; } diff --git a/src/main.zig b/src/main.zig index 24518d743d..f5855da6b9 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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)}); };