diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-06-08 22:35:54 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-06-09 05:25:30 -0400 |
| commit | 4d79806459618f1830772ed6dfbb82059589aaa4 (patch) | |
| tree | 0f6c6393f8bb285dd1c91936766b2619d1010352 /lib/std/Build | |
| parent | cffa98eef54568bf43cbbe14a3cbbf972a2c7a7a (diff) | |
| download | zig-4d79806459618f1830772ed6dfbb82059589aaa4.tar.gz zig-4d79806459618f1830772ed6dfbb82059589aaa4.zip | |
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
Diffstat (limited to 'lib/std/Build')
| -rw-r--r-- | lib/std/Build/Step/Run.zig | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index b7ad1307fb..7b5d4808a6 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -138,7 +138,7 @@ pub const StdIo = union(enum) { pub const Arg = union(enum) { artifact: PrefixedArtifact, lazy_path: PrefixedLazyPath, - directory_source: PrefixedLazyPath, + decorated_directory: DecoratedLazyPath, bytes: []u8, output_file: *Output, output_directory: *Output, @@ -154,6 +154,12 @@ pub const PrefixedLazyPath = struct { lazy_path: std.Build.LazyPath, }; +pub const DecoratedLazyPath = struct { + prefix: []const u8, + lazy_path: std.Build.LazyPath, + suffix: []const u8, +}; + pub const Output = struct { generated_file: std.Build.GeneratedFile, prefix: []const u8, @@ -360,19 +366,33 @@ pub fn addPrefixedOutputDirectoryArg( return .{ .generated = .{ .file = &output.generated_file } }; } -pub fn addDirectoryArg(run: *Run, directory_source: std.Build.LazyPath) void { - run.addPrefixedDirectoryArg("", directory_source); +pub fn addDirectoryArg(run: *Run, lazy_directory: std.Build.LazyPath) void { + run.addDecoratedDirectoryArg("", lazy_directory, ""); } -pub fn addPrefixedDirectoryArg(run: *Run, prefix: []const u8, directory_source: std.Build.LazyPath) void { +pub fn addPrefixedDirectoryArg(run: *Run, prefix: []const u8, lazy_directory: std.Build.LazyPath) void { const b = run.step.owner; + run.argv.append(b.allocator, .{ .decorated_directory = .{ + .prefix = b.dupe(prefix), + .lazy_path = lazy_directory.dupe(b), + .suffix = "", + } }) catch @panic("OOM"); + lazy_directory.addStepDependencies(&run.step); +} - const prefixed_directory_source: PrefixedLazyPath = .{ +pub fn addDecoratedDirectoryArg( + run: *Run, + prefix: []const u8, + lazy_directory: std.Build.LazyPath, + suffix: []const u8, +) void { + const b = run.step.owner; + run.argv.append(b.allocator, .{ .decorated_directory = .{ .prefix = b.dupe(prefix), - .lazy_path = directory_source.dupe(b), - }; - run.argv.append(b.allocator, .{ .directory_source = prefixed_directory_source }) catch @panic("OOM"); - directory_source.addStepDependencies(&run.step); + .lazy_path = lazy_directory.dupe(b), + .suffix = b.dupe(suffix), + } }) catch @panic("OOM"); + lazy_directory.addStepDependencies(&run.step); } /// 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 { man.hash.addBytes(file.prefix); _ = try man.addFile(file_path, null); }, - .directory_source => |file| { - const file_path = file.lazy_path.getPath2(b, step); - try argv_list.append(b.fmt("{s}{s}", .{ file.prefix, file_path })); - man.hash.addBytes(file.prefix); - man.hash.addBytes(file_path); + .decorated_directory => |dd| { + const file_path = dd.lazy_path.getPath3(b, step); + const resolved_arg = b.fmt("{s}{}{s}", .{ dd.prefix, file_path, dd.suffix }); + try argv_list.append(resolved_arg); + man.hash.addBytes(resolved_arg); }, .artifact => |pa| { const artifact = pa.artifact; @@ -882,9 +902,9 @@ pub fn rerunInFuzzMode( const file_path = file.lazy_path.getPath2(b, step); try argv_list.append(arena, b.fmt("{s}{s}", .{ file.prefix, file_path })); }, - .directory_source => |file| { - const file_path = file.lazy_path.getPath2(b, step); - try argv_list.append(arena, b.fmt("{s}{s}", .{ file.prefix, file_path })); + .decorated_directory => |dd| { + const file_path = dd.lazy_path.getPath3(b, step); + try argv_list.append(arena, b.fmt("{s}{}{s}", .{ dd.prefix, file_path, dd.suffix })); }, .artifact => |pa| { const artifact = pa.artifact; |
