@@ -414,15 +414,17 @@ impl Config {
414
414
// Set config values based on flags.
415
415
let mut exec_ctx = ExecutionContext :: new ( flags_verbose, flags_cmd. fail_fast ( ) ) ;
416
416
exec_ctx. set_dry_run ( if flags_dry_run { DryRun :: UserSelected } else { DryRun :: Disabled } ) ;
417
- let mut src = {
417
+
418
+ let default_src_dir = {
418
419
let manifest_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
419
420
// Undo `src/bootstrap`
420
421
manifest_dir. parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . to_owned ( )
421
422
} ;
422
-
423
- if let Some ( src_) = compute_src_directory ( flags_src, & exec_ctx) {
424
- src = src_;
425
- }
423
+ let src = if let Some ( s) = compute_src_directory ( flags_src, & exec_ctx) {
424
+ s
425
+ } else {
426
+ default_src_dir. clone ( )
427
+ } ;
426
428
427
429
#[ cfg( test) ]
428
430
{
@@ -659,6 +661,10 @@ impl Config {
659
661
out
660
662
} ;
661
663
664
+ let default_stage0_rustc_path = |dir : & Path | {
665
+ dir. join ( host_target) . join ( "stage0" ) . join ( "bin" ) . join ( exe ( "rustc" , host_target) )
666
+ } ;
667
+
662
668
if cfg ! ( test) {
663
669
// When configuring bootstrap for tests, make sure to set the rustc and Cargo to the
664
670
// same ones used to call the tests (if custom ones are not defined in the toml). If we
@@ -667,6 +673,22 @@ impl Config {
667
673
// Cargo in their bootstrap.toml.
668
674
build_rustc = build_rustc. take ( ) . or ( std:: env:: var_os ( "RUSTC" ) . map ( |p| p. into ( ) ) ) ;
669
675
build_cargo = build_cargo. take ( ) . or ( std:: env:: var_os ( "CARGO" ) . map ( |p| p. into ( ) ) ) ;
676
+
677
+ // If we are running only `cargo test` (and not `x test bootstrap`), which is useful
678
+ // e.g. for debugging bootstrap itself, then we won't have RUSTC and CARGO set to the
679
+ // proper paths.
680
+ // We thus "guess" that the build directory is located at <src>/build, and try to load
681
+ // rustc and cargo from there
682
+ let is_test_outside_x = std:: env:: var ( "CARGO_TARGET_DIR" ) . is_err ( ) ;
683
+ if is_test_outside_x && build_rustc. is_none ( ) {
684
+ let stage0_rustc = default_stage0_rustc_path ( & default_src_dir. join ( "build" ) ) ;
685
+ assert ! (
686
+ stage0_rustc. exists( ) ,
687
+ "Trying to run cargo test without having a stage0 rustc available in {}" ,
688
+ stage0_rustc. display( )
689
+ ) ;
690
+ build_rustc = Some ( stage0_rustc) ;
691
+ }
670
692
}
671
693
672
694
if !flags_skip_stage0_validation {
@@ -700,7 +722,7 @@ impl Config {
700
722
701
723
let initial_rustc = build_rustc. unwrap_or_else ( || {
702
724
download_beta_toolchain ( & dwn_ctx, & out) ;
703
- out . join ( host_target ) . join ( "stage0" ) . join ( "bin" ) . join ( exe ( "rustc" , host_target ) )
725
+ default_stage0_rustc_path ( & out )
704
726
} ) ;
705
727
706
728
let initial_sysroot = t ! ( PathBuf :: from_str(
@@ -1540,11 +1562,11 @@ impl Config {
1540
1562
println ! ( "WARNING: CI rustc has some fields that are no longer supported in bootstrap; download-rustc will be disabled." ) ;
1541
1563
println ! ( "HELP: Consider rebasing to a newer commit if available." ) ;
1542
1564
return None ;
1543
- } ,
1565
+ }
1544
1566
Err ( e) => {
1545
1567
eprintln ! ( "ERROR: Failed to parse CI rustc bootstrap.toml: {e}" ) ;
1546
1568
exit ! ( 2 ) ;
1547
- } ,
1569
+ }
1548
1570
} ;
1549
1571
1550
1572
let current_config_toml = Self :: get_toml ( config_path) . unwrap ( ) ;
0 commit comments