authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-24 17:49:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-29 23:50:20-07:00
logb68192254687e279bef4196cdf0575ed748964f7
tree0f390f7dde268e8ecfc58d6467f5a085b3d29b8d
parent519a47af31b0eaf41fc3649474e16f460b454795

Maker.Fetch: clarify that Cache import is not used


1 files changed, 24 insertions(+), 23 deletions(-)

lib/compiler/Maker/Fetch.zig+24-23
......@@ -44,7 +44,8 @@ const log = std.log.scoped(.fetch);
4444const assert = std.debug.assert;
4545const ascii = std.ascii;
4646const Allocator = std.mem.Allocator;
47const Cache = std.Build.Cache;
47const Path = std.Build.Cache.Path;
48const Directory = std.Build.Cache.Directory;
4849const git = @import("Fetch/git.zig");
4950const Package = @import("Package.zig");
5051const Manifest = Package.Manifest;
......@@ -58,8 +59,8 @@ name_tok: std.zig.Ast.TokenIndex,
5859lazy_status: LazyStatus,
5960/// Same as `parent_packge_root` except it is unchanged when recursing into
6061/// relative file paths (as opposed to URL).
61remote_package_root: Cache.Path,
62parent_package_root: Cache.Path,
62remote_package_root: Path,
63parent_package_root: Path,
6364parent_manifest_ast: ?*const std.zig.Ast,
6465prog_node: std.Progress.Node,
6566job_queue: *JobQueue,
......@@ -77,7 +78,7 @@ use_latest_commit: bool,
7778// Below this are fields populated by `run`.
7879
7980/// Relative to the build root of the root package.
80package_root: Cache.Path,
81package_root: Path,
8182error_bundle: ErrorBundle.Wip,
8283manifest: Manifest,
8384manifest_ast: std.zig.Ast,
......@@ -111,9 +112,9 @@ pub const LazyStatus = enum {
111112};
112113
113114pub const LocalStorage = struct {
114 cache_root: Cache.Path,
115 cache_root: Path,
115116 /// Path to "zig-pkg" inside the package in which the user ran `zig build`.
116 pkg_root: Cache.Path,
117 pkg_root: Path,
117118};
118119
119120/// Contains shared state among all `Fetch` tasks.
......@@ -133,7 +134,7 @@ pub const JobQueue = struct {
133134 http_client: *std.http.Client,
134135 /// This tracks `Fetch` tasks as well as recompression tasks.
135136 group: Io.Group = .init,
136 global_cache: Cache.Directory,
137 global_cache: Directory,
137138 /// If `null`, indicates fetch globally only.
138139 local_storage: ?*const LocalStorage,
139140 /// If true then, no fetching occurs, and:
......@@ -170,7 +171,7 @@ pub const JobQueue = struct {
170171 pub const ForkSet = std.array_hash_map.Custom(Fork, void, Fork.Context, false);
171172
172173 pub const Fork = struct {
173 path: Cache.Path,
174 path: Path,
174175 manifest_ast: std.zig.Ast,
175176 manifest: Package.Manifest,
176177 uses: usize,
......@@ -352,14 +353,14 @@ pub const JobQueue = struct {
352353 );
353354 }
354355
355 fn recompress(jq: *JobQueue, package_hash: Package.Hash, package_root: Cache.Path) Io.Cancelable!void {
356 fn recompress(jq: *JobQueue, package_hash: Package.Hash, package_root: Path) Io.Cancelable!void {
356357 const pkg_hash_slice = package_hash.toSlice();
357358
358359 const prog_node = jq.prog_node.startFmt(0, "recompress {s}", .{pkg_hash_slice});
359360 defer prog_node.end();
360361
361362 var dest_sub_path_buf: ["p/".len + Package.Hash.max_len + ".tar.gz".len]u8 = undefined;
362 const dest_path: Cache.Path = .{
363 const dest_path: Path = .{
363364 .root_dir = jq.global_cache,
364365 .sub_path = std.fmt.bufPrint(&dest_sub_path_buf, "p/{s}.tar.gz", .{pkg_hash_slice}) catch unreachable,
365366 };
......@@ -381,9 +382,9 @@ pub const JobQueue = struct {
381382 fn recompressFallible(
382383 jq: *JobQueue,
383384 arena: Allocator,
384 dest_path: Cache.Path,
385 dest_path: Path,
385386 pkg_hash_slice: []const u8,
386 package_root: Cache.Path,
387 package_root: Path,
387388 prog_node: std.Progress.Node,
388389 ) !void {
389390 const gpa = jq.http_client.allocator;
......@@ -493,7 +494,7 @@ fn stringCmp(_: void, lhs: ScannedFile, rhs: ScannedFile) bool {
493494pub const Location = union(enum) {
494495 remote: Remote,
495496 /// A directory found inside the parent package.
496 relative_path: Cache.Path,
497 relative_path: Path,
497498 /// Recursive Fetch tasks will never use this Location, but it may be
498499 /// passed in by the CLI. Indicates the file contents here should be copied
499500 /// into the global package cache. It may be a file relative to the cwd or
......@@ -641,7 +642,7 @@ pub fn run(f: *Fetch) RunError!void {
641642
642643 // Check global cache before remote fetch.
643644 const cached_tarball_sub_path = try std.fmt.allocPrint(arena, "p/{s}.tar.gz", .{expected_hash.toSlice()});
644 const cached_tarball_path: Cache.Path = .{
645 const cached_tarball_path: Path = .{
645646 .root_dir = job_queue.global_cache,
646647 .sub_path = cached_tarball_sub_path,
647648 };
......@@ -716,7 +717,7 @@ fn runResource(
716717 };
717718 const tmp_dir_sub_path = ".tmp-" ++ std.fmt.hex(rand_int);
718719 const tmp_tmp_dir_sub_path = "tmp/" ++ tmp_dir_sub_path;
719 const tmp_directory_path: Cache.Path = if (job_queue.local_storage) |ls|
720 const tmp_directory_path: Path = if (job_queue.local_storage) |ls|
720721 try ls.pkg_root.join(arena, tmp_dir_sub_path)
721722 else
722723 .{
......@@ -725,7 +726,7 @@ fn runResource(
725726 };
726727
727728 const package_sub_path = blk: {
728 var tmp_directory: Cache.Directory = .{
729 var tmp_directory: Directory = .{
729730 .path = tmp_directory_path.sub_path,
730731 .handle = handle: {
731732 const dir = tmp_directory_path.root_dir.handle.createDirPathOpen(io, tmp_directory_path.sub_path, .{
......@@ -746,7 +747,7 @@ fn runResource(
746747 // Fetch and unpack a resource into a temporary directory.
747748 var unpack_result = try unpackResource(f, resource, uri_path, tmp_directory);
748749
749 const pkg_path: Cache.Path = .{ .root_dir = tmp_directory, .sub_path = unpack_result.root_dir };
750 const pkg_path: Path = .{ .root_dir = tmp_directory, .sub_path = unpack_result.root_dir };
750751
751752 // Load, parse, and validate the unpacked build.zig.zon file. It is allowed
752753 // for the file to be missing, in which case this fetched package is
......@@ -874,7 +875,7 @@ fn checkBuildFileExistence(f: *Fetch) RunError!void {
874875}
875876
876877/// This function populates `f.manifest` or leaves it `null`.
877fn loadManifest(f: *Fetch, pkg_root: Cache.Path) RunError!void {
878fn loadManifest(f: *Fetch, pkg_root: Path) RunError!void {
878879 const io = f.job_queue.io;
879880 const eb = &f.error_bundle;
880881 const arena = f.arena.allocator();
......@@ -1038,7 +1039,7 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
10381039 }
10391040}
10401041
1041pub fn relativePathDigest(pkg_root: Cache.Path, cache_root: Cache.Directory) Package.Hash {
1042pub fn relativePathDigest(pkg_root: Path, cache_root: Directory) Package.Hash {
10421043 return .initPath(pkg_root.sub_path, pkg_root.root_dir.eql(cache_root));
10431044}
10441045
......@@ -1331,7 +1332,7 @@ fn unpackResource(
13311332 f: *Fetch,
13321333 resource: *Resource,
13331334 uri_path: []const u8,
1334 tmp_directory: Cache.Directory,
1335 tmp_directory: Directory,
13351336) RunError!UnpackResult {
13361337 const eb = &f.error_bundle;
13371338 const file_type = switch (resource.*) {
......@@ -1667,7 +1668,7 @@ fn recursiveDirectoryCopy(f: *Fetch, dir: Io.Dir, tmp_dir: Io.Dir) anyerror!void
16671668 }
16681669}
16691670
1670pub fn renameTmpIntoCache(io: Io, tmp_path: Cache.Path, dest_path: Cache.Path) !void {
1671pub fn renameTmpIntoCache(io: Io, tmp_path: Path, dest_path: Path) !void {
16711672 var handled_missing_dir = false;
16721673 while (true) {
16731674 Io.Dir.rename(
......@@ -1711,7 +1712,7 @@ const ComputedHash = struct {
17111712/// the hash are not present on the file system. Empty directories are *not
17121713/// hashed* and must not be present on the file system when calling this
17131714/// function.
1714fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!ComputedHash {
1715fn computeHash(f: *Fetch, pkg_path: Path, filter: Filter) RunError!ComputedHash {
17151716 const io = f.job_queue.io;
17161717 // All the path name strings need to be in memory for sorting.
17171718 const arena = f.arena.allocator();
......@@ -2035,7 +2036,7 @@ const Filter = struct {
20352036 }
20362037};
20372038
2038pub fn depDigest(pkg_root: Cache.Path, cache_root: Cache.Directory, dep: Manifest.Dependency) ?Package.Hash {
2039pub fn depDigest(pkg_root: Path, cache_root: Directory, dep: Manifest.Dependency) ?Package.Hash {
20392040 if (dep.hash) |h| return .fromSlice(h);
20402041
20412042 switch (dep.location) {