@@ -663,7 +663,6 @@ echo "---END-INVOCATION---" >> "{}"
663663 }
664664
665665 let toolchain_path = get_toolchain_path ( ) ;
666- let lean_backend_dir = toolchain_path. join ( "backends/lean" ) ;
667666
668667 // Resolve Mocks
669668
@@ -762,9 +761,18 @@ echo "---END-INVOCATION---" >> "{}"
762761 cmd. env ( "ANNEAL_FORCE_TTY" , "1" ) ;
763762 cmd. env ( "FORCE_COLOR" , "1" ) ;
764763 let isolated_aeneas_dir = self . sandbox_root . join ( "aeneas_cache" ) ;
765- fs:: create_dir_all ( & isolated_aeneas_dir) . unwrap ( ) ;
766- cmd. env ( "ANNEAL_AENEAS_DIR" , isolated_aeneas_dir) ;
767- cmd. env ( "ANNEAL_INTEGRATION_TEST_LEAN_CACHE_DIR" , & lean_backend_dir) ;
764+ let isolated_lean_dir = isolated_aeneas_dir. join ( "backends/lean" ) ;
765+
766+ if !isolated_lean_dir. exists ( ) {
767+ fs:: create_dir_all ( isolated_lean_dir. parent ( ) . unwrap ( ) ) . unwrap ( ) ;
768+
769+ // Populate the isolated Aeneas directory from the worker cache
770+ // to allow dependency pinning to work without test-specific code in src.
771+ smart_clone_cache ( & self . worker_cache . aeneas . join ( "backends/lean" ) , & isolated_lean_dir)
772+ . expect ( "Failed to populate isolated Aeneas directory" ) ;
773+ }
774+
775+ cmd. env ( "ANNEAL_AENEAS_DIR" , & isolated_aeneas_dir) ;
768776 cmd. env ( "ANNEAL_USE_PATH_FOR_TOOLS" , "1" ) ;
769777 cmd. env ( "RAYON_NUM_THREADS" , "1" ) ;
770778
@@ -821,7 +829,7 @@ echo "---END-INVOCATION---" >> "{}"
821829/// - Hardlinks heavy immutable binaries (.olean, .c) to save disk space and
822830/// time. Because these were previously marked as read-only, any attempts at
823831/// mutation will fail loudly rather than result in race conditions.
824- fn smart_clone_cache ( source : & Path , target : & Path ) -> io :: Result < ( ) > {
832+ fn smart_clone_cache ( source : & Path , target : & Path ) -> anyhow :: Result < ( ) > {
825833 let walker = new_sorted_walkdir ( source) . into_iter ( ) . filter_entry ( |e| {
826834 // Instantly bypass traversing inside ANY `.git/objects` directory!
827835 // This prevents ~230,000 file copies per Mathlib clone.
@@ -835,19 +843,29 @@ fn smart_clone_cache(source: &Path, target: &Path) -> io::Result<()> {
835843 } ) ;
836844
837845 for entry in walker {
838- let entry = entry. map_err ( io :: Error :: other ) ?;
846+ let entry = entry. map_err ( |e| anyhow :: anyhow! ( "Failed to walk directory: {}" , e ) ) ?;
839847 let source_path = entry. path ( ) ;
840848 let relative_path = source_path. strip_prefix ( source) . unwrap ( ) ;
841849 let target_path = target. join ( relative_path) ;
842850
843851 if entry. file_type ( ) . is_dir ( ) {
844- fs:: create_dir_all ( & target_path) ?;
852+ fs:: create_dir_all ( & target_path)
853+ . map_err ( |e| anyhow:: anyhow!( "Failed to create dir {:?}: {}" , target_path, e) ) ?;
845854
846855 // If this is a .git directory, manually symlink its objects folder
847856 if source_path. file_name ( ) . and_then ( |s| s. to_str ( ) ) == Some ( ".git" ) {
848857 let src_objects = source_path. join ( "objects" ) ;
849858 if src_objects. exists ( ) {
850- let _ = std:: os:: unix:: fs:: symlink ( & src_objects, target_path. join ( "objects" ) ) ;
859+ std:: os:: unix:: fs:: symlink ( & src_objects, target_path. join ( "objects" ) ) . map_err (
860+ |e| {
861+ anyhow:: anyhow!(
862+ "Failed to symlink .git/objects from {:?} to {:?}: {}" ,
863+ src_objects,
864+ target_path. join( "objects" ) ,
865+ e
866+ )
867+ } ,
868+ ) ?;
851869 }
852870 }
853871 } else if entry. file_type ( ) . is_file ( ) {
@@ -863,11 +881,19 @@ fn smart_clone_cache(source: &Path, target: &Path) -> io::Result<()> {
863881 || file_name == "lake.lock" ;
864882
865883 if is_mutable_metadata {
866- fs:: copy ( source_path, & target_path) ?;
867- let mut perms = fs:: metadata ( & target_path) ?. permissions ( ) ;
884+ fs:: copy ( source_path, & target_path) . map_err ( |e| {
885+ anyhow:: anyhow!( "Failed to copy {:?} to {:?}: {}" , source_path, target_path, e)
886+ } ) ?;
887+ let mut perms = fs:: metadata ( & target_path)
888+ . map_err ( |e| {
889+ anyhow:: anyhow!( "Failed to get metadata of {:?}: {}" , target_path, e)
890+ } ) ?
891+ . permissions ( ) ;
868892 #[ allow( clippy:: permissions_set_readonly_false) ]
869893 perms. set_readonly ( false ) ;
870- fs:: set_permissions ( & target_path, perms) ?;
894+ fs:: set_permissions ( & target_path, perms) . map_err ( |e| {
895+ anyhow:: anyhow!( "Failed to set permissions on {:?}: {}" , target_path, e)
896+ } ) ?;
871897 } else {
872898 // NOTE: It is crucial that we *don't* provide a deep-copy
873899 // fallback path here. The symlinked files consume a huge amount
@@ -879,7 +905,14 @@ fn smart_clone_cache(source: &Path, target: &Path) -> io::Result<()> {
879905 // that these errors are surfaced (rather than being worked
880906 // around – e.g. via deep copying) so that we know to fix the
881907 // bugs.
882- std:: os:: unix:: fs:: symlink ( source_path, & target_path) ?;
908+ std:: os:: unix:: fs:: symlink ( source_path, & target_path) . map_err ( |e| {
909+ anyhow:: anyhow!(
910+ "Failed to symlink {:?} to {:?}: {}" ,
911+ source_path,
912+ target_path,
913+ e
914+ )
915+ } ) ?;
883916 }
884917 }
885918 }
0 commit comments