@@ -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,14 +161,7 @@ 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
- println ! ( ) ;
175
-
176
- println ! ( "To get started, try one of the following commands:" ) ;
164
+ println ! ( "\n To get started, try one of the following commands:" ) ;
177
165
for cmd in suggestions {
178
166
println ! ( "- `x.py {}`" , cmd) ;
179
167
}
@@ -189,6 +177,9 @@ pub fn setup(config: &Config, profile: Profile) {
189
177
}
190
178
191
179
fn setup_config_toml ( path : & PathBuf , profile : Profile , config : & Config ) {
180
+ if profile == Profile :: None {
181
+ return ;
182
+ }
192
183
if path. exists ( ) {
193
184
eprintln ! ( ) ;
194
185
eprintln ! (
@@ -216,6 +207,41 @@ fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) {
216
207
println ! ( "`x.py` will now use the configuration at {}" , include_path. display( ) ) ;
217
208
}
218
209
210
+ /// Creates a toolchain link for stage1 using `rustup`
211
+ #[ derive( Clone , Copy , Debug , Eq , PartialEq , Hash ) ]
212
+ pub struct Link ;
213
+ impl Step for Link {
214
+ type Output = ( ) ;
215
+ const DEFAULT : bool = true ;
216
+ fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
217
+ run. alias ( "link" )
218
+ }
219
+ fn make_run ( run : RunConfig < ' _ > ) {
220
+ if run. builder . config . dry_run ( ) {
221
+ return ;
222
+ }
223
+ if let [ cmd] = & run. paths [ ..] {
224
+ if cmd. assert_single_path ( ) . path . as_path ( ) . as_os_str ( ) == "link" {
225
+ run. builder . ensure ( Link ) ;
226
+ }
227
+ }
228
+ }
229
+ fn run ( self , builder : & Builder < ' _ > ) -> Self :: Output {
230
+ let config = & builder. config ;
231
+ if config. dry_run ( ) {
232
+ return ;
233
+ }
234
+ let stage_path =
235
+ [ "build" , config. build . rustc_target_arg ( ) , "stage1" ] . join ( & MAIN_SEPARATOR . to_string ( ) ) ;
236
+
237
+ if !rustup_installed ( ) {
238
+ eprintln ! ( "`rustup` is not installed; cannot link `stage1` toolchain" ) ;
239
+ } else if stage_dir_exists ( & stage_path[ ..] ) && !config. dry_run ( ) {
240
+ attempt_toolchain_link ( & stage_path[ ..] ) ;
241
+ }
242
+ }
243
+ }
244
+
219
245
fn rustup_installed ( ) -> bool {
220
246
Command :: new ( "rustup" )
221
247
. arg ( "--version" )
@@ -393,6 +419,35 @@ fn prompt_user(prompt: &str) -> io::Result<Option<PromptResult>> {
393
419
}
394
420
}
395
421
422
+ /// Installs `src/etc/pre-push.sh` as a Git hook
423
+ #[ derive( Clone , Copy , Debug , Eq , PartialEq , Hash ) ]
424
+ pub struct Hook ;
425
+
426
+ impl Step for Hook {
427
+ type Output = ( ) ;
428
+ const DEFAULT : bool = true ;
429
+ fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
430
+ run. alias ( "hook" )
431
+ }
432
+ fn make_run ( run : RunConfig < ' _ > ) {
433
+ if run. builder . config . dry_run ( ) {
434
+ return ;
435
+ }
436
+ if let [ cmd] = & run. paths [ ..] {
437
+ if cmd. assert_single_path ( ) . path . as_path ( ) . as_os_str ( ) == "hook" {
438
+ run. builder . ensure ( Hook ) ;
439
+ }
440
+ }
441
+ }
442
+ fn run ( self , builder : & Builder < ' _ > ) -> Self :: Output {
443
+ let config = & builder. config ;
444
+ if config. dry_run ( ) {
445
+ return ;
446
+ }
447
+ t ! ( install_git_hook_maybe( & config) ) ;
448
+ }
449
+ }
450
+
396
451
// install a git hook to automatically run tidy, if they want
397
452
fn install_git_hook_maybe ( config : & Config ) -> io:: Result < ( ) > {
398
453
let git = t ! ( config. git( ) . args( & [ "rev-parse" , "--git-common-dir" ] ) . output( ) . map( |output| {
@@ -431,6 +486,35 @@ undesirable, simply delete the `pre-push` file from .git/hooks."
431
486
Ok ( ( ) )
432
487
}
433
488
489
+ /// Sets up or displays `src/etc/vscode_settings.json`
490
+ #[ derive( Clone , Copy , Debug , Eq , PartialEq , Hash ) ]
491
+ pub struct Vscode ;
492
+
493
+ impl Step for Vscode {
494
+ type Output = ( ) ;
495
+ const DEFAULT : bool = true ;
496
+ fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
497
+ run. alias ( "vscode" )
498
+ }
499
+ fn make_run ( run : RunConfig < ' _ > ) {
500
+ if run. builder . config . dry_run ( ) {
501
+ return ;
502
+ }
503
+ if let [ cmd] = & run. paths [ ..] {
504
+ if cmd. assert_single_path ( ) . path . as_path ( ) . as_os_str ( ) == "vscode" {
505
+ run. builder . ensure ( Vscode ) ;
506
+ }
507
+ }
508
+ }
509
+ fn run ( self , builder : & Builder < ' _ > ) -> Self :: Output {
510
+ let config = & builder. config ;
511
+ if config. dry_run ( ) {
512
+ return ;
513
+ }
514
+ t ! ( create_vscode_settings_maybe( & config) ) ;
515
+ }
516
+ }
517
+
434
518
/// Create a `.vscode/settings.json` file for rustc development, or just print it
435
519
fn create_vscode_settings_maybe ( config : & Config ) -> io:: Result < ( ) > {
436
520
let ( current_hash, historical_hashes) = SETTINGS_HASHES . split_last ( ) . unwrap ( ) ;
0 commit comments