From: kennytm Date: Sat, 5 May 2018 16:04:06 +0000 (+0800) Subject: Added `./x.py test --no-doc` option. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=1733f5e1c0a69c853adebf718fc7b4f81a1d257b;p=rust.git Added `./x.py test --no-doc` option. This enables `./x.py test --stage 0 src/libstd --no-doc` and ensures the stage2-rustc and rustdoc need to be built. --- diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 08bb8ab4815..408e61ef548 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -25,7 +25,7 @@ use install; use dist; use util::{exe, libdir, add_lib_path}; -use {Build, Mode}; +use {Build, Mode, DocTestsOption}; use cache::{INTERNER, Interned, Cache}; use check; use test; @@ -591,6 +591,8 @@ pub fn cargo(&self, format!("{} {}", env::var("RUSTFLAGS").unwrap_or_default(), extra_args)); } + let want_rustdoc = self.doc_tests != DocTestsOption::No; + // Customize the compiler we're running. Specify the compiler to cargo // as our shim and then pass it some various options used to configure // how the actual compiler itself is called. @@ -607,7 +609,7 @@ pub fn cargo(&self, .env("RUSTC_LIBDIR", self.rustc_libdir(compiler)) .env("RUSTC_RPATH", self.config.rust_rpath.to_string()) .env("RUSTDOC", self.out.join("bootstrap/debug/rustdoc")) - .env("RUSTDOC_REAL", if cmd == "doc" || cmd == "test" { + .env("RUSTDOC_REAL", if cmd == "doc" || (cmd == "test" && want_rustdoc) { self.rustdoc(compiler.host) } else { PathBuf::from("/path/to/nowhere/rustdoc/not/required") @@ -624,7 +626,7 @@ pub fn cargo(&self, if let Some(ref error_format) = self.config.rustc_error_format { cargo.env("RUSTC_ERROR_FORMAT", error_format); } - if cmd != "build" && cmd != "check" { + if cmd != "build" && cmd != "check" && want_rustdoc { cargo.env("RUSTDOC_LIBDIR", self.rustc_libdir(self.compiler(2, self.config.build))); } diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index 3eb9dca2aa8..fb7c8ba1351 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -19,7 +19,7 @@ use getopts::Options; -use Build; +use {Build, DocTestsOption}; use config::Config; use metadata; use builder::Builder; @@ -62,7 +62,7 @@ pub enum Subcommand { test_args: Vec, rustc_args: Vec, fail_fast: bool, - doc_tests: bool, + doc_tests: DocTestsOption, }, Bench { paths: Vec, @@ -171,7 +171,8 @@ pub fn parse(args: &[String]) -> Flags { "extra options to pass the compiler when running tests", "ARGS", ); - opts.optflag("", "doc", "run doc tests"); + opts.optflag("", "no-doc", "do not run doc tests"); + opts.optflag("", "doc", "only run doc tests"); }, "bench" => { opts.optmulti("", "test-args", "extra arguments", "ARGS"); }, "clean" => { opts.optflag("", "all", "clean all build artifacts"); }, @@ -324,7 +325,13 @@ pub fn parse(args: &[String]) -> Flags { test_args: matches.opt_strs("test-args"), rustc_args: matches.opt_strs("rustc-args"), fail_fast: !matches.opt_present("no-fail-fast"), - doc_tests: matches.opt_present("doc"), + doc_tests: if matches.opt_present("doc") { + DocTestsOption::Only + } else if matches.opt_present("no-doc") { + DocTestsOption::No + } else { + DocTestsOption::Yes + } } } "bench" => { @@ -411,10 +418,10 @@ pub fn fail_fast(&self) -> bool { } } - pub fn doc_tests(&self) -> bool { + pub fn doc_tests(&self) -> DocTestsOption { match *self { Subcommand::Test { doc_tests, .. } => doc_tests, - _ => false, + _ => DocTestsOption::Yes, } } } diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 0a7f0e5ff4e..624319485be 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -210,6 +210,16 @@ pub struct Compiler { host: Interned, } +#[derive(PartialEq, Eq, Copy, Clone, Debug)] +pub enum DocTestsOption { + // Default, run normal tests and doc tests. + Yes, + // Do not run any doc tests. + No, + // Only run doc tests. + Only, +} + /// Global configuration for the build system. /// /// This structure transitively contains all configuration for the build system. @@ -233,7 +243,7 @@ pub struct Build { rustfmt_info: channel::GitInfo, local_rebuild: bool, fail_fast: bool, - doc_tests: bool, + doc_tests: DocTestsOption, verbosity: usize, // Targets for which to build. diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index e8c40dfdb0a..0d430c30036 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -32,7 +32,7 @@ use native; use tool::{self, Tool}; use util::{self, dylib_path, dylib_path_var}; -use Mode; +use {Mode, DocTestsOption}; use toolstate::ToolState; const ADB_TEST_DIR: &str = "/data/tmp/work"; @@ -1519,8 +1519,14 @@ fn run(self, builder: &Builder) { if test_kind.subcommand() == "test" && !builder.fail_fast { cargo.arg("--no-fail-fast"); } - if builder.doc_tests { - cargo.arg("--doc"); + match builder.doc_tests { + DocTestsOption::Only => { + cargo.arg("--doc"); + } + DocTestsOption::No => { + cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]); + } + DocTestsOption::Yes => {} } cargo.arg("-p").arg(krate);