Skip to content

Commit c73c5dd

Browse files
committed
cleanup now that Kind is no longer used for excludes
1 parent 1205e6c commit c73c5dd

File tree

4 files changed

+27
-62
lines changed

4 files changed

+27
-62
lines changed

Diff for: src/bootstrap/builder.rs

+9-36
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::fs::{self, File};
88
use std::hash::Hash;
99
use std::io::{BufRead, BufReader};
1010
use std::ops::Deref;
11-
use std::path::{Component, Path, PathBuf};
11+
use std::path::{Path, PathBuf};
1212
use std::process::Command;
1313
use std::time::{Duration, Instant};
1414

@@ -150,29 +150,6 @@ pub struct TaskPath {
150150
pub kind: Option<Kind>,
151151
}
152152

153-
impl TaskPath {
154-
pub fn parse(path: impl Into<PathBuf>) -> TaskPath {
155-
let mut kind = None;
156-
let mut path = path.into();
157-
158-
let mut components = path.components();
159-
if let Some(Component::Normal(os_str)) = components.next() {
160-
if let Some(str) = os_str.to_str() {
161-
if let Some((found_kind, found_prefix)) = str.split_once("::") {
162-
if found_kind.is_empty() {
163-
panic!("empty kind in task path {}", path.display());
164-
}
165-
kind = Kind::parse(found_kind);
166-
assert!(kind.is_some());
167-
path = Path::new(found_prefix).join(components.as_path());
168-
}
169-
}
170-
}
171-
172-
TaskPath { path, kind }
173-
}
174-
}
175-
176153
impl Debug for TaskPath {
177154
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
178155
if let Some(kind) = &self.kind {
@@ -216,17 +193,17 @@ impl PathSet {
216193
PathSet::Set(set)
217194
}
218195

219-
fn has(&self, needle: &Path, module: Option<Kind>) -> bool {
196+
fn has(&self, needle: &Path, module: Kind) -> bool {
220197
match self {
221198
PathSet::Set(set) => set.iter().any(|p| Self::check(p, needle, module)),
222199
PathSet::Suite(suite) => Self::check(suite, needle, module),
223200
}
224201
}
225202

226203
// internal use only
227-
fn check(p: &TaskPath, needle: &Path, module: Option<Kind>) -> bool {
228-
if let (Some(p_kind), Some(kind)) = (&p.kind, module) {
229-
p.path.ends_with(needle) && *p_kind == kind
204+
fn check(p: &TaskPath, needle: &Path, module: Kind) -> bool {
205+
if let Some(p_kind) = &p.kind {
206+
p.path.ends_with(needle) && *p_kind == module
230207
} else {
231208
p.path.ends_with(needle)
232209
}
@@ -238,11 +215,7 @@ impl PathSet {
238215
/// This is used for `StepDescription::krate`, which passes all matching crates at once to
239216
/// `Step::make_run`, rather than calling it many times with a single crate.
240217
/// See `tests.rs` for examples.
241-
fn intersection_removing_matches(
242-
&self,
243-
needles: &mut Vec<&Path>,
244-
module: Option<Kind>,
245-
) -> PathSet {
218+
fn intersection_removing_matches(&self, needles: &mut Vec<&Path>, module: Kind) -> PathSet {
246219
let mut check = |p| {
247220
for (i, n) in needles.iter().enumerate() {
248221
let matched = Self::check(p, n, module);
@@ -307,7 +280,7 @@ impl StepDescription {
307280
}
308281

309282
fn is_excluded(&self, builder: &Builder<'_>, pathset: &PathSet) -> bool {
310-
if builder.config.exclude.iter().any(|e| pathset.has(&e.path, Some(builder.kind))) {
283+
if builder.config.exclude.iter().any(|e| pathset.has(&e, builder.kind)) {
311284
println!("Skipping {:?} because it is excluded", pathset);
312285
return true;
313286
}
@@ -562,7 +535,7 @@ impl<'a> ShouldRun<'a> {
562535
) -> Vec<PathSet> {
563536
let mut sets = vec![];
564537
for pathset in &self.paths {
565-
let subset = pathset.intersection_removing_matches(paths, Some(kind));
538+
let subset = pathset.intersection_removing_matches(paths, kind);
566539
if subset != PathSet::empty() {
567540
sets.push(subset);
568541
}
@@ -2130,7 +2103,7 @@ impl<'a> Builder<'a> {
21302103
let should_run = (desc.should_run)(ShouldRun::new(self, desc.kind));
21312104

21322105
for path in &self.paths {
2133-
if should_run.paths.iter().any(|s| s.has(path, Some(desc.kind)))
2106+
if should_run.paths.iter().any(|s| s.has(path, desc.kind))
21342107
&& !desc.is_excluded(
21352108
self,
21362109
&PathSet::Suite(TaskPath { path: path.clone(), kind: Some(desc.kind) }),

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

+15-22
Original file line numberDiff line numberDiff line change
@@ -101,23 +101,21 @@ fn test_invalid() {
101101

102102
#[test]
103103
fn test_intersection() {
104-
let set = PathSet::Set(
105-
["library/core", "library/alloc", "library/std"].into_iter().map(TaskPath::parse).collect(),
106-
);
104+
let set = |paths: &[&str]| {
105+
PathSet::Set(paths.into_iter().map(|p| TaskPath { path: p.into(), kind: None }).collect())
106+
};
107+
let library_set = set(&["library/core", "library/alloc", "library/std"]);
107108
let mut command_paths =
108109
vec![Path::new("library/core"), Path::new("library/alloc"), Path::new("library/stdarch")];
109-
let subset = set.intersection_removing_matches(&mut command_paths, None);
110-
assert_eq!(
111-
subset,
112-
PathSet::Set(["library/core", "library/alloc"].into_iter().map(TaskPath::parse).collect())
113-
);
110+
let subset = library_set.intersection_removing_matches(&mut command_paths, Kind::Build);
111+
assert_eq!(subset, set(&["library/core", "library/alloc"]),);
114112
assert_eq!(command_paths, vec![Path::new("library/stdarch")]);
115113
}
116114

117115
#[test]
118116
fn test_exclude() {
119117
let mut config = configure("test", &["A"], &["A"]);
120-
config.exclude = vec![TaskPath::parse("src/tools/tidy")];
118+
config.exclude = vec!["src/tools/tidy".into()];
121119
let cache = run_build(&[], config);
122120

123121
// Ensure we have really excluded tidy
@@ -129,21 +127,16 @@ fn test_exclude() {
129127

130128
#[test]
131129
fn test_exclude_kind() {
132-
let path = PathBuf::from("src/tools/cargotest");
133-
let exclude = TaskPath::parse("test::src/tools/cargotest");
134-
assert_eq!(exclude, TaskPath { kind: Some(Kind::Test), path: path.clone() });
130+
let path = PathBuf::from("compiler/rustc_data_structures");
135131

136132
let mut config = configure("test", &["A"], &["A"]);
137-
// Ensure our test is valid, and `test::Cargotest` would be run without the exclude.
138-
assert!(run_build(&[path.clone()], config.clone()).contains::<test::Cargotest>());
139-
// Ensure tests for cargotest are skipped.
140-
config.exclude = vec![exclude.clone()];
141-
assert!(!run_build(&[path.clone()], config).contains::<test::Cargotest>());
142-
143-
// Ensure builds for cargotest are not skipped.
144-
let mut config = configure("build", &["A"], &["A"]);
145-
config.exclude = vec![exclude];
146-
assert!(run_build(&[path], config).contains::<tool::CargoTest>());
133+
// Ensure our test is valid, and `test::Rustc` would be run without the exclude.
134+
assert!(run_build(&[], config.clone()).contains::<test::CrateLibrustc>());
135+
// Ensure tests for rustc are skipped.
136+
config.exclude = vec![path.clone()];
137+
assert!(!run_build(&[], config.clone()).contains::<test::CrateLibrustc>());
138+
// Ensure builds for rustc are not skipped.
139+
assert!(run_build(&[], config).contains::<compile::Rustc>());
147140
}
148141

149142
/// Ensure that if someone passes both a single crate and `library`, all library crates get built.

Diff for: src/bootstrap/config.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use std::path::{Path, PathBuf};
1616
use std::process::Command;
1717
use std::str::FromStr;
1818

19-
use crate::builder::TaskPath;
2019
use crate::cache::{Interned, INTERNER};
2120
use crate::cc_detect::{ndk_compiler, Language};
2221
use crate::channel::{self, GitInfo};
@@ -79,7 +78,7 @@ pub struct Config {
7978
pub sanitizers: bool,
8079
pub profiler: bool,
8180
pub omit_git_hash: bool,
82-
pub exclude: Vec<TaskPath>,
81+
pub exclude: Vec<PathBuf>,
8382
pub include_default_paths: bool,
8483
pub rustc_error_format: Option<String>,
8584
pub json_output: bool,
@@ -958,7 +957,7 @@ impl Config {
958957

959958
// Set flags.
960959
config.paths = std::mem::take(&mut flags.paths);
961-
config.exclude = flags.exclude.into_iter().map(|path| TaskPath::parse(path)).collect();
960+
config.exclude = flags.exclude;
962961
config.include_default_paths = flags.include_default_paths;
963962
config.rustc_error_format = flags.rustc_error_format;
964963
config.json_output = flags.json_output;

Diff for: src/bootstrap/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
15291529

15301530
for exclude in &builder.config.exclude {
15311531
cmd.arg("--skip");
1532-
cmd.arg(&exclude.path);
1532+
cmd.arg(&exclude);
15331533
}
15341534

15351535
// Get paths from cmd args

0 commit comments

Comments
 (0)