diff options
| author | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2016-11-25 22:13:59 +0100 |
|---|---|---|
| committer | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2016-11-25 22:15:52 +0100 |
| commit | b1566baa0bb1a410af22bd47adf9d40de25bd402 (patch) | |
| tree | e87b28ac1c6acefb5c11241a8304864fb0c3e3fe /src/bootstrap | |
| parent | 127a83df6615d09cda6ed9b53f7daba2d78c925d (diff) | |
rustbuild: Add bench subcommand
Add command `./x.py bench`; use `./x.py bench --help -v` to list all available benchmark targets.
Diffstat (limited to 'src/bootstrap')
| -rw-r--r-- | src/bootstrap/check.rs | 34 | ||||
| -rw-r--r-- | src/bootstrap/flags.rs | 17 | ||||
| -rw-r--r-- | src/bootstrap/lib.rs | 4 | ||||
| -rw-r--r-- | src/bootstrap/metadata.rs | 1 | ||||
| -rw-r--r-- | src/bootstrap/step.rs | 46 |
5 files changed, 88 insertions, 14 deletions
diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index ac6be2a870b..150232e4ab4 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -15,6 +15,7 @@ use std::collections::HashSet; use std::env; +use std::fmt; use std::fs; use std::path::{PathBuf, Path}; use std::process::Command; @@ -26,6 +27,34 @@ use util::{self, dylib_path, dylib_path_var}; const ADB_TEST_DIR: &'static str = "/data/tmp"; +/// The two modes of the test runner; tests or benchmarks. +#[derive(Copy, Clone)] +pub enum TestKind { + /// Run `cargo test` + Test, + /// Run `cargo bench` + Bench, +} + +impl TestKind { + // Return the cargo subcommand for this test kind + fn subcommand(self) -> &'static str { + match self { + TestKind::Test => "test", + TestKind::Bench => "bench", + } + } +} + +impl fmt::Display for TestKind { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str(match *self { + TestKind::Test => "Testing", + TestKind::Bench => "Benchmarking", + }) + } +} + /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler. /// /// This tool in `src/tools` will verify the validity of all our links in the @@ -278,6 +307,7 @@ pub fn krate(build: &Build, compiler: &Compiler, target: &str, mode: Mode, + test_kind: TestKind, krate: Option<&str>) { let (name, path, features, root) = match mode { Mode::Libstd => { @@ -291,7 +321,7 @@ pub fn krate(build: &Build, } _ => panic!("can only test libraries"), }; - println!("Testing {} stage{} ({} -> {})", name, compiler.stage, + println!("{} {} stage{} ({} -> {})", test_kind, name, compiler.stage, compiler.host, target); // Build up the base `cargo test` command. @@ -299,7 +329,7 @@ pub fn krate(build: &Build, // Pass in some standard flags then iterate over the graph we've discovered // in `cargo metadata` with the maps above and figure out what `-p` // arguments need to get passed. - let mut cargo = build.cargo(compiler, mode, target, "test"); + let mut cargo = build.cargo(compiler, mode, target, test_kind.subcommand()); cargo.arg("--manifest-path") .arg(build.src.join(path).join("Cargo.toml")) .arg("--features").arg(features); diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index d7516954f12..a7d80e4cdc4 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -49,6 +49,10 @@ pub enum Subcommand { paths: Vec<PathBuf>, test_args: Vec<String>, }, + Bench { + paths: Vec<PathBuf>, + test_args: Vec<String>, + }, Clean, Dist { install: bool, @@ -141,6 +145,7 @@ Arguments: command == "dist" || command == "doc" || command == "test" || + command == "bench" || command == "clean" { println!("Available invocations:"); if args.iter().any(|a| a == "-v") { @@ -163,6 +168,7 @@ println!("\ Subcommands: build Compile either the compiler or libraries test Build and run some test suites + bench Build and run some benchmarks doc Build documentation clean Clean out build directories dist Build and/or install distribution artifacts @@ -210,6 +216,14 @@ To learn more about a subcommand, run `./x.py <command> -h` test_args: m.opt_strs("test-args"), } } + "bench" => { + opts.optmulti("", "test-args", "extra arguments", "ARGS"); + m = parse(&opts); + Subcommand::Bench { + paths: remaining_as_path(&m), + test_args: m.opt_strs("test-args"), + } + } "clean" => { m = parse(&opts); if m.free.len() > 0 { @@ -259,7 +273,8 @@ To learn more about a subcommand, run `./x.py <command> -h` impl Subcommand { pub fn test_args(&self) -> Vec<&str> { match *self { - Subcommand::Test { ref test_args, .. } => { + Subcommand::Test { ref test_args, .. } | + Subcommand::Bench { ref test_args, .. } => { test_args.iter().flat_map(|s| s.split_whitespace()).collect() } _ => Vec::new(), diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 828e82d3832..518eafb6f36 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -141,6 +141,7 @@ struct Crate { doc_step: String, build_step: String, test_step: String, + bench_step: String, } /// The various "modes" of invoking Cargo. @@ -457,7 +458,8 @@ impl Build { if self.config.verbose || self.flags.verbose { cargo.arg("-v"); } - if self.config.rust_optimize { + // FIXME: cargo bench does not accept `--release` + if self.config.rust_optimize && cmd != "bench" { cargo.arg("--release"); } if self.config.vendor { diff --git a/src/bootstrap/metadata.rs b/src/bootstrap/metadata.rs index bf5cc6a4ad8..8befb105ff6 100644 --- a/src/bootstrap/metadata.rs +++ b/src/bootstrap/metadata.rs @@ -70,6 +70,7 @@ fn build_krate(build: &mut Build, krate: &str) { build_step: format!("build-crate-{}", package.name), doc_step: format!("doc-crate-{}", package.name), test_step: format!("test-crate-{}", package.name), + bench_step: format!("bench-crate-{}", package.name), name: package.name, deps: Vec::new(), path: path, diff --git a/src/bootstrap/step.rs b/src/bootstrap/step.rs index 56be2ccb235..4c1f58e52d9 100644 --- a/src/bootstrap/step.rs +++ b/src/bootstrap/step.rs @@ -11,7 +11,7 @@ use std::collections::{HashMap, HashSet}; use std::mem; -use check; +use check::{self, TestKind}; use compile; use dist; use doc; @@ -268,37 +268,55 @@ pub fn build_rules(build: &Build) -> Rules { rules.test(&krate.test_step, path) .dep(|s| s.name("libtest")) .run(move |s| check::krate(build, &s.compiler(), s.target, - Mode::Libstd, Some(&krate.name))); + Mode::Libstd, TestKind::Test, + Some(&krate.name))); } rules.test("check-std-all", "path/to/nowhere") .dep(|s| s.name("libtest")) .default(true) - .run(move |s| check::krate(build, &s.compiler(), s.target, Mode::Libstd, - None)); + .run(move |s| check::krate(build, &s.compiler(), s.target, + Mode::Libstd, TestKind::Test, None)); + + // std benchmarks + for (krate, path, _default) in krates("std_shim") { + rules.bench(&krate.bench_step, path) + .dep(|s| s.name("libtest")) + .run(move |s| check::krate(build, &s.compiler(), s.target, + Mode::Libstd, TestKind::Bench, + Some(&krate.name))); + } + rules.bench("bench-std-all", "path/to/nowhere") + .dep(|s| s.name("libtest")) + .default(true) + .run(move |s| check::krate(build, &s.compiler(), s.target, + Mode::Libstd, TestKind::Bench, None)); + for (krate, path, _default) in krates("test_shim") { rules.test(&krate.test_step, path) .dep(|s| s.name("libtest")) .run(move |s| check::krate(build, &s.compiler(), s.target, - Mode::Libtest, Some(&krate.name))); + Mode::Libtest, TestKind::Test, + Some(&krate.name))); } rules.test("check-test-all", "path/to/nowhere") .dep(|s| s.name("libtest")) .default(true) - .run(move |s| check::krate(build, &s.compiler(), s.target, Mode::Libtest, - None)); + .run(move |s| check::krate(build, &s.compiler(), s.target, + Mode::Libtest, TestKind::Test, None)); for (krate, path, _default) in krates("rustc-main") { rules.test(&krate.test_step, path) .dep(|s| s.name("librustc")) .host(true) .run(move |s| check::krate(build, &s.compiler(), s.target, - Mode::Librustc, Some(&krate.name))); + Mode::Librustc, TestKind::Test, + Some(&krate.name))); } rules.test("check-rustc-all", "path/to/nowhere") .dep(|s| s.name("librustc")) .default(true) .host(true) - .run(move |s| check::krate(build, &s.compiler(), s.target, Mode::Librustc, - None)); + .run(move |s| check::krate(build, &s.compiler(), s.target, + Mode::Librustc, TestKind::Test, None)); rules.test("check-linkchecker", "src/tools/linkchecker") .dep(|s| s.name("tool-linkchecker")) @@ -449,6 +467,7 @@ struct Rule<'a> { enum Kind { Build, Test, + Bench, Dist, Doc, } @@ -538,6 +557,11 @@ impl<'a> Rules<'a> { self.rule(name, path, Kind::Test) } + fn bench<'b>(&'b mut self, name: &'a str, path: &'a str) + -> RuleBuilder<'a, 'b> { + self.rule(name, path, Kind::Bench) + } + fn doc<'b>(&'b mut self, name: &'a str, path: &'a str) -> RuleBuilder<'a, 'b> { self.rule(name, path, Kind::Doc) @@ -583,6 +607,7 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd? "build" => Kind::Build, "doc" => Kind::Doc, "test" => Kind::Test, + "bench" => Kind::Bench, "dist" => Kind::Dist, _ => return, }; @@ -606,6 +631,7 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd? Subcommand::Build { ref paths } => (Kind::Build, &paths[..]), Subcommand::Doc { ref paths } => (Kind::Doc, &paths[..]), Subcommand::Test { ref paths, test_args: _ } => (Kind::Test, &paths[..]), + Subcommand::Bench { ref paths, test_args: _ } => (Kind::Bench, &paths[..]), Subcommand::Dist { install } => { if install { return vec![self.sbuild.name("install")] |
