Commit 7717cacacb

Andrew Kelley <andrew@ziglang.org>
2022-11-22 00:46:45
CLI: resolve zig lib directory before using it
Fixes issues with trailing slashes and things like this.
1 parent 58d3ee2
Changed files (2)
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;
 }
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)});
     };