authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-06-08 22:35:54-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-06-09 05:25:30-04:00
log4d79806459618f1830772ed6dfbb82059589aaa4
tree0f6c6393f8bb285dd1c91936766b2619d1010352
parentcffa98eef54568bf43cbbe14a3cbbf972a2c7a7a

std.Build.Step.Run: add addDecoratedDirectoryArg function

For directory arguments that need both prefix and suffix strings appended. Needed to unbreak ffmpeg package after fe855691f6f742a14678cb617422977c2a55be39

1 files changed, 37 insertions(+), 17 deletions(-)

lib/std/Build/Step/Run.zig+37-17
...@@ -138,7 +138,7 @@ pub const StdIo = union(enum) {...@@ -138,7 +138,7 @@ pub const StdIo = union(enum) {
138pub const Arg = union(enum) {138pub const Arg = union(enum) {
139 artifact: PrefixedArtifact,139 artifact: PrefixedArtifact,
140 lazy_path: PrefixedLazyPath,140 lazy_path: PrefixedLazyPath,
141 directory_source: PrefixedLazyPath,141 decorated_directory: DecoratedLazyPath,
142 bytes: []u8,142 bytes: []u8,
143 output_file: *Output,143 output_file: *Output,
144 output_directory: *Output,144 output_directory: *Output,
...@@ -154,6 +154,12 @@ pub const PrefixedLazyPath = struct {...@@ -154,6 +154,12 @@ pub const PrefixedLazyPath = struct {
154 lazy_path: std.Build.LazyPath,154 lazy_path: std.Build.LazyPath,
155};155};
156156
157pub const DecoratedLazyPath = struct {
158 prefix: []const u8,
159 lazy_path: std.Build.LazyPath,
160 suffix: []const u8,
161};
162
157pub const Output = struct {163pub const Output = struct {
158 generated_file: std.Build.GeneratedFile,164 generated_file: std.Build.GeneratedFile,
159 prefix: []const u8,165 prefix: []const u8,
...@@ -360,19 +366,33 @@ pub fn addPrefixedOutputDirectoryArg(...@@ -360,19 +366,33 @@ pub fn addPrefixedOutputDirectoryArg(
360 return .{ .generated = .{ .file = &output.generated_file } };366 return .{ .generated = .{ .file = &output.generated_file } };
361}367}
362368
363pub fn addDirectoryArg(run: *Run, directory_source: std.Build.LazyPath) void {369pub fn addDirectoryArg(run: *Run, lazy_directory: std.Build.LazyPath) void {
364 run.addPrefixedDirectoryArg("", directory_source);370 run.addDecoratedDirectoryArg("", lazy_directory, "");
365}371}
366372
367pub fn addPrefixedDirectoryArg(run: *Run, prefix: []const u8, directory_source: std.Build.LazyPath) void {373pub fn addPrefixedDirectoryArg(run: *Run, prefix: []const u8, lazy_directory: std.Build.LazyPath) void {
368 const b = run.step.owner;374 const b = run.step.owner;
375 run.argv.append(b.allocator, .{ .decorated_directory = .{
376 .prefix = b.dupe(prefix),
377 .lazy_path = lazy_directory.dupe(b),
378 .suffix = "",
379 } }) catch @panic("OOM");
380 lazy_directory.addStepDependencies(&run.step);
381}
369382
370 const prefixed_directory_source: PrefixedLazyPath = .{383pub fn addDecoratedDirectoryArg(
384 run: *Run,
385 prefix: []const u8,
386 lazy_directory: std.Build.LazyPath,
387 suffix: []const u8,
388) void {
389 const b = run.step.owner;
390 run.argv.append(b.allocator, .{ .decorated_directory = .{
371 .prefix = b.dupe(prefix),391 .prefix = b.dupe(prefix),
372 .lazy_path = directory_source.dupe(b),392 .lazy_path = lazy_directory.dupe(b),
373 };393 .suffix = b.dupe(suffix),
374 run.argv.append(b.allocator, .{ .directory_source = prefixed_directory_source }) catch @panic("OOM");394 } }) catch @panic("OOM");
375 directory_source.addStepDependencies(&run.step);395 lazy_directory.addStepDependencies(&run.step);
376}396}
377397
378/// Add a path argument to a dep file (.d) for the child process to write its398/// Add a path argument to a dep file (.d) for the child process to write its
...@@ -661,11 +681,11 @@ fn make(step: *Step, options: Step.MakeOptions) !void {...@@ -661,11 +681,11 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
661 man.hash.addBytes(file.prefix);681 man.hash.addBytes(file.prefix);
662 _ = try man.addFile(file_path, null);682 _ = try man.addFile(file_path, null);
663 },683 },
664 .directory_source => |file| {684 .decorated_directory => |dd| {
665 const file_path = file.lazy_path.getPath2(b, step);685 const file_path = dd.lazy_path.getPath3(b, step);
666 try argv_list.append(b.fmt("{s}{s}", .{ file.prefix, file_path }));686 const resolved_arg = b.fmt("{s}{}{s}", .{ dd.prefix, file_path, dd.suffix });
667 man.hash.addBytes(file.prefix);687 try argv_list.append(resolved_arg);
668 man.hash.addBytes(file_path);688 man.hash.addBytes(resolved_arg);
669 },689 },
670 .artifact => |pa| {690 .artifact => |pa| {
671 const artifact = pa.artifact;691 const artifact = pa.artifact;
...@@ -882,9 +902,9 @@ pub fn rerunInFuzzMode(...@@ -882,9 +902,9 @@ pub fn rerunInFuzzMode(
882 const file_path = file.lazy_path.getPath2(b, step);902 const file_path = file.lazy_path.getPath2(b, step);
883 try argv_list.append(arena, b.fmt("{s}{s}", .{ file.prefix, file_path }));903 try argv_list.append(arena, b.fmt("{s}{s}", .{ file.prefix, file_path }));
884 },904 },
885 .directory_source => |file| {905 .decorated_directory => |dd| {
886 const file_path = file.lazy_path.getPath2(b, step);906 const file_path = dd.lazy_path.getPath3(b, step);
887 try argv_list.append(arena, b.fmt("{s}{s}", .{ file.prefix, file_path }));907 try argv_list.append(arena, b.fmt("{s}{}{s}", .{ dd.prefix, file_path, dd.suffix }));
888 },908 },
889 .artifact => |pa| {909 .artifact => |pa| {
890 const artifact = pa.artifact;910 const artifact = pa.artifact;