@@ -55,6 +55,7 @@ use_latest_commit: bool,
55
55
/// This will either be relative to `global_cache`, or to the build root of
56
56
/// the root package.
57
57
package_root : Cache.Path ,
58
+ local_override : bool ,
58
59
error_bundle : ErrorBundle.Wip ,
59
60
manifest : ? Manifest ,
60
61
manifest_ast : std.zig.Ast ,
@@ -99,6 +100,7 @@ pub const JobQueue = struct {
99
100
thread_pool : * ThreadPool ,
100
101
wait_group : WaitGroup = .{},
101
102
global_cache : Cache.Directory ,
103
+ local_cache : ? Cache.Directory ,
102
104
/// If true then, no fetching occurs, and:
103
105
/// * The `global_cache` directory is assumed to be the direct parent
104
106
/// directory of on-disk packages rather than having the "p/" directory
@@ -210,6 +212,11 @@ pub const JobQueue = struct {
210
212
}
211
213
}
212
214
215
+ try buf .writer ().print (
216
+ \\ pub const local_override = {};
217
+ \\
218
+ , .{fetch .local_override });
219
+
213
220
try buf .writer ().print (
214
221
\\ pub const build_root = "{q}";
215
222
\\
@@ -398,6 +405,35 @@ pub fn run(f: *Fetch) RunError!void {
398
405
const prefixed_pkg_sub_path = prefixed_pkg_sub_path_buffer [0 .. 2 + hash_slice .len ];
399
406
const prefix_len : usize = if (f .job_queue .read_only ) "p/" .len else 0 ;
400
407
const pkg_sub_path = prefixed_pkg_sub_path [prefix_len .. ];
408
+
409
+ if (f .job_queue .local_cache ) | local_cache | local : {
410
+ const local_cache_path = if (f .job_queue .read_only ) prefixed_pkg_sub_path else pkg_sub_path ;
411
+ if (local_cache .handle .access (local_cache_path , .{})) | _ | {
412
+ f .local_override = true ;
413
+ if (f .job_queue .read_only ) break :local ;
414
+
415
+ assert (f .lazy_status != .unavailable );
416
+ f .package_root = .{
417
+ .root_dir = local_cache ,
418
+ .sub_path = try arena .dupe (u8 , local_cache_path ),
419
+ };
420
+ try loadManifest (f , f .package_root );
421
+ try checkBuildFileExistence (f );
422
+ if (! f .job_queue .recursive ) return ;
423
+ return queueJobsForDeps (f );
424
+ } else | err | switch (err ) {
425
+ error .FileNotFound = > {},
426
+ else = > | e | {
427
+ try eb .addRootErrorMessage (.{
428
+ .msg = try eb .printString ("unable to open local package cache directory '{}{s}': {s}" , .{
429
+ local_cache , local_cache_path , @errorName (e ),
430
+ }),
431
+ });
432
+ return error .FetchFailed ;
433
+ },
434
+ }
435
+ }
436
+
401
437
if (cache_root .handle .access (pkg_sub_path , .{})) | _ | {
402
438
assert (f .lazy_status != .unavailable );
403
439
f .package_root = .{
@@ -777,6 +813,7 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
777
813
.use_latest_commit = false ,
778
814
779
815
.package_root = undefined ,
816
+ .local_override = false ,
780
817
.error_bundle = undefined ,
781
818
.manifest = null ,
782
819
.manifest_ast = undefined ,
@@ -2332,6 +2369,7 @@ const TestFetchBuilder = struct {
2332
2369
.http_client = & self .http_client ,
2333
2370
.thread_pool = & self .thread_pool ,
2334
2371
.global_cache = self .global_cache_directory ,
2372
+ .local_cache = null ,
2335
2373
.recursive = false ,
2336
2374
.read_only = false ,
2337
2375
.debug_hash = false ,
@@ -2357,6 +2395,7 @@ const TestFetchBuilder = struct {
2357
2395
.use_latest_commit = true ,
2358
2396
2359
2397
.package_root = undefined ,
2398
+ .local_override = false ,
2360
2399
.error_bundle = undefined ,
2361
2400
.manifest = null ,
2362
2401
.manifest_ast = undefined ,
0 commit comments