mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 06:45:24 +00:00
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:
parent
a3de27ef3b
commit
26399b5249
@ -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;
|
||||
}
|
||||
@ -2196,6 +2205,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;
|
||||
|
||||
@ -2826,6 +2838,7 @@ test "Builder.dupePkg()" {
|
||||
"test",
|
||||
"test",
|
||||
"test",
|
||||
"test",
|
||||
);
|
||||
defer builder.destroy();
|
||||
|
||||
@ -2869,6 +2882,7 @@ test "LibExeObjStep.addBuildOption" {
|
||||
"test",
|
||||
"test",
|
||||
"test",
|
||||
"test",
|
||||
);
|
||||
defer builder.destroy();
|
||||
|
||||
@ -2906,6 +2920,7 @@ test "LibExeObjStep.addPackage" {
|
||||
"test",
|
||||
"test",
|
||||
"test",
|
||||
"test",
|
||||
);
|
||||
defer builder.destroy();
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -2260,6 +2260,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) {
|
||||
@ -2280,13 +2283,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;
|
||||
}
|
||||
}
|
||||
@ -2371,6 +2372,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 .{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user