@@ -21,6 +21,7 @@ pub enum Profile {
21
21
Library ,
22
22
Tools ,
23
23
User ,
24
+ None ,
24
25
}
25
26
26
27
/// A list of historical hashes of `src/etc/vscode_settings.json`.
@@ -41,7 +42,7 @@ impl Profile {
41
42
pub fn all ( ) -> impl Iterator < Item = Self > {
42
43
use Profile :: * ;
43
44
// N.B. these are ordered by how they are displayed, not alphabetically
44
- [ Library , Compiler , Codegen , Tools , User ] . iter ( ) . copied ( )
45
+ [ Library , Compiler , Codegen , Tools , User , None ] . iter ( ) . copied ( )
45
46
}
46
47
47
48
pub fn purpose ( & self ) -> String {
@@ -52,6 +53,7 @@ impl Profile {
52
53
Codegen => "Contribute to the compiler, and also modify LLVM or codegen" ,
53
54
Tools => "Contribute to tools which depend on the compiler, but do not modify it directly (e.g. rustdoc, clippy, miri)" ,
54
55
User => "Install Rust from source" ,
56
+ None => "Do not modify `config.toml`"
55
57
}
56
58
. to_string ( )
57
59
}
@@ -71,6 +73,7 @@ impl Profile {
71
73
Profile :: Library => "library" ,
72
74
Profile :: Tools => "tools" ,
73
75
Profile :: User => "user" ,
76
+ Profile :: None => "none" ,
74
77
}
75
78
}
76
79
}
@@ -87,6 +90,7 @@ impl FromStr for Profile {
87
90
"tools" | "tool" | "rustdoc" | "clippy" | "miri" | "rustfmt" | "rls" => {
88
91
Ok ( Profile :: Tools )
89
92
}
93
+ "none" => Ok ( Profile :: None ) ,
90
94
_ => Err ( format ! ( "unknown profile: '{}'" , s) ) ,
91
95
}
92
96
}
@@ -144,17 +148,8 @@ impl Step for Profile {
144
148
}
145
149
146
150
pub fn setup ( config : & Config , profile : Profile ) {
147
- let stage_path =
148
- [ "build" , config. build . rustc_target_arg ( ) , "stage1" ] . join ( & MAIN_SEPARATOR . to_string ( ) ) ;
149
-
150
- if !rustup_installed ( ) && profile != Profile :: User {
151
- eprintln ! ( "`rustup` is not installed; cannot link `stage1` toolchain" ) ;
152
- } else if stage_dir_exists ( & stage_path[ ..] ) && !config. dry_run ( ) {
153
- attempt_toolchain_link ( & stage_path[ ..] ) ;
154
- }
155
-
156
- let suggestions = match profile {
157
- Profile :: Codegen | Profile :: Compiler => & [ "check" , "build" , "test" ] [ ..] ,
151
+ let suggestions: & [ & str ] = match profile {
152
+ Profile :: Codegen | Profile :: Compiler | Profile :: None => & [ "check" , "build" , "test" ] ,
158
153
Profile :: Tools => & [
159
154
"check" ,
160
155
"build" ,
@@ -167,11 +162,6 @@ pub fn setup(config: &Config, profile: Profile) {
167
162
Profile :: User => & [ "dist" , "build" ] ,
168
163
} ;
169
164
170
- if !config. dry_run ( ) {
171
- t ! ( install_git_hook_maybe( & config) ) ;
172
- t ! ( create_vscode_settings_maybe( & config) ) ;
173
- }
174
-
175
165
println ! ( ) ;
176
166
177
167
println ! ( "To get started, try one of the following commands:" ) ;
@@ -190,6 +180,9 @@ pub fn setup(config: &Config, profile: Profile) {
190
180
}
191
181
192
182
fn setup_config_toml ( path : & PathBuf , profile : Profile , config : & Config ) {
183
+ if profile == Profile :: None {
184
+ return ;
185
+ }
193
186
if path. exists ( ) {
194
187
eprintln ! ( ) ;
195
188
eprintln ! (
@@ -217,6 +210,41 @@ fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) {
217
210
println ! ( "`x.py` will now use the configuration at {}" , include_path. display( ) ) ;
218
211
}
219
212
213
+ /// Creates a toolchain link for stage1 using `rustup`
214
+ #[ derive( Clone , Copy , Debug , Eq , PartialEq , Hash ) ]
215
+ pub struct Link ;
216
+ impl Step for Link {
217
+ type Output = ( ) ;
218
+ const DEFAULT : bool = true ;
219
+ fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
220
+ run. alias ( "link" )
221
+ }
222
+ fn make_run ( run : RunConfig < ' _ > ) {
223
+ if run. builder . config . dry_run ( ) {
224
+ return ;
225
+ }
226
+ if let [ cmd] = & run. paths [ ..] {
227
+ if cmd. assert_single_path ( ) . path . as_path ( ) . as_os_str ( ) == "link" {
228
+ run. builder . ensure ( Link ) ;
229
+ }
230
+ }
231
+ }
232
+ fn run ( self , builder : & Builder < ' _ > ) -> Self :: Output {
233
+ let config = & builder. config ;
234
+ if config. dry_run ( ) {
235
+ return ;
236
+ }
237
+ let stage_path =
238
+ [ "build" , config. build . rustc_target_arg ( ) , "stage1" ] . join ( & MAIN_SEPARATOR . to_string ( ) ) ;
239
+
240
+ if !rustup_installed ( ) {
241
+ eprintln ! ( "`rustup` is not installed; cannot link `stage1` toolchain" ) ;
242
+ } else if stage_dir_exists ( & stage_path[ ..] ) && !config. dry_run ( ) {
243
+ attempt_toolchain_link ( & stage_path[ ..] ) ;
244
+ }
245
+ }
246
+ }
247
+
220
248
fn rustup_installed ( ) -> bool {
221
249
Command :: new ( "rustup" )
222
250
. arg ( "--version" )
@@ -394,6 +422,35 @@ fn prompt_user(prompt: &str) -> io::Result<Option<PromptResult>> {
394
422
}
395
423
}
396
424
425
+ /// Installs `src/etc/pre-push.sh` as a Git hook
426
+ #[ derive( Clone , Copy , Debug , Eq , PartialEq , Hash ) ]
427
+ pub struct Hook ;
428
+
429
+ impl Step for Hook {
430
+ type Output = ( ) ;
431
+ const DEFAULT : bool = true ;
432
+ fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
433
+ run. alias ( "hook" )
434
+ }
435
+ fn make_run ( run : RunConfig < ' _ > ) {
436
+ if run. builder . config . dry_run ( ) {
437
+ return ;
438
+ }
439
+ if let [ cmd] = & run. paths [ ..] {
440
+ if cmd. assert_single_path ( ) . path . as_path ( ) . as_os_str ( ) == "hook" {
441
+ run. builder . ensure ( Hook ) ;
442
+ }
443
+ }
444
+ }
445
+ fn run ( self , builder : & Builder < ' _ > ) -> Self :: Output {
446
+ let config = & builder. config ;
447
+ if config. dry_run ( ) {
448
+ return ;
449
+ }
450
+ t ! ( install_git_hook_maybe( & config) ) ;
451
+ }
452
+ }
453
+
397
454
// install a git hook to automatically run tidy, if they want
398
455
fn install_git_hook_maybe ( config : & Config ) -> io:: Result < ( ) > {
399
456
let git = t ! ( config. git( ) . args( & [ "rev-parse" , "--git-common-dir" ] ) . output( ) . map( |output| {
@@ -432,6 +489,35 @@ undesirable, simply delete the `pre-push` file from .git/hooks."
432
489
Ok ( ( ) )
433
490
}
434
491
492
+ /// Sets up or displays `src/etc/vscode_settings.json`
493
+ #[ derive( Clone , Copy , Debug , Eq , PartialEq , Hash ) ]
494
+ pub struct Vscode ;
495
+
496
+ impl Step for Vscode {
497
+ type Output = ( ) ;
498
+ const DEFAULT : bool = true ;
499
+ fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
500
+ run. alias ( "vscode" )
501
+ }
502
+ fn make_run ( run : RunConfig < ' _ > ) {
503
+ if run. builder . config . dry_run ( ) {
504
+ return ;
505
+ }
506
+ if let [ cmd] = & run. paths [ ..] {
507
+ if cmd. assert_single_path ( ) . path . as_path ( ) . as_os_str ( ) == "vscode" {
508
+ run. builder . ensure ( Vscode ) ;
509
+ }
510
+ }
511
+ }
512
+ fn run ( self , builder : & Builder < ' _ > ) -> Self :: Output {
513
+ let config = & builder. config ;
514
+ if config. dry_run ( ) {
515
+ return ;
516
+ }
517
+ t ! ( create_vscode_settings_maybe( & config) ) ;
518
+ }
519
+ }
520
+
435
521
/// Create a `.vscode/settings.json` file for rustc development, or just print it
436
522
fn create_vscode_settings_maybe ( config : & Config ) -> io:: Result < ( ) > {
437
523
let ( current_hash, historical_hashes) = SETTINGS_HASHES . split_last ( ) . unwrap ( ) ;
0 commit comments