Skip to content

Commit 46f01ca

Browse files
authored
Rollup merge of #87282 - pietroalbini:refactor-extended, r=Mark-Simulacrum
Ensure `./x.py dist` adheres to `build.tools` According to `config.toml.example`, the way to produce dist artifacts for both the compiler and a *subset* of tools would be to enable the extended build and manually specify the list of tools to build: ```toml [build] extended = true tools = ["cargo", "rustfmt"] ``` This works as expected for `./x.py build` and `./x.py install`, but *not* for `./x.py dist`. Before this PR `./x.py dist` simply ignored the contents of `build.tools`, building just rustc/rustdoc if `build.extended = false` and all of the tools otherwise. This PR does two things: * Changes `./x.py dist extended` to only build the tools defined in `build.tools`, if `build.tools` is not empty. The rest of the extended step was refactored to simplify the code. * Changes how dist jobs for tools are gated: instead of `assert!(builder.config.extended)` to prevent tools from being built with `build.extended = false`, tools are simply built by default depending on `build.extended` and `build.tools`. This also enables to **explicitly** dist tools even with `build.extended = false`. This PR is best reviewed commit-by-commit. Fixes #86436
2 parents f386ae3 + 69f712c commit 46f01ca

File tree

3 files changed

+154
-135
lines changed

3 files changed

+154
-135
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)]

0 commit comments

Comments
 (0)