Skip to content

Commit e60b348

Browse files
committed
refactor gating of tools
1 parent 7167f8b commit e60b348

File tree

1 file changed

+75
-74
lines changed

1 file changed

+75
-74
lines changed

src/bootstrap/dist.rs

Lines changed: 75 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//! out to `rust-installer` still. This may one day be replaced with bits and
99
//! pieces of `rustup.rs`!
1010
11+
use std::collections::HashSet;
1112
use std::env;
1213
use std::fs;
1314
use std::path::{Path, PathBuf};
@@ -45,6 +46,18 @@ fn missing_tool(tool_name: &str, skip: bool) {
4546
}
4647
}
4748

49+
fn should_build_extended_tool(builder: &Builder<'_>, tool: &str) -> bool {
50+
if !builder.config.extended {
51+
return false;
52+
}
53+
54+
if let Some(tools) = &builder.config.tools {
55+
tools.is_empty() || tools.contains(tool)
56+
} else {
57+
true
58+
}
59+
}
60+
4861
#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
4962
pub struct Docs {
5063
pub host: TargetSelection,
@@ -671,11 +684,10 @@ pub struct Analysis {
671684

672685
impl Step for Analysis {
673686
type Output = Option<GeneratedTarball>;
674-
const DEFAULT: bool = true;
675687

676688
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
677-
let builder = run.builder;
678-
run.path("analysis").default_condition(builder.config.extended)
689+
let default = should_build_extended_tool(&run.builder, "analysis");
690+
run.path("analysis").default_condition(default)
679691
}
680692

681693
fn make_run(run: RunConfig<'_>) {
@@ -696,7 +708,6 @@ impl Step for Analysis {
696708
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
697709
let compiler = self.compiler;
698710
let target = self.target;
699-
assert!(builder.config.extended);
700711
if compiler.host != builder.config.build {
701712
return None;
702713
}
@@ -955,7 +966,8 @@ impl Step for Cargo {
955966
const ONLY_HOSTS: bool = true;
956967

957968
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
958-
run.path("cargo")
969+
let default = should_build_extended_tool(&run.builder, "cargo");
970+
run.path("cargo").default_condition(default)
959971
}
960972

961973
fn make_run(run: RunConfig<'_>) {
@@ -1009,7 +1021,8 @@ impl Step for Rls {
10091021
const ONLY_HOSTS: bool = true;
10101022

10111023
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1012-
run.path("rls")
1024+
let default = should_build_extended_tool(&run.builder, "rls");
1025+
run.path("rls").default_condition(default)
10131026
}
10141027

10151028
fn make_run(run: RunConfig<'_>) {
@@ -1026,7 +1039,6 @@ impl Step for Rls {
10261039
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
10271040
let compiler = self.compiler;
10281041
let target = self.target;
1029-
assert!(builder.config.extended);
10301042

10311043
let rls = builder
10321044
.ensure(tool::Rls { compiler, target, extra_features: Vec::new() })
@@ -1055,7 +1067,8 @@ impl Step for RustAnalyzer {
10551067
const ONLY_HOSTS: bool = true;
10561068

10571069
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1058-
run.path("rust-analyzer")
1070+
let default = should_build_extended_tool(&run.builder, "rust-analyzer");
1071+
run.path("rust-analyzer").default_condition(default)
10591072
}
10601073

10611074
fn make_run(run: RunConfig<'_>) {
@@ -1078,7 +1091,6 @@ impl Step for RustAnalyzer {
10781091
}
10791092
let compiler = self.compiler;
10801093
let target = self.target;
1081-
assert!(builder.config.extended);
10821094

10831095
if target.contains("riscv64") {
10841096
// riscv64 currently has an LLVM bug that makes rust-analyzer unable
@@ -1110,7 +1122,8 @@ impl Step for Clippy {
11101122
const ONLY_HOSTS: bool = true;
11111123

11121124
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1113-
run.path("clippy")
1125+
let default = should_build_extended_tool(&run.builder, "clippy");
1126+
run.path("clippy").default_condition(default)
11141127
}
11151128

11161129
fn make_run(run: RunConfig<'_>) {
@@ -1127,7 +1140,6 @@ impl Step for Clippy {
11271140
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
11281141
let compiler = self.compiler;
11291142
let target = self.target;
1130-
assert!(builder.config.extended);
11311143

11321144
// Prepare the image directory
11331145
// We expect clippy to build, because we've exited this step above if tool
@@ -1160,7 +1172,8 @@ impl Step for Miri {
11601172
const ONLY_HOSTS: bool = true;
11611173

11621174
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1163-
run.path("miri")
1175+
let default = should_build_extended_tool(&run.builder, "miri");
1176+
run.path("miri").default_condition(default)
11641177
}
11651178

11661179
fn make_run(run: RunConfig<'_>) {
@@ -1183,7 +1196,6 @@ impl Step for Miri {
11831196
}
11841197
let compiler = self.compiler;
11851198
let target = self.target;
1186-
assert!(builder.config.extended);
11871199

11881200
let miri = builder
11891201
.ensure(tool::Miri { compiler, target, extra_features: Vec::new() })
@@ -1219,7 +1231,8 @@ impl Step for Rustfmt {
12191231
const ONLY_HOSTS: bool = true;
12201232

12211233
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1222-
run.path("rustfmt")
1234+
let default = should_build_extended_tool(&run.builder, "rustfmt");
1235+
run.path("rustfmt").default_condition(default)
12231236
}
12241237

12251238
fn make_run(run: RunConfig<'_>) {
@@ -1344,6 +1357,17 @@ impl Step for Extended {
13441357
builder.info(&format!("Dist extended stage{} ({})", compiler.stage, target));
13451358

13461359
let mut tarballs = Vec::new();
1360+
let mut built_tools = HashSet::new();
1361+
macro_rules! add_tool {
1362+
($name:expr => $step:expr) => {
1363+
if should_build_extended_tool(builder, $name) {
1364+
if let Some(tarball) = builder.ensure($step) {
1365+
tarballs.push(tarball);
1366+
built_tools.insert($name);
1367+
}
1368+
}
1369+
};
1370+
}
13471371

13481372
// When rust-std package split from rustc, we needed to ensure that during
13491373
// upgrades rustc was upgraded before rust-std. To avoid rustc clobbering
@@ -1356,16 +1380,17 @@ impl Step for Extended {
13561380
tarballs.push(builder.ensure(Docs { host: target }));
13571381
}
13581382

1359-
let cargo_installer = builder.ensure(Cargo { compiler, target });
1360-
let rustfmt_installer = builder.ensure(Rustfmt { compiler, target });
1383+
add_tool!("cargo" => Cargo { compiler, target });
1384+
add_tool!("rustfmt" => Rustfmt { compiler, target });
1385+
add_tool!("rls" => Rls { compiler, target });
1386+
add_tool!("rust-analyzer" => RustAnalyzer { compiler, target });
1387+
add_tool!("llvm-tools" => LlvmTools { target });
1388+
add_tool!("clippy" => Clippy { compiler, target });
1389+
add_tool!("miri" => Miri { compiler, target });
1390+
add_tool!("analysis" => Analysis { compiler, target });
1391+
13611392
let rust_demangler_installer = builder.ensure(RustDemangler { compiler, target });
1362-
let rls_installer = builder.ensure(Rls { compiler, target });
1363-
let rust_analyzer_installer = builder.ensure(RustAnalyzer { compiler, target });
1364-
let llvm_tools_installer = builder.ensure(LlvmTools { target });
1365-
let clippy_installer = builder.ensure(Clippy { compiler, target });
1366-
let miri_installer = builder.ensure(Miri { compiler, target });
13671393
let mingw_installer = builder.ensure(Mingw { host: target });
1368-
let analysis_installer = builder.ensure(Analysis { compiler, target });
13691394

13701395
let etc = builder.src.join("src/etc/installer");
13711396

@@ -1374,17 +1399,8 @@ impl Step for Extended {
13741399
return;
13751400
}
13761401

1377-
tarballs.extend(cargo_installer);
1378-
tarballs.extend(clippy_installer);
13791402
tarballs.extend(rust_demangler_installer.clone());
1380-
tarballs.extend(rls_installer.clone());
1381-
tarballs.extend(rust_analyzer_installer.clone());
1382-
tarballs.extend(miri_installer.clone());
1383-
tarballs.extend(rustfmt_installer.clone());
1384-
tarballs.extend(llvm_tools_installer);
1385-
if let Some(analysis_installer) = analysis_installer {
1386-
tarballs.push(analysis_installer);
1387-
}
1403+
13881404
if target.contains("pc-windows-gnu") {
13891405
tarballs.push(mingw_installer.unwrap());
13901406
}
@@ -1434,17 +1450,11 @@ impl Step for Extended {
14341450
if rust_demangler_installer.is_none() {
14351451
contents = filter(&contents, "rust-demangler");
14361452
}
1437-
if rls_installer.is_none() {
1438-
contents = filter(&contents, "rls");
1439-
}
1440-
if rust_analyzer_installer.is_none() {
1441-
contents = filter(&contents, "rust-analyzer");
1442-
}
1443-
if miri_installer.is_none() {
1444-
contents = filter(&contents, "miri");
1445-
}
1446-
if rustfmt_installer.is_none() {
1447-
contents = filter(&contents, "rustfmt");
1453+
1454+
for tool in &["rls", "rust-analyzer", "miri", "rustfmt"] {
1455+
if !built_tools.contains(tool) {
1456+
contents = filter(&contents, tool);
1457+
}
14481458
}
14491459
let ret = tmp.join(p.file_name().unwrap());
14501460
t!(fs::write(&ret, &contents));
@@ -1485,16 +1495,11 @@ impl Step for Extended {
14851495
if rust_demangler_installer.is_some() {
14861496
prepare("rust-demangler");
14871497
}
1488-
if rls_installer.is_some() {
1489-
prepare("rls");
1490-
}
1491-
if rust_analyzer_installer.is_some() {
1492-
prepare("rust-analyzer");
1493-
}
1494-
if miri_installer.is_some() {
1495-
prepare("miri");
1498+
for tool in &["rls", "rust-analyzer", "miri"] {
1499+
if built_tools.contains(tool) {
1500+
prepare(tool);
1501+
}
14961502
}
1497-
14981503
// create an 'uninstall' package
14991504
builder.install(&etc.join("pkg/postinstall"), &pkg.join("uninstall"), 0o755);
15001505
pkgbuild("uninstall");
@@ -1554,14 +1559,10 @@ impl Step for Extended {
15541559
if rust_demangler_installer.is_some() {
15551560
prepare("rust-demangler");
15561561
}
1557-
if rls_installer.is_some() {
1558-
prepare("rls");
1559-
}
1560-
if rust_analyzer_installer.is_some() {
1561-
prepare("rust-analyzer");
1562-
}
1563-
if miri_installer.is_some() {
1564-
prepare("miri");
1562+
for tool in &["rls", "rust-analyzer", "miri"] {
1563+
if built_tools.contains(tool) {
1564+
prepare(tool);
1565+
}
15651566
}
15661567
if target.contains("windows-gnu") {
15671568
prepare("rust-mingw");
@@ -1640,7 +1641,7 @@ impl Step for Extended {
16401641
.arg("-out")
16411642
.arg(exe.join("StdGroup.wxs")),
16421643
);
1643-
if rls_installer.is_some() {
1644+
if built_tools.contains("rls") {
16441645
builder.run(
16451646
Command::new(&heat)
16461647
.current_dir(&exe)
@@ -1659,7 +1660,7 @@ impl Step for Extended {
16591660
.arg(etc.join("msi/remove-duplicates.xsl")),
16601661
);
16611662
}
1662-
if rust_analyzer_installer.is_some() {
1663+
if built_tools.contains("rust-analyzer") {
16631664
builder.run(
16641665
Command::new(&heat)
16651666
.current_dir(&exe)
@@ -1714,7 +1715,7 @@ impl Step for Extended {
17141715
.arg(etc.join("msi/remove-duplicates.xsl")),
17151716
);
17161717
}
1717-
if miri_installer.is_some() {
1718+
if built_tools.contains("miri") {
17181719
builder.run(
17191720
Command::new(&heat)
17201721
.current_dir(&exe)
@@ -1790,13 +1791,13 @@ impl Step for Extended {
17901791
if rust_demangler_installer.is_some() {
17911792
cmd.arg("-dRustDemanglerDir=rust-demangler");
17921793
}
1793-
if rls_installer.is_some() {
1794+
if built_tools.contains("rls") {
17941795
cmd.arg("-dRlsDir=rls");
17951796
}
1796-
if rust_analyzer_installer.is_some() {
1797+
if built_tools.contains("rust-analyzer") {
17971798
cmd.arg("-dRustAnalyzerDir=rust-analyzer");
17981799
}
1799-
if miri_installer.is_some() {
1800+
if built_tools.contains("miri") {
18001801
cmd.arg("-dMiriDir=miri");
18011802
}
18021803
if target.contains("windows-gnu") {
@@ -1815,13 +1816,13 @@ impl Step for Extended {
18151816
if rust_demangler_installer.is_some() {
18161817
candle("RustDemanglerGroup.wxs".as_ref());
18171818
}
1818-
if rls_installer.is_some() {
1819+
if built_tools.contains("rls") {
18191820
candle("RlsGroup.wxs".as_ref());
18201821
}
1821-
if rust_analyzer_installer.is_some() {
1822+
if built_tools.contains("rust-analyzer") {
18221823
candle("RustAnalyzerGroup.wxs".as_ref());
18231824
}
1824-
if miri_installer.is_some() {
1825+
if built_tools.contains("miri") {
18251826
candle("MiriGroup.wxs".as_ref());
18261827
}
18271828
candle("AnalysisGroup.wxs".as_ref());
@@ -1855,16 +1856,16 @@ impl Step for Extended {
18551856
.arg("ClippyGroup.wixobj")
18561857
.current_dir(&exe);
18571858

1858-
if rls_installer.is_some() {
1859+
if built_tools.contains("rls") {
18591860
cmd.arg("RlsGroup.wixobj");
18601861
}
1861-
if rust_analyzer_installer.is_some() {
1862+
if built_tools.contains("rust-analyzer") {
18621863
cmd.arg("RustAnalyzerGroup.wixobj");
18631864
}
18641865
if rust_demangler_installer.is_some() {
18651866
cmd.arg("RustDemanglerGroup.wixobj");
18661867
}
1867-
if miri_installer.is_some() {
1868+
if built_tools.contains("miri") {
18681869
cmd.arg("MiriGroup.wixobj");
18691870
}
18701871

@@ -1994,7 +1995,8 @@ impl Step for LlvmTools {
19941995
const ONLY_HOSTS: bool = true;
19951996

19961997
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1997-
run.path("llvm-tools")
1998+
let default = should_build_extended_tool(&run.builder, "llvm-tools");
1999+
run.path("llvm-tools").default_condition(default)
19982000
}
19992001

20002002
fn make_run(run: RunConfig<'_>) {
@@ -2003,7 +2005,6 @@ impl Step for LlvmTools {
20032005

20042006
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
20052007
let target = self.target;
2006-
assert!(builder.config.extended);
20072008

20082009
/* run only if llvm-config isn't used */
20092010
if let Some(config) = builder.config.target_config.get(&target) {

0 commit comments

Comments
 (0)