authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-20 18:07:51-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:36-07:00
log619f23b3c7a5276ab974478223ec41ce81c91b6c
treee4d5b01859781f8c95356bc38643bb160ccbb4fb
parent91a7ea4ff41fd21e7465ddfe68bace533ab8c77d

CLI: support both --fork=[path] and --fork [path]


3 files changed, 24 insertions(+), 15 deletions(-)

lib/compiler/Maker/ScannedConfig.zig+1-1
...@@ -343,7 +343,7 @@ pub fn printUsage(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void {...@@ -343,7 +343,7 @@ pub fn printUsage(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void {
343 \\ --fetch[=mode] Fetch dependency tree (optionally choose laziness) and exit343 \\ --fetch[=mode] Fetch dependency tree (optionally choose laziness) and exit
344 \\ needed (Default) Lazy dependencies are fetched as needed344 \\ needed (Default) Lazy dependencies are fetched as needed
345 \\ all Lazy dependencies are always fetched345 \\ all Lazy dependencies are always fetched
346 \\ --fork=[path] Override one or more projects from dependency tree346 \\ --fork=[path], --fork [path] Override one or more projects from dependency tree
347 \\347 \\
348 \\Advanced Options:348 \\Advanced Options:
349 \\ -freference-trace[=num] How many lines of reference trace should be shown per compile error349 \\ -freference-trace[=num] How many lines of reference trace should be shown per compile error
lib/compiler/Maker/Step.zig+3-3
...@@ -728,19 +728,19 @@ fn failWithCacheError(...@@ -728,19 +728,19 @@ fn failWithCacheError(
728 switch (err) {728 switch (err) {
729 error.CacheCheckFailed => switch (man.diagnostic) {729 error.CacheCheckFailed => switch (man.diagnostic) {
730 .none => unreachable,730 .none => unreachable,
731 .manifest_create, .manifest_read, .manifest_lock => |e| return s.fail(maker, "failed to check cache: {t} {t}", .{731 .manifest_create, .manifest_read, .manifest_lock => |e| return s.fail(maker, "failed checking cache: {t} {t}", .{
732 man.diagnostic, e,732 man.diagnostic, e,
733 }),733 }),
734 .file_open, .file_stat, .file_read, .file_hash => |op| {734 .file_open, .file_stat, .file_read, .file_hash => |op| {
735 const pp = man.files.keys()[op.file_index].prefixed_path;735 const pp = man.files.keys()[op.file_index].prefixed_path;
736 const prefix = man.cache.prefixes()[pp.prefix].path orelse "";736 const prefix = man.cache.prefixes()[pp.prefix].path orelse "";
737 return s.fail(maker, "failed to check cache: '{s}{c}{s}' {t} {t}", .{737 return s.fail(maker, "failed checking cache: {s}{c}{s} {t} {t}", .{
738 prefix, Dir.path.sep, pp.sub_path, man.diagnostic, op.err,738 prefix, Dir.path.sep, pp.sub_path, man.diagnostic, op.err,
739 });739 });
740 },740 },
741 },741 },
742 error.OutOfMemory, error.Canceled => |e| return e,742 error.OutOfMemory, error.Canceled => |e| return e,
743 error.InvalidFormat => return s.fail(maker, "failed to check cache: invalid manifest file format", .{}),743 error.InvalidFormat => return s.fail(maker, "failed checking cache: invalid manifest file format", .{}),
744 }744 }
745}745}
746746
src/main.zig+20-11
...@@ -5082,17 +5082,12 @@ fn cmdBuild(...@@ -5082,17 +5082,12 @@ fn cmdBuild(
5082 fetch_mode = std.meta.stringToEnum(Package.Fetch.JobQueue.Mode, sub_arg) orelse5082 fetch_mode = std.meta.stringToEnum(Package.Fetch.JobQueue.Mode, sub_arg) orelse
5083 fatal("expected [needed|all] after '--fetch=', found '{s}'", .{sub_arg});5083 fatal("expected [needed|all] after '--fetch=', found '{s}'", .{sub_arg});
5084 } else if (mem.cutPrefix(u8, arg, "--fork=")) |sub_arg| {5084 } else if (mem.cutPrefix(u8, arg, "--fork=")) |sub_arg| {
5085 try forks.append(arena, .{5085 try forks.append(arena, .init(sub_arg));
5086 .manifest_ast = undefined,5086 continue;
5087 .manifest = undefined,5087 } else if (mem.eql(u8, arg, "--fork")) {
5088 .error_bundle = undefined,5088 if (i + 1 >= args.len) fatal("expected argument after: {s}", .{arg});
5089 .arena_allocator = undefined,5089 i += 1;
5090 .path = .{5090 try forks.append(arena, .init(args[i]));
5091 .root_dir = .cwd(),
5092 .sub_path = sub_arg,
5093 },
5094 .failed = false,
5095 });
5096 continue;5091 continue;
5097 } else if (mem.cutPrefix(u8, arg, "-freference-trace=")) |num| {5092 } else if (mem.cutPrefix(u8, arg, "-freference-trace=")) |num| {
5098 reference_trace = std.fmt.parseUnsigned(u32, num, 10) catch |err| {5093 reference_trace = std.fmt.parseUnsigned(u32, num, 10) catch |err| {
...@@ -5874,6 +5869,20 @@ const Fork = struct {...@@ -5874,6 +5869,20 @@ const Fork = struct {
5874 failed: bool,5869 failed: bool,
5875 arena_allocator: std.heap.ArenaAllocator,5870 arena_allocator: std.heap.ArenaAllocator,
58765871
5872 fn init(cwd_relative_path: []const u8) Fork {
5873 return .{
5874 .manifest_ast = undefined,
5875 .manifest = undefined,
5876 .error_bundle = undefined,
5877 .arena_allocator = undefined,
5878 .path = .{
5879 .root_dir = .cwd(),
5880 .sub_path = cwd_relative_path,
5881 },
5882 .failed = false,
5883 };
5884 }
5885
5877 fn load(io: Io, gpa: Allocator, fork: *Fork, color: Color) Io.Cancelable!void {5886 fn load(io: Io, gpa: Allocator, fork: *Fork, color: Color) Io.Cancelable!void {
5878 loadFallible(io, gpa, fork, color) catch |err| switch (err) {5887 loadFallible(io, gpa, fork, color) catch |err| switch (err) {
5879 error.Canceled => |e| return e,5888 error.Canceled => |e| return e,