@@ -50,26 +50,39 @@ use crate::utils::channel;
5050use crate :: utils:: helpers:: exe;
5151use crate :: { Command , GitInfo , OnceLock , TargetSelection , check_ci_llvm, helpers, output, t} ;
5252
53- /// Each path in this list is considered "allowed" in the `download-rustc="if-unchanged"` logic.
53+ /// Each path from this function is considered "allowed" in the `download-rustc="if-unchanged"` logic.
5454/// This means they can be modified and changes to these paths should never trigger a compiler build
5555/// when "if-unchanged" is set.
56- ///
57- /// NOTE: Paths must have the ":!" prefix to tell git to ignore changes in those paths during
58- /// the diff check.
59- ///
60- /// WARNING: Be cautious when adding paths to this list. If a path that influences the compiler build
61- /// is added here, it will cause bootstrap to skip necessary rebuilds, which may lead to risky results.
62- /// For example, "src/bootstrap" should never be included in this list as it plays a crucial role in the
63- /// final output/compiler, which can be significantly affected by changes made to the bootstrap sources.
64- #[ rustfmt:: skip] // We don't want rustfmt to oneline this list
65- pub const RUSTC_IF_UNCHANGED_ALLOWED_PATHS : & [ & str ] = & [
66- ":!library" ,
67- ":!src/tools" ,
68- ":!src/librustdoc" ,
69- ":!src/rustdoc-json-types" ,
70- ":!tests" ,
71- ":!triagebot.toml" ,
72- ] ;
56+ pub fn rustc_if_unchanged_allowed_paths ( ) -> Vec < & ' static str > {
57+ // NOTE: Paths must have the ":!" prefix to tell git to ignore changes in those paths during
58+ // the diff check.
59+ //
60+ // WARNING: Be cautious when adding paths to this list. If a path that influences the compiler build
61+ // is added here, it will cause bootstrap to skip necessary rebuilds, which may lead to risky results.
62+ // For example, "src/bootstrap" should never be included in this list as it plays a crucial role in the
63+ // final output/compiler, which can be significantly affected by changes made to the bootstrap sources.
64+ let mut paths = vec ! [
65+ ":!library" ,
66+ ":!src/tools" ,
67+ ":!src/librustdoc" ,
68+ ":!src/rustdoc-json-types" ,
69+ ":!tests" ,
70+ ":!triagebot.toml" ,
71+ ] ;
72+
73+ if !CiEnv :: is_ci ( ) {
74+ // When a dependency is added/updated/removed in the library tree (or in some tools),
75+ // `Cargo.lock` will be updated by `cargo`. This update will incorrectly invalidate the
76+ // `download-rustc=if-unchanged` cache.
77+ //
78+ // To prevent this, add `Cargo.lock` to the list of allowed paths when not running on CI.
79+ // This is generally safe because changes to dependencies typically involve modifying
80+ // `Cargo.toml`, which would already invalidate the CI-rustc cache on non-allowed paths.
81+ paths. push ( ":!Cargo.lock" ) ;
82+ }
83+
84+ paths
85+ }
7386
7487/// Global configuration for the entire build and/or bootstrap.
7588///
@@ -1503,7 +1516,7 @@ impl Config {
15031516 let commit = if self . rust_info . is_managed_git_subrepository ( ) {
15041517 // Look for a version to compare to based on the current commit.
15051518 // Only commits merged by bors will have CI artifacts.
1506- let freshness = self . check_path_modifications ( RUSTC_IF_UNCHANGED_ALLOWED_PATHS ) ;
1519+ let freshness = self . check_path_modifications ( & rustc_if_unchanged_allowed_paths ( ) ) ;
15071520 self . verbose ( || {
15081521 eprintln ! ( "rustc freshness: {freshness:?}" ) ;
15091522 } ) ;
0 commit comments