Skip to content

Commit 8815103

Browse files
committed
remove special cases for setup subcommand
1 parent a9d1caf commit 8815103

File tree

4 files changed

+63
-13
lines changed

4 files changed

+63
-13
lines changed

src/bootstrap/builder.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::flags::{Color, Subcommand};
2020
use crate::install;
2121
use crate::native;
2222
use crate::run;
23+
use crate::setup;
2324
use crate::test;
2425
use crate::tool::{self, SourceType};
2526
use crate::util::{self, add_dylib_path, add_link_lib_path, exe, libdir, output, t};
@@ -436,8 +437,12 @@ impl<'a> ShouldRun<'a> {
436437

437438
// single alias, which does not correspond to any on-disk path
438439
pub fn alias(mut self, alias: &str) -> Self {
440+
// exceptional case for `Kind::Setup` because its `library`
441+
// and `compiler` options would otherwise naively match with
442+
// `compiler` and `library` folders respectively.
439443
assert!(
440-
!self.builder.src.join(alias).exists(),
444+
self.kind == Kind::Setup
445+
|| !self.builder.src.join(alias).exists(),
441446
"use `builder.path()` for real paths: {}",
442447
alias
443448
);
@@ -754,8 +759,9 @@ impl<'a> Builder<'a> {
754759
run::BumpStage0,
755760
run::ReplaceVersionPlaceholder,
756761
),
762+
Kind::Setup => describe!(setup::Profile),
757763
// These commands either don't use paths, or they're special-cased in Build::build()
758-
Kind::Clean | Kind::Format | Kind::Setup => vec![],
764+
Kind::Clean | Kind::Format => vec![],
759765
}
760766
}
761767

@@ -818,7 +824,8 @@ impl<'a> Builder<'a> {
818824
Subcommand::Install { ref paths } => (Kind::Install, &paths[..]),
819825
Subcommand::Run { ref paths } => (Kind::Run, &paths[..]),
820826
Subcommand::Format { .. } => (Kind::Format, &[][..]),
821-
Subcommand::Clean { .. } | Subcommand::Setup { .. } => {
827+
Subcommand::Setup { ref paths } => (Kind::Setup, &paths[..]),
828+
Subcommand::Clean { .. } => {
822829
panic!()
823830
}
824831
};

src/bootstrap/flags.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub enum Subcommand {
142142
paths: Vec<PathBuf>,
143143
},
144144
Setup {
145-
profile: Profile,
145+
paths: Vec<PathBuf>,
146146
},
147147
}
148148

@@ -633,7 +633,7 @@ Arguments:
633633
} else {
634634
t!(crate::setup::interactive_path())
635635
};
636-
Subcommand::Setup { profile }
636+
Subcommand::Setup { paths: vec![PathBuf::from(profile.as_str())] }
637637
}
638638
};
639639

src/bootstrap/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,6 @@ impl Build {
673673
return clean::clean(self, all);
674674
}
675675

676-
if let Subcommand::Setup { profile } = &self.config.cmd {
677-
return setup::setup(&self.config, *profile);
678-
}
679-
680676
// Download rustfmt early so that it can be used in rust-analyzer configs.
681677
let _ = &builder::Builder::new(&self).initial_rustfmt();
682678

src/bootstrap/setup.rs

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::builder::{Builder, RunConfig, ShouldRun, Step};
12
use crate::{t, VERSION};
23
use crate::{Config, TargetSelection};
34
use std::env::consts::EXE_SUFFIX;
@@ -11,7 +12,7 @@ use std::{
1112
io::{self, Write},
1213
};
1314

14-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
15+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
1516
pub enum Profile {
1617
Compiler,
1718
Codegen,
@@ -50,6 +51,16 @@ impl Profile {
5051
}
5152
out
5253
}
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+
}
5364
}
5465

5566
impl FromStr for Profile {
@@ -81,6 +92,37 @@ impl fmt::Display for Profile {
8192
}
8293
}
8394

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+
84126
pub fn setup(config: &Config, profile: Profile) {
85127
let path = &config.config;
86128

@@ -103,7 +145,10 @@ pub fn setup(config: &Config, profile: Profile) {
103145
changelog-seen = {}\n",
104146
profile, VERSION
105147
);
106-
t!(fs::write(path, settings));
148+
149+
if !config.dry_run {
150+
t!(fs::write(path, settings));
151+
}
107152

108153
let include_path = profile.include_path(&config.src);
109154
println!("`x.py` will now use the configuration at {}", include_path.display());
@@ -116,7 +161,7 @@ pub fn setup(config: &Config, profile: Profile) {
116161

117162
if !rustup_installed() && profile != Profile::User {
118163
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 {
120165
attempt_toolchain_link(&stage_path[..]);
121166
}
122167

@@ -136,7 +181,9 @@ pub fn setup(config: &Config, profile: Profile) {
136181

137182
println!();
138183

139-
t!(install_git_hook_maybe(&config));
184+
if !config.dry_run {
185+
t!(install_git_hook_maybe(&config));
186+
}
140187

141188
println!();
142189

0 commit comments

Comments
 (0)