authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-08-18 01:09:08-07:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-08-18 20:58:46+02:00
log08ddfb17a9e48576581de2c8acb1f231731f8f57
treead1579a8a82229ede8a3dc7986251bb2321e7127
parent5e087bd4fd944080af9c0a039d1f3314924baa10

Maker: Fix fetch-generated build.zig.zon location when build_root is not cwd

This fixes what was previously a guaranteed PathAlreadyExists error when LoadManifestOptions.dir (the build_root) was not equal to CWD, since the file would always get written to the CWD but then looked for in the build root, so after creation the retry would fail and then the re-creation would fail since it's created with an exclusive lock.

1 files changed, 5 insertions(+), 5 deletions(-)

lib/compiler/Maker.zig+5-5
...@@ -2017,7 +2017,7 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void {...@@ -2017,7 +2017,7 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void {
2017 return process.cleanExit(io);2017 return process.cleanExit(io);
2018 },2018 },
2019 .minimal => {2019 .minimal => {
2020 Templates.writeSimpleFile(io, Package.Manifest.basename,2020 Templates.writeSimpleFile(io, Io.Dir.cwd(), Package.Manifest.basename,
2021 \\.{{2021 \\.{{
2022 \\ .name = .{s},2022 \\ .name = .{s},
2023 \\ .version = "0.0.1",2023 \\ .version = "0.0.1",
...@@ -2034,7 +2034,7 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void {...@@ -2034,7 +2034,7 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void {
2034 else => fatal("failed to create {q}: {t}", .{ Package.Manifest.basename, err }),2034 else => fatal("failed to create {q}: {t}", .{ Package.Manifest.basename, err }),
2035 error.PathAlreadyExists => fatal("refusing to overwrite {q}", .{Package.Manifest.basename}),2035 error.PathAlreadyExists => fatal("refusing to overwrite {q}", .{Package.Manifest.basename}),
2036 };2036 };
2037 Templates.writeSimpleFile(io, default_build_zig_basename,2037 Templates.writeSimpleFile(io, Io.Dir.cwd(), default_build_zig_basename,
2038 \\const std = @import("std");2038 \\const std = @import("std");
2039 \\2039 \\
2040 \\pub fn build(b: *std.Build) void {{2040 \\pub fn build(b: *std.Build) void {{
...@@ -3840,7 +3840,7 @@ fn loadManifest(...@@ -3840,7 +3840,7 @@ fn loadManifest(
3840 0,3840 0,
3841 ) catch |err| switch (err) {3841 ) catch |err| switch (err) {
3842 error.FileNotFound => {3842 error.FileNotFound => {
3843 Templates.writeSimpleFile(io, Package.Manifest.basename,3843 Templates.writeSimpleFile(io, options.dir, Package.Manifest.basename,
3844 \\.{{3844 \\.{{
3845 \\ .name = .{s},3845 \\ .name = .{s},
3846 \\ .version = "0.0.1",3846 \\ .version = "0.0.1",
...@@ -4002,8 +4002,8 @@ const Templates = struct {...@@ -4002,8 +4002,8 @@ const Templates = struct {
4002 };4002 };
4003 }4003 }
40044004
4005 fn writeSimpleFile(io: Io, file_name: []const u8, comptime format: []const u8, args: anytype) !void {4005 fn writeSimpleFile(io: Io, dir: Io.Dir, file_name: []const u8, comptime format: []const u8, args: anytype) !void {
4006 const f = try Io.Dir.cwd().createFile(io, file_name, .{ .exclusive = true });4006 const f = try dir.createFile(io, file_name, .{ .exclusive = true });
4007 defer f.close(io);4007 defer f.close(io);
4008 var buf: [4096]u8 = undefined;4008 var buf: [4096]u8 = undefined;
4009 var fw = f.writer(io, &buf);4009 var fw = f.writer(io, &buf);