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(
279279 const sub_prefix = try std.fmt.allocPrint(arena, "{s}{s}.", .{ name_prefix, name });
280280 const fqn = sub_prefix[0 .. sub_prefix.len - 1];
281281
282 const sub_pkg = try fetchAndUnpack(
282 const sub = try fetchAndUnpack(
283283 thread_pool,
284284 http_client,
285285 global_cache_directory,
......@@ -290,28 +290,30 @@ pub fn fetchAndAddDependencies(
290290 all_modules,
291291 );
292292
293 try sub_pkg.fetchAndAddDependencies(
294 deps_pkg,
295 arena,
296 thread_pool,
297 http_client,
298 sub_pkg.root_src_directory,
299 global_cache_directory,
300 local_cache_directory,
301 dependencies_source,
302 build_roots_source,
303 sub_prefix,
304 error_bundle,
305 all_modules,
306 );
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 }
307309
308 try pkg.add(gpa, name, sub_pkg);
310 try pkg.add(gpa, name, sub.mod);
309311 if (deps_pkg.table.get(dep.hash.?)) |other_sub| {
310312 // This should be the same package (and hence module) since it's the same hash
311313 // TODO: dedup multiple versions of the same package
312 assert(other_sub == sub_pkg);
314 assert(other_sub == sub.mod);
313315 } else {
314 try deps_pkg.add(gpa, dep.hash.?, sub_pkg);
316 try deps_pkg.add(gpa, dep.hash.?, sub.mod);
315317 }
316318
317319 try dependencies_source.writer().print(" pub const {s} = @import(\"{}\");\n", .{
......@@ -413,7 +415,7 @@ fn fetchAndUnpack(
413415 build_roots_source: *std.ArrayList(u8),
414416 fqn: []const u8,
415417 all_modules: *AllModules,
416) !*Package {
418) !struct { mod: *Package, found_existing: bool } {
417419 const gpa = http_client.allocator;
418420 const s = fs.path.sep_str;
419421
......@@ -441,7 +443,10 @@ fn fetchAndUnpack(
441443 const gop = try all_modules.getOrPut(gpa, hex_digest.*);
442444 if (gop.found_existing) {
443445 gpa.free(build_root);
444 return gop.value_ptr.*;
446 return .{
447 .mod = gop.value_ptr.*,
448 .found_existing = true,
449 };
445450 }
446451
447452 const ptr = try gpa.create(Package);
......@@ -460,7 +465,10 @@ fn fetchAndUnpack(
460465 };
461466
462467 gop.value_ptr.* = ptr;
463 return ptr;
468 return .{
469 .mod = ptr,
470 .found_existing = false,
471 };
464472 }
465473
466474 const uri = try std.Uri.parse(dep.url);
......@@ -575,7 +583,11 @@ fn fetchAndUnpack(
575583 std.zig.fmtId(fqn), std.zig.fmtEscapes(build_root),
576584 });
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 };
579591}
580592
581593fn unpackTarball(