Merge pull request #1494 from ziglang/stage1-caching

stage1 caching
This commit is contained in:
Andrew Kelley
2018-09-12 12:40:16 -04:00
committed by GitHub
30 changed files with 2686 additions and 577 deletions

View File

@@ -232,6 +232,8 @@ pub const Builder = struct {
}
pub fn make(self: *Builder, step_names: []const []const u8) !void {
try self.makePath(self.cache_root);
var wanted_steps = ArrayList(*Step).init(self.allocator);
defer wanted_steps.deinit();
@@ -1641,6 +1643,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 +1662,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 +1686,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 +1768,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| {