authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-04-23 02:11:04+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-18 00:27:21-07:00
logdb7496d6efb64d8210816e49008753b5a81d46f4
tree32b684f3a6eafb0fdfcf81d3e7a798f1f687a3fc
parentf65e8c78621c90c9b9932903a9ed99c973dbcf63

Only add build.zig module dependencies once


1 files changed, 34 insertions(+), 22 deletions(-)

src/Package.zig+34-22
...@@ -279,7 +279,7 @@ pub fn fetchAndAddDependencies(...@@ -279,7 +279,7 @@ pub fn fetchAndAddDependencies(
279 const sub_prefix = try std.fmt.allocPrint(arena, "{s}{s}.", .{ name_prefix, name });279 const sub_prefix = try std.fmt.allocPrint(arena, "{s}{s}.", .{ name_prefix, name });
280 const fqn = sub_prefix[0 .. sub_prefix.len - 1];280 const fqn = sub_prefix[0 .. sub_prefix.len - 1];
281281
282 const sub_pkg = try fetchAndUnpack(282 const sub = try fetchAndUnpack(
283 thread_pool,283 thread_pool,
284 http_client,284 http_client,
285 global_cache_directory,285 global_cache_directory,
...@@ -290,28 +290,30 @@ pub fn fetchAndAddDependencies(...@@ -290,28 +290,30 @@ pub fn fetchAndAddDependencies(
290 all_modules,290 all_modules,
291 );291 );
292292
293 try sub_pkg.fetchAndAddDependencies(293 if (!sub.found_existing) {
294 deps_pkg,294 try sub.mod.fetchAndAddDependencies(
295 arena,295 deps_pkg,
296 thread_pool,296 arena,
297 http_client,297 thread_pool,
298 sub_pkg.root_src_directory,298 http_client,
299 global_cache_directory,299 sub.mod.root_src_directory,
300 local_cache_directory,300 global_cache_directory,
301 dependencies_source,301 local_cache_directory,
302 build_roots_source,302 dependencies_source,
303 sub_prefix,303 build_roots_source,
304 error_bundle,304 sub_prefix,
305 all_modules,305 error_bundle,
306 );306 all_modules,
307 );
308 }
307309
308 try pkg.add(gpa, name, sub_pkg);310 try pkg.add(gpa, name, sub.mod);
309 if (deps_pkg.table.get(dep.hash.?)) |other_sub| {311 if (deps_pkg.table.get(dep.hash.?)) |other_sub| {
310 // This should be the same package (and hence module) since it's the same hash312 // This should be the same package (and hence module) since it's the same hash
311 // TODO: dedup multiple versions of the same package313 // TODO: dedup multiple versions of the same package
312 assert(other_sub == sub_pkg);314 assert(other_sub == sub.mod);
313 } else {315 } else {
314 try deps_pkg.add(gpa, dep.hash.?, sub_pkg);316 try deps_pkg.add(gpa, dep.hash.?, sub.mod);
315 }317 }
316318
317 try dependencies_source.writer().print(" pub const {s} = @import(\"{}\");\n", .{319 try dependencies_source.writer().print(" pub const {s} = @import(\"{}\");\n", .{
...@@ -413,7 +415,7 @@ fn fetchAndUnpack(...@@ -413,7 +415,7 @@ fn fetchAndUnpack(
413 build_roots_source: *std.ArrayList(u8),415 build_roots_source: *std.ArrayList(u8),
414 fqn: []const u8,416 fqn: []const u8,
415 all_modules: *AllModules,417 all_modules: *AllModules,
416) !*Package {418) !struct { mod: *Package, found_existing: bool } {
417 const gpa = http_client.allocator;419 const gpa = http_client.allocator;
418 const s = fs.path.sep_str;420 const s = fs.path.sep_str;
419421
...@@ -441,7 +443,10 @@ fn fetchAndUnpack(...@@ -441,7 +443,10 @@ fn fetchAndUnpack(
441 const gop = try all_modules.getOrPut(gpa, hex_digest.*);443 const gop = try all_modules.getOrPut(gpa, hex_digest.*);
442 if (gop.found_existing) {444 if (gop.found_existing) {
443 gpa.free(build_root);445 gpa.free(build_root);
444 return gop.value_ptr.*;446 return .{
447 .mod = gop.value_ptr.*,
448 .found_existing = true,
449 };
445 }450 }
446451
447 const ptr = try gpa.create(Package);452 const ptr = try gpa.create(Package);
...@@ -460,7 +465,10 @@ fn fetchAndUnpack(...@@ -460,7 +465,10 @@ fn fetchAndUnpack(
460 };465 };
461466
462 gop.value_ptr.* = ptr;467 gop.value_ptr.* = ptr;
463 return ptr;468 return .{
469 .mod = ptr,
470 .found_existing = false,
471 };
464 }472 }
465473
466 const uri = try std.Uri.parse(dep.url);474 const uri = try std.Uri.parse(dep.url);
...@@ -575,7 +583,11 @@ fn fetchAndUnpack(...@@ -575,7 +583,11 @@ fn fetchAndUnpack(
575 std.zig.fmtId(fqn), std.zig.fmtEscapes(build_root),583 std.zig.fmtId(fqn), std.zig.fmtEscapes(build_root),
576 });584 });
577585
578 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 };
579}591}
580592
581fn unpackTarball(593fn unpackTarball(