authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-20 19:58:39-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-20 19:58:39-07:00
logbc9fabcc3fb6c44ca0de8d21a0e7b0a46b404b78
treef792b43c08ded9dc3b744044781d71e4b437c170
parent3a9b16db446379d6fd22bd614e6741e1142b456a

zig fetch: add --debug-log [scope] arg


1 files changed, 21 insertions(+), 14 deletions(-)

src/main.zig+21-14
......@@ -1359,12 +1359,7 @@ fn buildOutputType(
13591359 } else if (mem.eql(u8, arg, "--zig-lib-dir")) {
13601360 override_lib_dir = args_iter.nextOrFatal();
13611361 } else if (mem.eql(u8, arg, "--debug-log")) {
1362 if (!build_options.enable_logging) {
1363 warn("Zig was compiled without logging enabled (-Dlog). --debug-log has no effect.", .{});
1364 _ = args_iter.nextOrFatal();
1365 } else {
1366 try log_scopes.append(arena, args_iter.nextOrFatal());
1367 }
1362 try addDebugLog(arena, args_iter.nextOrFatal());
13681363 } else if (mem.eql(u8, arg, "--listen")) {
13691364 const next_arg = args_iter.nextOrFatal();
13701365 if (mem.eql(u8, next_arg, "-")) {
......@@ -5098,11 +5093,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
50985093 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
50995094 try child_argv.appendSlice(arena, args[i .. i + 2]);
51005095 i += 1;
5101 if (!build_options.enable_logging) {
5102 warn("Zig was compiled without logging enabled (-Dlog). --debug-log has no effect.", .{});
5103 } else {
5104 try log_scopes.append(arena, args[i]);
5105 }
5096 try addDebugLog(arena, args[i]);
51065097 continue;
51075098 } else if (mem.eql(u8, arg, "--debug-compile-errors")) {
51085099 if (build_options.enable_debug_extensions) {
......@@ -5380,6 +5371,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
53805371 .hash_tok = .none,
53815372 .name_tok = 0,
53825373 .lazy_status = .eager,
5374 .remote_package_root = phantom_package_root,
53835375 .parent_package_root = phantom_package_root,
53845376 .parent_manifest_ast = null,
53855377 .prog_node = fetch_prog_node,
......@@ -5400,6 +5392,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
54005392
54015393 .module = build_mod,
54025394 };
5395
54035396 job_queue.all_fetches.appendAssumeCapacity(&fetch);
54045397
54055398 job_queue.table.putAssumeCapacityNoClobber(
......@@ -7034,6 +7027,7 @@ const usage_fetch =
70347027 \\ --cache-dir [path] Override path to local cache directory
70357028 \\ --pkg-dir [path] Override path to local package directory
70367029 \\ --debug-hash Print verbose hash information to stdout
7030 \\ --debug-log [scope] Enable printing debug/info log messages for scope
70377031 \\ --save Add the fetched package to build.zig.zon
70387032 \\ --save=[name] Add the fetched package to build.zig.zon as name
70397033 \\ --save-exact Add the fetched package to build.zig.zon, storing the URL verbatim
......@@ -7071,19 +7065,23 @@ fn cmdFetch(
70717065 try Io.File.stdout().writeStreamingAll(io, usage_fetch);
70727066 return cleanExit(io);
70737067 } else if (mem.eql(u8, arg, "--global-cache-dir")) {
7074 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
7068 if (i + 1 >= args.len) fatal("expected argument after: {s}", .{arg});
70757069 i += 1;
70767070 override_global_cache_dir = args[i];
70777071 } else if (mem.eql(u8, arg, "--cache-dir")) {
7078 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
7072 if (i + 1 >= args.len) fatal("expected argument after: {s}", .{arg});
70797073 i += 1;
70807074 override_local_cache_dir = args[i];
70817075 } else if (mem.eql(u8, arg, "--pkg-dir")) {
7082 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
7076 if (i + 1 >= args.len) fatal("expected argument after: {s}", .{arg});
70837077 i += 1;
70847078 override_pkg_dir = args[i];
70857079 } else if (mem.eql(u8, arg, "--debug-hash")) {
70867080 debug_hash = true;
7081 } else if (mem.eql(u8, arg, "--debug-log")) {
7082 if (i + 1 >= args.len) fatal("expected argument after: {s}", .{arg});
7083 i += 1;
7084 try addDebugLog(arena, args[i]);
70877085 } else if (mem.eql(u8, arg, "--save")) {
70887086 save = .{ .yes = null };
70897087 } else if (mem.cutPrefix(u8, arg, "--save=")) |rest| {
......@@ -7172,6 +7170,7 @@ fn cmdFetch(
71727170 .hash_tok = .none,
71737171 .name_tok = 0,
71747172 .lazy_status = .eager,
7173 .remote_package_root = undefined,
71757174 .parent_package_root = undefined,
71767175 .parent_manifest_ast = null,
71777176 .prog_node = root_prog_node,
......@@ -7816,3 +7815,11 @@ fn randInt(io: Io, comptime T: type) T {
78167815 io.random(@ptrCast(&x));
78177816 return x;
78187817}
7818
7819fn addDebugLog(arena: Allocator, scope_name: []const u8) error{OutOfMemory}!void {
7820 if (!build_options.enable_logging) {
7821 warn("Zig was compiled without logging enabled (-Dlog). --debug-log has no effect.", .{});
7822 } else {
7823 try log_scopes.append(arena, scope_name);
7824 }
7825}