authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-05-22 03:26:11+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-05-22 08:43:37+01:00
log9a3540d61e57535b719b32942a4bc9ac065cbeac
tree9defecc1fd368737191fc12b4552260bd316c994
parent931c6f90f588e5b923e59c38efade9dfd92cd0dd

std.Build: resolved generated paths are cwd-relative

The doc comment here agreed with the implementation, but not with *any* `Step` which populates a `GeneratedFile`, where they are treated as cwd-relative. This is the obvious correct choice, because these paths usually come from joining onto a cache root, and those are cwd-relative if not absolute. This was a pre-existing bug, but #23836 caused it to trigger more often, because the compiler now commonly passes the local cache directory to the build runner process as a relative path where it was previously an absolute path. Resolves: #23954

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

lib/std/Build.zig+2-2
...@@ -2443,12 +2443,12 @@ pub const GeneratedFile = struct {...@@ -2443,12 +2443,12 @@ pub const GeneratedFile = struct {
2443 /// The step that generates the file2443 /// The step that generates the file
2444 step: *Step,2444 step: *Step,
24452445
2446 /// The path to the generated file. Must be either absolute or relative to the build root.2446 /// The path to the generated file. Must be either absolute or relative to the build runner cwd.
2447 /// This value must be set in the `fn make()` of the `step` and must not be `null` afterwards.2447 /// This value must be set in the `fn make()` of the `step` and must not be `null` afterwards.
2448 path: ?[]const u8 = null,2448 path: ?[]const u8 = null,
24492449
2450 pub fn getPath(gen: GeneratedFile) []const u8 {2450 pub fn getPath(gen: GeneratedFile) []const u8 {
2451 return gen.step.owner.pathFromRoot(gen.path orelse std.debug.panic(2451 return gen.step.owner.pathFromCwd(gen.path orelse std.debug.panic(
2452 "getPath() was called on a GeneratedFile that wasn't built yet. Is there a missing Step dependency on step '{s}'?",2452 "getPath() was called on a GeneratedFile that wasn't built yet. Is there a missing Step dependency on step '{s}'?",
2453 .{gen.step.name},2453 .{gen.step.name},
2454 ));2454 ));