about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-08-10 10:23:46 +0200
committerLukas Wirth <lukastw97@gmail.com>2022-08-10 10:23:46 +0200
commit25d4fbe9dae2b875ebfa81a28e10796475def74b (patch)
tree2d1c385786ff2fe0c5aef0396a0dd0a978ad88fd
parent950de7c3c355398a9c15812b74376e252cb176db (diff)
downloadrust-25d4fbe9dae2b875ebfa81a28e10796475def74b.tar.gz
rust-25d4fbe9dae2b875ebfa81a28e10796475def74b.zip
Re-try build script building with --keep-going
-rw-r--r--crates/project-model/src/build_scripts.rs33
1 files changed, 23 insertions, 10 deletions
diff --git a/crates/project-model/src/build_scripts.rs b/crates/project-model/src/build_scripts.rs
index 4b00479a4c9..84e772d1684 100644
--- a/crates/project-model/src/build_scripts.rs
+++ b/crates/project-model/src/build_scripts.rs
@@ -39,7 +39,7 @@ pub(crate) struct BuildScriptOutput {
 }
 
 impl WorkspaceBuildScripts {
-    fn build_command(config: &CargoConfig, toolchain: &Option<Version>) -> Command {
+    fn build_command(config: &CargoConfig) -> Command {
         if let Some([program, args @ ..]) = config.run_build_script_command.as_deref() {
             let mut cmd = Command::new(program);
             cmd.args(args);
@@ -71,26 +71,39 @@ impl WorkspaceBuildScripts {
             }
         }
 
+        cmd
+    }
+
+    pub(crate) fn run(
+        config: &CargoConfig,
+        workspace: &CargoWorkspace,
+        progress: &dyn Fn(String),
+        toolchain: &Option<Version>,
+    ) -> io::Result<WorkspaceBuildScripts> {
         const RUST_1_62: Version = Version::new(1, 62, 0);
 
-        match toolchain {
-            Some(v) if v >= &RUST_1_62 => {
+        match Self::run_(Self::build_command(config), config, workspace, progress) {
+            Ok(WorkspaceBuildScripts { error: Some(error), .. })
+                if toolchain.as_ref().map_or(false, |it| *it >= RUST_1_62) =>
+            {
+                // building build scripts failed, attempt to build with --keep-going so
+                // that we potentially get more build data
+                let mut cmd = Self::build_command(config);
                 cmd.args(&["-Z", "unstable-options", "--keep-going"]).env("RUSTC_BOOTSTRAP", "1");
+                let mut res = Self::run_(cmd, config, workspace, progress)?;
+                res.error = Some(error);
+                Ok(res)
             }
-            _ => (),
+            res => res,
         }
-
-        cmd
     }
 
-    pub(crate) fn run(
+    fn run_(
+        mut cmd: Command,
         config: &CargoConfig,
         workspace: &CargoWorkspace,
         progress: &dyn Fn(String),
-        toolchain: &Option<Version>,
     ) -> io::Result<WorkspaceBuildScripts> {
-        let mut cmd = Self::build_command(config, toolchain);
-
         if config.wrap_rustc_in_build_scripts {
             // Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use
             // that to compile only proc macros and build scripts during the initial