aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-09-11 17:23:36 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-09-11 17:23:36 -0400
commit9227315bf24238c05c0c01a9f516449aa8525e41 (patch)
treec7d3b147b905cf7a378a9f981d9c132c4d6a545e /std
parent15c67d2d50aae11dd425ad2629ebc9770fb95f30 (diff)
downloadzig-9227315bf24238c05c0c01a9f516449aa8525e41.tar.gz
zig-9227315bf24238c05c0c01a9f516449aa8525e41.zip
zig build: better placement of test exe artifact
Diffstat (limited to 'std')
-rw-r--r--std/build.zig24
1 files changed, 24 insertions, 0 deletions
diff --git a/std/build.zig b/std/build.zig
index 4e323eaf7b..0ef6109bc8 100644
--- a/std/build.zig
+++ b/std/build.zig
@@ -1641,6 +1641,7 @@ pub const TestStep = struct {
lib_paths: ArrayList([]const u8),
object_files: ArrayList([]const u8),
no_rosegment: bool,
+ output_path: ?[]const u8,
pub fn init(builder: *Builder, root_src: []const u8) TestStep {
const step_name = builder.fmt("test {}", root_src);
@@ -1659,6 +1660,7 @@ pub const TestStep = struct {
.lib_paths = ArrayList([]const u8).init(builder.allocator),
.object_files = ArrayList([]const u8).init(builder.allocator),
.no_rosegment = false,
+ .output_path = null,
};
}
@@ -1682,6 +1684,24 @@ pub const TestStep = struct {
self.build_mode = mode;
}
+ pub fn setOutputPath(self: *TestStep, file_path: []const u8) void {
+ self.output_path = file_path;
+
+ // catch a common mistake
+ if (mem.eql(u8, self.builder.pathFromRoot(file_path), self.builder.pathFromRoot("."))) {
+ debug.panic("setOutputPath wants a file path, not a directory\n");
+ }
+ }
+
+ pub fn getOutputPath(self: *TestStep) []const u8 {
+ if (self.output_path) |output_path| {
+ return output_path;
+ } else {
+ const basename = self.builder.fmt("test{}", self.target.exeFileExt());
+ return os.path.join(self.builder.allocator, self.builder.cache_root, basename) catch unreachable;
+ }
+ }
+
pub fn linkSystemLibrary(self: *TestStep, name: []const u8) void {
self.link_libs.put(name) catch unreachable;
}
@@ -1746,6 +1766,10 @@ pub const TestStep = struct {
builtin.Mode.ReleaseSmall => try zig_args.append("--release-small"),
}
+ const output_path = builder.pathFromRoot(self.getOutputPath());
+ try zig_args.append("--output");
+ try zig_args.append(output_path);
+
switch (self.target) {
Target.Native => {},
Target.Cross => |cross_target| {