mirror of
https://github.com/ziglang/zig.git
synced 2026-01-23 15:55:28 +00:00
This is necessary in two cases: * On POSIX, the exe path (`argv[0]`) must contain a path separator * Some programs might treat a file named e.g. `-foo` as a flag, which can be avoided by passing `./-foo` Rather than detecting these two cases, just always include the prefix; there's no harm in it. Also, if the cwd is specified, include it in the manifest. If the user has set the cwd of a Run step, it is clearly because this affects the behavior of the executable somehow, so that cwd path should be a part of the step's manifest. Resolves: #24216
31 lines
1.1 KiB
Zig
31 lines
1.1 KiB
Zig
pub fn build(b: *Build) void {
|
|
const exe = b.addExecutable(.{
|
|
.name = "check_file_exists",
|
|
.root_module = b.createModule(.{
|
|
.target = b.graph.host,
|
|
.optimize = .Debug,
|
|
.root_source_file = b.path("check_file_exists.zig"),
|
|
}),
|
|
});
|
|
|
|
const test_step = b.step("test", "Test it");
|
|
b.default_step = test_step;
|
|
|
|
test_step.dependOn(addCheck(b, exe, ".", null));
|
|
test_step.dependOn(addCheck(b, exe, "..", b.path("..")));
|
|
test_step.dependOn(addCheck(b, exe, "exe dir", exe.getEmittedBin().dirname()));
|
|
test_step.dependOn(addCheck(b, exe, "exe dir/..", exe.getEmittedBin().dirname().dirname()));
|
|
test_step.dependOn(addCheck(b, exe, "./empty_dir", b.path("empty_dir")));
|
|
}
|
|
|
|
fn addCheck(b: *Build, exe: *Build.Step.Compile, cwd_name: []const u8, opt_cwd: ?Build.LazyPath) *Build.Step {
|
|
const run = b.addRunArtifact(exe);
|
|
if (opt_cwd) |cwd| run.setCwd(cwd);
|
|
run.addFileArg(b.path("file_that_exists.txt"));
|
|
run.setName(b.fmt("check in '{s}'", .{cwd_name}));
|
|
run.expectExitCode(0);
|
|
return &run.step;
|
|
}
|
|
|
|
const Build = @import("std").Build;
|