@@ -692,10 +692,21 @@ impl Config {
692
692
let mut llvm_from_ci = false ;
693
693
let mut lld_enabled = false ;
694
694
let mut channel = "dev" . to_string ( ) ;
695
- let mut out = PathBuf :: from ( "build" ) ;
695
+ let mut out = flags_build_dir
696
+ . or ( build_build_dir. map ( PathBuf :: from) )
697
+ . unwrap_or_else ( || PathBuf :: from ( "build" ) ) ;
696
698
let mut rust_info = GitInfo :: Absent ;
697
699
698
700
if cfg ! ( test) {
701
+ // Use the build directory of the original x.py invocation, so that we can set `initial_rustc` properly.
702
+ if out == PathBuf :: from ( "build" ) {
703
+ out = Path :: new (
704
+ & env:: var_os ( "CARGO_TARGET_DIR" ) . expect ( "cargo test directly is not supported" ) ,
705
+ )
706
+ . parent ( )
707
+ . unwrap ( )
708
+ . to_path_buf ( ) ;
709
+ }
699
710
// When configuring bootstrap for tests, make sure to set the rustc and Cargo to the
700
711
// same ones used to call the tests (if custom ones are not defined in the toml). If we
701
712
// don't do that, bootstrap will use its own detection logic to find a suitable rustc
@@ -705,7 +716,13 @@ impl Config {
705
716
build_cargo = build_cargo. take ( ) . or ( std:: env:: var_os ( "CARGO" ) . map ( |p| p. into ( ) ) ) ;
706
717
}
707
718
708
- let build_dir_ = flags_build_dir. or ( build_build_dir. map ( PathBuf :: from) ) ;
719
+ // NOTE: Bootstrap spawns various commands with different working directories.
720
+ // To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
721
+ if !out. is_absolute ( ) {
722
+ // `canonicalize` requires the path to already exist. Use our vendored copy of `absolute` instead.
723
+ out = absolute ( & out) . expect ( "can't make empty path absolute" ) ;
724
+ }
725
+
709
726
let host_ = if let Some ( TargetSelectionList ( hosts) ) = flags_host {
710
727
Some ( hosts)
711
728
} else {
@@ -736,18 +753,6 @@ impl Config {
736
753
paths_. extend ( exclude) ;
737
754
}
738
755
739
- // Infer the rest of the configuration.
740
-
741
- if cfg ! ( test) {
742
- // Use the build directory of the original x.py invocation, so that we can set `initial_rustc` properly.
743
- out = Path :: new (
744
- & env:: var_os ( "CARGO_TARGET_DIR" ) . expect ( "cargo test directly is not supported" ) ,
745
- )
746
- . parent ( )
747
- . unwrap ( )
748
- . to_path_buf ( ) ;
749
- }
750
-
751
756
let skip = paths_
752
757
. into_iter ( )
753
758
. map ( |p| {
@@ -769,14 +774,6 @@ impl Config {
769
774
"config.skip" = ?skip,
770
775
) ;
771
776
772
- set ( & mut out, build_dir_) ;
773
- // NOTE: Bootstrap spawns various commands with different working directories.
774
- // To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
775
- if !out. is_absolute ( ) {
776
- // `canonicalize` requires the path to already exist. Use our vendored copy of `absolute` instead.
777
- out = absolute ( & out) . expect ( "can't make empty path absolute" ) ;
778
- }
779
-
780
777
if build_cargo_clippy. is_some ( ) && build_rustc. is_none ( ) {
781
778
println ! (
782
779
"WARNING: Using `build.cargo-clippy` without `build.rustc` usually fails due to toolchain conflict."
0 commit comments