From f4c6e5d94e1d06a2b438632de0808947f6561798 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 5 Oct 2022 00:41:17 -0700 Subject: [PATCH 1/2] CLI: better error message for bad input path Previously it just said `error: NotDir` but now it says `error: unable to open '': NotDir`. --- src/main.zig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index 2f005b57a4..7df247f1a9 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2763,7 +2763,14 @@ fn buildOutputType( defer gpa.free(rel_src_path); break :blk try Package.create(gpa, p, rel_src_path); } else { - break :blk try Package.create(gpa, fs.path.dirname(src_path), fs.path.basename(src_path)); + const root_src_dir_path = fs.path.dirname(src_path); + break :blk Package.create(gpa, root_src_dir_path, fs.path.basename(src_path)) catch |err| { + if (root_src_dir_path) |p| { + fatal("unable to open '{s}': {s}", .{ p, @errorName(err) }); + } else { + return err; + } + }; } } else null; defer if (main_pkg) |p| p.destroy(gpa); @@ -2792,7 +2799,7 @@ fn buildOutputType( 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 from 'zig-lib-dir' argument or env, '{s}': {s}", .{ lib_dir, @errorName(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)}); From 6152f043c0446ace7c992c33f27174152d9bd8a0 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 5 Oct 2022 00:42:08 -0700 Subject: [PATCH 2/2] stage2: resolve file before putting them into cache This was an accidental misuse of the Cache API which intends to call resolve on all file paths going into it. This one callsite was failing to do that; fixed now. Fixes relative file paths from making it into the global cache manifest. See #13050 --- src/Module.zig | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Module.zig b/src/Module.zig index 959c2ab4b2..b268e3a4cc 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -4478,9 +4478,17 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void { try reportRetryableFileError(mod, file, "unable to load source: {s}", .{@errorName(err)}); return error.AnalysisFail; }; - const resolved_path = try file.pkg.root_src_directory.join(gpa, &.{ - file.sub_file_path, - }); + + const resolved_path = std.fs.path.resolve( + gpa, + if (file.pkg.root_src_directory.path) |pkg_path| + &[_][]const u8{ pkg_path, file.sub_file_path } + else + &[_][]const u8{file.sub_file_path}, + ) catch |err| { + try reportRetryableFileError(mod, file, "unable to resolve path: {s}", .{@errorName(err)}); + return error.AnalysisFail; + }; errdefer gpa.free(resolved_path); try man.addFilePostContents(resolved_path, source.bytes, source.stat);