@@ -141,6 +141,9 @@ pub const StdIo = union(enum) {
141141pub  const  Arg  =  union (enum ) {
142142    artifact : PrefixedArtifact ,
143143    lazy_path : PrefixedLazyPath ,
144+     // Needed for `enableTestRunnerMode` as you need to pass the cache directory 
145+     // without caching it. 
146+     uncached_decorated_directory : DecoratedLazyPath ,
144147    decorated_directory : DecoratedLazyPath ,
145148    file_content : PrefixedLazyPath ,
146149    bytes : []u8 ,
@@ -229,7 +232,7 @@ pub fn setName(run: *Run, name: []const u8) void {
229232pub  fn  enableTestRunnerMode (run : * Run ) void  {
230233    const  b  =  run .step .owner ;
231234    run .stdio  =  .zig_test ;
232-     run .addPrefixedDirectoryArg ("--cache-dir=" , .{ .cwd_relative  =  b .cache_root .path  orelse  "."  });
235+     run .addUncachedPrefixedDirectoryArg ("--cache-dir=" , .{ .cwd_relative  =  b .cache_root .path  orelse  "."  });
233236    run .addArgs (&.{
234237        b .fmt ("--seed=0x{x}" , .{b .graph .random_seed }),
235238        "--listen=-" ,
@@ -472,6 +475,25 @@ pub fn addDecoratedDirectoryArg(
472475    lazy_directory .addStepDependencies (& run .step );
473476}
474477
478+ fn  addUncachedPrefixedDirectoryArg (run : * Run , prefix : []const  u8 , lazy_directory : std.Build.LazyPath ) void  {
479+     run .addUncachedDecoratedDirectoryArg (prefix , lazy_directory , "" );
480+ }
481+ 
482+ fn  addUncachedDecoratedDirectoryArg (
483+     run : * Run ,
484+     prefix : []const  u8 ,
485+     lazy_directory : std.Build.LazyPath ,
486+     suffix : []const  u8 ,
487+ ) void  {
488+     const  b  =  run .step .owner ;
489+     run .argv .append (b .allocator , .{ .uncached_decorated_directory  =  .{
490+         .prefix  =  b .dupe (prefix ),
491+         .lazy_path  =  lazy_directory .dupe (b ),
492+         .suffix  =  b .dupe (suffix ),
493+     } }) catch  @panic ("OOM" );
494+     lazy_directory .addStepDependencies (& run .step );
495+ }
496+ 
475497/// Add a path argument to a dep file (.d) for the child process to write its 
476498/// discovered additional dependencies. 
477499/// Only one dep file argument is allowed by instance. 
@@ -542,7 +564,7 @@ pub fn addPathDir(run: *Run, search_path: []const u8) void {
542564            }
543565            break  :use_wine  std .mem .endsWith (u8 , p .lazy_path .basename (b , & run .step ), ".exe" );
544566        },
545-         .decorated_directory  = >  false ,
567+         .uncached_decorated_directory  ,  . decorated_directory= >  false ,
546568        .file_content  = >  unreachable , // not allowed as first arg 
547569        .bytes  = >  | bytes |  std .mem .endsWith (u8 , bytes , ".exe" ),
548570        .output_file , .output_directory  = >  false ,
@@ -809,11 +831,42 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
809831                man .hash .addBytes (file .prefix );
810832                _  =  try  man .addFilePath (file_path , null );
811833            },
834+             .uncached_decorated_directory  = >  | dd |  {
835+                 const  src_dir_path  =  dd .lazy_path .getPath3 (b , step );
836+                 try  argv_list .append (b .fmt ("{s}{s}{s}" , .{ dd .prefix , run .convertPathArg (src_dir_path ), dd .suffix  }));
837+             },
812838            .decorated_directory  = >  | dd |  {
813-                 const  file_path  =  dd .lazy_path .getPath3 (b , step );
814-                 const  resolved_arg  =  b .fmt ("{s}{s}{s}" , .{ dd .prefix , run .convertPathArg (file_path ), dd .suffix  });
815-                 try  argv_list .append (resolved_arg );
816-                 man .hash .addBytes (resolved_arg );
839+                 const  src_dir_path  =  dd .lazy_path .getPath3 (b , step );
840+                 try  argv_list .append (b .fmt ("{s}{s}{s}" , .{ dd .prefix , run .convertPathArg (src_dir_path ), dd .suffix  }));
841+                 man .hash .addBytes (dd .prefix );
842+                 man .hash .addBytes (dd .suffix );
843+ 
844+                 const  need_derived_inputs  =  try  step .addDirectoryWatchInput (dd .lazy_path );
845+ 
846+                 var  src_dir  =  src_dir_path .root_dir .handle .openDir (src_dir_path .subPathOrDot (), .{ .iterate  =  true  }) catch  | err |  {
847+                     return  step .fail ("unable to open source directory '{f}': {s}" , .{
848+                         src_dir_path , @errorName (err ),
849+                     });
850+                 };
851+ 
852+                 var  it  =  try  src_dir .walk (arena );
853+                 defer  it .deinit ();
854+ 
855+                 while  (try  it .next ()) | entry |  {
856+                     switch  (entry .kind ) {
857+                         .directory  = >  {
858+                             if  (need_derived_inputs ) {
859+                                 const  entry_path  =  try  src_dir_path .join (arena , entry .path );
860+                                 try  step .addDirectoryWatchInputFromPath (entry_path );
861+                             }
862+                         },
863+                         .file  = >  {
864+                             const  entry_path  =  try  src_dir_path .join (arena , entry .path );
865+                             _  =  try  man .addFilePath (entry_path , null );
866+                         },
867+                         else  = >  continue ,
868+                     }
869+                 }
817870            },
818871            .file_content  = >  | file_plp |  {
819872                const  file_path  =  file_plp .lazy_path .getPath3 (b , step );
@@ -1075,7 +1128,7 @@ pub fn rerunInFuzzMode(
10751128                const  file_path  =  file .lazy_path .getPath3 (b , step );
10761129                try  argv_list .append (arena , b .fmt ("{s}{s}" , .{ file .prefix , run .convertPathArg (file_path ) }));
10771130            },
1078-             .decorated_directory  = >  | dd |  {
1131+             .uncached_decorated_directory  ,  . decorated_directory= >  | dd |  {
10791132                const  file_path  =  dd .lazy_path .getPath3 (b , step );
10801133                try  argv_list .append (arena , b .fmt ("{s}{s}{s}" , .{ dd .prefix , run .convertPathArg (file_path ), dd .suffix  }));
10811134            },
0 commit comments