about summary refs log tree commit diff
diff options
context:
space:
mode:
authoronur-ozkan <work@onurozkan.dev>2024-10-16 19:42:25 +0300
committeronur-ozkan <work@onurozkan.dev>2024-11-10 23:11:47 +0300
commitbaa95efa7a8045d7174bf5aa57508d4ac82899f8 (patch)
tree799ff99ecf111620999f82632aeffcc4133f69b8
parentf5b62577f79396979585ee98ed3a52594207bce7 (diff)
downloadrust-baa95efa7a8045d7174bf5aa57508d4ac82899f8.tar.gz
rust-baa95efa7a8045d7174bf5aa57508d4ac82899f8.zip
use allowed "if-unchanged" logic for compiler builds
Signed-off-by: onur-ozkan <work@onurozkan.dev>
-rw-r--r--src/bootstrap/src/core/config/config.rs82
1 files changed, 65 insertions, 17 deletions
diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs
index f977c285a74..bb1c7219eda 100644
--- a/src/bootstrap/src/core/config/config.rs
+++ b/src/bootstrap/src/core/config/config.rs
@@ -28,6 +28,53 @@ use crate::utils::cache::{INTERNER, Interned};
 use crate::utils::channel::{self, GitInfo};
 use crate::utils::helpers::{self, exe, output, t};
 
+/// Each path in this list is considered "allowed" in the `download-rustc="if-unchanged"` logic.
+/// This means they can be modified and changes to these paths should never trigger a compiler build
+/// when "if-unchanged" is set.
+///
+/// NOTE: Paths must have the ":!" prefix to tell git to ignore changes in those paths during
+/// the diff check.
+///
+/// WARNING: Be cautious when adding paths to this list. If a path that influences the compiler build
+/// is added here, it will cause bootstrap to skip necessary rebuilds, which may lead to risky results.
+const RUSTC_IF_UNCHANGED_ALLOWED_PATHS: &[&str] = &[
+    ":!.clang-format",
+    ":!.editorconfig",
+    ":!.git-blame-ignore-revs",
+    ":!.gitattributes",
+    ":!.gitignore",
+    ":!.gitmodules",
+    ":!.ignore",
+    ":!.mailmap",
+    ":!CODE_OF_CONDUCT.md",
+    ":!CONTRIBUTING.md",
+    ":!COPYRIGHT",
+    ":!INSTALL.md",
+    ":!LICENSE-APACHE",
+    ":!LICENSE-MIT",
+    ":!LICENSES",
+    ":!README.md",
+    ":!RELEASES.md",
+    ":!REUSE.toml",
+    ":!config.example.toml",
+    ":!configure",
+    ":!rust-bors.toml",
+    ":!rustfmt.toml",
+    ":!tests",
+    ":!triagebot.toml",
+    ":!x",
+    ":!x.ps1",
+    ":!x.py",
+    ":!src/ci/cpu-usage-over-time.py",
+    ":!src/ci/publish_toolstate.sh",
+    ":!src/doc",
+    ":!src/etc",
+    ":!src/librustdoc",
+    ":!src/rustdoc-json-types",
+    ":!src/tools",
+    ":!src/README.md",
+];
+
 macro_rules! check_ci_llvm {
     ($name:expr) => {
         assert!(
@@ -2768,32 +2815,33 @@ impl Config {
             }
         };
 
-        let mut files_to_track = vec!["compiler", "src/version", "src/stage0", "src/ci/channel"];
+        // RUSTC_IF_UNCHANGED_ALLOWED_PATHS
+        let mut allowed_paths = RUSTC_IF_UNCHANGED_ALLOWED_PATHS.to_vec();
 
-        // In CI, disable ci-rustc if there are changes in the library tree. But for non-CI, ignore
+        // In CI, disable ci-rustc if there are changes in the library tree. But for non-CI, allow
         // these changes to speed up the build process for library developers. This provides consistent
         // functionality for library developers between `download-rustc=true` and `download-rustc="if-unchanged"`
         // options.
-        if CiEnv::is_ci() {
-            files_to_track.push("library");
+        if !CiEnv::is_ci() {
+            allowed_paths.push(":!library");
         }
 
         // Look for a version to compare to based on the current commit.
         // Only commits merged by bors will have CI artifacts.
-        let commit =
-            match self.last_modified_commit(&files_to_track, "download-rustc", if_unchanged) {
-                Some(commit) => commit,
-                None => {
-                    if if_unchanged {
-                        return None;
-                    }
-                    println!("ERROR: could not find commit hash for downloading rustc");
-                    println!("HELP: maybe your repository history is too shallow?");
-                    println!("HELP: consider disabling `download-rustc`");
-                    println!("HELP: or fetch enough history to include one upstream commit");
-                    crate::exit!(1);
+        let commit = match self.last_modified_commit(&allowed_paths, "download-rustc", if_unchanged)
+        {
+            Some(commit) => commit,
+            None => {
+                if if_unchanged {
+                    return None;
                 }
-            };
+                println!("ERROR: could not find commit hash for downloading rustc");
+                println!("HELP: maybe your repository history is too shallow?");
+                println!("HELP: consider setting `rust.download-rustc=false` in config.toml");
+                println!("HELP: or fetch enough history to include one upstream commit");
+                crate::exit!(1);
+            }
+        };
 
         if CiEnv::is_ci() && {
             let head_sha =