From 3bac5c0f39d9db39cb82f4fb77ef9deee7ff9e0f Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 21 Apr 2022 21:50:33 -0500 Subject: [PATCH] Use `run_build` helper consistently across most bootstrap tests This is not super important to do, but the consistency is nice. I didn't change any tests that call `configure("dist")` and then override the subcommand - doing that at all is pretty sketchy, but I don't want to mess with it while already doing a refactor. --- src/bootstrap/builder/tests.rs | 165 ++++++++++++++------------------- 1 file changed, 69 insertions(+), 96 deletions(-) diff --git a/src/bootstrap/builder/tests.rs b/src/bootstrap/builder/tests.rs index 52978375996..3b6cd7564f0 100644 --- a/src/bootstrap/builder/tests.rs +++ b/src/bootstrap/builder/tests.rs @@ -38,16 +38,13 @@ fn run_build(paths: &[PathBuf], config: Config) -> Cache { 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), &[]); + let cache = run_build(&[], config); // Ensure we have really excluded tidy - assert!(!builder.cache.contains::()); + assert!(!cache.contains::()); // Ensure other tests are not affected. - assert!(builder.cache.contains::()); + assert!(cache.contains::()); } #[test] @@ -70,35 +67,33 @@ fn test_exclude_kind() { } mod defaults { - use super::{configure, first}; + use super::{configure, first, run_build}; use crate::builder::*; use crate::Config; use pretty_assertions::assert_eq; #[test] fn build_default() { - let build = Build::new(configure("build", &["A"], &["A"])); - let mut builder = Builder::new(&build); - builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]); + let mut cache = run_build(&[], configure("build", &["A"], &["A"])); let a = TargetSelection::from_user("A"); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[ compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a }, compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a }, ] ); - assert!(!builder.cache.all::().is_empty()); + assert!(!cache.all::().is_empty()); // Make sure rustdoc is only built once. assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), // Recall that rustdoc stages are off-by-one // - this is the compiler it's _linked_ to, not built with. &[tool::Rustdoc { compiler: Compiler { host: a, stage: 1 } }], ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },] ); } @@ -106,31 +101,27 @@ mod defaults { #[test] fn build_stage_0() { let config = Config { stage: 0, ..configure("build", &["A"], &["A"]) }; - let build = Build::new(config); - let mut builder = Builder::new(&build); - builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]); + let mut cache = run_build(&[], config); let a = TargetSelection::from_user("A"); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },] ); - assert!(!builder.cache.all::().is_empty()); + assert!(!cache.all::().is_empty()); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), // This is the beta rustdoc. // Add an assert here to make sure this is the only rustdoc built. &[tool::Rustdoc { compiler: Compiler { host: a, stage: 0 } }], ); - assert!(builder.cache.all::().is_empty()); + assert!(cache.all::().is_empty()); } #[test] fn build_cross_compile() { let config = Config { stage: 1, ..configure("build", &["A", "B"], &["A", "B"]) }; - let build = Build::new(config); - let mut builder = Builder::new(&build); - builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]); + let mut cache = run_build(&[], config); let a = TargetSelection::from_user("A"); let b = TargetSelection::from_user("B"); @@ -141,7 +132,7 @@ mod defaults { // (since we're producing stage 1 libraries/binaries). But currently // rustbuild is just a bit buggy here; this should be fixed though. assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[ compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a }, compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a }, @@ -150,7 +141,7 @@ mod defaults { ] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[ compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } }, compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } }, @@ -158,14 +149,14 @@ mod defaults { ] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[ tool::Rustdoc { compiler: Compiler { host: a, stage: 1 } }, tool::Rustdoc { compiler: Compiler { host: b, stage: 1 } }, ], ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[ compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a }, compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: b }, @@ -178,33 +169,28 @@ mod defaults { let mut config = configure("doc", &["A"], &["A"]); config.compiler_docs = true; config.cmd = Subcommand::Doc { paths: Vec::new(), open: false }; - let build = Build::new(config); - let mut builder = Builder::new(&build); - builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Doc), &[]); + let mut cache = run_build(&[], config); let a = TargetSelection::from_user("A"); // error_index_generator uses stage 0 to share rustdoc artifacts with the // rustdoc tool. + assert_eq!(first(cache.all::()), &[doc::ErrorIndex { target: a },]); assert_eq!( - first(builder.cache.all::()), - &[doc::ErrorIndex { target: a },] - ); - assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[tool::ErrorIndex { compiler: Compiler { host: a, stage: 0 } }] ); // docs should be built with the beta compiler, not with the stage0 artifacts. // recall that rustdoc is off-by-one: `stage` is the compiler rustdoc is _linked_ to, // not the one it was built by. assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[tool::Rustdoc { compiler: Compiler { host: a, stage: 0 } },] ); } } mod dist { - use super::{first, Config}; + use super::{first, run_build, Config}; use crate::builder::*; use pretty_assertions::assert_eq; @@ -214,94 +200,88 @@ mod dist { #[test] fn dist_baseline() { - let build = Build::new(configure(&["A"], &["A"])); - let mut builder = Builder::new(&build); - builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]); + let mut cache = run_build(&[], configure(&["A"], &["A"])); let a = TargetSelection::from_user("A"); - assert_eq!(first(builder.cache.all::()), &[dist::Docs { host: a },]); - assert_eq!(first(builder.cache.all::()), &[dist::Mingw { host: a },]); + assert_eq!(first(cache.all::()), &[dist::Docs { host: a },]); + assert_eq!(first(cache.all::()), &[dist::Mingw { host: a },]); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[dist::Rustc { compiler: Compiler { host: a, stage: 2 } },] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },] ); - assert_eq!(first(builder.cache.all::()), &[dist::Src]); + assert_eq!(first(cache.all::()), &[dist::Src]); // Make sure rustdoc is only built once. assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[tool::Rustdoc { compiler: Compiler { host: a, stage: 2 } },] ); } #[test] fn dist_with_targets() { - let build = Build::new(configure(&["A"], &["A", "B"])); - let mut builder = Builder::new(&build); - builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]); + let mut cache = run_build(&[], configure(&["A"], &["A", "B"])); let a = TargetSelection::from_user("A"); let b = TargetSelection::from_user("B"); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[dist::Docs { host: a }, dist::Docs { host: b },] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[dist::Mingw { host: a }, dist::Mingw { host: b },] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[dist::Rustc { compiler: Compiler { host: a, stage: 2 } },] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[ dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a }, dist::Std { compiler: Compiler { host: a, stage: 2 }, target: b }, ] ); - assert_eq!(first(builder.cache.all::()), &[dist::Src]); + assert_eq!(first(cache.all::()), &[dist::Src]); } #[test] fn dist_with_hosts() { - let build = Build::new(configure(&["A", "B"], &["A", "B"])); - let mut builder = Builder::new(&build); - builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]); + let mut cache = run_build(&[], configure(&["A", "B"], &["A", "B"])); let a = TargetSelection::from_user("A"); let b = TargetSelection::from_user("B"); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[dist::Docs { host: a }, dist::Docs { host: b },] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[dist::Mingw { host: a }, dist::Mingw { host: b },] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[ dist::Rustc { compiler: Compiler { host: a, stage: 2 } }, dist::Rustc { compiler: Compiler { host: b, stage: 2 } }, ] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[ dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a }, dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b }, ] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[ compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a }, compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a }, @@ -310,26 +290,25 @@ mod dist { compile::Std { compiler: Compiler { host: a, stage: 2 }, target: b }, ], ); - assert_eq!(first(builder.cache.all::()), &[dist::Src]); + assert_eq!(first(cache.all::()), &[dist::Src]); } #[test] fn dist_only_cross_host() { let a = TargetSelection::from_user("A"); let b = TargetSelection::from_user("B"); - let mut build = Build::new(configure(&["A", "B"], &["A", "B"])); - build.config.docs = false; - build.config.extended = true; - build.hosts = vec![b]; - let mut builder = Builder::new(&build); - builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]); + let mut config = configure(&["A", "B"], &["A", "B"]); + config.docs = false; + config.extended = true; + config.hosts = vec![b]; + let mut cache = run_build(&[], config); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[dist::Rustc { compiler: Compiler { host: b, stage: 2 } },] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[ compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a }, compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: b }, @@ -339,92 +318,86 @@ mod dist { #[test] fn dist_with_targets_and_hosts() { - let build = Build::new(configure(&["A", "B"], &["A", "B", "C"])); - let mut builder = Builder::new(&build); - builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]); + let mut cache = run_build(&[], configure(&["A", "B"], &["A", "B", "C"])); let a = TargetSelection::from_user("A"); let b = TargetSelection::from_user("B"); let c = TargetSelection::from_user("C"); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[dist::Docs { host: a }, dist::Docs { host: b }, dist::Docs { host: c },] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[dist::Mingw { host: a }, dist::Mingw { host: b }, dist::Mingw { host: c },] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[ dist::Rustc { compiler: Compiler { host: a, stage: 2 } }, dist::Rustc { compiler: Compiler { host: b, stage: 2 } }, ] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[ dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a }, dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b }, dist::Std { compiler: Compiler { host: a, stage: 2 }, target: c }, ] ); - assert_eq!(first(builder.cache.all::()), &[dist::Src]); + assert_eq!(first(cache.all::()), &[dist::Src]); } #[test] fn dist_with_empty_host() { let config = configure(&[], &["C"]); - let build = Build::new(config); - let mut builder = Builder::new(&build); - builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]); + let mut cache = run_build(&[], config); let a = TargetSelection::from_user("A"); let c = TargetSelection::from_user("C"); - assert_eq!(first(builder.cache.all::()), &[dist::Docs { host: c },]); - assert_eq!(first(builder.cache.all::()), &[dist::Mingw { host: c },]); + assert_eq!(first(cache.all::()), &[dist::Docs { host: c },]); + assert_eq!(first(cache.all::()), &[dist::Mingw { host: c },]); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[dist::Std { compiler: Compiler { host: a, stage: 2 }, target: c },] ); } #[test] fn dist_with_same_targets_and_hosts() { - let build = Build::new(configure(&["A", "B"], &["A", "B"])); - let mut builder = Builder::new(&build); - builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]); + let mut cache = run_build(&[], configure(&["A", "B"], &["A", "B"])); let a = TargetSelection::from_user("A"); let b = TargetSelection::from_user("B"); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[dist::Docs { host: a }, dist::Docs { host: b },] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[dist::Mingw { host: a }, dist::Mingw { host: b },] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[ dist::Rustc { compiler: Compiler { host: a, stage: 2 } }, dist::Rustc { compiler: Compiler { host: b, stage: 2 } }, ] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[ dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a }, dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b }, ] ); - assert_eq!(first(builder.cache.all::()), &[dist::Src]); + assert_eq!(first(cache.all::()), &[dist::Src]); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[ compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a }, compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a }, @@ -434,7 +407,7 @@ mod dist { ] ); assert_eq!( - first(builder.cache.all::()), + first(cache.all::()), &[ compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } }, compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } },