Don't depend on python for RUST_BOOTSTRAP_CONFIG

This commit is contained in:
Joshua Nelson 2022-02-06 18:10:49 -06:00 committed by Mark Rousskov
parent 240f288329
commit 62b522ec3a
5 changed files with 21 additions and 21 deletions

View file

@ -1303,8 +1303,6 @@ def bootstrap(help_triggered):
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid()) env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
env["BOOTSTRAP_PYTHON"] = sys.executable env["BOOTSTRAP_PYTHON"] = sys.executable
env["RUSTC_BOOTSTRAP"] = '1' env["RUSTC_BOOTSTRAP"] = '1'
if toml_path:
env["BOOTSTRAP_CONFIG"] = toml_path
if build.rustc_commit is not None: if build.rustc_commit is not None:
env["BOOTSTRAP_DOWNLOAD_RUSTC"] = '1' env["BOOTSTRAP_DOWNLOAD_RUSTC"] = '1'
run(args, env=env, verbose=build.verbose, is_bootstrap=True) run(args, env=env, verbose=build.verbose, is_bootstrap=True)

View file

@ -657,7 +657,15 @@ impl Config {
} }
}; };
let mut toml = flags.config.as_deref().map(get_toml).unwrap_or_else(TomlConfig::default); // check --config first, then `$RUST_BOOTSTRAP_CONFIG` first, then `config.toml`
let toml_path = flags
.config
.clone()
.or_else(|| env::var_os("RUST_BOOTSTRAP_CONFIG").map(PathBuf::from))
.unwrap_or_else(|| PathBuf::from("config.toml"));
let mut toml =
if toml_path.exists() { get_toml(&toml_path) } else { TomlConfig::default() };
if let Some(include) = &toml.profile { if let Some(include) = &toml.profile {
let mut include_path = config.src.clone(); let mut include_path = config.src.clone();
include_path.push("src"); include_path.push("src");
@ -669,9 +677,7 @@ impl Config {
} }
config.changelog_seen = toml.changelog_seen; config.changelog_seen = toml.changelog_seen;
if let Some(cfg) = flags.config { config.config = toml_path;
config.config = cfg;
}
let build = toml.build.unwrap_or_default(); let build = toml.build.unwrap_or_default();

View file

@ -3,7 +3,6 @@
//! This module implements the command-line parsing of the build system which //! This module implements the command-line parsing of the build system which
//! has various flags to configure how it's run. //! has various flags to configure how it's run.
use std::env;
use std::path::PathBuf; use std::path::PathBuf;
use std::process; use std::process;
@ -541,7 +540,6 @@ Arguments:
// Get any optional paths which occur after the subcommand // Get any optional paths which occur after the subcommand
let mut paths = matches.free[1..].iter().map(|p| p.into()).collect::<Vec<PathBuf>>(); let mut paths = matches.free[1..].iter().map(|p| p.into()).collect::<Vec<PathBuf>>();
let cfg_file = env::var_os("BOOTSTRAP_CONFIG").map(PathBuf::from);
let verbose = matches.opt_present("verbose"); let verbose = matches.opt_present("verbose");
// User passed in -h/--help? // User passed in -h/--help?
@ -671,7 +669,7 @@ Arguments:
} else { } else {
None None
}, },
config: cfg_file, config: matches.opt_str("config").map(PathBuf::from),
jobs: matches.opt_str("jobs").map(|j| j.parse().expect("`jobs` should be a number")), jobs: matches.opt_str("jobs").map(|j| j.parse().expect("`jobs` should be a number")),
cmd, cmd,
incremental: matches.opt_present("incremental"), incremental: matches.opt_present("incremental"),

View file

@ -629,7 +629,7 @@ impl Build {
} }
if let Subcommand::Setup { profile } = &self.config.cmd { if let Subcommand::Setup { profile } = &self.config.cmd {
return setup::setup(&self.config.src, *profile); return setup::setup(&self.config, *profile);
} }
{ {

View file

@ -1,5 +1,5 @@
use crate::TargetSelection;
use crate::{t, VERSION}; use crate::{t, VERSION};
use crate::{Config, TargetSelection};
use std::env::consts::EXE_SUFFIX; use std::env::consts::EXE_SUFFIX;
use std::fmt::Write as _; use std::fmt::Write as _;
use std::fs::File; use std::fs::File;
@ -81,24 +81,22 @@ impl fmt::Display for Profile {
} }
} }
pub fn setup(src_path: &Path, profile: Profile) { pub fn setup(config: &Config, profile: Profile) {
let cfg_file = env::var_os("BOOTSTRAP_CONFIG").map(PathBuf::from); let path = &config.config;
if cfg_file.as_ref().map_or(false, |f| f.exists()) { if path.exists() {
let file = cfg_file.unwrap();
println!( println!(
"error: you asked `x.py` to setup a new config file, but one already exists at `{}`", "error: you asked `x.py` to setup a new config file, but one already exists at `{}`",
file.display() path.display()
); );
println!("help: try adding `profile = \"{}\"` at the top of {}", profile, file.display()); println!("help: try adding `profile = \"{}\"` at the top of {}", profile, path.display());
println!( println!(
"note: this will use the configuration in {}", "note: this will use the configuration in {}",
profile.include_path(src_path).display() profile.include_path(&config.src).display()
); );
std::process::exit(1); std::process::exit(1);
} }
let path = cfg_file.unwrap_or_else(|| "config.toml".into());
let settings = format!( let settings = format!(
"# Includes one of the default files in src/bootstrap/defaults\n\ "# Includes one of the default files in src/bootstrap/defaults\n\
profile = \"{}\"\n\ profile = \"{}\"\n\
@ -107,7 +105,7 @@ pub fn setup(src_path: &Path, profile: Profile) {
); );
t!(fs::write(path, settings)); t!(fs::write(path, settings));
let include_path = profile.include_path(src_path); let include_path = profile.include_path(&config.src);
println!("`x.py` will now use the configuration at {}", include_path.display()); println!("`x.py` will now use the configuration at {}", include_path.display());
let build = TargetSelection::from_user(&env!("BUILD_TRIPLE")); let build = TargetSelection::from_user(&env!("BUILD_TRIPLE"));
@ -138,7 +136,7 @@ pub fn setup(src_path: &Path, profile: Profile) {
println!(); println!();
t!(install_git_hook_maybe(src_path)); t!(install_git_hook_maybe(&config.src));
println!(); println!();