mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
std: add prefixed versions of addFileSource and addDirectorySource to Step.Run
This commit is contained in:
parent
49ac816e36
commit
44df3a148b
@ -112,12 +112,17 @@ pub const StdIo = union(enum) {
|
||||
|
||||
pub const Arg = union(enum) {
|
||||
artifact: *Step.Compile,
|
||||
file_source: std.Build.FileSource,
|
||||
directory_source: std.Build.FileSource,
|
||||
file_source: PrefixedFileSource,
|
||||
directory_source: PrefixedFileSource,
|
||||
bytes: []u8,
|
||||
output: *Output,
|
||||
};
|
||||
|
||||
pub const PrefixedFileSource = struct {
|
||||
prefix: []const u8,
|
||||
file_source: std.Build.FileSource,
|
||||
};
|
||||
|
||||
pub const Output = struct {
|
||||
generated_file: std.Build.GeneratedFile,
|
||||
prefix: []const u8,
|
||||
@ -145,9 +150,9 @@ pub fn setName(self: *Run, name: []const u8) void {
|
||||
self.rename_step_with_output_arg = false;
|
||||
}
|
||||
|
||||
pub fn enableTestRunnerMode(rs: *Run) void {
|
||||
rs.stdio = .zig_test;
|
||||
rs.addArgs(&.{"--listen=-"});
|
||||
pub fn enableTestRunnerMode(self: *Run) void {
|
||||
self.stdio = .zig_test;
|
||||
self.addArgs(&.{"--listen=-"});
|
||||
}
|
||||
|
||||
pub fn addArtifactArg(self: *Run, artifact: *Step.Compile) void {
|
||||
@ -158,43 +163,59 @@ pub fn addArtifactArg(self: *Run, artifact: *Step.Compile) void {
|
||||
/// This provides file path as a command line argument to the command being
|
||||
/// run, and returns a FileSource which can be used as inputs to other APIs
|
||||
/// throughout the build system.
|
||||
pub fn addOutputFileArg(rs: *Run, basename: []const u8) std.Build.FileSource {
|
||||
return addPrefixedOutputFileArg(rs, "", basename);
|
||||
pub fn addOutputFileArg(self: *Run, basename: []const u8) std.Build.FileSource {
|
||||
return self.addPrefixedOutputFileArg("", basename);
|
||||
}
|
||||
|
||||
pub fn addPrefixedOutputFileArg(
|
||||
rs: *Run,
|
||||
self: *Run,
|
||||
prefix: []const u8,
|
||||
basename: []const u8,
|
||||
) std.Build.FileSource {
|
||||
const b = rs.step.owner;
|
||||
const b = self.step.owner;
|
||||
|
||||
const output = b.allocator.create(Output) catch @panic("OOM");
|
||||
output.* = .{
|
||||
.prefix = prefix,
|
||||
.basename = basename,
|
||||
.generated_file = .{ .step = &rs.step },
|
||||
.generated_file = .{ .step = &self.step },
|
||||
};
|
||||
rs.argv.append(.{ .output = output }) catch @panic("OOM");
|
||||
self.argv.append(.{ .output = output }) catch @panic("OOM");
|
||||
|
||||
if (rs.rename_step_with_output_arg) {
|
||||
rs.setName(b.fmt("{s} ({s})", .{ rs.step.name, basename }));
|
||||
if (self.rename_step_with_output_arg) {
|
||||
self.setName(b.fmt("{s} ({s})", .{ self.step.name, basename }));
|
||||
}
|
||||
|
||||
return .{ .generated = &output.generated_file };
|
||||
}
|
||||
|
||||
pub fn addFileSourceArg(self: *Run, file_source: std.Build.FileSource) void {
|
||||
self.argv.append(.{
|
||||
.file_source = file_source.dupe(self.step.owner),
|
||||
}) catch @panic("OOM");
|
||||
self.addPrefixedFileSourceArg("", file_source);
|
||||
}
|
||||
|
||||
pub fn addPrefixedFileSourceArg(self: *Run, prefix: []const u8, file_source: std.Build.FileSource) void {
|
||||
const b = self.step.owner;
|
||||
|
||||
const prefixed_file_source: PrefixedFileSource = .{
|
||||
.prefix = b.dupe(prefix),
|
||||
.file_source = file_source.dupe(b),
|
||||
};
|
||||
self.argv.append(.{ .file_source = prefixed_file_source }) catch @panic("OOM");
|
||||
file_source.addStepDependencies(&self.step);
|
||||
}
|
||||
|
||||
pub fn addDirectorySourceArg(self: *Run, directory_source: std.Build.FileSource) void {
|
||||
self.argv.append(.{
|
||||
.directory_source = directory_source.dupe(self.step.owner),
|
||||
}) catch @panic("OOM");
|
||||
self.addPrefixedDirectorySourceArg("", directory_source);
|
||||
}
|
||||
|
||||
pub fn addPrefixedDirectorySourceArg(self: *Run, prefix: []const u8, directory_source: std.Build.FileSource) void {
|
||||
const b = self.step.owner;
|
||||
|
||||
const prefixed_directory_source: PrefixedFileSource = .{
|
||||
.prefix = b.dupe(prefix),
|
||||
.file_source = directory_source.dupe(b),
|
||||
};
|
||||
self.argv.append(.{ .directory_source = prefixed_directory_source }) catch @panic("OOM");
|
||||
directory_source.addStepDependencies(&self.step);
|
||||
}
|
||||
|
||||
@ -395,13 +416,15 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
|
||||
man.hash.addBytes(bytes);
|
||||
},
|
||||
.file_source => |file| {
|
||||
const file_path = file.getPath(b);
|
||||
try argv_list.append(file_path);
|
||||
const file_path = file.file_source.getPath(b);
|
||||
try argv_list.append(b.fmt("{s}{s}", .{ file.prefix, file_path }));
|
||||
man.hash.addBytes(file.prefix);
|
||||
_ = try man.addFile(file_path, null);
|
||||
},
|
||||
.directory_source => |file| {
|
||||
const file_path = file.getPath(b);
|
||||
try argv_list.append(file_path);
|
||||
const file_path = file.file_source.getPath(b);
|
||||
try argv_list.append(b.fmt("{s}{s}", .{ file.prefix, file_path }));
|
||||
man.hash.addBytes(file.prefix);
|
||||
man.hash.addBytes(file_path);
|
||||
},
|
||||
.artifact => |artifact| {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user