| 1 | pub fn build(b: *Build) void { |
| 2 | const exe = b.addExecutable(.{ |
| 3 | .name = "check_file_exists", |
| 4 | .root_module = b.createModule(.{ |
| 5 | .target = b.graph.host, |
| 6 | .optimize = .debug, |
| 7 | .root_source_file = b.path("check_file_exists.zig"), |
| 8 | }), |
| 9 | }); |
| 10 | |
| 11 | const test_step = b.step("test", "Test it"); |
| 12 | b.default_step = test_step; |
| 13 | |
| 14 | test_step.dependOn(addCheck(b, exe, ".", null)); |
| 15 | test_step.dependOn(addCheck(b, exe, "..", b.path(".."))); |
| 16 | test_step.dependOn(addCheck(b, exe, "exe dir", exe.getEmittedBin().dirname())); |
| 17 | test_step.dependOn(addCheck(b, exe, "exe dir/..", exe.getEmittedBin().dirname().dirname())); |
| 18 | test_step.dependOn(addCheck(b, exe, "./empty_dir", b.path("empty_dir"))); |
| 19 | } |
| 20 | |
| 21 | fn addCheck(b: *Build, exe: *Build.Step.Compile, cwd_name: []const u8, opt_cwd: ?Build.LazyPath) *Build.Step { |
| 22 | const run = b.addRunArtifact(exe); |
| 23 | if (opt_cwd) |cwd| run.setCwd(cwd); |
| 24 | run.addFileArg(b.path("file_that_exists.txt")); |
| 25 | run.setName(b.fmt("check in '{s}'", .{cwd_name})); |
| 26 | run.expectExitCode(0); |
| 27 | return &run.step; |
| 28 | } |
| 29 | |
| 30 | const Build = @import("std").Build; |