Added global-cache argument to build system + removed extra args.

* Field global_cache_root was added to Builder struct along with
mandatory argument for build_runner.zig. Logic for using the custom
global cache was also added.

* The arguments --cache-dir and --global-cache-dir are no longer passed
directly through to build_runner.zig and are instead only passed through the
mandatory cache_root and global_cache_root arguments.
This commit is contained in:
antlilja 2020-12-01 16:47:47 +01:00 committed by Andrew Kelley
parent 235d56cb82
commit ea70a983ba
3 changed files with 32 additions and 4 deletions

View file

@ -61,6 +61,7 @@ pub const Builder = struct {
installed_files: ArrayList(InstalledFile),
build_root: []const u8,
cache_root: []const u8,
global_cache_root: []const u8,
release_mode: ?builtin.Mode,
is_release: bool,
override_lib_dir: ?[]const u8,
@ -126,6 +127,7 @@ pub const Builder = struct {
zig_exe: []const u8,
build_root: []const u8,
cache_root: []const u8,
global_cache_root: []const u8,
) !*Builder {
const env_map = try allocator.create(BufMap);
env_map.* = try process.getEnvMap(allocator);
@ -135,6 +137,7 @@ pub const Builder = struct {
.zig_exe = zig_exe,
.build_root = build_root,
.cache_root = try fs.path.relative(allocator, build_root, cache_root),
.global_cache_root = global_cache_root,
.verbose = false,
.verbose_tokenize = false,
.verbose_ast = false,
@ -1128,7 +1131,13 @@ test "builder.findProgram compiles" {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const builder = try Builder.create(&arena.allocator, "zig", "zig-cache", "zig-cache");
const builder = try Builder.create(
&arena.allocator,
"zig",
"zig-cache",
"zig-cache",
"zig-cache",
);
defer builder.destroy();
_ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;
}
@ -2124,6 +2133,9 @@ pub const LibExeObjStep = struct {
try zig_args.append("--cache-dir");
try zig_args.append(builder.pathFromRoot(builder.cache_root));
try zig_args.append("--global-cache-dir");
try zig_args.append(builder.pathFromRoot(builder.global_cache_root));
zig_args.append("--name") catch unreachable;
zig_args.append(self.name) catch unreachable;
@ -2735,6 +2747,7 @@ test "Builder.dupePkg()" {
"test",
"test",
"test",
"test",
);
defer builder.destroy();
@ -2778,6 +2791,7 @@ test "LibExeObjStep.addBuildOption" {
"test",
"test",
"test",
"test",
);
defer builder.destroy();
@ -2815,6 +2829,7 @@ test "LibExeObjStep.addPackage" {
"test",
"test",
"test",
"test",
);
defer builder.destroy();

View file

@ -41,8 +41,18 @@ pub fn main() !void {
warn("Expected third argument to be cache root directory path\n", .{});
return error.InvalidArgs;
};
const global_cache_root = nextArg(args, &arg_idx) orelse {
warn("Expected third argument to be global cache root directory path\n", .{});
return error.InvalidArgs;
};
const builder = try Builder.create(allocator, zig_exe, build_root, cache_root);
const builder = try Builder.create(
allocator,
zig_exe,
build_root,
cache_root,
global_cache_root,
);
defer builder.destroy();
var targets = ArrayList([]const u8).init(allocator);

View file

@ -2228,6 +2228,9 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
const argv_index_cache_dir = child_argv.items.len;
_ = try child_argv.addOne();
const argv_index_global_cache_dir = child_argv.items.len;
_ = try child_argv.addOne();
{
var i: usize = 0;
while (i < args.len) : (i += 1) {
@ -2248,13 +2251,11 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
if (i + 1 >= args.len) fatal("expected argument after '{}'", .{arg});
i += 1;
override_local_cache_dir = args[i];
try child_argv.appendSlice(&[_][]const u8{ arg, args[i] });
continue;
} else if (mem.eql(u8, arg, "--global-cache-dir")) {
if (i + 1 >= args.len) fatal("expected argument after '{}'", .{arg});
i += 1;
override_global_cache_dir = args[i];
try child_argv.appendSlice(&[_][]const u8{ arg, args[i] });
continue;
}
}
@ -2339,6 +2340,8 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
};
defer global_cache_directory.handle.close();
child_argv.items[argv_index_global_cache_dir] = global_cache_directory.path orelse cwd_path;
var local_cache_directory: Compilation.Directory = l: {
if (override_local_cache_dir) |local_cache_dir_path| {
break :l .{