authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-05 09:41:03-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-10-05 09:41:03-04:00
log3234e8de3a50575195fab625f818a6e5fe141c7b
tree68a5a69cee94e1ecaf6ff725cc55ce5ebd2cd9e6
parente563af13296cdb3e64f0f396fdc58112d4484968
parent6152f043c0446ace7c992c33f27174152d9bd8a0
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #13071 from ziglang/resolve-cache-files

stage2: resolve file before putting them into cache

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

src/Module.zig+11-3
...@@ -4478,9 +4478,17 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {...@@ -4478,9 +4478,17 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
4478 try reportRetryableFileError(mod, file, "unable to load source: {s}", .{@errorName(err)});4478 try reportRetryableFileError(mod, file, "unable to load source: {s}", .{@errorName(err)});
4479 return error.AnalysisFail;4479 return error.AnalysisFail;
4480 };4480 };
4481 const resolved_path = try file.pkg.root_src_directory.join(gpa, &.{4481
4482 file.sub_file_path,4482 const resolved_path = std.fs.path.resolve(
4483 });4483 gpa,
4484 if (file.pkg.root_src_directory.path) |pkg_path|
4485 &[_][]const u8{ pkg_path, file.sub_file_path }
4486 else
4487 &[_][]const u8{file.sub_file_path},
4488 ) catch |err| {
4489 try reportRetryableFileError(mod, file, "unable to resolve path: {s}", .{@errorName(err)});
4490 return error.AnalysisFail;
4491 };
4484 errdefer gpa.free(resolved_path);4492 errdefer gpa.free(resolved_path);
44854493
4486 try man.addFilePostContents(resolved_path, source.bytes, source.stat);4494 try man.addFilePostContents(resolved_path, source.bytes, source.stat);
src/main.zig+9-2
...@@ -2763,7 +2763,14 @@ fn buildOutputType(...@@ -2763,7 +2763,14 @@ fn buildOutputType(
2763 defer gpa.free(rel_src_path);2763 defer gpa.free(rel_src_path);
2764 break :blk try Package.create(gpa, p, rel_src_path);2764 break :blk try Package.create(gpa, p, rel_src_path);
2765 } else {2765 } else {
2766 break :blk try Package.create(gpa, fs.path.dirname(src_path), fs.path.basename(src_path));2766 const root_src_dir_path = fs.path.dirname(src_path);
2767 break :blk Package.create(gpa, root_src_dir_path, fs.path.basename(src_path)) catch |err| {
2768 if (root_src_dir_path) |p| {
2769 fatal("unable to open '{s}': {s}", .{ p, @errorName(err) });
2770 } else {
2771 return err;
2772 }
2773 };
2767 }2774 }
2768 } else null;2775 } else null;
2769 defer if (main_pkg) |p| p.destroy(gpa);2776 defer if (main_pkg) |p| p.destroy(gpa);
...@@ -2792,7 +2799,7 @@ fn buildOutputType(...@@ -2792,7 +2799,7 @@ fn buildOutputType(
2792 var zig_lib_directory: Compilation.Directory = if (override_lib_dir) |lib_dir| .{2799 var zig_lib_directory: Compilation.Directory = if (override_lib_dir) |lib_dir| .{
2793 .path = lib_dir,2800 .path = lib_dir,
2794 .handle = fs.cwd().openDir(lib_dir, .{}) catch |err| {2801 .handle = fs.cwd().openDir(lib_dir, .{}) catch |err| {
2795 fatal("unable to open zig lib directory from 'zig-lib-dir' argument or env, '{s}': {s}", .{ lib_dir, @errorName(err) });2802 fatal("unable to open zig lib directory '{s}': {s}", .{ lib_dir, @errorName(err) });
2796 },2803 },
2797 } else introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {2804 } else introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {
2798 fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});2805 fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});