| author | |
| committer | |
| log | 1c0d6f9c0020188326560e058baf36b8034d76e5 |
| tree | 08388d23839c1461cac0da48c1fc969ffd24730d |
| parent | d0bcc390e8f61ada470b524e3fd203c1af521a99 |
see #143113 files changed, 24 insertions(+), 9 deletions(-)
src/Manifest.zig+13-2| ... | ... | @@ -59,9 +59,13 @@ paths: std.StringArrayHashMapUnmanaged(void), |
| 59 | 59 | errors: []ErrorMessage, |
| 60 | 60 | arena_state: std.heap.ArenaAllocator.State, |
| 61 | 61 | |
| 62 | pub const ParseOptions = struct { | |
| 63 | allow_missing_paths_field: bool = false, | |
| 64 | }; | |
| 65 | ||
| 62 | 66 | pub const Error = Allocator.Error; |
| 63 | 67 | |
| 64 | pub fn parse(gpa: Allocator, ast: std.zig.Ast) Error!Manifest { | |
| 68 | pub fn parse(gpa: Allocator, ast: std.zig.Ast, options: ParseOptions) Error!Manifest { | |
| 65 | 69 | const node_tags = ast.nodes.items(.tag); |
| 66 | 70 | const node_datas = ast.nodes.items(.data); |
| 67 | 71 | assert(node_tags[0] == .root); |
| ... | ... | @@ -80,6 +84,7 @@ pub fn parse(gpa: Allocator, ast: std.zig.Ast) Error!Manifest { |
| 80 | 84 | .version = undefined, |
| 81 | 85 | .dependencies = .{}, |
| 82 | 86 | .paths = .{}, |
| 87 | .allow_missing_paths_field = options.allow_missing_paths_field, | |
| 83 | 88 | .buf = .{}, |
| 84 | 89 | }; |
| 85 | 90 | defer p.buf.deinit(gpa); |
| ... | ... | @@ -152,6 +157,7 @@ const Parse = struct { |
| 152 | 157 | version: std.SemanticVersion, |
| 153 | 158 | dependencies: std.StringArrayHashMapUnmanaged(Dependency), |
| 154 | 159 | paths: std.StringArrayHashMapUnmanaged(void), |
| 160 | allow_missing_paths_field: bool, | |
| 155 | 161 | |
| 156 | 162 | const InnerError = error{ ParseFailure, OutOfMemory }; |
| 157 | 163 | |
| ... | ... | @@ -178,6 +184,7 @@ const Parse = struct { |
| 178 | 184 | if (mem.eql(u8, field_name, "dependencies")) { |
| 179 | 185 | try parseDependencies(p, field_init); |
| 180 | 186 | } else if (mem.eql(u8, field_name, "paths")) { |
| 187 | have_included_paths = true; | |
| 181 | 188 | try parseIncludedPaths(p, field_init); |
| 182 | 189 | } else if (mem.eql(u8, field_name, "name")) { |
| 183 | 190 | p.name = try parseString(p, field_init); |
| ... | ... | @@ -204,7 +211,11 @@ const Parse = struct { |
| 204 | 211 | } |
| 205 | 212 | |
| 206 | 213 | if (!have_included_paths) { |
| 207 | try appendError(p, main_token, "missing top-level 'paths' field", .{}); | |
| 214 | if (p.allow_missing_paths_field) { | |
| 215 | try p.paths.put(p.gpa, "", {}); | |
| 216 | } else { | |
| 217 | try appendError(p, main_token, "missing top-level 'paths' field", .{}); | |
| 218 | } | |
| 208 | 219 | } |
| 209 | 220 | } |
| 210 | 221 |
src/Package/Fetch.zig+9-2| ... | ... | @@ -38,6 +38,10 @@ job_queue: *JobQueue, |
| 38 | 38 | /// If true, don't add an error for a missing hash. This flag is not passed |
| 39 | 39 | /// down to recursive dependencies. It's intended to be used only be the CLI. |
| 40 | 40 | omit_missing_hash_error: bool, |
| 41 | /// If true, don't fail when a manifest file is missing the `paths` field, | |
| 42 | /// which specifies inclusion rules. This is intended to be true for the first | |
| 43 | /// fetch task and false for the recursive dependencies. | |
| 44 | allow_missing_paths_field: bool, | |
| 41 | 45 | |
| 42 | 46 | // Above this are fields provided as inputs to `run`. |
| 43 | 47 | // Below this are fields populated by `run`. |
| ... | ... | @@ -365,7 +369,9 @@ fn loadManifest(f: *Fetch, pkg_root: Package.Path) RunError!void { |
| 365 | 369 | return error.FetchFailed; |
| 366 | 370 | } |
| 367 | 371 | |
| 368 | f.manifest = try Manifest.parse(arena, ast.*); | |
| 372 | f.manifest = try Manifest.parse(arena, ast.*, .{ | |
| 373 | .allow_missing_paths_field = f.allow_missing_paths_field, | |
| 374 | }); | |
| 369 | 375 | const manifest = &f.manifest.?; |
| 370 | 376 | |
| 371 | 377 | if (manifest.errors.len > 0) { |
| ... | ... | @@ -452,6 +458,7 @@ fn queueJobsForDeps(f: *Fetch, hash: Manifest.MultiHashHexDigest) RunError!void |
| 452 | 458 | .prog_node = f.prog_node, |
| 453 | 459 | .job_queue = f.job_queue, |
| 454 | 460 | .omit_missing_hash_error = false, |
| 461 | .allow_missing_paths_field = false, | |
| 455 | 462 | |
| 456 | 463 | .package_root = undefined, |
| 457 | 464 | .error_bundle = undefined, |
| ... | ... | @@ -481,7 +488,7 @@ fn queueJobsForDeps(f: *Fetch, hash: Manifest.MultiHashHexDigest) RunError!void |
| 481 | 488 | } |
| 482 | 489 | } |
| 483 | 490 | |
| 484 | fn workerRun(f: *Fetch) void { | |
| 491 | pub fn workerRun(f: *Fetch) void { | |
| 485 | 492 | defer f.job_queue.wait_group.finish(); |
| 486 | 493 | run(f) catch |err| switch (err) { |
| 487 | 494 | error.OutOfMemory => f.oom_flag = true, |
src/main.zig+2-5| ... | ... | @@ -6640,7 +6640,6 @@ fn cmdFetch( |
| 6640 | 6640 | std.process.hasEnvVarConstant("ZIG_BTRFS_WORKAROUND"); |
| 6641 | 6641 | var opt_path_or_url: ?[]const u8 = null; |
| 6642 | 6642 | var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR"); |
| 6643 | var recursive = false; | |
| 6644 | 6643 | |
| 6645 | 6644 | { |
| 6646 | 6645 | var i: usize = 0; |
| ... | ... | @@ -6656,9 +6655,6 @@ fn cmdFetch( |
| 6656 | 6655 | i += 1; |
| 6657 | 6656 | override_global_cache_dir = args[i]; |
| 6658 | 6657 | continue; |
| 6659 | } else if (mem.eql(u8, arg, "--recursive")) { | |
| 6660 | recursive = true; | |
| 6661 | continue; | |
| 6662 | 6658 | } else { |
| 6663 | 6659 | fatal("unrecognized parameter: '{s}'", .{arg}); |
| 6664 | 6660 | } |
| ... | ... | @@ -6696,7 +6692,7 @@ fn cmdFetch( |
| 6696 | 6692 | .http_client = &http_client, |
| 6697 | 6693 | .thread_pool = &thread_pool, |
| 6698 | 6694 | .global_cache = global_cache_directory, |
| 6699 | .recursive = recursive, | |
| 6695 | .recursive = false, | |
| 6700 | 6696 | .work_around_btrfs_bug = work_around_btrfs_bug, |
| 6701 | 6697 | }; |
| 6702 | 6698 | defer job_queue.deinit(); |
| ... | ... | @@ -6711,6 +6707,7 @@ fn cmdFetch( |
| 6711 | 6707 | .prog_node = root_prog_node, |
| 6712 | 6708 | .job_queue = &job_queue, |
| 6713 | 6709 | .omit_missing_hash_error = true, |
| 6710 | .allow_missing_paths_field = true, | |
| 6714 | 6711 | |
| 6715 | 6712 | .package_root = undefined, |
| 6716 | 6713 | .error_bundle = undefined, |