Skip to content

Commit b27d59d

Browse files
committed
replace paths in PathSet with a dedicated TaskPath struct
1 parent 523be2e commit b27d59d

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

src/bootstrap/builder.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ struct StepDescription {
107107
name: &'static str,
108108
}
109109

110+
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq)]
111+
pub struct TaskPath {
112+
pub path: PathBuf,
113+
pub module: Option<String>,
114+
}
115+
116+
impl TaskPath {
117+
pub fn parse(path: impl Into<PathBuf>) -> TaskPath {
118+
TaskPath { path: path.into(), module: None }
119+
}
120+
}
121+
110122
/// Collection of paths used to match a task rule.
111123
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq)]
112124
pub enum PathSet {
@@ -115,14 +127,14 @@ pub enum PathSet {
115127
/// These are generally matched as a path suffix. For example, a
116128
/// command-line value of `libstd` will match if `src/libstd` is in the
117129
/// set.
118-
Set(BTreeSet<PathBuf>),
130+
Set(BTreeSet<TaskPath>),
119131
/// A "suite" of paths.
120132
///
121133
/// These can match as a path suffix (like `Set`), or as a prefix. For
122134
/// example, a command-line value of `src/test/ui/abi/variadic-ffi.rs`
123135
/// will match `src/test/ui`. A command-line value of `ui` would also
124136
/// match `src/test/ui`.
125-
Suite(PathBuf),
137+
Suite(TaskPath),
126138
}
127139

128140
impl PathSet {
@@ -132,21 +144,23 @@ impl PathSet {
132144

133145
fn one<P: Into<PathBuf>>(path: P) -> PathSet {
134146
let mut set = BTreeSet::new();
135-
set.insert(path.into());
147+
set.insert(TaskPath::parse(path));
136148
PathSet::Set(set)
137149
}
138150

139151
fn has(&self, needle: &Path) -> bool {
140152
match self {
141-
PathSet::Set(set) => set.iter().any(|p| p.ends_with(needle)),
142-
PathSet::Suite(suite) => suite.ends_with(needle),
153+
PathSet::Set(set) => set.iter().any(|p| p.path.ends_with(needle)),
154+
PathSet::Suite(suite) => suite.path.ends_with(needle),
143155
}
144156
}
145157

146158
fn path(&self, builder: &Builder<'_>) -> PathBuf {
147159
match self {
148-
PathSet::Set(set) => set.iter().next().unwrap_or(&builder.build.src).to_path_buf(),
149-
PathSet::Suite(path) => PathBuf::from(path),
160+
PathSet::Set(set) => {
161+
set.iter().next().map(|p| &p.path).unwrap_or(&builder.build.src).clone()
162+
}
163+
PathSet::Suite(path) => path.path.clone(),
150164
}
151165
}
152166
}
@@ -293,7 +307,7 @@ impl<'a> ShouldRun<'a> {
293307
let mut set = BTreeSet::new();
294308
for krate in self.builder.in_tree_crates(name, None) {
295309
let path = krate.local_path(self.builder);
296-
set.insert(path);
310+
set.insert(TaskPath::parse(path));
297311
}
298312
self.paths.insert(PathSet::Set(set));
299313
self
@@ -318,19 +332,19 @@ impl<'a> ShouldRun<'a> {
318332

319333
// multiple aliases for the same job
320334
pub fn paths(mut self, paths: &[&str]) -> Self {
321-
self.paths.insert(PathSet::Set(paths.iter().map(PathBuf::from).collect()));
335+
self.paths.insert(PathSet::Set(paths.iter().map(|p| TaskPath::parse(p)).collect()));
322336
self
323337
}
324338

325339
pub fn is_suite_path(&self, path: &Path) -> Option<&PathSet> {
326340
self.paths.iter().find(|pathset| match pathset {
327-
PathSet::Suite(p) => path.starts_with(p),
341+
PathSet::Suite(p) => path.starts_with(&p.path),
328342
PathSet::Set(_) => false,
329343
})
330344
}
331345

332346
pub fn suite_path(mut self, suite: &str) -> Self {
333-
self.paths.insert(PathSet::Suite(PathBuf::from(suite)));
347+
self.paths.insert(PathSet::Suite(TaskPath::parse(suite)));
334348
self
335349
}
336350

@@ -552,11 +566,11 @@ impl<'a> Builder<'a> {
552566
match pathset {
553567
PathSet::Set(set) => {
554568
for path in set {
555-
add_path(&path);
569+
add_path(&path.path);
556570
}
557571
}
558572
PathSet::Suite(path) => {
559-
add_path(&path.join("..."));
573+
add_path(&path.path.join("..."));
560574
}
561575
}
562576
}
@@ -1648,7 +1662,7 @@ impl<'a> Builder<'a> {
16481662

16491663
for path in &self.paths {
16501664
if should_run.paths.iter().any(|s| s.has(path))
1651-
&& !desc.is_excluded(self, &PathSet::Suite(path.clone()))
1665+
&& !desc.is_excluded(self, &PathSet::Suite(TaskPath::parse(path)))
16521666
{
16531667
return true;
16541668
}

0 commit comments

Comments
 (0)