authorgravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2020-12-01 16:47:47+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-10 17:00:38-07:00
logea70a983ba54efe1d73b85d393596dcb98e19c02
tree425c5a97c39b42decdad4edae498f978835a531d
parent235d56cb828b97cb72895b310119e08abb0fe907

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.

3 files changed, 32 insertions(+), 4 deletions(-)

lib/std/build.zig+16-1
......@@ -61,6 +61,7 @@ pub const Builder = struct {
6161 installed_files: ArrayList(InstalledFile),
6262 build_root: []const u8,
6363 cache_root: []const u8,
64 global_cache_root: []const u8,
6465 release_mode: ?builtin.Mode,
6566 is_release: bool,
6667 override_lib_dir: ?[]const u8,
......@@ -126,6 +127,7 @@ pub const Builder = struct {
126127 zig_exe: []const u8,
127128 build_root: []const u8,
128129 cache_root: []const u8,
130 global_cache_root: []const u8,
129131 ) !*Builder {
130132 const env_map = try allocator.create(BufMap);
131133 env_map.* = try process.getEnvMap(allocator);
......@@ -135,6 +137,7 @@ pub const Builder = struct {
135137 .zig_exe = zig_exe,
136138 .build_root = build_root,
137139 .cache_root = try fs.path.relative(allocator, build_root, cache_root),
140 .global_cache_root = global_cache_root,
138141 .verbose = false,
139142 .verbose_tokenize = false,
140143 .verbose_ast = false,
......@@ -1128,7 +1131,13 @@ test "builder.findProgram compiles" {
11281131 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
11291132 defer arena.deinit();
11301133
1131 const builder = try Builder.create(&arena.allocator, "zig", "zig-cache", "zig-cache");
1134 const builder = try Builder.create(
1135 &arena.allocator,
1136 "zig",
1137 "zig-cache",
1138 "zig-cache",
1139 "zig-cache",
1140 );
11321141 defer builder.destroy();
11331142 _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;
11341143}
......@@ -2124,6 +2133,9 @@ pub const LibExeObjStep = struct {
21242133 try zig_args.append("--cache-dir");
21252134 try zig_args.append(builder.pathFromRoot(builder.cache_root));
21262135
2136 try zig_args.append("--global-cache-dir");
2137 try zig_args.append(builder.pathFromRoot(builder.global_cache_root));
2138
21272139 zig_args.append("--name") catch unreachable;
21282140 zig_args.append(self.name) catch unreachable;
21292141
......@@ -2735,6 +2747,7 @@ test "Builder.dupePkg()" {
27352747 "test",
27362748 "test",
27372749 "test",
2750 "test",
27382751 );
27392752 defer builder.destroy();
27402753
......@@ -2778,6 +2791,7 @@ test "LibExeObjStep.addBuildOption" {
27782791 "test",
27792792 "test",
27802793 "test",
2794 "test",
27812795 );
27822796 defer builder.destroy();
27832797
......@@ -2815,6 +2829,7 @@ test "LibExeObjStep.addPackage" {
28152829 "test",
28162830 "test",
28172831 "test",
2832 "test",
28182833 );
28192834 defer builder.destroy();
28202835
lib/std/special/build_runner.zig+11-1
......@@ -41,8 +41,18 @@ pub fn main() !void {
4141 warn("Expected third argument to be cache root directory path\n", .{});
4242 return error.InvalidArgs;
4343 };
44 const global_cache_root = nextArg(args, &arg_idx) orelse {
45 warn("Expected third argument to be global cache root directory path\n", .{});
46 return error.InvalidArgs;
47 };
4448
45 const builder = try Builder.create(allocator, zig_exe, build_root, cache_root);
49 const builder = try Builder.create(
50 allocator,
51 zig_exe,
52 build_root,
53 cache_root,
54 global_cache_root,
55 );
4656 defer builder.destroy();
4757
4858 var targets = ArrayList([]const u8).init(allocator);
src/main.zig+5-2
......@@ -2228,6 +2228,9 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
22282228 const argv_index_cache_dir = child_argv.items.len;
22292229 _ = try child_argv.addOne();
22302230
2231 const argv_index_global_cache_dir = child_argv.items.len;
2232 _ = try child_argv.addOne();
2233
22312234 {
22322235 var i: usize = 0;
22332236 while (i < args.len) : (i += 1) {
......@@ -2248,13 +2251,11 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
22482251 if (i + 1 >= args.len) fatal("expected argument after '{}'", .{arg});
22492252 i += 1;
22502253 override_local_cache_dir = args[i];
2251 try child_argv.appendSlice(&[_][]const u8{ arg, args[i] });
22522254 continue;
22532255 } else if (mem.eql(u8, arg, "--global-cache-dir")) {
22542256 if (i + 1 >= args.len) fatal("expected argument after '{}'", .{arg});
22552257 i += 1;
22562258 override_global_cache_dir = args[i];
2257 try child_argv.appendSlice(&[_][]const u8{ arg, args[i] });
22582259 continue;
22592260 }
22602261 }
......@@ -2339,6 +2340,8 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
23392340 };
23402341 defer global_cache_directory.handle.close();
23412342
2343 child_argv.items[argv_index_global_cache_dir] = global_cache_directory.path orelse cwd_path;
2344
23422345 var local_cache_directory: Compilation.Directory = l: {
23432346 if (override_local_cache_dir) |local_cache_dir_path| {
23442347 break :l .{