diff --git a/config.example.toml b/config.example.toml index f5395375afe4c..865f53e6a59be 100644 --- a/config.example.toml +++ b/config.example.toml @@ -420,6 +420,9 @@ # What custom diff tool to use for displaying compiletest tests. #compiletest-diff-tool = +# List of tests or directories to exclude from the test suite. For example, exclude = ["tests/assembly", "tests/codegen"]; +#exclude = [] + # Indicates whether ccache is used when building certain artifacts (e.g. LLVM). # Set to `true` to use the first `ccache` in PATH, or set an absolute path to use # a specific version. diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index daef8fa3c8a34..8963386dd3373 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -257,8 +257,10 @@ impl PathSet { fn has(&self, needle: &Path, module: Kind) -> bool { match self { - PathSet::Set(set) => set.iter().any(|p| Self::check(p, needle, module)), - PathSet::Suite(suite) => Self::check(suite, needle, module), + PathSet::Set(set) => { + set.iter().any(|p| p.path == needle && Self::check(p, needle, module)) + } + PathSet::Suite(suite) => suite.path == needle && Self::check(suite, needle, module), } } @@ -426,13 +428,28 @@ impl StepDescription { } fn is_excluded(&self, builder: &Builder<'_>, pathset: &PathSet) -> bool { - if builder.config.skip.iter().any(|e| pathset.has(e, builder.kind)) { + // Helper function to determine if a path is explicitly excluded + let is_path_excluded = |exclude: &PathBuf| { + let exclude_path: &Path = exclude.as_path(); + pathset.has(exclude_path, builder.kind) + }; + // Check if the path is excluded by the --exclude flags + if builder.config.skip.iter().any(is_path_excluded) { if !matches!(builder.config.dry_run, DryRun::SelfCheck) { - println!("Skipping {pathset:?} because it is excluded"); + println!("Skipping {pathset:?} because it is excluded by --exclude flag"); } return true; } - + // Check if the path is excluded by the exclude field in config.toml + if let Some(ref excludes) = builder.config.exclude { + if excludes.iter().any(is_path_excluded) { + if !matches!(builder.config.dry_run, DryRun::SelfCheck) { + println!("Skipping {pathset:?} because it is excluded by config.toml"); + } + return true; + } + } + // Verbose logging if not excluded if !builder.config.skip.is_empty() && !matches!(builder.config.dry_run, DryRun::SelfCheck) { builder.verbose(|| { println!( @@ -441,6 +458,7 @@ impl StepDescription { ) }); } + false } diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index d27a8b155df73..780e16454b227 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -396,6 +396,9 @@ pub struct Config { /// Command for visual diff display, e.g. `diff-tool --color=always`. pub compiletest_diff_tool: Option, + + // For excluding tests from the test suite + pub exclude: Option>, } #[derive(Clone, Debug, Default)] @@ -935,6 +938,7 @@ define_config! { optimized_compiler_builtins: Option = "optimized-compiler-builtins", jobs: Option = "jobs", compiletest_diff_tool: Option = "compiletest-diff-tool", + exclude: Option> = "exclude", ccache: Option = "ccache", } } @@ -1624,6 +1628,7 @@ impl Config { optimized_compiler_builtins, jobs, compiletest_diff_tool, + exclude, mut ccache, } = toml.build.unwrap_or_default(); @@ -2315,6 +2320,7 @@ impl Config { config.optimized_compiler_builtins = optimized_compiler_builtins.unwrap_or(config.channel != "dev"); config.compiletest_diff_tool = compiletest_diff_tool; + config.exclude = exclude.map(|excludes| excludes.into_iter().map(PathBuf::from).collect()); let download_rustc = config.download_rustc_commit.is_some(); // See https://github.com/rust-lang/compiler-team/issues/326