1+ use crate :: builder:: { Builder , RunConfig , ShouldRun , Step } ;
12use crate :: { t, VERSION } ;
23use crate :: { Config , TargetSelection } ;
34use std:: env:: consts:: EXE_SUFFIX ;
@@ -11,7 +12,7 @@ use std::{
1112 io:: { self , Write } ,
1213} ;
1314
14- #[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
15+ #[ derive( Clone , Copy , Debug , Eq , PartialEq , Hash ) ]
1516pub enum Profile {
1617 Compiler ,
1718 Codegen ,
@@ -50,6 +51,16 @@ impl Profile {
5051 }
5152 out
5253 }
54+
55+ pub fn as_str ( & self ) -> & ' static str {
56+ match self {
57+ Profile :: Compiler => "compiler" ,
58+ Profile :: Codegen => "codegen" ,
59+ Profile :: Library => "library" ,
60+ Profile :: Tools => "tools" ,
61+ Profile :: User => "user" ,
62+ }
63+ }
5364}
5465
5566impl FromStr for Profile {
@@ -81,6 +92,37 @@ impl fmt::Display for Profile {
8192 }
8293}
8394
95+ impl Step for Profile {
96+ type Output = ( ) ;
97+
98+ fn should_run ( mut run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
99+ for choice in Profile :: all ( ) {
100+ run = run. alias ( & choice. to_string ( ) ) ;
101+ }
102+ run
103+ }
104+
105+ fn make_run ( run : RunConfig < ' _ > ) {
106+ let profile: Profile = run
107+ . paths
108+ . first ( )
109+ . unwrap ( )
110+ . assert_single_path ( )
111+ . path
112+ . to_owned ( )
113+ . into_os_string ( )
114+ . into_string ( )
115+ . unwrap ( )
116+ . parse ( )
117+ . unwrap ( ) ;
118+ run. builder . ensure ( profile) ;
119+ }
120+
121+ fn run ( self , builder : & Builder < ' _ > ) {
122+ setup ( & builder. build . config , self )
123+ }
124+ }
125+
84126pub fn setup ( config : & Config , profile : Profile ) {
85127 let path = & config. config ;
86128
@@ -103,7 +145,10 @@ pub fn setup(config: &Config, profile: Profile) {
103145 changelog-seen = {}\n ",
104146 profile, VERSION
105147 ) ;
106- t ! ( fs:: write( path, settings) ) ;
148+
149+ if !config. dry_run {
150+ t ! ( fs:: write( path, settings) ) ;
151+ }
107152
108153 let include_path = profile. include_path ( & config. src ) ;
109154 println ! ( "`x.py` will now use the configuration at {}" , include_path. display( ) ) ;
@@ -116,7 +161,7 @@ pub fn setup(config: &Config, profile: Profile) {
116161
117162 if !rustup_installed ( ) && profile != Profile :: User {
118163 eprintln ! ( "`rustup` is not installed; cannot link `stage1` toolchain" ) ;
119- } else if stage_dir_exists ( & stage_path[ ..] ) {
164+ } else if stage_dir_exists ( & stage_path[ ..] ) && !config . dry_run {
120165 attempt_toolchain_link ( & stage_path[ ..] ) ;
121166 }
122167
@@ -136,7 +181,9 @@ pub fn setup(config: &Config, profile: Profile) {
136181
137182 println ! ( ) ;
138183
139- t ! ( install_git_hook_maybe( & config) ) ;
184+ if !config. dry_run {
185+ t ! ( install_git_hook_maybe( & config) ) ;
186+ }
140187
141188 println ! ( ) ;
142189
0 commit comments