Commit fb9d5529da

Felix (xq) Queißner <git@mq32.de>
2020-07-25 18:36:55
Adds support for RunStep to use the result of a WriteFileStep.
1 parent f0ed2ed
Changed files (1)
lib
std
build
lib/std/build/run.zig
@@ -4,6 +4,7 @@ const build = std.build;
 const Step = build.Step;
 const Builder = build.Builder;
 const LibExeObjStep = build.LibExeObjStep;
+const WriteFileStep = build.WriteFileStep;
 const fs = std.fs;
 const mem = std.mem;
 const process = std.process;
@@ -42,6 +43,10 @@ pub const RunStep = struct {
 
     pub const Arg = union(enum) {
         Artifact: *LibExeObjStep,
+        WriteFile: struct {
+            step: *WriteFileStep,
+            file_name: []const u8,
+        },
         Bytes: []u8,
     };
 
@@ -62,6 +67,16 @@ pub const RunStep = struct {
         self.step.dependOn(&artifact.step);
     }
 
+    pub fn addWriteFileArg(self: *RunStep, write_file: *WriteFileStep, file_name: []const u8) void {
+        self.argv.append(Arg{
+            .WriteFile = .{
+                .step = write_file,
+                .file_name = file_name,
+            },
+        }) catch unreachable;
+        self.step.dependOn(&write_file.step);
+    }
+
     pub fn addArg(self: *RunStep, arg: []const u8) void {
         self.argv.append(Arg{ .Bytes = self.builder.dupe(arg) }) catch unreachable;
     }
@@ -142,6 +157,9 @@ pub const RunStep = struct {
         for (self.argv.span()) |arg| {
             switch (arg) {
                 Arg.Bytes => |bytes| try argv_list.append(bytes),
+                Arg.WriteFile => |file| {
+                    try argv_list.append(file.step.getOutputPath(file.file_name));
+                },
                 Arg.Artifact => |artifact| {
                     if (artifact.target.isWindows()) {
                         // On Windows we don't have rpaths so we have to add .dll search paths to PATH