diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2024-05-04 15:12:24 -0400 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2024-05-05 15:58:08 -0400 |
| commit | dee9f82f69db0d034251b844e0bc4083a1b25fdd (patch) | |
| tree | 14adb7ca55844ef04872501174cd006812edbf43 /test | |
| parent | e3424332d3fa1264e1f6861b76bb0d1b2996728d (diff) | |
| download | zig-dee9f82f69db0d034251b844e0bc4083a1b25fdd.tar.gz zig-dee9f82f69db0d034251b844e0bc4083a1b25fdd.zip | |
Run: add output directory arguments
This allows running commands that take an output directory argument. The
main thing that was needed for this feature was generated file subpaths,
to allow access to the files in a generated directory. Additionally, a
minor change was required to so that the correct directory is created
for output directory args.
Diffstat (limited to 'test')
| -rw-r--r-- | test/standalone/build.zig.zon | 3 | ||||
| -rw-r--r-- | test/standalone/run_output_paths/build.zig | 40 | ||||
| -rw-r--r-- | test/standalone/run_output_paths/create_file.zig | 19 | ||||
| -rw-r--r-- | test/standalone/windows_resources/build.zig | 2 |
4 files changed, 63 insertions, 1 deletions
diff --git a/test/standalone/build.zig.zon b/test/standalone/build.zig.zon index 7ddde1611a..e1b856a4be 100644 --- a/test/standalone/build.zig.zon +++ b/test/standalone/build.zig.zon @@ -164,6 +164,9 @@ .dependencyFromBuildZig = .{ .path = "dependencyFromBuildZig", }, + .run_output_paths = .{ + .path = "run_output_paths", + }, }, .paths = .{ "build.zig", diff --git a/test/standalone/run_output_paths/build.zig b/test/standalone/run_output_paths/build.zig new file mode 100644 index 0000000000..f4c7254d8f --- /dev/null +++ b/test/standalone/run_output_paths/build.zig @@ -0,0 +1,40 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const test_step = b.step("test", "Test it"); + b.default_step = test_step; + + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const create_file_exe = b.addExecutable(.{ + .name = "create_file", + .root_source_file = b.path("create_file.zig"), + .target = target, + .optimize = optimize, + }); + + const create_first = b.addRunArtifact(create_file_exe); + const first_dir = create_first.addOutputDirectoryArg("first"); + create_first.addArg("hello1.txt"); + test_step.dependOn(&b.addCheckFile(first_dir.path(b, "hello1.txt"), .{ .expected_matches = &.{ + std.fs.path.sep_str ++ + \\first + \\hello1.txt + \\Hello, world! + \\ + , + } }).step); + + const create_second = b.addRunArtifact(create_file_exe); + const second_dir = create_second.addPrefixedOutputDirectoryArg("--dir=", "second"); + create_second.addArg("hello2.txt"); + test_step.dependOn(&b.addCheckFile(second_dir.path(b, "hello2.txt"), .{ .expected_matches = &.{ + std.fs.path.sep_str ++ + \\second + \\hello2.txt + \\Hello, world! + \\ + , + } }).step); +} diff --git a/test/standalone/run_output_paths/create_file.zig b/test/standalone/run_output_paths/create_file.zig new file mode 100644 index 0000000000..041ebc3e50 --- /dev/null +++ b/test/standalone/run_output_paths/create_file.zig @@ -0,0 +1,19 @@ +const std = @import("std"); + +pub fn main() !void { + var args = try std.process.argsWithAllocator(std.heap.page_allocator); + _ = args.skip(); + const dir_name = args.next().?; + const dir = try std.fs.cwd().openDir(if (std.mem.startsWith(u8, dir_name, "--dir=")) + dir_name["--dir=".len..] + else + dir_name, .{}); + const file_name = args.next().?; + const file = try dir.createFile(file_name, .{}); + try file.writer().print( + \\{s} + \\{s} + \\Hello, world! + \\ + , .{ dir_name, file_name }); +} diff --git a/test/standalone/windows_resources/build.zig b/test/standalone/windows_resources/build.zig index 15130d3b87..da88659b4d 100644 --- a/test/standalone/windows_resources/build.zig +++ b/test/standalone/windows_resources/build.zig @@ -36,7 +36,7 @@ fn add( .file = b.path("res/zig.rc"), .flags = &.{"/c65001"}, // UTF-8 code page .include_paths = &.{ - .{ .generated = &generated_h_step.generated_directory }, + .{ .generated = .{ .file = &generated_h_step.generated_directory } }, }, }); exe.rc_includes = switch (rc_includes) { |
