@@ -53,6 +53,7 @@ use_latest_commit: bool,
53
53
/// This will either be relative to `global_cache`, or to the build root of
54
54
/// the root package.
55
55
package_root : Cache.Path ,
56
+ local_override : bool ,
56
57
error_bundle : ErrorBundle.Wip ,
57
58
manifest : ? Manifest ,
58
59
manifest_ast : std.zig.Ast ,
@@ -97,6 +98,7 @@ pub const JobQueue = struct {
97
98
thread_pool : * ThreadPool ,
98
99
wait_group : WaitGroup = .{},
99
100
global_cache : Cache.Directory ,
101
+ local_cache : ? Cache.Directory ,
100
102
/// If true then, no fetching occurs, and:
101
103
/// * The `global_cache` directory is assumed to be the direct parent
102
104
/// directory of on-disk packages rather than having the "p/" directory
@@ -198,6 +200,11 @@ pub const JobQueue = struct {
198
200
}
199
201
}
200
202
203
+ try buf .writer ().print (
204
+ \\ pub const local_override = {};
205
+ \\
206
+ , .{fetch .local_override });
207
+
201
208
try buf .writer ().print (
202
209
\\ pub const build_root = "{q}";
203
210
\\
@@ -372,6 +379,35 @@ pub fn run(f: *Fetch) RunError!void {
372
379
const prefixed_pkg_sub_path = "p" ++ s ++ expected_hash ;
373
380
const prefix_len : usize = if (f .job_queue .read_only ) "p/" .len else 0 ;
374
381
const pkg_sub_path = prefixed_pkg_sub_path [prefix_len .. ];
382
+
383
+ if (f .job_queue .local_cache ) | local_cache | local : {
384
+ const local_cache_path = if (f .job_queue .read_only ) prefixed_pkg_sub_path else pkg_sub_path ;
385
+ if (local_cache .handle .access (local_cache_path , .{})) | _ | {
386
+ f .local_override = true ;
387
+ if (f .job_queue .read_only ) break :local ;
388
+
389
+ assert (f .lazy_status != .unavailable );
390
+ f .package_root = .{
391
+ .root_dir = local_cache ,
392
+ .sub_path = try arena .dupe (u8 , local_cache_path ),
393
+ };
394
+ try loadManifest (f , f .package_root );
395
+ try checkBuildFileExistence (f );
396
+ if (! f .job_queue .recursive ) return ;
397
+ return queueJobsForDeps (f );
398
+ } else | err | switch (err ) {
399
+ error .FileNotFound = > {},
400
+ else = > | e | {
401
+ try eb .addRootErrorMessage (.{
402
+ .msg = try eb .printString ("unable to open local package cache directory '{}{s}': {s}" , .{
403
+ local_cache , local_cache_path , @errorName (e ),
404
+ }),
405
+ });
406
+ return error .FetchFailed ;
407
+ },
408
+ }
409
+ }
410
+
375
411
if (cache_root .handle .access (pkg_sub_path , .{})) | _ | {
376
412
assert (f .lazy_status != .unavailable );
377
413
f .package_root = .{
@@ -708,6 +744,7 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
708
744
.use_latest_commit = false ,
709
745
710
746
.package_root = undefined ,
747
+ .local_override = false ,
711
748
.error_bundle = undefined ,
712
749
.manifest = null ,
713
750
.manifest_ast = undefined ,
@@ -2276,6 +2313,7 @@ const TestFetchBuilder = struct {
2276
2313
.allow_missing_paths_field = false ,
2277
2314
2278
2315
.package_root = undefined ,
2316
+ .local_override = false ,
2279
2317
.error_bundle = undefined ,
2280
2318
.manifest = null ,
2281
2319
.manifest_ast = undefined ,
0 commit comments