@@ -21,6 +21,7 @@ pub enum Profile {
2121 Library ,
2222 Tools ,
2323 User ,
24+ None ,
2425}
2526
2627/// A list of historical hashes of `src/etc/vscode_settings.json`.
@@ -40,7 +41,7 @@ impl Profile {
4041 pub fn all ( ) -> impl Iterator < Item = Self > {
4142 use Profile :: * ;
4243 // 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 ( )
4445 }
4546
4647 pub fn purpose ( & self ) -> String {
@@ -51,6 +52,7 @@ impl Profile {
5152 Codegen => "Contribute to the compiler, and also modify LLVM or codegen" ,
5253 Tools => "Contribute to tools which depend on the compiler, but do not modify it directly (e.g. rustdoc, clippy, miri)" ,
5354 User => "Install Rust from source" ,
55+ None => "Do not modify `config.toml`"
5456 }
5557 . to_string ( )
5658 }
@@ -70,6 +72,7 @@ impl Profile {
7072 Profile :: Library => "library" ,
7173 Profile :: Tools => "tools" ,
7274 Profile :: User => "user" ,
75+ Profile :: None => "none" ,
7376 }
7477 }
7578}
@@ -86,6 +89,7 @@ impl FromStr for Profile {
8689 "tools" | "tool" | "rustdoc" | "clippy" | "miri" | "rustfmt" | "rls" => {
8790 Ok ( Profile :: Tools )
8891 }
92+ "none" => Ok ( Profile :: None ) ,
8993 _ => Err ( format ! ( "unknown profile: '{}'" , s) ) ,
9094 }
9195 }
@@ -143,17 +147,8 @@ impl Step for Profile {
143147}
144148
145149pub 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" ] ,
157152 Profile :: Tools => & [
158153 "check" ,
159154 "build" ,
@@ -166,11 +161,6 @@ pub fn setup(config: &Config, profile: Profile) {
166161 Profile :: User => & [ "dist" , "build" ] ,
167162 } ;
168163
169- if !config. dry_run ( ) {
170- t ! ( install_git_hook_maybe( & config) ) ;
171- t ! ( create_vscode_settings_maybe( & config) ) ;
172- }
173-
174164 println ! ( ) ;
175165
176166 println ! ( "To get started, try one of the following commands:" ) ;
@@ -189,6 +179,9 @@ pub fn setup(config: &Config, profile: Profile) {
189179}
190180
191181fn setup_config_toml ( path : & PathBuf , profile : Profile , config : & Config ) {
182+ if profile == Profile :: None {
183+ return ;
184+ }
192185 if path. exists ( ) {
193186 eprintln ! ( ) ;
194187 eprintln ! (
@@ -216,6 +209,41 @@ fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) {
216209 println ! ( "`x.py` will now use the configuration at {}" , include_path. display( ) ) ;
217210}
218211
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+
219247fn rustup_installed ( ) -> bool {
220248 Command :: new ( "rustup" )
221249 . arg ( "--version" )
@@ -393,6 +421,35 @@ fn prompt_user(prompt: &str) -> io::Result<Option<PromptResult>> {
393421 }
394422}
395423
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+
396453// install a git hook to automatically run tidy, if they want
397454fn install_git_hook_maybe ( config : & Config ) -> io:: Result < ( ) > {
398455 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."
431488 Ok ( ( ) )
432489}
433490
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+
434520/// Create a `.vscode/settings.json` file for rustc development, or just print it
435521fn create_vscode_settings_maybe ( config : & Config ) -> io:: Result < ( ) > {
436522 let ( current_hash, historical_hashes) = SETTINGS_HASHES . split_last ( ) . unwrap ( ) ;
0 commit comments