Skip to content

Commit 2468461

Browse files
committed
add test coverage for rustc "if-unchanged" paths
Signed-off-by: onur-ozkan <[email protected]>
1 parent 0644e54 commit 2468461

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/bootstrap/src/core/config/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::utils::helpers::{self, exe, output, t};
3737
///
3838
/// WARNING: Be cautious when adding paths to this list. If a path that influences the compiler build
3939
/// is added here, it will cause bootstrap to skip necessary rebuilds, which may lead to risky results.
40-
const RUSTC_IF_UNCHANGED_ALLOWED_PATHS: &[&str] = &[
40+
pub(crate) const RUSTC_IF_UNCHANGED_ALLOWED_PATHS: &[&str] = &[
4141
":!.github",
4242
":!.clang-format",
4343
":!.editorconfig",
@@ -72,7 +72,7 @@ const RUSTC_IF_UNCHANGED_ALLOWED_PATHS: &[&str] = &[
7272
];
7373

7474
/// Holds subpaths from [`RUSTC_IF_UNCHANGED_ALLOWED_PATHS`] that should not be allowed.
75-
const RUSTC_IF_UNCHANGED_DENIED_SUBPATHS: &[&str] = &[
75+
pub(crate) const RUSTC_IF_UNCHANGED_DENIED_SUBPATHS: &[&str] = &[
7676
"src/stage0",
7777
"src/version",
7878
"src/ci/channel",

src/bootstrap/src/core/config/tests.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use clap::CommandFactory;
88
use serde::Deserialize;
99

1010
use super::flags::Flags;
11-
use super::{ChangeIdWrapper, Config};
11+
use super::{
12+
ChangeIdWrapper, Config, RUSTC_IF_UNCHANGED_ALLOWED_PATHS, RUSTC_IF_UNCHANGED_DENIED_SUBPATHS,
13+
};
1214
use crate::core::build_steps::clippy::get_clippy_rules_in_order;
1315
use crate::core::build_steps::llvm;
1416
use crate::core::config::{LldMode, Target, TargetSelection, TomlConfig};
@@ -352,3 +354,30 @@ fn parse_rust_std_features_empty() {
352354
fn parse_rust_std_features_invalid() {
353355
parse("rust.std-features = \"backtrace\"");
354356
}
357+
358+
#[test]
359+
fn check_rustc_if_unchaged_paths() {
360+
let config = parse("");
361+
let normalised_allowed_paths: Vec<_> = RUSTC_IF_UNCHANGED_ALLOWED_PATHS
362+
.iter()
363+
.map(|t| {
364+
t.strip_prefix(":!").expect(&format!("{t} doesn't have ':!' prefix, but it should."))
365+
})
366+
.collect();
367+
368+
let check_existence = |paths| {
369+
for p in paths {
370+
assert!(config.src.join(p).exists(), "{p} doesn't exist.");
371+
}
372+
};
373+
374+
check_existence(normalised_allowed_paths.as_slice());
375+
check_existence(RUSTC_IF_UNCHANGED_DENIED_SUBPATHS);
376+
377+
for p in RUSTC_IF_UNCHANGED_DENIED_SUBPATHS {
378+
assert!(
379+
normalised_allowed_paths.iter().any(|t| p.starts_with(t)),
380+
"{p} is not a subpath of an allowed path, there is no need to keep it in the denied list."
381+
);
382+
}
383+
}

0 commit comments

Comments
 (0)