diff --git a/src/bootstrap/builder/tests.rs b/src/bootstrap/builder/tests.rs
index 0d321f139118..529783759966 100644
--- a/src/bootstrap/builder/tests.rs
+++ b/src/bootstrap/builder/tests.rs
@@ -26,6 +26,49 @@ fn first(v: Vec<(A, B)>) -> Vec {
v.into_iter().map(|(a, _)| a).collect::>()
}
+fn run_build(paths: &[PathBuf], config: Config) -> Cache {
+ let kind = config.cmd.kind();
+ let build = Build::new(config);
+ let builder = Builder::new(&build);
+ builder.run_step_descriptions(&Builder::get_step_descriptions(kind), paths);
+ builder.cache
+}
+
+#[test]
+fn test_exclude() {
+ let mut config = configure("test", &["A"], &["A"]);
+ config.exclude = vec![TaskPath::parse("src/tools/tidy")];
+
+ let build = Build::new(config);
+ let builder = Builder::new(&build);
+ builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Test), &[]);
+
+ // Ensure we have really excluded tidy
+ assert!(!builder.cache.contains::());
+
+ // Ensure other tests are not affected.
+ assert!(builder.cache.contains::());
+}
+
+#[test]
+fn test_exclude_kind() {
+ let path = PathBuf::from("src/tools/cargotest");
+ let exclude = TaskPath::parse("test::src/tools/cargotest");
+ assert_eq!(exclude, TaskPath { kind: Some(Kind::Test), path: path.clone() });
+
+ let mut config = configure("test", &["A"], &["A"]);
+ // Ensure our test is valid, and `test::Cargotest` would be run without the exclude.
+ assert!(run_build(&[path.clone()], config.clone()).contains::());
+ // Ensure tests for cargotest are skipped.
+ config.exclude = vec![exclude.clone()];
+ assert!(!run_build(&[path.clone()], config).contains::());
+
+ // Ensure builds for cargotest are not skipped.
+ let mut config = configure("build", &["A"], &["A"]);
+ config.exclude = vec![exclude];
+ assert!(run_build(&[path], config).contains::());
+}
+
mod defaults {
use super::{configure, first};
use crate::builder::*;
@@ -515,35 +558,6 @@ mod dist {
);
}
- #[test]
- fn test_exclude() {
- let mut config = configure(&["A"], &["A"]);
- config.exclude = vec![TaskPath::parse("src/tools/tidy")];
- config.cmd = Subcommand::Test {
- paths: Vec::new(),
- test_args: Vec::new(),
- rustc_args: Vec::new(),
- fail_fast: true,
- doc_tests: DocTests::No,
- bless: false,
- force_rerun: false,
- compare_mode: None,
- rustfix_coverage: false,
- pass: None,
- run: None,
- };
-
- let build = Build::new(config);
- let builder = Builder::new(&build);
- builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Test), &[]);
-
- // Ensure we have really excluded tidy
- assert!(!builder.cache.contains::());
-
- // Ensure other tests are not affected.
- assert!(builder.cache.contains::());
- }
-
#[test]
fn doc_ci() {
let mut config = configure(&["A"], &["A"]);
diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs
index f273fb42215e..1638d3ed3c28 100644
--- a/src/bootstrap/config.rs
+++ b/src/bootstrap/config.rs
@@ -41,6 +41,7 @@ macro_rules! check_ci_llvm {
/// each field, see the corresponding fields in
/// `config.toml.example`.
#[derive(Default)]
+#[cfg_attr(test, derive(Clone))]
pub struct Config {
pub changelog_seen: Option,
pub ccache: Option,
@@ -330,6 +331,7 @@ impl PartialEq<&str> for TargetSelection {
/// Per-target configuration stored in the global configuration structure.
#[derive(Default)]
+#[cfg_attr(test, derive(Clone))]
pub struct Target {
/// Some(path to llvm-config) if using an external LLVM.
pub llvm_config: Option,
diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs
index a82eb52e232b..58571ea129c1 100644
--- a/src/bootstrap/flags.rs
+++ b/src/bootstrap/flags.rs
@@ -14,6 +14,7 @@ use crate::setup::Profile;
use crate::util::t;
use crate::{Build, DocTests};
+#[derive(Copy, Clone)]
pub enum Color {
Always,
Never,
@@ -79,6 +80,7 @@ pub struct Flags {
pub llvm_profile_generate: bool,
}
+#[cfg_attr(test, derive(Clone))]
pub enum Subcommand {
Build {
paths: Vec,
@@ -668,6 +670,24 @@ Arguments:
}
impl Subcommand {
+ pub fn kind(&self) -> Kind {
+ match self {
+ Subcommand::Bench { .. } => Kind::Bench,
+ Subcommand::Build { .. } => Kind::Build,
+ Subcommand::Check { .. } => Kind::Check,
+ Subcommand::Clippy { .. } => Kind::Clippy,
+ Subcommand::Doc { .. } => Kind::Doc,
+ Subcommand::Fix { .. } => Kind::Fix,
+ Subcommand::Format { .. } => Kind::Format,
+ Subcommand::Test { .. } => Kind::Test,
+ Subcommand::Clean { .. } => Kind::Clean,
+ Subcommand::Dist { .. } => Kind::Dist,
+ Subcommand::Install { .. } => Kind::Install,
+ Subcommand::Run { .. } => Kind::Run,
+ Subcommand::Setup { .. } => Kind::Setup,
+ }
+ }
+
pub fn test_args(&self) -> Vec<&str> {
match *self {
Subcommand::Test { ref test_args, .. } | Subcommand::Bench { ref test_args, .. } => {