| ... | @@ -58,6 +58,12 @@ has_build_zig: bool, | ... | @@ -58,6 +58,12 @@ has_build_zig: bool, |
| 58 | /// Indicates whether the task aborted due to an out-of-memory condition. | 58 | /// Indicates whether the task aborted due to an out-of-memory condition. |
| 59 | oom_flag: bool, | 59 | oom_flag: bool, |
| 60 | | 60 | |
| | 61 | // This field is used by the CLI only, untouched by this file. |
| | 62 | |
| | 63 | /// The module for this `Fetch` tasks's package, which exposes `build.zig` as |
| | 64 | /// the root source file. |
| | 65 | module: ?*Package.Module, |
| | 66 | |
| 61 | /// Contains shared state among all `Fetch` tasks. | 67 | /// Contains shared state among all `Fetch` tasks. |
| 62 | pub const JobQueue = struct { | 68 | pub const JobQueue = struct { |
| 63 | mutex: std.Thread.Mutex = .{}, | 69 | mutex: std.Thread.Mutex = .{}, |
| ... | @@ -147,10 +153,10 @@ pub const JobQueue = struct { | ... | @@ -147,10 +153,10 @@ pub const JobQueue = struct { |
| 147 | \\ | 153 | \\ |
| 148 | ); | 154 | ); |
| 149 | for (manifest.dependencies.keys(), manifest.dependencies.values()) |name, dep| { | 155 | for (manifest.dependencies.keys(), manifest.dependencies.values()) |name, dep| { |
| 150 | const h = dep.hash orelse continue; | 156 | const h = depDigest(fetch.package_root, jq.global_cache, dep) orelse continue; |
| 151 | try buf.writer().print( | 157 | try buf.writer().print( |
| 152 | " .{{ \"{}\", \"{}\" }},\n", | 158 | " .{{ \"{}\", \"{}\" }},\n", |
| 153 | .{ std.zig.fmtEscapes(name), std.zig.fmtEscapes(h) }, | 159 | .{ std.zig.fmtEscapes(name), std.zig.fmtEscapes(&h) }, |
| 154 | ); | 160 | ); |
| 155 | } | 161 | } |
| 156 | | 162 | |
| ... | @@ -179,10 +185,10 @@ pub const JobQueue = struct { | ... | @@ -179,10 +185,10 @@ pub const JobQueue = struct { |
| 179 | const root_manifest = &root_fetch.manifest.?; | 185 | const root_manifest = &root_fetch.manifest.?; |
| 180 | | 186 | |
| 181 | for (root_manifest.dependencies.keys(), root_manifest.dependencies.values()) |name, dep| { | 187 | for (root_manifest.dependencies.keys(), root_manifest.dependencies.values()) |name, dep| { |
| 182 | const h = dep.hash orelse continue; | 188 | const h = depDigest(root_fetch.package_root, jq.global_cache, dep) orelse continue; |
| 183 | try buf.writer().print( | 189 | try buf.writer().print( |
| 184 | " .{{ \"{}\", \"{}\" }},\n", | 190 | " .{{ \"{}\", \"{}\" }},\n", |
| 185 | .{ std.zig.fmtEscapes(name), std.zig.fmtEscapes(h) }, | 191 | .{ std.zig.fmtEscapes(name), std.zig.fmtEscapes(&h) }, |
| 186 | ); | 192 | ); |
| 187 | } | 193 | } |
| 188 | try buf.appendSlice("};\n"); | 194 | try buf.appendSlice("};\n"); |
| ... | @@ -258,7 +264,7 @@ pub fn run(f: *Fetch) RunError!void { | ... | @@ -258,7 +264,7 @@ pub fn run(f: *Fetch) RunError!void { |
| 258 | } | 264 | } |
| 259 | f.package_root = pkg_root; | 265 | f.package_root = pkg_root; |
| 260 | try loadManifest(f, pkg_root); | 266 | try loadManifest(f, pkg_root); |
| 261 | try checkBuildFileExistence(f); | 267 | if (!f.has_build_zig) try checkBuildFileExistence(f); |
| 262 | if (!f.job_queue.recursive) return; | 268 | if (!f.job_queue.recursive) return; |
| 263 | return queueJobsForDeps(f); | 269 | return queueJobsForDeps(f); |
| 264 | }, | 270 | }, |
| ... | @@ -604,6 +610,8 @@ fn queueJobsForDeps(f: *Fetch) RunError!void { | ... | @@ -604,6 +610,8 @@ fn queueJobsForDeps(f: *Fetch) RunError!void { |
| 604 | .actual_hash = undefined, | 610 | .actual_hash = undefined, |
| 605 | .has_build_zig = false, | 611 | .has_build_zig = false, |
| 606 | .oom_flag = false, | 612 | .oom_flag = false, |
| | 613 | |
| | 614 | .module = null, |
| 607 | }; | 615 | }; |
| 608 | } | 616 | } |
| 609 | | 617 | |
| ... | @@ -1400,6 +1408,25 @@ const Filter = struct { | ... | @@ -1400,6 +1408,25 @@ const Filter = struct { |
| 1400 | } | 1408 | } |
| 1401 | }; | 1409 | }; |
| 1402 | | 1410 | |
| | 1411 | pub fn depDigest( |
| | 1412 | pkg_root: Package.Path, |
| | 1413 | cache_root: Cache.Directory, |
| | 1414 | dep: Manifest.Dependency, |
| | 1415 | ) ?Manifest.MultiHashHexDigest { |
| | 1416 | if (dep.hash) |h| return h[0..Manifest.multihash_hex_digest_len].*; |
| | 1417 | |
| | 1418 | switch (dep.location) { |
| | 1419 | .url => return null, |
| | 1420 | .path => |rel_path| { |
| | 1421 | var buf: [fs.MAX_PATH_BYTES]u8 = undefined; |
| | 1422 | var fba = std.heap.FixedBufferAllocator.init(&buf); |
| | 1423 | const new_root = pkg_root.resolvePosix(fba.allocator(), rel_path) catch |
| | 1424 | return null; |
| | 1425 | return relativePathDigest(new_root, cache_root); |
| | 1426 | }, |
| | 1427 | } |
| | 1428 | } |
| | 1429 | |
| 1403 | // These are random bytes. | 1430 | // These are random bytes. |
| 1404 | const package_hash_prefix_cached = [8]u8{ 0x53, 0x7e, 0xfa, 0x94, 0x65, 0xe9, 0xf8, 0x73 }; | 1431 | const package_hash_prefix_cached = [8]u8{ 0x53, 0x7e, 0xfa, 0x94, 0x65, 0xe9, 0xf8, 0x73 }; |
| 1405 | const package_hash_prefix_project = [8]u8{ 0xe1, 0x25, 0xee, 0xfa, 0xa6, 0x17, 0x38, 0xcc }; | 1432 | const package_hash_prefix_project = [8]u8{ 0xe1, 0x25, 0xee, 0xfa, 0xa6, 0x17, 0x38, 0xcc }; |