From 13123c621f3b5c5cf2f85b36d5529ee61da8e5c3 Mon Sep 17 00:00:00 2001 From: Aditya-PS-05 Date: Wed, 15 Jan 2025 20:29:44 +0530 Subject: [PATCH] Add support for excluding tests via config.toml --- config.example.toml | 3 +++ src/bootstrap/src/core/builder/mod.rs | 28 ++++++++++++++++++++----- src/bootstrap/src/core/config/config.rs | 6 ++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/config.example.toml b/config.example.toml index 04e7310e6bc34..13d32a4f37ad2 100644 --- a/config.example.toml +++ b/config.example.toml @@ -424,6 +424,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 = [] + # ============================================================================= # General install configuration options # ============================================================================= diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index 17de176242732..652fa5ecff9ee 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -251,8 +251,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), } } @@ -417,13 +419,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!( @@ -432,6 +449,7 @@ impl StepDescription { ) }); } + false } diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 026380a46c685..39c31b263b148 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -392,6 +392,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)] @@ -924,6 +927,7 @@ define_config! { optimized_compiler_builtins: Option = "optimized-compiler-builtins", jobs: Option = "jobs", compiletest_diff_tool: Option = "compiletest-diff-tool", + exclude: Option> = "exclude", } } @@ -1564,6 +1568,7 @@ impl Config { optimized_compiler_builtins, jobs, compiletest_diff_tool, + exclude, } = toml.build.unwrap_or_default(); config.jobs = Some(threads_from_config(flags.jobs.unwrap_or(jobs.unwrap_or(0)))); @@ -2245,6 +2250,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