@@ -70,7 +70,8 @@ fn show_usage() {
70
70
--use-system-gcc : Use system installed libgccjit
71
71
--build-only : Only build rustc_codegen_gcc then exits
72
72
--nb-parts : Used to split rustc_tests (for CI needs)
73
- --current-part : Used with `--nb-parts`, allows you to specify which parts to test"#
73
+ --current-part : Used with `--nb-parts`, allows you to specify which parts to test
74
+ --toolchain [arg] : The (rustc) toolchain to be used"#
74
75
) ;
75
76
ConfigInfo :: show_usage ( ) ;
76
77
for ( option, ( doc, _) ) in get_runners ( ) {
@@ -95,6 +96,7 @@ struct TestArg {
95
96
sysroot_panic_abort : bool ,
96
97
config_info : ConfigInfo ,
97
98
sysroot_features : Vec < String > ,
99
+ toolchain_name : Option < String > ,
98
100
keep_lto_tests : bool ,
99
101
}
100
102
@@ -142,6 +144,18 @@ impl TestArg {
142
144
return Err ( format ! ( "Expected an argument after `{}`, found nothing" , arg) ) ;
143
145
}
144
146
} ,
147
+ "--toolchain" => match args. next ( ) {
148
+ Some ( toolchain_name) if !toolchain_name. is_empty ( ) => {
149
+ if !toolchain_name. starts_with ( '+' ) {
150
+ test_arg. toolchain_name = Some ( format ! ( "+{toolchain_name}" ) ) ;
151
+ } else {
152
+ test_arg. toolchain_name = Some ( toolchain_name) ;
153
+ }
154
+ }
155
+ _ => {
156
+ return Err ( format ! ( "Expected an argument after `{}`, found nothing" , arg) ) ;
157
+ }
158
+ } ,
145
159
"--help" => {
146
160
show_usage ( ) ;
147
161
return Ok ( None ) ;
@@ -181,7 +195,7 @@ impl TestArg {
181
195
}
182
196
183
197
fn build_if_no_backend ( env : & Env , args : & TestArg ) -> Result < ( ) , String > {
184
- if args. config_info . backend . is_some ( ) {
198
+ if args. config_info . backend . is_some ( ) || args . toolchain_name . is_some ( ) {
185
199
return Ok ( ( ) ) ;
186
200
}
187
201
let mut command: Vec < & dyn AsRef < OsStr > > = vec ! [ & "cargo" , & "rustc" ] ;
@@ -459,6 +473,15 @@ fn std_tests(env: &Env, args: &TestArg) -> Result<(), String> {
459
473
Ok ( ( ) )
460
474
}
461
475
476
+ fn get_rustc_path_for_toolchain ( toolchain : & str , cwd : Option < & Path > ) -> Result < String , String > {
477
+ String :: from_utf8 ( run_command ( & [ & "rustup" , & toolchain, & "which" , & "rustc" ] , cwd) ?. stdout )
478
+ . map_err ( |error| format ! ( "Failed to retrieve rustc path: {:?}" , error) )
479
+ . and_then ( |rustc| {
480
+ let rustc = rustc. trim ( ) . to_owned ( ) ;
481
+ if rustc. is_empty ( ) { Err ( format ! ( "`rustc` path is empty" ) ) } else { Ok ( rustc) }
482
+ } )
483
+ }
484
+
462
485
fn setup_rustc ( env : & mut Env , args : & TestArg ) -> Result < PathBuf , String > {
463
486
let toolchain = format ! (
464
487
"+{channel}-{host}" ,
@@ -517,15 +540,7 @@ fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<PathBuf, String> {
517
540
let cargo = cargo. trim ( ) . to_owned ( ) ;
518
541
if cargo. is_empty ( ) { Err ( format ! ( "`cargo` path is empty" ) ) } else { Ok ( cargo) }
519
542
} ) ?;
520
- let rustc = String :: from_utf8 (
521
- run_command_with_env ( & [ & "rustup" , & toolchain, & "which" , & "rustc" ] , rust_dir, Some ( env) ) ?
522
- . stdout ,
523
- )
524
- . map_err ( |error| format ! ( "Failed to retrieve rustc path: {:?}" , error) )
525
- . and_then ( |rustc| {
526
- let rustc = rustc. trim ( ) . to_owned ( ) ;
527
- if rustc. is_empty ( ) { Err ( format ! ( "`rustc` path is empty" ) ) } else { Ok ( rustc) }
528
- } ) ?;
543
+ let rustc = get_rustc_path_for_toolchain ( & toolchain, rust_dir) ?;
529
544
let llvm_filecheck = match run_command_with_env (
530
545
& [
531
546
& "bash" ,
@@ -644,8 +659,10 @@ fn run_cargo_command_with_callback<F>(
644
659
where
645
660
F : Fn ( & [ & dyn AsRef < OsStr > ] , Option < & Path > , & Env ) -> Result < ( ) , String > ,
646
661
{
647
- let toolchain = get_toolchain ( ) ?;
648
- let toolchain_arg = format ! ( "+{}" , toolchain) ;
662
+ let toolchain_arg = match args. toolchain_name {
663
+ Some ( ref toolchain) => toolchain. clone ( ) ,
664
+ None => format ! ( "+{}" , get_toolchain( ) ?) ,
665
+ } ;
649
666
let rustc_version = String :: from_utf8 (
650
667
run_command_with_env ( & [ & args. config_info . rustc_command [ 0 ] , & "-V" ] , cwd, Some ( env) ) ?. stdout ,
651
668
)
@@ -1098,21 +1115,19 @@ where
1098
1115
1099
1116
env. get_mut ( "RUSTFLAGS" ) . unwrap ( ) . clear ( ) ;
1100
1117
1101
- run_command_with_output_and_env (
1102
- & [
1103
- & "./x.py" ,
1104
- & "test" ,
1105
- & "--run" ,
1106
- & "always" ,
1107
- & "--stage" ,
1108
- & "0" ,
1109
- & format ! ( "tests/{}" , test_type) ,
1110
- & "--compiletest-rustc-args" ,
1111
- & rustc_args,
1112
- ] ,
1113
- Some ( & rust_path) ,
1114
- Some ( & env) ,
1115
- ) ?;
1118
+ let test_type = format ! ( "tests/{}" , test_type) ;
1119
+ let mut command: Vec < & dyn AsRef < OsStr > > =
1120
+ vec ! [ & "./x.py" , & "test" , & "--run" , & "always" , & "--stage" , & "0" , & test_type] ;
1121
+ let rustc;
1122
+ if let Some ( ref toolchain) = args. toolchain_name {
1123
+ env. insert ( "COMPILETEST_FORCE_STAGE0=1" . to_string ( ) , "1" . to_string ( ) ) ;
1124
+ command. push ( & "--set" ) ;
1125
+ rustc = format ! ( "build.rustc={}" , get_rustc_path_for_toolchain( toolchain, None ) ?) ;
1126
+ command. push ( & rustc) ;
1127
+ }
1128
+ command. push ( & "--compiletest-rustc-args" ) ;
1129
+ command. push ( & rustc_args) ;
1130
+ run_command_with_output_and_env ( & command, Some ( & rust_path) , Some ( & env) ) ?;
1116
1131
Ok ( ( ) )
1117
1132
}
1118
1133
0 commit comments