mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 12:36:35 +03:00
cleanup now that Kind is no longer used for excludes
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
use std::hash::Hash;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::ops::Deref;
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
@@ -150,29 +150,6 @@ pub struct TaskPath {
|
||||
pub kind: Option<Kind>,
|
||||
}
|
||||
|
||||
impl TaskPath {
|
||||
pub fn parse(path: impl Into<PathBuf>) -> TaskPath {
|
||||
let mut kind = None;
|
||||
let mut path = path.into();
|
||||
|
||||
let mut components = path.components();
|
||||
if let Some(Component::Normal(os_str)) = components.next() {
|
||||
if let Some(str) = os_str.to_str() {
|
||||
if let Some((found_kind, found_prefix)) = str.split_once("::") {
|
||||
if found_kind.is_empty() {
|
||||
panic!("empty kind in task path {}", path.display());
|
||||
}
|
||||
kind = Kind::parse(found_kind);
|
||||
assert!(kind.is_some());
|
||||
path = Path::new(found_prefix).join(components.as_path());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TaskPath { path, kind }
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for TaskPath {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
if let Some(kind) = &self.kind {
|
||||
@@ -216,7 +193,7 @@ fn one<P: Into<PathBuf>>(path: P, kind: Kind) -> PathSet {
|
||||
PathSet::Set(set)
|
||||
}
|
||||
|
||||
fn has(&self, needle: &Path, module: Option<Kind>) -> bool {
|
||||
fn has(&self, needle: &Path, module: Kind) -> bool {
|
||||
match self {
|
||||
PathSet::Set(set) => set.iter().any(|p| Self::check(p, needle, module)),
|
||||
PathSet::Suite(suite) => Self::check(suite, needle, module),
|
||||
@@ -224,9 +201,9 @@ fn has(&self, needle: &Path, module: Option<Kind>) -> bool {
|
||||
}
|
||||
|
||||
// internal use only
|
||||
fn check(p: &TaskPath, needle: &Path, module: Option<Kind>) -> bool {
|
||||
if let (Some(p_kind), Some(kind)) = (&p.kind, module) {
|
||||
p.path.ends_with(needle) && *p_kind == kind
|
||||
fn check(p: &TaskPath, needle: &Path, module: Kind) -> bool {
|
||||
if let Some(p_kind) = &p.kind {
|
||||
p.path.ends_with(needle) && *p_kind == module
|
||||
} else {
|
||||
p.path.ends_with(needle)
|
||||
}
|
||||
@@ -238,11 +215,7 @@ fn check(p: &TaskPath, needle: &Path, module: Option<Kind>) -> bool {
|
||||
/// This is used for `StepDescription::krate`, which passes all matching crates at once to
|
||||
/// `Step::make_run`, rather than calling it many times with a single crate.
|
||||
/// See `tests.rs` for examples.
|
||||
fn intersection_removing_matches(
|
||||
&self,
|
||||
needles: &mut Vec<&Path>,
|
||||
module: Option<Kind>,
|
||||
) -> PathSet {
|
||||
fn intersection_removing_matches(&self, needles: &mut Vec<&Path>, module: Kind) -> PathSet {
|
||||
let mut check = |p| {
|
||||
for (i, n) in needles.iter().enumerate() {
|
||||
let matched = Self::check(p, n, module);
|
||||
@@ -307,7 +280,7 @@ fn maybe_run(&self, builder: &Builder<'_>, pathsets: Vec<PathSet>) {
|
||||
}
|
||||
|
||||
fn is_excluded(&self, builder: &Builder<'_>, pathset: &PathSet) -> bool {
|
||||
if builder.config.exclude.iter().any(|e| pathset.has(&e.path, Some(builder.kind))) {
|
||||
if builder.config.exclude.iter().any(|e| pathset.has(&e, builder.kind)) {
|
||||
println!("Skipping {:?} because it is excluded", pathset);
|
||||
return true;
|
||||
}
|
||||
@@ -562,7 +535,7 @@ fn pathset_for_paths_removing_matches(
|
||||
) -> Vec<PathSet> {
|
||||
let mut sets = vec![];
|
||||
for pathset in &self.paths {
|
||||
let subset = pathset.intersection_removing_matches(paths, Some(kind));
|
||||
let subset = pathset.intersection_removing_matches(paths, kind);
|
||||
if subset != PathSet::empty() {
|
||||
sets.push(subset);
|
||||
}
|
||||
@@ -2130,7 +2103,7 @@ pub(crate) fn was_invoked_explicitly<S: Step>(&'a self, kind: Kind) -> bool {
|
||||
let should_run = (desc.should_run)(ShouldRun::new(self, desc.kind));
|
||||
|
||||
for path in &self.paths {
|
||||
if should_run.paths.iter().any(|s| s.has(path, Some(desc.kind)))
|
||||
if should_run.paths.iter().any(|s| s.has(path, desc.kind))
|
||||
&& !desc.is_excluded(
|
||||
self,
|
||||
&PathSet::Suite(TaskPath { path: path.clone(), kind: Some(desc.kind) }),
|
||||
|
||||
@@ -101,23 +101,21 @@ fn test_invalid() {
|
||||
|
||||
#[test]
|
||||
fn test_intersection() {
|
||||
let set = PathSet::Set(
|
||||
["library/core", "library/alloc", "library/std"].into_iter().map(TaskPath::parse).collect(),
|
||||
);
|
||||
let set = |paths: &[&str]| {
|
||||
PathSet::Set(paths.into_iter().map(|p| TaskPath { path: p.into(), kind: None }).collect())
|
||||
};
|
||||
let library_set = set(&["library/core", "library/alloc", "library/std"]);
|
||||
let mut command_paths =
|
||||
vec![Path::new("library/core"), Path::new("library/alloc"), Path::new("library/stdarch")];
|
||||
let subset = set.intersection_removing_matches(&mut command_paths, None);
|
||||
assert_eq!(
|
||||
subset,
|
||||
PathSet::Set(["library/core", "library/alloc"].into_iter().map(TaskPath::parse).collect())
|
||||
);
|
||||
let subset = library_set.intersection_removing_matches(&mut command_paths, Kind::Build);
|
||||
assert_eq!(subset, set(&["library/core", "library/alloc"]),);
|
||||
assert_eq!(command_paths, vec![Path::new("library/stdarch")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_exclude() {
|
||||
let mut config = configure("test", &["A"], &["A"]);
|
||||
config.exclude = vec![TaskPath::parse("src/tools/tidy")];
|
||||
config.exclude = vec!["src/tools/tidy".into()];
|
||||
let cache = run_build(&[], config);
|
||||
|
||||
// Ensure we have really excluded tidy
|
||||
@@ -129,21 +127,16 @@ fn test_exclude() {
|
||||
|
||||
#[test]
|
||||
fn test_exclude_kind() {
|
||||
let path = PathBuf::from("src/tools/cargotest");
|
||||
let exclude = TaskPath::parse("test::src/tools/cargotest");
|
||||
assert_eq!(exclude, TaskPath { kind: Some(Kind::Test), path: path.clone() });
|
||||
let path = PathBuf::from("compiler/rustc_data_structures");
|
||||
|
||||
let mut config = configure("test", &["A"], &["A"]);
|
||||
// Ensure our test is valid, and `test::Cargotest` would be run without the exclude.
|
||||
assert!(run_build(&[path.clone()], config.clone()).contains::<test::Cargotest>());
|
||||
// Ensure tests for cargotest are skipped.
|
||||
config.exclude = vec![exclude.clone()];
|
||||
assert!(!run_build(&[path.clone()], config).contains::<test::Cargotest>());
|
||||
|
||||
// Ensure builds for cargotest are not skipped.
|
||||
let mut config = configure("build", &["A"], &["A"]);
|
||||
config.exclude = vec![exclude];
|
||||
assert!(run_build(&[path], config).contains::<tool::CargoTest>());
|
||||
// Ensure our test is valid, and `test::Rustc` would be run without the exclude.
|
||||
assert!(run_build(&[], config.clone()).contains::<test::CrateLibrustc>());
|
||||
// Ensure tests for rustc are skipped.
|
||||
config.exclude = vec![path.clone()];
|
||||
assert!(!run_build(&[], config.clone()).contains::<test::CrateLibrustc>());
|
||||
// Ensure builds for rustc are not skipped.
|
||||
assert!(run_build(&[], config).contains::<compile::Rustc>());
|
||||
}
|
||||
|
||||
/// Ensure that if someone passes both a single crate and `library`, all library crates get built.
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
use std::process::Command;
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::builder::TaskPath;
|
||||
use crate::cache::{Interned, INTERNER};
|
||||
use crate::cc_detect::{ndk_compiler, Language};
|
||||
use crate::channel::{self, GitInfo};
|
||||
@@ -79,7 +78,7 @@ pub struct Config {
|
||||
pub sanitizers: bool,
|
||||
pub profiler: bool,
|
||||
pub omit_git_hash: bool,
|
||||
pub exclude: Vec<TaskPath>,
|
||||
pub exclude: Vec<PathBuf>,
|
||||
pub include_default_paths: bool,
|
||||
pub rustc_error_format: Option<String>,
|
||||
pub json_output: bool,
|
||||
@@ -958,7 +957,7 @@ fn parse_inner(args: &[String], get_toml: impl Fn(&Path) -> TomlConfig) -> Confi
|
||||
|
||||
// Set flags.
|
||||
config.paths = std::mem::take(&mut flags.paths);
|
||||
config.exclude = flags.exclude.into_iter().map(|path| TaskPath::parse(path)).collect();
|
||||
config.exclude = flags.exclude;
|
||||
config.include_default_paths = flags.include_default_paths;
|
||||
config.rustc_error_format = flags.rustc_error_format;
|
||||
config.json_output = flags.json_output;
|
||||
|
||||
@@ -1529,7 +1529,7 @@ fn run(self, builder: &Builder<'_>) {
|
||||
|
||||
for exclude in &builder.config.exclude {
|
||||
cmd.arg("--skip");
|
||||
cmd.arg(&exclude.path);
|
||||
cmd.arg(&exclude);
|
||||
}
|
||||
|
||||
// Get paths from cmd args
|
||||
|
||||
Reference in New Issue
Block a user