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