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 {
20172017 return process.cleanExit(io);
20182018 },
20192019 .minimal => {
2020 Templates.writeSimpleFile(io, Package.Manifest.basename,
2020 Templates.writeSimpleFile(io, Io.Dir.cwd(), Package.Manifest.basename,
20212021 \\.{{
20222022 \\ .name = .{s},
20232023 \\ .version = "0.0.1",
......@@ -2034,7 +2034,7 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void {
20342034 else => fatal("failed to create {q}: {t}", .{ Package.Manifest.basename, err }),
20352035 error.PathAlreadyExists => fatal("refusing to overwrite {q}", .{Package.Manifest.basename}),
20362036 };
2037 Templates.writeSimpleFile(io, default_build_zig_basename,
2037 Templates.writeSimpleFile(io, Io.Dir.cwd(), default_build_zig_basename,
20382038 \\const std = @import("std");
20392039 \\
20402040 \\pub fn build(b: *std.Build) void {{
......@@ -3840,7 +3840,7 @@ fn loadManifest(
38403840 0,
38413841 ) catch |err| switch (err) {
38423842 error.FileNotFound => {
3843 Templates.writeSimpleFile(io, Package.Manifest.basename,
3843 Templates.writeSimpleFile(io, options.dir, Package.Manifest.basename,
38443844 \\.{{
38453845 \\ .name = .{s},
38463846 \\ .version = "0.0.1",
......@@ -4002,8 +4002,8 @@ const Templates = struct {
40024002 };
40034003 }
40044004
4005 fn writeSimpleFile(io: Io, file_name: []const u8, comptime format: []const u8, args: anytype) !void {
4006 const f = try Io.Dir.cwd().createFile(io, file_name, .{ .exclusive = true });
4005 fn writeSimpleFile(io: Io, dir: Io.Dir, file_name: []const u8, comptime format: []const u8, args: anytype) !void {
4006 const f = try dir.createFile(io, file_name, .{ .exclusive = true });
40074007 defer f.close(io);
40084008 var buf: [4096]u8 = undefined;
40094009 var fw = f.writer(io, &buf);