Skip to content

Commit 93022be

Browse files
committed
bootstrap: read config from $RUST_BOOTSTRAP_CONFIG
This commit modifies bootstrap so that `config.toml` is read first from `RUST_BOOTSTRAP_CONFIG`, then `--config` and finally `config.toml` in the current directory. This is a subjective change, intended to improve the ergnomics when using "development shells" for rustc development (for example, using tools such as Nix) which set environment variables to ensure a reproducible environment (these development shells can then be version controlled). By optionally reading `config.toml` from an environment variable, a `config.toml` can be defined in the development shell and a path to it exposed in the `RUST_BOOTSTRAP_CONFIG` environment variable - avoiding the need to manually symlink the contents of this file to `config.toml` in the working directory. Signed-off-by: David Wood <[email protected]>
1 parent 1fb612b commit 93022be

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

src/bootstrap/bootstrap.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ def bootstrap(help_triggered):
894894
build.clean = args.clean
895895

896896
try:
897-
toml_path = args.config or 'config.toml'
897+
toml_path = os.getenv('RUST_BOOTSTRAP_CONFIG') or args.config or 'config.toml'
898898
if not os.path.exists(toml_path):
899899
toml_path = os.path.join(build.rust_root, toml_path)
900900

@@ -947,6 +947,7 @@ def bootstrap(help_triggered):
947947
env["SRC"] = build.rust_root
948948
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
949949
env["BOOTSTRAP_PYTHON"] = sys.executable
950+
env["BOOTSTRAP_CONFIG"] = toml_path
950951
env["BUILD_DIR"] = build.build_dir
951952
env["RUSTC_BOOTSTRAP"] = '1'
952953
env["CARGO"] = build.cargo()

src/bootstrap/flags.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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::fs;
6+
use std::env;
77
use std::path::PathBuf;
88
use std::process;
99

@@ -433,13 +433,7 @@ Arguments:
433433
// Get any optional paths which occur after the subcommand
434434
let paths = matches.free[1..].iter().map(|p| p.into()).collect::<Vec<PathBuf>>();
435435

436-
let cfg_file = matches.opt_str("config").map(PathBuf::from).or_else(|| {
437-
if fs::metadata("config.toml").is_ok() {
438-
Some(PathBuf::from("config.toml"))
439-
} else {
440-
None
441-
}
442-
});
436+
let cfg_file = env::var_os("BOOTSTRAP_CONFIG").map(PathBuf::from);
443437

444438
// All subcommands except `clean` can have an optional "Available paths" section
445439
if matches.opt_present("verbose") {

0 commit comments

Comments
 (0)