about summary refs log tree commit diff
diff options
context:
space:
mode:
authoronur-ozkan <work@onurozkan.dev>2024-03-28 17:27:17 +0300
committeronur-ozkan <work@onurozkan.dev>2024-03-28 17:27:17 +0300
commit3683b11d212d938b5c314a0d0971b794d521046f (patch)
treedd847442ae80ed51bb0132ecd9ae03c34faf36dd
parentb75e6b4e7e7b12b461e70a5ffaf280b46c746575 (diff)
downloadrust-3683b11d212d938b5c314a0d0971b794d521046f.tar.gz
rust-3683b11d212d938b5c314a0d0971b794d521046f.zip
create `Build::update_existing_submodule` and use for llvm
Signed-off-by: onur-ozkan <work@onurozkan.dev>
-rw-r--r--src/bootstrap/src/core/build_steps/llvm.rs5
-rw-r--r--src/bootstrap/src/lib.rs12
2 files changed, 17 insertions, 0 deletions
diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs
index 327dc04b4e5..59fdd2e3caf 100644
--- a/src/bootstrap/src/core/build_steps/llvm.rs
+++ b/src/bootstrap/src/core/build_steps/llvm.rs
@@ -76,6 +76,9 @@ pub fn prebuilt_llvm_config(
     builder: &Builder<'_>,
     target: TargetSelection,
 ) -> Result<LlvmResult, Meta> {
+    // If we have llvm submodule initialized already, sync it.
+    builder.update_existing_submodule(&Path::new("src").join("llvm-project"));
+
     builder.config.maybe_download_ci_llvm();
 
     // If we're using a custom LLVM bail out here, but we can only use a
@@ -94,7 +97,9 @@ pub fn prebuilt_llvm_config(
         }
     }
 
+    // Initialize the llvm submodule if not initialized already.
     builder.update_submodule(&Path::new("src").join("llvm-project"));
+
     let root = "src/llvm-project/llvm";
     let out_dir = builder.llvm_out(target);
 
diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs
index f0fe994d155..9568514db51 100644
--- a/src/bootstrap/src/lib.rs
+++ b/src/bootstrap/src/lib.rs
@@ -625,6 +625,18 @@ impl Build {
         }
     }
 
+    /// Updates the given submodule only if it's initialized already; nothing happens otherwise.
+    pub fn update_existing_submodule(&self, submodule: &Path) {
+        // Avoid running git when there isn't a git checkout.
+        if !self.config.submodules(self.rust_info()) {
+            return;
+        }
+
+        if GitInfo::new(false, submodule).is_managed_git_subrepository() {
+            self.update_submodule(submodule);
+        }
+    }
+
     /// Executes the entire build, as configured by the flags and configuration.
     pub fn build(&mut self) {
         unsafe {