Skip to content

Commit 04e41dd

Browse files
authored
Rollup merge of rust-lang#112297 - jyn514:remove-exclude-kind, r=Mark-Simulacrum
bootstrap: Disallow `--exclude test::std` Use the top-level Kind to determine whether Steps are excluded. Previously, this would use the `Kind` passed to `--exclude` (and not do any filtering at all if no kind was passed). That meant that `x test linkchecker --exclude std` would fail - you had to explicitly say `--exclude test::std`. Change bootstrap to use the top-level Kind instead, which does the right thing automatically. Note that this breaks things like `x test --exclude doc::std`, but I'm not sure why you'd ever want to do that. There's a lot of churn here, but the 1-line change in the first commit is the actual behavior change, the rest is just cleanup. Fixes rust-lang#103201. Note that this effectively reverts most of rust-lang#91965. cc `@pietroalbini`
2 parents 4b71d79 + c73c5dd commit 04e41dd

File tree

5 files changed

+28
-62
lines changed

5 files changed

+28
-62
lines changed

Diff for: src/bootstrap/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1818
- `x.py fmt` now formats only files modified between the merge-base of HEAD and the last commit in the master branch of the rust-lang repository and the current working directory. To restore old behaviour, use `x.py fmt .`. The check mode is not affected by this change. [#105702](https://github.com/rust-lang/rust/pull/105702)
1919
- The `llvm.version-check` config option has been removed. Older versions were never supported. If you still need to support older versions (e.g. you are applying custom patches), patch `check_llvm_version` in bootstrap to change the minimum version. [#108619](https://github.com/rust-lang/rust/pull/108619)
2020
- The `rust.ignore-git` option has been renamed to `rust.omit-git-hash`. [#110059](https://github.com/rust-lang/rust/pull/110059)
21+
- `--exclude` no longer accepts a `Kind` as part of a Step; instead it uses the top-level Kind of the subcommand. If this matches how you were already using --exclude (e.g. `x test --exclude test::std`), simply remove the kind: `--exclude std`. If you were using a kind that did not match the top-level subcommand, please open an issue explaining why you wanted this feature.
2122

2223
### Non-breaking changes
2324

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, e.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
}
@@ -2138,7 +2111,7 @@ impl<'a> Builder<'a> {
21382111
let should_run = (desc.should_run)(ShouldRun::new(self, desc.kind));
21392112

21402113
for path in &self.paths {
2141-
if should_run.paths.iter().any(|s| s.has(path, Some(desc.kind)))
2114+
if should_run.paths.iter().any(|s| s.has(path, desc.kind))
21422115
&& !desc.is_excluded(
21432116
self,
21442117
&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
@@ -17,7 +17,6 @@ use std::path::{Path, PathBuf};
1717
use std::process::Command;
1818
use std::str::FromStr;
1919

20-
use crate::builder::TaskPath;
2120
use crate::cache::{Interned, INTERNER};
2221
use crate::cc_detect::{ndk_compiler, Language};
2322
use crate::channel::{self, GitInfo};
@@ -80,7 +79,7 @@ pub struct Config {
8079
pub sanitizers: bool,
8180
pub profiler: bool,
8281
pub omit_git_hash: bool,
83-
pub exclude: Vec<TaskPath>,
82+
pub exclude: Vec<PathBuf>,
8483
pub include_default_paths: bool,
8584
pub rustc_error_format: Option<String>,
8685
pub json_output: bool,
@@ -957,7 +956,7 @@ impl Config {
957956

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

Diff for: src/bootstrap/test.rs

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

15381538
for exclude in &builder.config.exclude {
15391539
cmd.arg("--skip");
1540-
cmd.arg(&exclude.path);
1540+
cmd.arg(&exclude);
15411541
}
15421542

15431543
// Get paths from cmd args

0 commit comments

Comments
 (0)