11//! This module contains shared utilities for bootstrap tests.
22
3+ use std:: path:: { Path , PathBuf } ;
4+ use std:: thread;
5+
6+ use tempfile:: TempDir ;
7+
38use crate :: core:: builder:: Builder ;
49use crate :: core:: config:: DryRun ;
5- use crate :: { Build , Config , Flags } ;
10+ use crate :: { Build , Config , Flags , t } ;
611
712pub mod git;
813
14+ /// Holds temporary state of a bootstrap test.
15+ /// Right now it is only used to redirect the build directory of the bootstrap
16+ /// invocation, in the future it would be great if we could actually execute
17+ /// the whole test with this directory set as the workdir.
18+ pub struct TestCtx {
19+ directory : TempDir ,
20+ }
21+
22+ impl TestCtx {
23+ pub fn new ( ) -> Self {
24+ let directory = TempDir :: new ( ) . expect ( "cannot create temporary directory" ) ;
25+ eprintln ! ( "Running test in {}" , directory. path( ) . display( ) ) ;
26+ Self { directory }
27+ }
28+
29+ /// Starts a new invocation of bootstrap that executes `kind` as its top level command
30+ /// (i.e. `x <kind>`). Returns a builder that configures the created config through CLI flags.
31+ pub fn config ( & self , kind : & str ) -> ConfigBuilder {
32+ ConfigBuilder :: from_args ( & [ kind] , self . directory . path ( ) . to_owned ( ) )
33+ }
34+ }
35+
936/// Used to configure an invocation of bootstrap.
1037/// Currently runs in the rustc checkout, long-term it should be switched
1138/// to run in a (cache-primed) temporary directory instead.
1239pub struct ConfigBuilder {
1340 args : Vec < String > ,
41+ directory : PathBuf ,
1442}
1543
1644impl ConfigBuilder {
17- pub fn from_args ( args : & [ & str ] ) -> Self {
18- Self :: new ( args)
19- }
20-
21- pub fn build ( ) -> Self {
22- Self :: new ( & [ "build" ] )
45+ fn from_args ( args : & [ & str ] , directory : PathBuf ) -> Self {
46+ Self { args : args. iter ( ) . copied ( ) . map ( String :: from) . collect ( ) , directory }
2347 }
2448
2549 pub fn path ( mut self , path : & str ) -> Self {
@@ -33,14 +57,18 @@ impl ConfigBuilder {
3357 self
3458 }
3559
36- fn new ( args : & [ & str ] ) -> Self {
37- Self { args : args. iter ( ) . copied ( ) . map ( String :: from) . collect ( ) }
38- }
39-
4060 pub fn create_config ( mut self ) -> Config {
41- let mut config = Config :: parse ( Flags :: parse ( & self . args ) ) ;
4261 // Run in dry-check, otherwise the test would be too slow
43- config. set_dry_run ( DryRun :: SelfCheck ) ;
44- config
62+ self . args . push ( "--dry-run" . to_string ( ) ) ;
63+
64+ // Ignore submodules
65+ self . args . push ( "--set" . to_string ( ) ) ;
66+ self . args . push ( "build.submodules=false" . to_string ( ) ) ;
67+
68+ // Do not mess with the local rustc checkout build directory
69+ self . args . push ( "--build-dir" . to_string ( ) ) ;
70+ self . args . push ( self . directory . join ( "build" ) . display ( ) . to_string ( ) ) ;
71+
72+ Config :: parse ( Flags :: parse ( & self . args ) )
4573 }
4674}
0 commit comments