Skip to content

Commit f76d415

Browse files
authored
Unrolled build for rust-lang#135058
Rollup merge of rust-lang#135058 - onur-ozkan:path-resolution, r=jieyouxu refactor bootstrap path resolution Previously we removed paths as soon as we found the first intersection, which made it impossible to find other intersecting paths (and that is the reason of rust-lang#135022). This patch changes that by marking the intersecting paths instead, so we can collect them all and remove them together when needed. Which means, `x build compiler` would compile anything that ends or starts with `"compiler"` instead of picking the first matching `Step` from `builder::get_step_descriptions`. Fixes rust-lang#135022
2 parents 3f43b1a + baa7fce commit f76d415

File tree

4 files changed

+76
-27
lines changed

4 files changed

+76
-27
lines changed

Diff for: src/bootstrap/src/core/build_steps/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl Step for Std {
9393
const DEFAULT: bool = true;
9494

9595
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
96-
run.crate_or_deps("sysroot").path("library")
96+
run.crate_or_deps("sysroot").path("library").alias("core")
9797
}
9898

9999
fn make_run(run: RunConfig<'_>) {

Diff for: src/bootstrap/src/core/build_steps/doc.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,10 @@ impl Step for Std {
574574

575575
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
576576
let builder = run.builder;
577-
run.crate_or_deps("sysroot").path("library").default_condition(builder.config.docs)
577+
run.crate_or_deps("sysroot")
578+
.path("library")
579+
.alias("core")
580+
.default_condition(builder.config.docs)
578581
}
579582

580583
fn make_run(run: RunConfig<'_>) {

Diff for: src/bootstrap/src/core/builder/mod.rs

+43-21
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod cargo;
33
use std::any::{Any, type_name};
44
use std::cell::{Cell, RefCell};
55
use std::collections::BTreeSet;
6-
use std::fmt::{Debug, Write};
6+
use std::fmt::{self, Debug, Write};
77
use std::hash::Hash;
88
use std::ops::Deref;
99
use std::path::{Path, PathBuf};
@@ -271,16 +271,17 @@ impl PathSet {
271271
/// This is used for `StepDescription::krate`, which passes all matching crates at once to
272272
/// `Step::make_run`, rather than calling it many times with a single crate.
273273
/// See `tests.rs` for examples.
274-
fn intersection_removing_matches(&self, needles: &mut Vec<PathBuf>, module: Kind) -> PathSet {
274+
fn intersection_removing_matches(&self, needles: &mut [CLIStepPath], module: Kind) -> PathSet {
275275
let mut check = |p| {
276-
for (i, n) in needles.iter().enumerate() {
277-
let matched = Self::check(p, n, module);
276+
let mut result = false;
277+
for n in needles.iter_mut() {
278+
let matched = Self::check(p, &n.path, module);
278279
if matched {
279-
needles.remove(i);
280-
return true;
280+
n.will_be_executed = true;
281+
result = true;
281282
}
282283
}
283-
false
284+
result
284285
};
285286
match self {
286287
PathSet::Set(set) => PathSet::Set(set.iter().filter(|&p| check(p)).cloned().collect()),
@@ -361,6 +362,32 @@ fn remap_paths(paths: &mut Vec<PathBuf>) {
361362
paths.append(&mut add);
362363
}
363364

365+
#[derive(Clone, PartialEq)]
366+
struct CLIStepPath {
367+
path: PathBuf,
368+
will_be_executed: bool,
369+
}
370+
371+
#[cfg(test)]
372+
impl CLIStepPath {
373+
fn will_be_executed(mut self, will_be_executed: bool) -> Self {
374+
self.will_be_executed = will_be_executed;
375+
self
376+
}
377+
}
378+
379+
impl Debug for CLIStepPath {
380+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
381+
write!(f, "{}", self.path.display())
382+
}
383+
}
384+
385+
impl From<PathBuf> for CLIStepPath {
386+
fn from(path: PathBuf) -> Self {
387+
Self { path, will_be_executed: false }
388+
}
389+
}
390+
364391
impl StepDescription {
365392
fn from<S: Step>(kind: Kind) -> StepDescription {
366393
StepDescription {
@@ -478,7 +505,8 @@ impl StepDescription {
478505
return;
479506
}
480507

481-
let mut path_lookup: Vec<(PathBuf, bool)> =
508+
let mut paths: Vec<CLIStepPath> = paths.into_iter().map(|p| p.into()).collect();
509+
let mut path_lookup: Vec<(CLIStepPath, bool)> =
482510
paths.clone().into_iter().map(|p| (p, false)).collect();
483511

484512
// List of `(usize, &StepDescription, Vec<PathSet>)` where `usize` is the closest index of a path
@@ -518,8 +546,10 @@ impl StepDescription {
518546
}
519547
}
520548

549+
paths.retain(|p| !p.will_be_executed);
550+
521551
if !paths.is_empty() {
522-
eprintln!("ERROR: no `{}` rules matched {:?}", builder.kind.as_str(), paths,);
552+
eprintln!("ERROR: no `{}` rules matched {:?}", builder.kind.as_str(), paths);
523553
eprintln!(
524554
"HELP: run `x.py {} --help --verbose` to show a list of available paths",
525555
builder.kind.as_str()
@@ -682,7 +712,7 @@ impl<'a> ShouldRun<'a> {
682712
/// (for now, just `all_krates` and `paths`, but we may want to add an `aliases` function in the future?)
683713
fn pathset_for_paths_removing_matches(
684714
&self,
685-
paths: &mut Vec<PathBuf>,
715+
paths: &mut [CLIStepPath],
686716
kind: Kind,
687717
) -> Vec<PathSet> {
688718
let mut sets = vec![];
@@ -825,12 +855,8 @@ impl<'a> Builder<'a> {
825855
match kind {
826856
Kind::Build => describe!(
827857
compile::Std,
828-
// FIXME(#135022): `compile::Assemble` **must** come before `compile::Rustc` after
829-
// `PathSet` also permits prefix-matching, because `compile::Rustc` can consume the
830-
// `"compiler"` path filter first, causing `compile::Assemble` to no longer run when
831-
// the user writes `./x build compiler --stage 0`.
832-
compile::Assemble,
833858
compile::Rustc,
859+
compile::Assemble,
834860
compile::CodegenBackend,
835861
compile::StartupObjects,
836862
tool::BuildManifest,
@@ -929,14 +955,10 @@ impl<'a> Builder<'a> {
929955
test::Rustdoc,
930956
test::CoverageRunRustdoc,
931957
test::Pretty,
932-
test::Crate,
933-
test::CrateLibrustc,
934-
// The cranelift and gcc tests need to be listed after the
935-
// compiler unit tests (CrateLibrustc) so that they don't
936-
// hijack the whole `compiler` directory during path matching.
937-
// <https://github.com/rust-lang/rust/pull/134919>
938958
test::CodegenCranelift,
939959
test::CodegenGCC,
960+
test::Crate,
961+
test::CrateLibrustc,
940962
test::CrateRustdoc,
941963
test::CrateRustdocJsonTypes,
942964
test::CrateBootstrap,

Diff for: src/bootstrap/src/core/builder/tests.rs

+28-4
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,37 @@ fn test_intersection() {
108108
};
109109
let library_set = set(&["library/core", "library/alloc", "library/std"]);
110110
let mut command_paths = vec![
111-
PathBuf::from("library/core"),
112-
PathBuf::from("library/alloc"),
113-
PathBuf::from("library/stdarch"),
111+
CLIStepPath::from(PathBuf::from("library/core")),
112+
CLIStepPath::from(PathBuf::from("library/alloc")),
113+
CLIStepPath::from(PathBuf::from("library/stdarch")),
114114
];
115115
let subset = library_set.intersection_removing_matches(&mut command_paths, Kind::Build);
116116
assert_eq!(subset, set(&["library/core", "library/alloc"]),);
117-
assert_eq!(command_paths, vec![PathBuf::from("library/stdarch")]);
117+
assert_eq!(command_paths, vec![
118+
CLIStepPath::from(PathBuf::from("library/core")).will_be_executed(true),
119+
CLIStepPath::from(PathBuf::from("library/alloc")).will_be_executed(true),
120+
CLIStepPath::from(PathBuf::from("library/stdarch")).will_be_executed(false),
121+
]);
122+
}
123+
124+
#[test]
125+
fn test_resolve_parent_and_subpaths() {
126+
let set = |paths: &[&str]| {
127+
PathSet::Set(paths.into_iter().map(|p| TaskPath { path: p.into(), kind: None }).collect())
128+
};
129+
130+
let mut command_paths = vec![
131+
CLIStepPath::from(PathBuf::from("src/tools/miri")),
132+
CLIStepPath::from(PathBuf::from("src/tools/miri/cargo-miri")),
133+
];
134+
135+
let library_set = set(&["src/tools/miri", "src/tools/miri/cargo-miri"]);
136+
library_set.intersection_removing_matches(&mut command_paths, Kind::Build);
137+
138+
assert_eq!(command_paths, vec![
139+
CLIStepPath::from(PathBuf::from("src/tools/miri")).will_be_executed(true),
140+
CLIStepPath::from(PathBuf::from("src/tools/miri/cargo-miri")).will_be_executed(true),
141+
]);
118142
}
119143

120144
#[test]

0 commit comments

Comments
 (0)