authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-11 17:23:36-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-11 17:23:36-04:00
log9227315bf24238c05c0c01a9f516449aa8525e41
treec7d3b147b905cf7a378a9f981d9c132c4d6a545e
parent15c67d2d50aae11dd425ad2629ebc9770fb95f30
signaturelock-open Commit is signed but in an unrecognized format.

zig build: better placement of test exe artifact


1 files changed, 24 insertions(+), 0 deletions(-)

std/build.zig+24
......@@ -1641,6 +1641,7 @@ pub const TestStep = struct {
16411641 lib_paths: ArrayList([]const u8),
16421642 object_files: ArrayList([]const u8),
16431643 no_rosegment: bool,
1644 output_path: ?[]const u8,
16441645
16451646 pub fn init(builder: *Builder, root_src: []const u8) TestStep {
16461647 const step_name = builder.fmt("test {}", root_src);
......@@ -1659,6 +1660,7 @@ pub const TestStep = struct {
16591660 .lib_paths = ArrayList([]const u8).init(builder.allocator),
16601661 .object_files = ArrayList([]const u8).init(builder.allocator),
16611662 .no_rosegment = false,
1663 .output_path = null,
16621664 };
16631665 }
16641666
......@@ -1682,6 +1684,24 @@ pub const TestStep = struct {
16821684 self.build_mode = mode;
16831685 }
16841686
1687 pub fn setOutputPath(self: *TestStep, file_path: []const u8) void {
1688 self.output_path = file_path;
1689
1690 // catch a common mistake
1691 if (mem.eql(u8, self.builder.pathFromRoot(file_path), self.builder.pathFromRoot("."))) {
1692 debug.panic("setOutputPath wants a file path, not a directory\n");
1693 }
1694 }
1695
1696 pub fn getOutputPath(self: *TestStep) []const u8 {
1697 if (self.output_path) |output_path| {
1698 return output_path;
1699 } else {
1700 const basename = self.builder.fmt("test{}", self.target.exeFileExt());
1701 return os.path.join(self.builder.allocator, self.builder.cache_root, basename) catch unreachable;
1702 }
1703 }
1704
16851705 pub fn linkSystemLibrary(self: *TestStep, name: []const u8) void {
16861706 self.link_libs.put(name) catch unreachable;
16871707 }
......@@ -1746,6 +1766,10 @@ pub const TestStep = struct {
17461766 builtin.Mode.ReleaseSmall => try zig_args.append("--release-small"),
17471767 }
17481768
1769 const output_path = builder.pathFromRoot(self.getOutputPath());
1770 try zig_args.append("--output");
1771 try zig_args.append(output_path);
1772
17491773 switch (self.target) {
17501774 Target.Native => {},
17511775 Target.Cross => |cross_target| {