@@ -485,19 +485,25 @@ fn std_tests(env: &Env, args: &TestArg) -> Result<(), String> {
485485 Ok ( ( ) )
486486}
487487
488- fn setup_rustc ( env : & mut Env , args : & TestArg ) -> Result < ( ) , String > {
488+ fn setup_rustc ( env : & mut Env , args : & TestArg ) -> Result < PathBuf , String > {
489489 let toolchain = format ! (
490490 "+{channel}-{host}" ,
491491 channel = get_toolchain( ) ?, // May also include date
492492 host = args. config_info. host_triple
493493 ) ;
494- let rust_dir = Some ( Path :: new ( "rust" ) ) ;
494+ let rust_dir_path = Path :: new ( crate :: BUILD_DIR ) . join ( "rust" ) ;
495495 // If the repository was already cloned, command will fail, so doesn't matter.
496496 let _ = run_command_with_output_and_env (
497- & [ & "git" , & "clone" , & "https://github.com/rust-lang/rust.git" ] ,
497+ & [
498+ & "git" ,
499+ & "clone" ,
500+ & "https://github.com/rust-lang/rust.git" ,
501+ & rust_dir_path,
502+ ] ,
498503 None ,
499504 Some ( env) ,
500505 ) ;
506+ let rust_dir: Option < & Path > = Some ( & rust_dir_path) ;
501507 run_command ( & [ & "git" , & "checkout" , & "--" , & "tests/" ] , rust_dir) ?;
502508 run_command_with_output_and_env ( & [ & "git" , & "fetch" ] , rust_dir, Some ( env) ) ?;
503509 let rustc_commit = match rustc_version_info ( env. get ( "RUSTC" ) . map ( |s| s. as_str ( ) ) ) ?. commit_hash {
@@ -561,8 +567,9 @@ fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<(), String> {
561567 String :: new ( )
562568 }
563569 } ;
570+ let file_path = rust_dir_path. join ( "config.toml" ) ;
564571 std:: fs:: write (
565- "rust/config.toml" ,
572+ & file_path ,
566573 & format ! (
567574 r#"change-id = 115898
568575
@@ -587,13 +594,19 @@ download-ci-llvm = false
587594 llvm_filecheck = llvm_filecheck. trim( ) ,
588595 ) ,
589596 )
590- . map_err ( |error| format ! ( "Failed to write into `rust/config.toml`: {:?}" , error) ) ?;
591- Ok ( ( ) )
597+ . map_err ( |error| {
598+ format ! (
599+ "Failed to write into `{}`: {:?}" ,
600+ file_path. display( ) ,
601+ error
602+ )
603+ } ) ?;
604+ Ok ( rust_dir_path)
592605}
593606
594607fn asm_tests ( env : & Env , args : & TestArg ) -> Result < ( ) , String > {
595608 let mut env = env. clone ( ) ;
596- setup_rustc ( & mut env, args) ?;
609+ let rust_dir = setup_rustc ( & mut env, args) ?;
597610 // FIXME: create a function "display_if_not_quiet" or something along the line.
598611 println ! ( "[TEST] rustc asm test suite" ) ;
599612
@@ -621,7 +634,7 @@ fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
621634 )
622635 . as_str ( ) ,
623636 ] ,
624- Some ( Path :: new ( "rust" ) ) ,
637+ Some ( & rust_dir ) ,
625638 Some ( & env) ,
626639 ) ?;
627640 Ok ( ( ) )
@@ -761,11 +774,11 @@ fn extended_rand_tests(env: &Env, args: &TestArg) -> Result<(), String> {
761774 println ! ( "Not using GCC master branch. Skipping `extended_rand_tests`." ) ;
762775 return Ok ( ( ) ) ;
763776 }
764- let path = Path :: new ( "rand" ) ;
765- run_cargo_command ( & [ & "clean" ] , Some ( path) , env, args) ?;
777+ let path = Path :: new ( crate :: BUILD_DIR ) . join ( "rand" ) ;
778+ run_cargo_command ( & [ & "clean" ] , Some ( & path) , env, args) ?;
766779 // FIXME: create a function "display_if_not_quiet" or something along the line.
767780 println ! ( "[TEST] rust-random/rand" ) ;
768- run_cargo_command ( & [ & "test" , & "--workspace" ] , Some ( path) , env, args) ?;
781+ run_cargo_command ( & [ & "test" , & "--workspace" ] , Some ( & path) , env, args) ?;
769782 Ok ( ( ) )
770783}
771784
@@ -774,8 +787,8 @@ fn extended_regex_example_tests(env: &Env, args: &TestArg) -> Result<(), String>
774787 println ! ( "Not using GCC master branch. Skipping `extended_regex_example_tests`." ) ;
775788 return Ok ( ( ) ) ;
776789 }
777- let path = Path :: new ( "regex" ) ;
778- run_cargo_command ( & [ & "clean" ] , Some ( path) , env, args) ?;
790+ let path = Path :: new ( crate :: BUILD_DIR ) . join ( "regex" ) ;
791+ run_cargo_command ( & [ & "clean" ] , Some ( & path) , env, args) ?;
779792 // FIXME: create a function "display_if_not_quiet" or something along the line.
780793 println ! ( "[TEST] rust-lang/regex example shootout-regex-dna" ) ;
781794 let mut env = env. clone ( ) ;
@@ -788,14 +801,14 @@ fn extended_regex_example_tests(env: &Env, args: &TestArg) -> Result<(), String>
788801 // Make sure `[codegen mono items] start` doesn't poison the diff
789802 run_cargo_command (
790803 & [ & "build" , & "--example" , & "shootout-regex-dna" ] ,
791- Some ( path) ,
804+ Some ( & path) ,
792805 & env,
793806 args,
794807 ) ?;
795808
796809 run_cargo_command_with_callback (
797810 & [ & "run" , & "--example" , & "shootout-regex-dna" ] ,
798- Some ( path) ,
811+ Some ( & path) ,
799812 & env,
800813 args,
801814 |cargo_command, cwd, env| {
@@ -838,6 +851,7 @@ fn extended_regex_tests(env: &Env, args: &TestArg) -> Result<(), String> {
838851 env. get( "RUSTFLAGS" ) . cloned( ) . unwrap_or_default( )
839852 ) ;
840853 env. insert ( "RUSTFLAGS" . to_string ( ) , rustflags) ;
854+ let path = Path :: new ( crate :: BUILD_DIR ) . join ( "regex" ) ;
841855 run_cargo_command (
842856 & [
843857 & "test" ,
@@ -850,7 +864,7 @@ fn extended_regex_tests(env: &Env, args: &TestArg) -> Result<(), String> {
850864 & "-Zunstable-options" ,
851865 & "-q" ,
852866 ] ,
853- Some ( Path :: new ( "regex" ) ) ,
867+ Some ( & path ) ,
854868 & env,
855869 args,
856870 ) ?;
@@ -928,17 +942,15 @@ fn should_remove_test(file_path: &Path) -> Result<bool, String> {
928942
929943fn test_rustc_inner < F > ( env : & Env , args : & TestArg , prepare_files_callback : F ) -> Result < ( ) , String >
930944where
931- F : Fn ( ) -> Result < bool , String > ,
945+ F : Fn ( & Path ) -> Result < bool , String > ,
932946{
933947 // FIXME: create a function "display_if_not_quiet" or something along the line.
934948 println ! ( "[TEST] rust-lang/rust" ) ;
935949 let mut env = env. clone ( ) ;
936- setup_rustc ( & mut env, args) ?;
937-
938- let rust_path = Path :: new ( "rust" ) ;
950+ let rust_path = setup_rustc ( & mut env, args) ?;
939951
940952 walk_dir (
941- "rust/ tests/ui",
953+ rust_path . join ( " tests/ui") ,
942954 |dir| {
943955 let dir_name = dir. file_name ( ) . and_then ( |name| name. to_str ( ) ) . unwrap_or ( "" ) ;
944956 if [
@@ -1001,7 +1013,7 @@ where
10011013
10021014 walk_dir ( rust_path. join ( "tests/ui" ) , dir_handling, file_handling) ?;
10031015
1004- if !prepare_files_callback ( ) ? {
1016+ if !prepare_files_callback ( & rust_path ) ? {
10051017 // FIXME: create a function "display_if_not_quiet" or something along the line.
10061018 println ! ( "Keeping all UI tests" ) ;
10071019 }
@@ -1027,7 +1039,7 @@ where
10271039 & "-path" ,
10281040 & "*/auxiliary/*" ,
10291041 ] ,
1030- Some ( rust_path) ,
1042+ Some ( & rust_path) ,
10311043 ) ?
10321044 . stdout ,
10331045 )
@@ -1072,18 +1084,18 @@ where
10721084 & "--rustc-args" ,
10731085 & rustc_args,
10741086 ] ,
1075- Some ( rust_path) ,
1087+ Some ( & rust_path) ,
10761088 Some ( & env) ,
10771089 ) ?;
10781090 Ok ( ( ) )
10791091}
10801092
10811093fn test_rustc ( env : & Env , args : & TestArg ) -> Result < ( ) , String > {
1082- test_rustc_inner ( env, args, || Ok ( false ) )
1094+ test_rustc_inner ( env, args, |_ | Ok ( false ) )
10831095}
10841096
10851097fn test_failing_rustc ( env : & Env , args : & TestArg ) -> Result < ( ) , String > {
1086- test_rustc_inner ( env, args, || {
1098+ test_rustc_inner ( env, args, |rust_path | {
10871099 // Removing all tests.
10881100 run_command (
10891101 & [
@@ -1098,7 +1110,7 @@ fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
10981110 & "*/auxiliary/*" ,
10991111 & "-delete" ,
11001112 ] ,
1101- Some ( Path :: new ( "rust" ) ) ,
1113+ Some ( rust_path ) ,
11021114 ) ?;
11031115 // Putting back only the failing ones.
11041116 let path = "tests/failing-ui-tests.txt" ;
@@ -1108,10 +1120,7 @@ fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
11081120 . map ( |line| line. trim ( ) )
11091121 . filter ( |line| !line. is_empty ( ) )
11101122 {
1111- run_command (
1112- & [ & "git" , & "checkout" , & "--" , & file] ,
1113- Some ( Path :: new ( "rust" ) ) ,
1114- ) ?;
1123+ run_command ( & [ & "git" , & "checkout" , & "--" , & file] , Some ( & rust_path) ) ?;
11151124 }
11161125 } else {
11171126 println ! (
@@ -1124,7 +1133,7 @@ fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
11241133}
11251134
11261135fn test_successful_rustc ( env : & Env , args : & TestArg ) -> Result < ( ) , String > {
1127- test_rustc_inner ( env, args, || {
1136+ test_rustc_inner ( env, args, |rust_path | {
11281137 // Removing the failing tests.
11291138 let path = "tests/failing-ui-tests.txt" ;
11301139 if let Ok ( files) = std:: fs:: read_to_string ( path) {
@@ -1133,7 +1142,7 @@ fn test_successful_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
11331142 . map ( |line| line. trim ( ) )
11341143 . filter ( |line| !line. is_empty ( ) )
11351144 {
1136- let path = Path :: new ( "rust" ) . join ( file) ;
1145+ let path = rust_path . join ( file) ;
11371146 remove_file ( & path) ?;
11381147 }
11391148 } else {
0 commit comments