Skip to content

Commit

Permalink
Added ./x.py test --no-doc option.
Browse files Browse the repository at this point in the history
This enables `./x.py test --stage 0 src/libstd --no-doc` and ensures the
stage2-rustc and rustdoc need to be built.
  • Loading branch information
kennytm committed May 5, 2018
1 parent fa30ae5 commit 1733f5e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use compile;
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;
Expand Down Expand Up @@ -591,6 +591,8 @@ impl<'a> Builder<'a> {
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.
Expand All @@ -607,7 +609,7 @@ impl<'a> Builder<'a> {
.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")
Expand All @@ -624,7 +626,7 @@ impl<'a> Builder<'a> {
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)));
}

Expand Down
19 changes: 13 additions & 6 deletions src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::process;

use getopts::Options;

use Build;
use {Build, DocTestsOption};
use config::Config;
use metadata;
use builder::Builder;
Expand Down Expand Up @@ -62,7 +62,7 @@ pub enum Subcommand {
test_args: Vec<String>,
rustc_args: Vec<String>,
fail_fast: bool,
doc_tests: bool,
doc_tests: DocTestsOption,
},
Bench {
paths: Vec<PathBuf>,
Expand Down Expand Up @@ -171,7 +171,8 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
"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"); },
Expand Down Expand Up @@ -324,7 +325,13 @@ Arguments:
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" => {
Expand Down Expand Up @@ -411,10 +418,10 @@ impl Subcommand {
}
}

pub fn doc_tests(&self) -> bool {
pub fn doc_tests(&self) -> DocTestsOption {
match *self {
Subcommand::Test { doc_tests, .. } => doc_tests,
_ => false,
_ => DocTestsOption::Yes,
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ pub struct Compiler {
host: Interned<String>,
}

#[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.
Expand All @@ -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.
Expand Down
12 changes: 9 additions & 3 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use dist;
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";
Expand Down Expand Up @@ -1519,8 +1519,14 @@ impl Step for Crate {
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);
Expand Down

0 comments on commit 1733f5e

Please sign in to comment.