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) {
138138pub const Arg = union(enum) {
139139 artifact: PrefixedArtifact,
140140 lazy_path: PrefixedLazyPath,
141 directory_source: PrefixedLazyPath,
141 decorated_directory: DecoratedLazyPath,
142142 bytes: []u8,
143143 output_file: *Output,
144144 output_directory: *Output,
......@@ -154,6 +154,12 @@ pub const PrefixedLazyPath = struct {
154154 lazy_path: std.Build.LazyPath,
155155};
156156
157pub const DecoratedLazyPath = struct {
158 prefix: []const u8,
159 lazy_path: std.Build.LazyPath,
160 suffix: []const u8,
161};
162
157163pub const Output = struct {
158164 generated_file: std.Build.GeneratedFile,
159165 prefix: []const u8,
......@@ -360,19 +366,33 @@ pub fn addPrefixedOutputDirectoryArg(
360366 return .{ .generated = .{ .file = &output.generated_file } };
361367}
362368
363pub fn addDirectoryArg(run: *Run, directory_source: std.Build.LazyPath) void {
364 run.addPrefixedDirectoryArg("", directory_source);
369pub fn addDirectoryArg(run: *Run, lazy_directory: std.Build.LazyPath) void {
370 run.addDecoratedDirectoryArg("", lazy_directory, "");
365371}
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 {
368374 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 = .{
371391 .prefix = b.dupe(prefix),
372 .lazy_path = directory_source.dupe(b),
373 };
374 run.argv.append(b.allocator, .{ .directory_source = prefixed_directory_source }) catch @panic("OOM");
375 directory_source.addStepDependencies(&run.step);
392 .lazy_path = lazy_directory.dupe(b),
393 .suffix = b.dupe(suffix),
394 } }) catch @panic("OOM");
395 lazy_directory.addStepDependencies(&run.step);
376396}
377397
378398/// 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 {
661681 man.hash.addBytes(file.prefix);
662682 _ = try man.addFile(file_path, null);
663683 },
664 .directory_source => |file| {
665 const file_path = file.lazy_path.getPath2(b, step);
666 try argv_list.append(b.fmt("{s}{s}", .{ file.prefix, file_path }));
667 man.hash.addBytes(file.prefix);
668 man.hash.addBytes(file_path);
684 .decorated_directory => |dd| {
685 const file_path = dd.lazy_path.getPath3(b, step);
686 const resolved_arg = b.fmt("{s}{}{s}", .{ dd.prefix, file_path, dd.suffix });
687 try argv_list.append(resolved_arg);
688 man.hash.addBytes(resolved_arg);
669689 },
670690 .artifact => |pa| {
671691 const artifact = pa.artifact;
......@@ -882,9 +902,9 @@ pub fn rerunInFuzzMode(
882902 const file_path = file.lazy_path.getPath2(b, step);
883903 try argv_list.append(arena, b.fmt("{s}{s}", .{ file.prefix, file_path }));
884904 },
885 .directory_source => |file| {
886 const file_path = file.lazy_path.getPath2(b, step);
887 try argv_list.append(arena, b.fmt("{s}{s}", .{ file.prefix, file_path }));
905 .decorated_directory => |dd| {
906 const file_path = dd.lazy_path.getPath3(b, step);
907 try argv_list.append(arena, b.fmt("{s}{}{s}", .{ dd.prefix, file_path, dd.suffix }));
888908 },
889909 .artifact => |pa| {
890910 const artifact = pa.artifact;