Skip to content

Commit

Permalink
Merge pull request ziglang#13071 from ziglang/resolve-cache-files
Browse files Browse the repository at this point in the history
stage2: resolve file before putting them into cache
  • Loading branch information
andrewrk authored Oct 5, 2022
2 parents e563af1 + 6152f04 commit 3234e8d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/Module.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)});
Expand Down

0 comments on commit 3234e8d

Please sign in to comment.