Skip to content

Commit de82703

Browse files
committed
make out variable streamlined
1 parent ed62c3c commit de82703

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

src/bootstrap/src/core/config/config.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,21 @@ impl Config {
692692
let mut llvm_from_ci = false;
693693
let mut lld_enabled = false;
694694
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"));
696698
let mut rust_info = GitInfo::Absent;
697699

698700
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+
}
699710
// When configuring bootstrap for tests, make sure to set the rustc and Cargo to the
700711
// same ones used to call the tests (if custom ones are not defined in the toml). If we
701712
// don't do that, bootstrap will use its own detection logic to find a suitable rustc
@@ -705,7 +716,13 @@ impl Config {
705716
build_cargo = build_cargo.take().or(std::env::var_os("CARGO").map(|p| p.into()));
706717
}
707718

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+
709726
let host_ = if let Some(TargetSelectionList(hosts)) = flags_host {
710727
Some(hosts)
711728
} else {
@@ -736,18 +753,6 @@ impl Config {
736753
paths_.extend(exclude);
737754
}
738755

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-
751756
let skip = paths_
752757
.into_iter()
753758
.map(|p| {
@@ -769,14 +774,6 @@ impl Config {
769774
"config.skip" = ?skip,
770775
);
771776

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-
780777
if build_cargo_clippy.is_some() && build_rustc.is_none() {
781778
println!(
782779
"WARNING: Using `build.cargo-clippy` without `build.rustc` usually fails due to toolchain conflict."

0 commit comments

Comments
 (0)