Skip to content

Commit 3890992

Browse files
committed
Fix panic on x build --help --verbose
This also makes the panic message a little more informative in case it happens again.
1 parent 88c58e3 commit 3890992

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/bootstrap/flags.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,17 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
351351

352352
// fn usage()
353353
let usage = |exit_code: i32, opts: &Options, verbose: bool, subcommand_help: &str| -> ! {
354-
let config = Config::parse(&["setup".to_string()]);
354+
// We have an unfortunate situation here: some Steps use `builder.in_tree_crates` to determine their paths.
355+
// To determine those crates, we need to run `cargo metadata`, which means we need all submodules to be checked out.
356+
// That takes a while to run, so only do it when paths were explicitly requested, not on all CLI errors.
357+
// `Build::new` won't load submodules for the `setup` command.
358+
let cmd = if verbose {
359+
println!("note: updating submodules before printing available paths");
360+
"build"
361+
} else {
362+
"setup"
363+
};
364+
let config = Config::parse(&[cmd.to_string()]);
355365
let build = Build::new(config);
356366
let paths = Builder::get_help(&build, subcommand);
357367

src/bootstrap/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,10 @@ impl Build {
14001400
let mut list = vec![INTERNER.intern_str(root)];
14011401
let mut visited = HashSet::new();
14021402
while let Some(krate) = list.pop() {
1403-
let krate = &self.crates[&krate];
1403+
let krate = self
1404+
.crates
1405+
.get(&krate)
1406+
.unwrap_or_else(|| panic!("metadata missing for {krate}: {:?}", self.crates));
14041407
ret.push(krate);
14051408
for dep in &krate.deps {
14061409
if !self.crates.contains_key(dep) {

0 commit comments

Comments
 (0)