Appends the content of an input file to the command line arguments prepended with a string.
For example, a prefix of "-F" will result in the child process seeing something like this: "-Fmy file content"
The child process will see a single argument, even if the prefix and/or the file contain whitespace. This means that the entire file content up to EOF is rendered as one contiguous string, including escape sequences. Notably, any (trailing) newlines will show up like this: "hello,\nfile world!\n"
Modifications to the source file will be detected as a cache miss in subsequent builds, causing the child process to be re-executed.
This function may not be used to supply the first argument of a Run step.
Related:
addFileContentArg - same thing but without the prefixpub fn addFileContentArg2(run: *Run, lp: std.Build.LazyPath, options: ArgOptions) void
pub fn addFileContentArg2(run: *Run, lp: std.Build.LazyPath, options: ArgOptions) void {
const graph = run.step.owner.graph;
const arena = graph.arena;
// Some parts of this step's configure phase API rely on the first argument being somewhat
// transparent/readable, but the content of the file specified by `lp` remains completely
// opaque until its path can be resolved during the make phase.
if (run.argv.items.len == 0) {
@panic("'addFileContentArg'/'addPrefixedFileContentArg' cannot be first argument");
}
const file_content: DecoratedFileContent = .{
.prefix = graph.dupeString(options.prefix),
.lazy_path = lp.dupe(graph),
.suffix = graph.dupeString(options.suffix),
};
run.argv.append(arena, .{ .file_content = file_content }) catch @panic("OOM");
lp.addStepDependencies(&run.step);
}