about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-12-27 04:44:42 +0000
committerbors <bors@rust-lang.org>2022-12-27 04:44:42 +0000
commite3961864075eaa9e855e5eec6b4f148029684539 (patch)
tree6485353169f1faa148975a3fd4ee7b68e4cc79c8
parent58f5a0180ccd4ab87363c4b35a23fbe15a9a310c (diff)
parent3890992d0a9509bfab77659bc23f065ebcd3c2ba (diff)
downloadrust-e3961864075eaa9e855e5eec6b4f148029684539.tar.gz
rust-e3961864075eaa9e855e5eec6b4f148029684539.zip
Auto merge of #106166 - jyn514:print-paths, r=Mark-Simulacrum
Fix panic on `x build --help --verbose`

See https://github.com/rust-lang/rust/issues/106165 for a detailed description of what went wrong here.

This also makes the panic message a little more informative in case it happens again.
-rw-r--r--src/bootstrap/flags.rs12
-rw-r--r--src/bootstrap/lib.rs5
2 files changed, 15 insertions, 2 deletions
diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs
index 851cb5ecf4c..de39868d692 100644
--- a/src/bootstrap/flags.rs
+++ b/src/bootstrap/flags.rs
@@ -351,7 +351,17 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
 
         // fn usage()
         let usage = |exit_code: i32, opts: &Options, verbose: bool, subcommand_help: &str| -> ! {
-            let config = Config::parse(&["setup".to_string()]);
+            // We have an unfortunate situation here: some Steps use `builder.in_tree_crates` to determine their paths.
+            // To determine those crates, we need to run `cargo metadata`, which means we need all submodules to be checked out.
+            // That takes a while to run, so only do it when paths were explicitly requested, not on all CLI errors.
+            // `Build::new` won't load submodules for the `setup` command.
+            let cmd = if verbose {
+                println!("note: updating submodules before printing available paths");
+                "build"
+            } else {
+                "setup"
+            };
+            let config = Config::parse(&[cmd.to_string()]);
             let build = Build::new(config);
             let paths = Builder::get_help(&build, subcommand);
 
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index f84fcd21cfc..ced1e397807 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -1400,7 +1400,10 @@ impl Build {
         let mut list = vec![INTERNER.intern_str(root)];
         let mut visited = HashSet::new();
         while let Some(krate) = list.pop() {
-            let krate = &self.crates[&krate];
+            let krate = self
+                .crates
+                .get(&krate)
+                .unwrap_or_else(|| panic!("metadata missing for {krate}: {:?}", self.crates));
             ret.push(krate);
             for dep in &krate.deps {
                 if !self.crates.contains_key(dep) {