Skip to content

Commit 62b522e

Browse files
jyn514Mark-Simulacrum
authored andcommitted
Don't depend on python for RUST_BOOTSTRAP_CONFIG
1 parent 240f288 commit 62b522e

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

src/bootstrap/bootstrap.py

-2
Original file line numberDiff line numberDiff line change
@@ -1303,8 +1303,6 @@ def bootstrap(help_triggered):
13031303
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
13041304
env["BOOTSTRAP_PYTHON"] = sys.executable
13051305
env["RUSTC_BOOTSTRAP"] = '1'
1306-
if toml_path:
1307-
env["BOOTSTRAP_CONFIG"] = toml_path
13081306
if build.rustc_commit is not None:
13091307
env["BOOTSTRAP_DOWNLOAD_RUSTC"] = '1'
13101308
run(args, env=env, verbose=build.verbose, is_bootstrap=True)

src/bootstrap/config.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,15 @@ impl Config {
657657
}
658658
};
659659

660-
let mut toml = flags.config.as_deref().map(get_toml).unwrap_or_else(TomlConfig::default);
660+
// check --config first, then `$RUST_BOOTSTRAP_CONFIG` first, then `config.toml`
661+
let toml_path = flags
662+
.config
663+
.clone()
664+
.or_else(|| env::var_os("RUST_BOOTSTRAP_CONFIG").map(PathBuf::from))
665+
.unwrap_or_else(|| PathBuf::from("config.toml"));
666+
let mut toml =
667+
if toml_path.exists() { get_toml(&toml_path) } else { TomlConfig::default() };
668+
661669
if let Some(include) = &toml.profile {
662670
let mut include_path = config.src.clone();
663671
include_path.push("src");
@@ -669,9 +677,7 @@ impl Config {
669677
}
670678

671679
config.changelog_seen = toml.changelog_seen;
672-
if let Some(cfg) = flags.config {
673-
config.config = cfg;
674-
}
680+
config.config = toml_path;
675681

676682
let build = toml.build.unwrap_or_default();
677683

src/bootstrap/flags.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! This module implements the command-line parsing of the build system which
44
//! has various flags to configure how it's run.
55
6-
use std::env;
76
use std::path::PathBuf;
87
use std::process;
98

@@ -541,7 +540,6 @@ Arguments:
541540
// Get any optional paths which occur after the subcommand
542541
let mut paths = matches.free[1..].iter().map(|p| p.into()).collect::<Vec<PathBuf>>();
543542

544-
let cfg_file = env::var_os("BOOTSTRAP_CONFIG").map(PathBuf::from);
545543
let verbose = matches.opt_present("verbose");
546544

547545
// User passed in -h/--help?
@@ -671,7 +669,7 @@ Arguments:
671669
} else {
672670
None
673671
},
674-
config: cfg_file,
672+
config: matches.opt_str("config").map(PathBuf::from),
675673
jobs: matches.opt_str("jobs").map(|j| j.parse().expect("`jobs` should be a number")),
676674
cmd,
677675
incremental: matches.opt_present("incremental"),

src/bootstrap/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ impl Build {
629629
}
630630

631631
if let Subcommand::Setup { profile } = &self.config.cmd {
632-
return setup::setup(&self.config.src, *profile);
632+
return setup::setup(&self.config, *profile);
633633
}
634634

635635
{

src/bootstrap/setup.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::TargetSelection;
21
use crate::{t, VERSION};
2+
use crate::{Config, TargetSelection};
33
use std::env::consts::EXE_SUFFIX;
44
use std::fmt::Write as _;
55
use std::fs::File;
@@ -81,24 +81,22 @@ impl fmt::Display for Profile {
8181
}
8282
}
8383

84-
pub fn setup(src_path: &Path, profile: Profile) {
85-
let cfg_file = env::var_os("BOOTSTRAP_CONFIG").map(PathBuf::from);
84+
pub fn setup(config: &Config, profile: Profile) {
85+
let path = &config.config;
8686

87-
if cfg_file.as_ref().map_or(false, |f| f.exists()) {
88-
let file = cfg_file.unwrap();
87+
if path.exists() {
8988
println!(
9089
"error: you asked `x.py` to setup a new config file, but one already exists at `{}`",
91-
file.display()
90+
path.display()
9291
);
93-
println!("help: try adding `profile = \"{}\"` at the top of {}", profile, file.display());
92+
println!("help: try adding `profile = \"{}\"` at the top of {}", profile, path.display());
9493
println!(
9594
"note: this will use the configuration in {}",
96-
profile.include_path(src_path).display()
95+
profile.include_path(&config.src).display()
9796
);
9897
std::process::exit(1);
9998
}
10099

101-
let path = cfg_file.unwrap_or_else(|| "config.toml".into());
102100
let settings = format!(
103101
"# Includes one of the default files in src/bootstrap/defaults\n\
104102
profile = \"{}\"\n\
@@ -107,7 +105,7 @@ pub fn setup(src_path: &Path, profile: Profile) {
107105
);
108106
t!(fs::write(path, settings));
109107

110-
let include_path = profile.include_path(src_path);
108+
let include_path = profile.include_path(&config.src);
111109
println!("`x.py` will now use the configuration at {}", include_path.display());
112110

113111
let build = TargetSelection::from_user(&env!("BUILD_TRIPLE"));
@@ -138,7 +136,7 @@ pub fn setup(src_path: &Path, profile: Profile) {
138136

139137
println!();
140138

141-
t!(install_git_hook_maybe(src_path));
139+
t!(install_git_hook_maybe(&config.src));
142140

143141
println!();
144142

0 commit comments

Comments
 (0)