From 41ee6fe14725011c327e18a77ff71738b17cd869 Mon Sep 17 00:00:00 2001 From: Collins Abitekaniza Date: Thu, 12 Apr 2018 14:49:31 +0300 Subject: [PATCH 1/2] ./x.py test should be able to run individual tests trim and pass relative test paths as test-args use collect for getting test_args move suite_path to ShouldRun and make Option append existing args to test_args use enum for PathSet handle Suites differently from Paths Error out if part of test suite but not file refactor, make requested changes --- src/bootstrap/builder.rs | 51 ++++++++++++++++++++++++++++++---------- src/bootstrap/test.rs | 27 +++++++++++++++++++-- 2 files changed, 63 insertions(+), 15 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index b9c82127342fd..cea8e139f33a6 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -111,27 +111,34 @@ struct StepDescription { } #[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq)] -struct PathSet { - set: BTreeSet, +pub enum PathSet { + Set (BTreeSet), + Suite (PathBuf) } impl PathSet { fn empty() -> PathSet { - PathSet { set: BTreeSet::new() } + PathSet::Set(BTreeSet::new()) } fn one>(path: P) -> PathSet { let mut set = BTreeSet::new(); set.insert(path.into()); - PathSet { set } + PathSet::Set(set) } fn has(&self, needle: &Path) -> bool { - self.set.iter().any(|p| p.ends_with(needle)) + match self { + PathSet::Set(set) => set.iter().any(|p| p.ends_with(needle)), + PathSet::Suite(_) => false + } } fn path(&self, builder: &Builder) -> PathBuf { - self.set.iter().next().unwrap_or(&builder.build.src).to_path_buf() + match self { + PathSet::Set(set) => set.iter().next().unwrap_or(&builder.build.src).to_path_buf(), + PathSet::Suite(path) => PathBuf::from(path) + } } } @@ -203,7 +210,10 @@ impl StepDescription { for path in paths { let mut attempted_run = false; for (desc, should_run) in v.iter().zip(&should_runs) { - if let Some(pathset) = should_run.pathset_for_path(path) { + if let Some(suite) = should_run.is_suite_path(path) { + attempted_run = true; + desc.maybe_run(builder, suite); + } else if let Some(pathset) = should_run.pathset_for_path(path) { attempted_run = true; desc.maybe_run(builder, pathset); } @@ -250,7 +260,7 @@ impl<'a> ShouldRun<'a> { for krate in self.builder.in_tree_crates(name) { set.insert(PathBuf::from(&krate.path)); } - self.paths.insert(PathSet { set }); + self.paths.insert(PathSet::Set(set)); self } @@ -268,9 +278,21 @@ impl<'a> ShouldRun<'a> { // multiple aliases for the same job pub fn paths(mut self, paths: &[&str]) -> Self { - self.paths.insert(PathSet { - set: paths.iter().map(PathBuf::from).collect(), - }); + self.paths.insert(PathSet::Set(paths.iter().map(PathBuf::from).collect())); + self + } + + pub fn is_suite_path(&self, path: &Path) -> Option<&PathSet> { + self.paths.iter().find(|pathset| { + match pathset { + PathSet::Suite(p) => path.starts_with(p), + PathSet::Set(_) => false + } + }) + } + + pub fn suite_path(mut self, suite: &str) -> Self { + self.paths.insert(PathSet::Suite(PathBuf::from(suite))); self } @@ -372,8 +394,10 @@ impl<'a> Builder<'a> { } let mut help = String::from("Available paths:\n"); for pathset in should_run.paths { - for path in pathset.set { - help.push_str(format!(" ./x.py {} {}\n", subcommand, path.display()).as_str()); + if let PathSet::Set(set) = pathset{ + set.iter().for_each(|path| help.push_str( + format!(" ./x.py {} {}\n", subcommand, path.display()).as_str() + )) } } Some(help) @@ -404,6 +428,7 @@ impl<'a> Builder<'a> { parent: Cell::new(None), }; + if kind == Kind::Dist { assert!(!builder.config.test_miri, "Do not distribute with miri enabled.\n\ The distributed libraries would include all MIR (increasing binary size). diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 08bbd68c756b4..efb92be60e66b 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -34,6 +34,7 @@ use tool::{self, Tool}; use util::{self, dylib_path, dylib_path_var}; use Mode; use toolstate::ToolState; +use flags::Subcommand; const ADB_TEST_DIR: &str = "/data/tmp/work"; @@ -556,6 +557,7 @@ impl Step for RustdocUi { target: self.target, mode: "ui", suite: "rustdoc-ui", + path: None, compare_mode: None, }) } @@ -660,7 +662,7 @@ macro_rules! test_definitions { const ONLY_HOSTS: bool = $host; fn should_run(run: ShouldRun) -> ShouldRun { - run.path($path) + run.suite_path($path) } fn make_run(run: RunConfig) { @@ -678,6 +680,7 @@ macro_rules! test_definitions { target: self.target, mode: $mode, suite: $suite, + path: Some($path), compare_mode: $compare_mode, }) } @@ -850,6 +853,7 @@ struct Compiletest { target: Interned, mode: &'static str, suite: &'static str, + path: Option<&'static str>, compare_mode: Option<&'static str>, } @@ -872,6 +876,9 @@ impl Step for Compiletest { let suite = self.suite; let compare_mode = self.compare_mode; + // Path for test suite + let suite_path = self.path.unwrap_or(""); + // Skip codegen tests if they aren't enabled in configuration. if !builder.config.codegen_tests && suite == "codegen" { return; @@ -994,7 +1001,23 @@ impl Step for Compiletest { cmd.arg("--lldb-python-dir").arg(dir); } - cmd.args(&builder.config.cmd.test_args()); + // Get paths from cmd args + let paths = match &builder.config.cmd { + Subcommand::Test { ref paths, ..} => &paths[..], + _ => &[] + }; + + // Get test-args by striping suite path + let assert_file = |p: &PathBuf| { + assert!(p.is_file(), "Expected {:?} to be a path to a test file", p); + return true + }; + let mut test_args: Vec<&str> = paths.iter().filter(|p| p.starts_with(suite_path) && + assert_file(p)).map(|p| p.strip_prefix(suite_path).unwrap().to_str().unwrap()).collect(); + + test_args.append(&mut builder.config.cmd.test_args()); + + cmd.args(&test_args); if builder.is_verbose() { cmd.arg("--verbose"); From 2f8c2a93bf5277774d93f690d1b03fe3e1a7b43f Mon Sep 17 00:00:00 2001 From: Collins Abitekaniza Date: Tue, 8 May 2018 15:23:32 +0300 Subject: [PATCH 2/2] ignore test-args if user specifies suite_path --- src/bootstrap/test.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index efb92be60e66b..1b07b4b96da3d 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1008,12 +1008,8 @@ impl Step for Compiletest { }; // Get test-args by striping suite path - let assert_file = |p: &PathBuf| { - assert!(p.is_file(), "Expected {:?} to be a path to a test file", p); - return true - }; let mut test_args: Vec<&str> = paths.iter().filter(|p| p.starts_with(suite_path) && - assert_file(p)).map(|p| p.strip_prefix(suite_path).unwrap().to_str().unwrap()).collect(); + p.is_file()).map(|p| p.strip_prefix(suite_path).unwrap().to_str().unwrap()).collect(); test_args.append(&mut builder.config.cmd.test_args());