feature. See also
. The project being documented here (as the example) is the Zig library itself.
Run.rerunInFuzzMode
pub fn rerunInFuzzMode(
run: *Run,
run_index: Configuration.Step.Index,
fuzz: *Fuzz,
prog_node: std.Progress.Node,
) !void
File
Code
pub fn rerunInFuzzMode(
run: *Run,
run_index: Configuration.Step.Index,
fuzz: *Fuzz,
prog_node: std.Progress.Node,
) !void {
const maker = fuzz.maker;
const graph = maker.graph;
const step = maker.stepByIndex(run_index);
const io = graph.io;
const gpa = maker.gpa;
const conf = &maker.scanned_config.configuration;
const conf_step = run_index.ptr(conf);
const conf_run = conf_step.extended.get(conf.extra).run;
const cache_root = graph.local_cache_root;
var arena_allocator: std.heap.ArenaAllocator = .init(gpa);
defer arena_allocator.deinit();
const arena = arena_allocator.allocator();
var argv_list: std.ArrayList([]const u8) = .empty;
defer argv_list.deinit(gpa);
for (conf_run.args.slice) |arg_index| {
const arg = arg_index.get(conf);
try argv_list.ensureUnusedCapacity(gpa, 1);
switch (arg.flags.tag) {
.string => {
const prefix = arg.prefix.value.?.slice(conf);
argv_list.appendAssumeCapacity(prefix);
},
.path_file => {
const prefix = if (arg.prefix.value) |p| p.slice(conf) else "";
const suffix = if (arg.suffix.value) |p| p.slice(conf) else "";
const file_path = try maker.resolveLazyPathIndex(arena, arg.path.value.?, run_index);
argv_list.appendAssumeCapacity(try mem.concat(arena, u8, &.{
prefix, try convertPathArg(arena, run_index, maker, file_path, arg.flags.make_absolute), suffix,
}));
},
.path_directory => {
const prefix = if (arg.prefix.value) |p| p.slice(conf) else "";
const suffix = if (arg.suffix.value) |p| p.slice(conf) else "";
const file_path = try maker.resolveLazyPathIndex(arena, arg.path.value.?, run_index);
const resolved_arg = try mem.concat(arena, u8, &.{
prefix, try convertPathArg(arena, run_index, maker, file_path, arg.flags.make_absolute), suffix,
});
argv_list.appendAssumeCapacity(resolved_arg);
},
.file_content => {
const prefix = if (arg.prefix.value) |p| p.slice(conf) else "";
const suffix = if (arg.suffix.value) |p| p.slice(conf) else "";
const file_path = try maker.resolveLazyPathIndex(arena, arg.path.value.?, run_index);
var result: std.Io.Writer.Allocating = .init(arena);
result.writer.writeAll(prefix) catch return error.OutOfMemory;
const file = file_path.root_dir.handle.openFile(io, file_path.sub_path, .{}) catch |err|
return step.fail(maker, "unable to open input file {f}: {t}", .{ file_path, err });
defer file.close(io);
var file_reader = file.reader(io, &.{});
_ = file_reader.interface.streamRemaining(&result.writer) catch |err| switch (err) {
error.ReadFailed => switch (file_reader.err.?) {
error.Canceled => |e| return e,
else => |e| return step.fail(maker, "failed to read from {f}: {t}", .{ file_path, e }),
},
error.WriteFailed => return error.OutOfMemory,
};
result.writer.writeAll(suffix) catch return error.OutOfMemory;
argv_list.appendAssumeCapacity(result.written());
},
.artifact => {
const prefix = if (arg.prefix.value) |p| p.slice(conf) else "";
const suffix = if (arg.suffix.value) |p| p.slice(conf) else "";
const producer_index = arg.producer.value.?;
const producer_step = producer_index.ptr(conf);
const producer = producer_step.extended.get(conf.extra).compile;
const producer_make_comp_step = maker.stepByIndex(producer_index);
const producer_make_comp = &producer_make_comp_step.extended.compile;
const file_path: Path = if (producer_index == conf_run.producer.value.?)
run.rebuilt_executable.?
else
producer_make_comp.installed_path orelse
maker.generatedPath(producer.generated_bin.value.?).*;
argv_list.appendAssumeCapacity(try mem.concat(arena, u8, &.{
prefix, try convertPathArg(arena, run_index, maker, file_path, arg.flags.make_absolute), suffix,
}));
},
.output_file => unreachable,
.output_directory => unreachable,
.passthru => unreachable,
}
}
if (conf_run.flags.test_runner_mode) {
const cache_dir_string = try convertPathArg(arena, run_index, maker, .{ .root_dir = cache_root }, false);
try argv_list.ensureUnusedCapacity(gpa, 3);
argv_list.appendAssumeCapacity(try arena.print("--cache-dir={s}", .{cache_dir_string}));
argv_list.appendAssumeCapacity(try arena.print("--seed=0x{x}", .{graph.random_seed}));
argv_list.appendAssumeCapacity("--listen=-");
}
step.clearFailedCommand(gpa);
const has_side_effects = false;
var rand_int: u64 = undefined;
io.random(@ptrCast(&rand_int));
const tmp_dir_path = "tmp" ++ Dir.path.sep_str ++ std.fmt.hex(rand_int);
try runCommand(arena, run, run_index, maker, prog_node, argv_list.items, has_side_effects, tmp_dir_path, .{
.fuzz = fuzz,
});
}