1
+ use crate :: builder:: { Builder , RunConfig , ShouldRun , Step } ;
1
2
use crate :: { t, VERSION } ;
2
3
use crate :: { Config , TargetSelection } ;
3
4
use std:: env:: consts:: EXE_SUFFIX ;
@@ -11,7 +12,7 @@ use std::{
11
12
io:: { self , Write } ,
12
13
} ;
13
14
14
- #[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
15
+ #[ derive( Clone , Copy , Debug , Eq , PartialEq , Hash ) ]
15
16
pub enum Profile {
16
17
Compiler ,
17
18
Codegen ,
@@ -50,6 +51,16 @@ impl Profile {
50
51
}
51
52
out
52
53
}
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
+ }
53
64
}
54
65
55
66
impl FromStr for Profile {
@@ -81,6 +92,37 @@ impl fmt::Display for Profile {
81
92
}
82
93
}
83
94
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
+
84
126
pub fn setup ( config : & Config , profile : Profile ) {
85
127
let path = & config. config ;
86
128
@@ -103,7 +145,10 @@ pub fn setup(config: &Config, profile: Profile) {
103
145
changelog-seen = {}\n ",
104
146
profile, VERSION
105
147
) ;
106
- t ! ( fs:: write( path, settings) ) ;
148
+
149
+ if !config. dry_run {
150
+ t ! ( fs:: write( path, settings) ) ;
151
+ }
107
152
108
153
let include_path = profile. include_path ( & config. src ) ;
109
154
println ! ( "`x.py` will now use the configuration at {}" , include_path. display( ) ) ;
@@ -116,7 +161,7 @@ pub fn setup(config: &Config, profile: Profile) {
116
161
117
162
if !rustup_installed ( ) && profile != Profile :: User {
118
163
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 {
120
165
attempt_toolchain_link ( & stage_path[ ..] ) ;
121
166
}
122
167
@@ -136,7 +181,9 @@ pub fn setup(config: &Config, profile: Profile) {
136
181
137
182
println ! ( ) ;
138
183
139
- t ! ( install_git_hook_maybe( & config) ) ;
184
+ if !config. dry_run {
185
+ t ! ( install_git_hook_maybe( & config) ) ;
186
+ }
140
187
141
188
println ! ( ) ;
142
189
0 commit comments