Skip to content

Commit b711d17

Browse files
authored
Rollup merge of #94592 - jyn514:consistent-config-loading, r=Mark-Simulacrum
Fallback to top-level config.toml if not present in current directory, and remove fallback for env vars and CLI flags This preserves the behavior where x.py will only give a hard error on a missing config file if it was configured through `--config` or RUST_BOOTSTRAP_CONFIG. It also removes the top-level fallback for everything except the default path; presumably if you're passing the path explicitly, you expect it to be exactly there and don't want to look in the root directory. Fixes #94589.
2 parents 7189fce + 4d56f09 commit b711d17

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

Diff for: src/bootstrap/bootstrap.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1233,16 +1233,18 @@ def bootstrap(help_triggered):
12331233
build.verbose = args.verbose
12341234
build.clean = args.clean
12351235

1236-
# Read from `--config`, then `RUST_BOOTSTRAP_CONFIG`, then fallback to `config.toml` (if it
1237-
# exists).
1236+
# Read from `--config`, then `RUST_BOOTSTRAP_CONFIG`, then `./config.toml`,
1237+
# then `config.toml` in the root directory.
12381238
toml_path = args.config or os.getenv('RUST_BOOTSTRAP_CONFIG')
1239-
if not toml_path and os.path.exists('config.toml'):
1239+
using_default_path = toml_path is None
1240+
if using_default_path:
12401241
toml_path = 'config.toml'
1241-
1242-
if toml_path:
12431242
if not os.path.exists(toml_path):
12441243
toml_path = os.path.join(build.rust_root, toml_path)
12451244

1245+
# Give a hard error if `--config` or `RUST_BOOTSTRAP_CONFIG` are set to a missing path,
1246+
# but not if `config.toml` hasn't been created.
1247+
if not using_default_path or os.path.exists(toml_path):
12461248
with open(toml_path) as config:
12471249
build.config_toml = config.read()
12481250

Diff for: src/bootstrap/config.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,8 @@ impl Config {
647647
let get_toml = |file: &Path| {
648648
use std::process;
649649

650-
let contents = t!(fs::read_to_string(file), "`include` config not found");
650+
let contents =
651+
t!(fs::read_to_string(file), format!("config file {} not found", file.display()));
651652
match toml::from_str(&contents) {
652653
Ok(table) => table,
653654
Err(err) => {
@@ -657,14 +658,24 @@ impl Config {
657658
}
658659
};
659660

660-
// check --config first, then `$RUST_BOOTSTRAP_CONFIG` first, then `config.toml`
661+
// Read from `--config`, then `RUST_BOOTSTRAP_CONFIG`, then `./config.toml`, then `config.toml` in the root directory.
661662
let toml_path = flags
662663
.config
663664
.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() };
665+
.or_else(|| env::var_os("RUST_BOOTSTRAP_CONFIG").map(PathBuf::from));
666+
let using_default_path = toml_path.is_none();
667+
let mut toml_path = toml_path.unwrap_or_else(|| PathBuf::from("config.toml"));
668+
if using_default_path && !toml_path.exists() {
669+
toml_path = config.src.join(toml_path);
670+
}
671+
672+
// Give a hard error if `--config` or `RUST_BOOTSTRAP_CONFIG` are set to a missing path,
673+
// but not if `config.toml` hasn't been created.
674+
let mut toml = if !using_default_path || toml_path.exists() {
675+
get_toml(&toml_path)
676+
} else {
677+
TomlConfig::default()
678+
};
668679

669680
if let Some(include) = &toml.profile {
670681
let mut include_path = config.src.clone();

0 commit comments

Comments
 (0)