Skip to content

Commit c15e248

Browse files
committed
refactor extended tarball generaton to use the new ensure_if_default
1 parent 2cfac3f commit c15e248

File tree

3 files changed

+55
-38
lines changed

3 files changed

+55
-38
lines changed

src/bootstrap/builder.rs

+37-7
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,8 @@ impl StepDescription {
163163
}
164164

165165
fn maybe_run(&self, builder: &Builder<'_>, pathset: &PathSet) {
166-
if builder.config.exclude.iter().any(|e| pathset.has(e)) {
167-
eprintln!("Skipping {:?} because it is excluded", pathset);
166+
if self.is_excluded(builder, pathset) {
168167
return;
169-
} else if !builder.config.exclude.is_empty() {
170-
eprintln!(
171-
"{:?} not skipped for {:?} -- not in {:?}",
172-
pathset, self.name, builder.config.exclude
173-
);
174168
}
175169

176170
// Determine the targets participating in this rule.
@@ -182,6 +176,21 @@ impl StepDescription {
182176
}
183177
}
184178

179+
fn is_excluded(&self, builder: &Builder<'_>, pathset: &PathSet) -> bool {
180+
if builder.config.exclude.iter().any(|e| pathset.has(e)) {
181+
eprintln!("Skipping {:?} because it is excluded", pathset);
182+
return true;
183+
}
184+
185+
if !builder.config.exclude.is_empty() {
186+
eprintln!(
187+
"{:?} not skipped for {:?} -- not in {:?}",
188+
pathset, self.name, builder.config.exclude
189+
);
190+
}
191+
false
192+
}
193+
185194
fn run(v: &[StepDescription], builder: &Builder<'_>, paths: &[PathBuf]) {
186195
let should_runs =
187196
v.iter().map(|desc| (desc.should_run)(ShouldRun::new(builder))).collect::<Vec<_>>();
@@ -1579,6 +1588,27 @@ impl<'a> Builder<'a> {
15791588
self.cache.put(step, out.clone());
15801589
out
15811590
}
1591+
1592+
/// Ensure that a given step is built *only if it's supposed to be built by default*, returning
1593+
/// its output. This will cache the step, so it's safe (and good!) to call this as often as
1594+
/// needed to ensure that all dependencies are build.
1595+
pub(crate) fn ensure_if_default<T, S: Step<Output = Option<T>>>(
1596+
&'a self,
1597+
step: S,
1598+
) -> S::Output {
1599+
let desc = StepDescription::from::<S>();
1600+
let should_run = (desc.should_run)(ShouldRun::new(self));
1601+
1602+
// Avoid running steps contained in --exclude
1603+
for pathset in &should_run.paths {
1604+
if desc.is_excluded(self, pathset) {
1605+
return None;
1606+
}
1607+
}
1608+
1609+
// Only execute if it's supposed to run as default
1610+
if desc.default && should_run.is_really_default() { self.ensure(step) } else { None }
1611+
}
15821612
}
15831613

15841614
#[cfg(test)]

src/bootstrap/dist.rs

+17-30
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub struct Docs {
5959
}
6060

6161
impl Step for Docs {
62-
type Output = GeneratedTarball;
62+
type Output = Option<GeneratedTarball>;
6363
const DEFAULT: bool = true;
6464

6565
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
@@ -72,7 +72,7 @@ impl Step for Docs {
7272
}
7373

7474
/// Builds the `rust-docs` installer component.
75-
fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
75+
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
7676
let host = self.host;
7777
builder.default_doc(&[]);
7878

@@ -82,7 +82,7 @@ impl Step for Docs {
8282
tarball.set_product_name("Rust Documentation");
8383
tarball.add_bulk_dir(&builder.doc_out(host), dest);
8484
tarball.add_file(&builder.src.join("src/doc/robots.txt"), dest, 0o644);
85-
tarball.generate()
85+
Some(tarball.generate())
8686
}
8787
}
8888

@@ -1359,13 +1359,11 @@ impl Step for Extended {
13591359

13601360
let mut tarballs = Vec::new();
13611361
let mut built_tools = HashSet::new();
1362-
macro_rules! add_tool {
1362+
macro_rules! add_component {
13631363
($name:expr => $step:expr) => {
1364-
if should_build_extended_tool(builder, $name) {
1365-
if let Some(tarball) = builder.ensure($step) {
1366-
tarballs.push(tarball);
1367-
built_tools.insert($name);
1368-
}
1364+
if let Some(tarball) = builder.ensure_if_default($step) {
1365+
tarballs.push(tarball);
1366+
built_tools.insert($name);
13691367
}
13701368
};
13711369
}
@@ -1377,31 +1375,20 @@ impl Step for Extended {
13771375
tarballs.push(builder.ensure(Rustc { compiler: builder.compiler(stage, target) }));
13781376
tarballs.push(builder.ensure(Std { compiler, target }).expect("missing std"));
13791377

1380-
if builder.config.docs {
1381-
tarballs.push(builder.ensure(Docs { host: target }));
1382-
}
1383-
13841378
if target.contains("windows-gnu") {
13851379
tarballs.push(builder.ensure(Mingw { host: target }).expect("missing mingw"));
13861380
}
13871381

1388-
if builder.config.profiler_enabled(target)
1389-
|| should_build_extended_tool(builder, "rust-demangler")
1390-
{
1391-
if let Some(tarball) = builder.ensure(RustDemangler { compiler, target }) {
1392-
tarballs.push(tarball);
1393-
built_tools.insert("rust-demangler");
1394-
}
1395-
}
1396-
1397-
add_tool!("cargo" => Cargo { compiler, target });
1398-
add_tool!("rustfmt" => Rustfmt { compiler, target });
1399-
add_tool!("rls" => Rls { compiler, target });
1400-
add_tool!("rust-analyzer" => RustAnalyzer { compiler, target });
1401-
add_tool!("llvm-tools" => LlvmTools { target });
1402-
add_tool!("clippy" => Clippy { compiler, target });
1403-
add_tool!("miri" => Miri { compiler, target });
1404-
add_tool!("analysis" => Analysis { compiler, target });
1382+
add_component!("rust-docs" => Docs { host: target });
1383+
add_component!("rust-demangler"=> RustDemangler { compiler, target });
1384+
add_component!("cargo" => Cargo { compiler, target });
1385+
add_component!("rustfmt" => Rustfmt { compiler, target });
1386+
add_component!("rls" => Rls { compiler, target });
1387+
add_component!("rust-analyzer" => RustAnalyzer { compiler, target });
1388+
add_component!("llvm-components" => LlvmTools { target });
1389+
add_component!("clippy" => Clippy { compiler, target });
1390+
add_component!("miri" => Miri { compiler, target });
1391+
add_component!("analysis" => Analysis { compiler, target });
14051392

14061393
let etc = builder.src.join("src/etc/installer");
14071394

src/bootstrap/install.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ macro_rules! install {
139139

140140
install!((self, builder, _config),
141141
Docs, "src/doc", _config.docs, only_hosts: false, {
142-
let tarball = builder.ensure(dist::Docs { host: self.target });
142+
let tarball = builder.ensure(dist::Docs { host: self.target }).expect("missing docs");
143143
install_sh(builder, "docs", self.compiler.stage, Some(self.target), &tarball);
144144
};
145145
Std, "library/std", true, only_hosts: false, {

0 commit comments

Comments
 (0)