| ... | ... | @@ -216,7 +216,7 @@ pub const build_zig_basename = "build.zig"; |
| 216 | 216 | |
| 217 | 217 | pub fn fetchAndAddDependencies( |
| 218 | 218 | pkg: *Package, |
| 219 | | root_pkg: *Package, |
| 219 | deps_pkg: *Package, |
| 220 | 220 | arena: Allocator, |
| 221 | 221 | thread_pool: *ThreadPool, |
| 222 | 222 | http_client: *std.http.Client, |
| ... | ... | @@ -272,7 +272,6 @@ pub fn fetchAndAddDependencies( |
| 272 | 272 | .error_bundle = error_bundle, |
| 273 | 273 | }; |
| 274 | 274 | |
| 275 | | var any_error = false; |
| 276 | 275 | const deps_list = manifest.dependencies.values(); |
| 277 | 276 | for (manifest.dependencies.keys(), 0..) |name, i| { |
| 278 | 277 | const dep = deps_list[i]; |
| ... | ... | @@ -280,7 +279,7 @@ pub fn fetchAndAddDependencies( |
| 280 | 279 | const sub_prefix = try std.fmt.allocPrint(arena, "{s}{s}.", .{ name_prefix, name }); |
| 281 | 280 | const fqn = sub_prefix[0 .. sub_prefix.len - 1]; |
| 282 | 281 | |
| 283 | | const sub_pkg = try fetchAndUnpack( |
| 282 | const sub = try fetchAndUnpack( |
| 284 | 283 | thread_pool, |
| 285 | 284 | http_client, |
| 286 | 285 | global_cache_directory, |
| ... | ... | @@ -291,30 +290,36 @@ pub fn fetchAndAddDependencies( |
| 291 | 290 | all_modules, |
| 292 | 291 | ); |
| 293 | 292 | |
| 294 | | try sub_pkg.fetchAndAddDependencies( |
| 295 | | root_pkg, |
| 296 | | arena, |
| 297 | | thread_pool, |
| 298 | | http_client, |
| 299 | | sub_pkg.root_src_directory, |
| 300 | | global_cache_directory, |
| 301 | | local_cache_directory, |
| 302 | | dependencies_source, |
| 303 | | build_roots_source, |
| 304 | | sub_prefix, |
| 305 | | error_bundle, |
| 306 | | all_modules, |
| 307 | | ); |
| 293 | if (!sub.found_existing) { |
| 294 | try sub.mod.fetchAndAddDependencies( |
| 295 | deps_pkg, |
| 296 | arena, |
| 297 | thread_pool, |
| 298 | http_client, |
| 299 | sub.mod.root_src_directory, |
| 300 | global_cache_directory, |
| 301 | local_cache_directory, |
| 302 | dependencies_source, |
| 303 | build_roots_source, |
| 304 | sub_prefix, |
| 305 | error_bundle, |
| 306 | all_modules, |
| 307 | ); |
| 308 | } |
| 308 | 309 | |
| 309 | | try pkg.add(gpa, name, sub_pkg); |
| 310 | | try root_pkg.add(gpa, fqn, sub_pkg); |
| 310 | try pkg.add(gpa, name, sub.mod); |
| 311 | if (deps_pkg.table.get(dep.hash.?)) |other_sub| { |
| 312 | // This should be the same package (and hence module) since it's the same hash |
| 313 | // TODO: dedup multiple versions of the same package |
| 314 | assert(other_sub == sub.mod); |
| 315 | } else { |
| 316 | try deps_pkg.add(gpa, dep.hash.?, sub.mod); |
| 317 | } |
| 311 | 318 | |
| 312 | 319 | try dependencies_source.writer().print(" pub const {s} = @import(\"{}\");\n", .{ |
| 313 | | std.zig.fmtId(fqn), std.zig.fmtEscapes(fqn), |
| 320 | std.zig.fmtId(fqn), std.zig.fmtEscapes(dep.hash.?), |
| 314 | 321 | }); |
| 315 | 322 | } |
| 316 | | |
| 317 | | if (any_error) return error.InvalidBuildManifestFile; |
| 318 | 323 | } |
| 319 | 324 | |
| 320 | 325 | pub fn createFilePkg( |
| ... | ... | @@ -410,7 +415,7 @@ fn fetchAndUnpack( |
| 410 | 415 | build_roots_source: *std.ArrayList(u8), |
| 411 | 416 | fqn: []const u8, |
| 412 | 417 | all_modules: *AllModules, |
| 413 | | ) !*Package { |
| 418 | ) !struct { mod: *Package, found_existing: bool } { |
| 414 | 419 | const gpa = http_client.allocator; |
| 415 | 420 | const s = fs.path.sep_str; |
| 416 | 421 | |
| ... | ... | @@ -438,7 +443,10 @@ fn fetchAndUnpack( |
| 438 | 443 | const gop = try all_modules.getOrPut(gpa, hex_digest.*); |
| 439 | 444 | if (gop.found_existing) { |
| 440 | 445 | gpa.free(build_root); |
| 441 | | return gop.value_ptr.*; |
| 446 | return .{ |
| 447 | .mod = gop.value_ptr.*, |
| 448 | .found_existing = true, |
| 449 | }; |
| 442 | 450 | } |
| 443 | 451 | |
| 444 | 452 | const ptr = try gpa.create(Package); |
| ... | ... | @@ -457,7 +465,10 @@ fn fetchAndUnpack( |
| 457 | 465 | }; |
| 458 | 466 | |
| 459 | 467 | gop.value_ptr.* = ptr; |
| 460 | | return ptr; |
| 468 | return .{ |
| 469 | .mod = ptr, |
| 470 | .found_existing = false, |
| 471 | }; |
| 461 | 472 | } |
| 462 | 473 | |
| 463 | 474 | const uri = try std.Uri.parse(dep.url); |
| ... | ... | @@ -572,7 +583,11 @@ fn fetchAndUnpack( |
| 572 | 583 | std.zig.fmtId(fqn), std.zig.fmtEscapes(build_root), |
| 573 | 584 | }); |
| 574 | 585 | |
| 575 | | return createWithDir(gpa, global_cache_directory, pkg_dir_sub_path, build_zig_basename); |
| 586 | const mod = try createWithDir(gpa, global_cache_directory, pkg_dir_sub_path, build_zig_basename); |
| 587 | return .{ |
| 588 | .mod = mod, |
| 589 | .found_existing = false, |
| 590 | }; |
| 576 | 591 | } |
| 577 | 592 | |
| 578 | 593 | fn unpackTarball( |