Run rustfmt

This commit is contained in:
Santiago Pastorino
2018-05-30 14:33:43 -03:00
parent b970feedc2
commit b39a1d6f1a
4 changed files with 1205 additions and 782 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -19,10 +19,10 @@ use std::process;
use getopts::Options; use getopts::Options;
use {Build, DocTests}; use builder::Builder;
use config::Config; use config::Config;
use metadata; use metadata;
use builder::Builder; use {Build, DocTests};
use cache::{Interned, INTERNER}; use cache::{Interned, INTERNER};
@@ -93,7 +93,8 @@ impl Default for Subcommand {
impl Flags { impl Flags {
pub fn parse(args: &[String]) -> Flags { pub fn parse(args: &[String]) -> Flags {
let mut extra_help = String::new(); let mut extra_help = String::new();
let mut subcommand_help = format!("\ let mut subcommand_help = format!(
"\
Usage: x.py <subcommand> [options] [<paths>...] Usage: x.py <subcommand> [options] [<paths>...]
Subcommands: Subcommands:
@@ -106,7 +107,8 @@ Subcommands:
dist Build distribution artifacts dist Build distribution artifacts
install Install distribution artifacts install Install distribution artifacts
To learn more about a subcommand, run `./x.py <subcommand> -h`"); To learn more about a subcommand, run `./x.py <subcommand> -h`"
);
let mut opts = Options::new(); let mut opts = Options::new();
// Options common to all subcommands // Options common to all subcommands
@@ -124,12 +126,17 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
opts.optopt("", "src", "path to the root of the rust checkout", "DIR"); opts.optopt("", "src", "path to the root of the rust checkout", "DIR");
opts.optopt("j", "jobs", "number of jobs to run in parallel", "JOBS"); opts.optopt("j", "jobs", "number of jobs to run in parallel", "JOBS");
opts.optflag("h", "help", "print this help message"); opts.optflag("h", "help", "print this help message");
opts.optopt("", "warnings", "if value is deny, will deny warnings, otherwise use default", opts.optopt(
"VALUE"); "",
"warnings",
"if value is deny, will deny warnings, otherwise use default",
"VALUE",
);
opts.optopt("", "error-format", "rustc error format", "FORMAT"); opts.optopt("", "error-format", "rustc error format", "FORMAT");
// fn usage() // fn usage()
let usage = |exit_code: i32, opts: &Options, subcommand_help: &str, extra_help: &str| -> ! { let usage =
|exit_code: i32, opts: &Options, subcommand_help: &str, extra_help: &str| -> ! {
println!("{}", opts.usage(subcommand_help)); println!("{}", opts.usage(subcommand_help));
if !extra_help.is_empty() { if !extra_help.is_empty() {
println!("{}", extra_help); println!("{}", extra_help);
@@ -142,7 +149,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
// the subcommand. Therefore we must manually identify the subcommand first, so that we can // the subcommand. Therefore we must manually identify the subcommand first, so that we can
// complete the definition of the options. Then we can use the getopt::Matches object from // complete the definition of the options. Then we can use the getopt::Matches object from
// there on out. // there on out.
let subcommand = args.iter().find(|&s| let subcommand = args.iter().find(|&s| {
(s == "build") (s == "build")
|| (s == "check") || (s == "check")
|| (s == "test") || (s == "test")
@@ -150,7 +157,8 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
|| (s == "doc") || (s == "doc")
|| (s == "clean") || (s == "clean")
|| (s == "dist") || (s == "dist")
|| (s == "install")); || (s == "install")
});
let subcommand = match subcommand { let subcommand = match subcommand {
Some(s) => s, Some(s) => s,
None => { None => {
@@ -176,12 +184,25 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
); );
opts.optflag("", "no-doc", "do not run doc tests"); opts.optflag("", "no-doc", "do not run doc tests");
opts.optflag("", "doc", "only run doc tests"); opts.optflag("", "doc", "only run doc tests");
opts.optflag("", "bless", "update all stderr/stdout files of failing ui tests"); opts.optflag(
opts.optopt("", "compare-mode", "mode describing what file the actual ui output will be compared to", "COMPARE MODE"); "",
}, "bless",
"bench" => { opts.optmulti("", "test-args", "extra arguments", "ARGS"); }, "update all stderr/stdout files of failing ui tests",
"clean" => { opts.optflag("", "all", "clean all build artifacts"); }, );
_ => { }, opts.optopt(
"",
"compare-mode",
"mode describing what file the actual ui output will be compared to",
"COMPARE MODE",
);
}
"bench" => {
opts.optmulti("", "test-args", "extra arguments", "ARGS");
}
"clean" => {
opts.optflag("", "all", "clean all build artifacts");
}
_ => {}
}; };
// Done specifying what options are possible, so do the getopts parsing // Done specifying what options are possible, so do the getopts parsing
@@ -201,21 +222,24 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
if check_subcommand != subcommand { if check_subcommand != subcommand {
pass_sanity_check = false; pass_sanity_check = false;
} }
}, }
None => { None => {
pass_sanity_check = false; pass_sanity_check = false;
} }
} }
if !pass_sanity_check { if !pass_sanity_check {
println!("{}\n", subcommand_help); println!("{}\n", subcommand_help);
println!("Sorry, I couldn't figure out which subcommand you were trying to specify.\n\ println!(
You may need to move some options to after the subcommand.\n"); "Sorry, I couldn't figure out which subcommand you were trying to specify.\n\
You may need to move some options to after the subcommand.\n"
);
process::exit(1); process::exit(1);
} }
// Extra help text for some commands // Extra help text for some commands
match subcommand.as_str() { match subcommand.as_str() {
"build" => { "build" => {
subcommand_help.push_str("\n subcommand_help.push_str(
"\n
Arguments: Arguments:
This subcommand accepts a number of paths to directories to the crates This subcommand accepts a number of paths to directories to the crates
and/or artifacts to compile. For example: and/or artifacts to compile. For example:
@@ -237,10 +261,12 @@ Arguments:
This will first build everything once (like --stage 0 without further This will first build everything once (like --stage 0 without further
arguments would), and then use the compiler built in stage 0 to build arguments would), and then use the compiler built in stage 0 to build
src/libtest and its dependencies. src/libtest and its dependencies.
Once this is done, build/$ARCH/stage1 contains a usable compiler."); Once this is done, build/$ARCH/stage1 contains a usable compiler.",
);
} }
"check" => { "check" => {
subcommand_help.push_str("\n subcommand_help.push_str(
"\n
Arguments: Arguments:
This subcommand accepts a number of paths to directories to the crates This subcommand accepts a number of paths to directories to the crates
and/or artifacts to compile. For example: and/or artifacts to compile. For example:
@@ -252,10 +278,12 @@ Arguments:
also that since we use `cargo check`, by default this will automatically enable incremental also that since we use `cargo check`, by default this will automatically enable incremental
compilation, so there's no need to pass it separately, though it won't hurt. We also completely compilation, so there's no need to pass it separately, though it won't hurt. We also completely
ignore the stage passed, as there's no way to compile in non-stage 0 without actually building ignore the stage passed, as there's no way to compile in non-stage 0 without actually building
the compiler."); the compiler.",
);
} }
"test" => { "test" => {
subcommand_help.push_str("\n subcommand_help.push_str(
"\n
Arguments: Arguments:
This subcommand accepts a number of paths to directories to tests that This subcommand accepts a number of paths to directories to tests that
should be compiled and run. For example: should be compiled and run. For example:
@@ -270,10 +298,12 @@ Arguments:
compiled and tested. compiled and tested.
./x.py test ./x.py test
./x.py test --stage 1"); ./x.py test --stage 1",
);
} }
"doc" => { "doc" => {
subcommand_help.push_str("\n subcommand_help.push_str(
"\n
Arguments: Arguments:
This subcommand accepts a number of paths to directories of documentation This subcommand accepts a number of paths to directories of documentation
to build. For example: to build. For example:
@@ -285,12 +315,16 @@ Arguments:
If no arguments are passed then everything is documented: If no arguments are passed then everything is documented:
./x.py doc ./x.py doc
./x.py doc --stage 1"); ./x.py doc --stage 1",
);
} }
_ => {} _ => {}
}; };
// Get any optional paths which occur after the subcommand // Get any optional paths which occur after the subcommand
let paths = matches.free[1..].iter().map(|p| p.into()).collect::<Vec<PathBuf>>(); let paths = matches.free[1..]
.iter()
.map(|p| p.into())
.collect::<Vec<PathBuf>>();
let cfg_file = matches.opt_str("config").map(PathBuf::from).or_else(|| { let cfg_file = matches.opt_str("config").map(PathBuf::from).or_else(|| {
if fs::metadata("config.toml").is_ok() { if fs::metadata("config.toml").is_ok() {
@@ -309,9 +343,12 @@ Arguments:
let maybe_rules_help = Builder::get_help(&build, subcommand.as_str()); let maybe_rules_help = Builder::get_help(&build, subcommand.as_str());
extra_help.push_str(maybe_rules_help.unwrap_or_default().as_str()); extra_help.push_str(maybe_rules_help.unwrap_or_default().as_str());
} else if subcommand.as_str() != "clean" { } else if subcommand.as_str() != "clean" {
extra_help.push_str(format!( extra_help.push_str(
format!(
"Run `./x.py {} -h -v` to see a list of available paths.", "Run `./x.py {} -h -v` to see a list of available paths.",
subcommand).as_str()); subcommand
).as_str(),
);
} }
// User passed in -h/--help? // User passed in -h/--help?
@@ -320,14 +357,9 @@ Arguments:
} }
let cmd = match subcommand.as_str() { let cmd = match subcommand.as_str() {
"build" => { "build" => Subcommand::Build { paths: paths },
Subcommand::Build { paths: paths } "check" => Subcommand::Check { paths: paths },
} "test" => Subcommand::Test {
"check" => {
Subcommand::Check { paths: paths }
}
"test" => {
Subcommand::Test {
paths, paths,
bless: matches.opt_present("bless"), bless: matches.opt_present("bless"),
compare_mode: matches.opt_str("compare-mode"), compare_mode: matches.opt_str("compare-mode"),
@@ -340,18 +372,13 @@ Arguments:
DocTests::No DocTests::No
} else { } else {
DocTests::Yes DocTests::Yes
} },
} },
} "bench" => Subcommand::Bench {
"bench" => {
Subcommand::Bench {
paths, paths,
test_args: matches.opt_strs("test-args"), test_args: matches.opt_strs("test-args"),
} },
} "doc" => Subcommand::Doc { paths: paths },
"doc" => {
Subcommand::Doc { paths: paths }
}
"clean" => { "clean" => {
if paths.len() > 0 { if paths.len() > 0 {
println!("\nclean does not take a path argument\n"); println!("\nclean does not take a path argument\n");
@@ -362,22 +389,13 @@ Arguments:
all: matches.opt_present("all"), all: matches.opt_present("all"),
} }
} }
"dist" => { "dist" => Subcommand::Dist { paths },
Subcommand::Dist { "install" => Subcommand::Install { paths },
paths,
}
}
"install" => {
Subcommand::Install {
paths,
}
}
_ => { _ => {
usage(1, &opts, &subcommand_help, &extra_help); usage(1, &opts, &subcommand_help, &extra_help);
} }
}; };
Flags { Flags {
verbose: matches.opt_count("verbose"), verbose: matches.opt_count("verbose"),
stage: matches.opt_str("stage").map(|j| j.parse().unwrap()), stage: matches.opt_str("stage").map(|j| j.parse().unwrap()),
@@ -386,15 +404,21 @@ Arguments:
rustc_error_format: matches.opt_str("error-format"), rustc_error_format: matches.opt_str("error-format"),
keep_stage: matches.opt_str("keep-stage").map(|j| j.parse().unwrap()), keep_stage: matches.opt_str("keep-stage").map(|j| j.parse().unwrap()),
host: split(matches.opt_strs("host")) host: split(matches.opt_strs("host"))
.into_iter().map(|x| INTERNER.intern_string(x)).collect::<Vec<_>>(), .into_iter()
.map(|x| INTERNER.intern_string(x))
.collect::<Vec<_>>(),
target: split(matches.opt_strs("target")) target: split(matches.opt_strs("target"))
.into_iter().map(|x| INTERNER.intern_string(x)).collect::<Vec<_>>(), .into_iter()
.map(|x| INTERNER.intern_string(x))
.collect::<Vec<_>>(),
config: cfg_file, config: cfg_file,
jobs: matches.opt_str("jobs").map(|j| j.parse().unwrap()), jobs: matches.opt_str("jobs").map(|j| j.parse().unwrap()),
cmd, cmd,
incremental: matches.opt_present("incremental"), incremental: matches.opt_present("incremental"),
exclude: split(matches.opt_strs("exclude")) exclude: split(matches.opt_strs("exclude"))
.into_iter().map(|p| p.into()).collect::<Vec<_>>(), .into_iter()
.map(|p| p.into())
.collect::<Vec<_>>(),
warnings: matches.opt_str("warnings").map(|v| v == "deny"), warnings: matches.opt_str("warnings").map(|v| v == "deny"),
} }
} }
@@ -403,9 +427,11 @@ Arguments:
impl Subcommand { impl Subcommand {
pub fn test_args(&self) -> Vec<&str> { pub fn test_args(&self) -> Vec<&str> {
match *self { match *self {
Subcommand::Test { ref test_args, .. } | Subcommand::Test { ref test_args, .. } | Subcommand::Bench { ref test_args, .. } => {
Subcommand::Bench { ref test_args, .. } => { test_args
test_args.iter().flat_map(|s| s.split_whitespace()).collect() .iter()
.flat_map(|s| s.split_whitespace())
.collect()
} }
_ => Vec::new(), _ => Vec::new(),
} }
@@ -413,9 +439,10 @@ impl Subcommand {
pub fn rustc_args(&self) -> Vec<&str> { pub fn rustc_args(&self) -> Vec<&str> {
match *self { match *self {
Subcommand::Test { ref rustc_args, .. } => { Subcommand::Test { ref rustc_args, .. } => rustc_args
rustc_args.iter().flat_map(|s| s.split_whitespace()).collect() .iter()
} .flat_map(|s| s.split_whitespace())
.collect(),
_ => Vec::new(), _ => Vec::new(),
} }
} }
@@ -443,12 +470,17 @@ impl Subcommand {
pub fn compare_mode(&self) -> Option<&str> { pub fn compare_mode(&self) -> Option<&str> {
match *self { match *self {
Subcommand::Test { ref compare_mode, .. } => compare_mode.as_ref().map(|s| &s[..]), Subcommand::Test {
ref compare_mode, ..
} => compare_mode.as_ref().map(|s| &s[..]),
_ => None, _ => None,
} }
} }
} }
fn split(s: Vec<String>) -> Vec<String> { fn split(s: Vec<String>) -> Vec<String> {
s.iter().flat_map(|s| s.split(',')).map(|s| s.to_string()).collect() s.iter()
.flat_map(|s| s.split(','))
.map(|s| s.to_string())
.collect()
} }

View File

@@ -15,26 +15,26 @@
use std::env; use std::env;
use std::ffi::OsString; use std::ffi::OsString;
use std::iter;
use std::fmt; use std::fmt;
use std::fs::{self, File}; use std::fs::{self, File};
use std::path::{PathBuf, Path};
use std::process::Command;
use std::io::Read; use std::io::Read;
use std::iter;
use std::path::{Path, PathBuf};
use std::process::Command;
use build_helper::{self, output}; use build_helper::{self, output};
use builder::{Kind, RunConfig, ShouldRun, Builder, Compiler, Step}; use builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
use Crate as CargoCrate; use cache::{Interned, INTERNER};
use cache::{INTERNER, Interned};
use compile; use compile;
use dist; use dist;
use flags::Subcommand;
use native; use native;
use tool::{self, Tool}; use tool::{self, Tool};
use util::{self, dylib_path, dylib_path_var};
use {Mode, DocTests};
use toolstate::ToolState; use toolstate::ToolState;
use flags::Subcommand; use util::{self, dylib_path, dylib_path_var};
use Crate as CargoCrate;
use {DocTests, Mode};
const ADB_TEST_DIR: &str = "/data/tmp/work"; const ADB_TEST_DIR: &str = "/data/tmp/work";
@@ -52,7 +52,7 @@ impl From<Kind> for TestKind {
match kind { match kind {
Kind::Test => TestKind::Test, Kind::Test => TestKind::Test,
Kind::Bench => TestKind::Bench, Kind::Bench => TestKind::Bench,
_ => panic!("unexpected kind in crate: {:?}", kind) _ => panic!("unexpected kind in crate: {:?}", kind),
} }
} }
} }
@@ -124,13 +124,18 @@ impl Step for Linkcheck {
builder.default_doc(None); builder.default_doc(None);
let _time = util::timeit(&builder); let _time = util::timeit(&builder);
try_run(builder, builder.tool_cmd(Tool::Linkchecker) try_run(
.arg(builder.out.join(host).join("doc"))); builder,
builder
.tool_cmd(Tool::Linkchecker)
.arg(builder.out.join(host).join("doc")),
);
} }
fn should_run(run: ShouldRun) -> ShouldRun { fn should_run(run: ShouldRun) -> ShouldRun {
let builder = run.builder; let builder = run.builder;
run.path("src/tools/linkchecker").default_condition(builder.config.docs) run.path("src/tools/linkchecker")
.default_condition(builder.config.docs)
} }
fn make_run(run: RunConfig) { fn make_run(run: RunConfig) {
@@ -165,7 +170,10 @@ impl Step for Cargotest {
/// test` to ensure that we don't regress the test suites there. /// test` to ensure that we don't regress the test suites there.
fn run(self, builder: &Builder) { fn run(self, builder: &Builder) {
let compiler = builder.compiler(self.stage, self.host); let compiler = builder.compiler(self.stage, self.host);
builder.ensure(compile::Rustc { compiler, target: compiler.host }); builder.ensure(compile::Rustc {
compiler,
target: compiler.host,
});
// Note that this is a short, cryptic, and not scoped directory name. This // Note that this is a short, cryptic, and not scoped directory name. This
// is currently to minimize the length of path on Windows where we otherwise // is currently to minimize the length of path on Windows where we otherwise
@@ -175,10 +183,13 @@ impl Step for Cargotest {
let _time = util::timeit(&builder); let _time = util::timeit(&builder);
let mut cmd = builder.tool_cmd(Tool::CargoTest); let mut cmd = builder.tool_cmd(Tool::CargoTest);
try_run(builder, cmd.arg(&builder.initial_cargo) try_run(
builder,
cmd.arg(&builder.initial_cargo)
.arg(&out_dir) .arg(&out_dir)
.env("RUSTC", builder.rustc(compiler)) .env("RUSTC", builder.rustc(compiler))
.env("RUSTDOC", builder.rustdoc(compiler.host))); .env("RUSTDOC", builder.rustdoc(compiler.host)),
);
} }
} }
@@ -207,9 +218,14 @@ impl Step for Cargo {
fn run(self, builder: &Builder) { fn run(self, builder: &Builder) {
let compiler = builder.compiler(self.stage, self.host); let compiler = builder.compiler(self.stage, self.host);
builder.ensure(tool::Cargo { compiler, target: self.host }); builder.ensure(tool::Cargo {
compiler,
target: self.host,
});
let mut cargo = builder.cargo(compiler, Mode::Tool, self.host, "test"); let mut cargo = builder.cargo(compiler, Mode::Tool, self.host, "test");
cargo.arg("--manifest-path").arg(builder.src.join("src/tools/cargo/Cargo.toml")); cargo
.arg("--manifest-path")
.arg(builder.src.join("src/tools/cargo/Cargo.toml"));
if !builder.fail_fast { if !builder.fail_fast {
cargo.arg("--no-fail-fast"); cargo.arg("--no-fail-fast");
} }
@@ -221,7 +237,10 @@ impl Step for Cargo {
// available. // available.
cargo.env("CFG_DISABLE_CROSS_TESTS", "1"); cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
try_run(builder, cargo.env("PATH", &path_for_cargo(builder, compiler))); try_run(
builder,
cargo.env("PATH", &path_for_cargo(builder, compiler)),
);
} }
} }
@@ -262,11 +281,7 @@ impl Step for Rls {
return; return;
} }
let mut cargo = tool::prepare_tool_cargo(builder, let mut cargo = tool::prepare_tool_cargo(builder, compiler, host, "test", "src/tools/rls");
compiler,
host,
"test",
"src/tools/rls");
// Don't build tests dynamically, just a pain to work with // Don't build tests dynamically, just a pain to work with
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1"); cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
@@ -316,11 +331,8 @@ impl Step for Rustfmt {
return; return;
} }
let mut cargo = tool::prepare_tool_cargo(builder, let mut cargo =
compiler, tool::prepare_tool_cargo(builder, compiler, host, "test", "src/tools/rustfmt");
host,
"test",
"src/tools/rustfmt");
// Don't build tests dynamically, just a pain to work with // Don't build tests dynamically, just a pain to work with
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1"); cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
@@ -372,7 +384,9 @@ impl Step for Miri {
}); });
if let Some(miri) = miri { if let Some(miri) = miri {
let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test"); let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
cargo.arg("--manifest-path").arg(builder.src.join("src/tools/miri/Cargo.toml")); cargo
.arg("--manifest-path")
.arg(builder.src.join("src/tools/miri/Cargo.toml"));
// Don't build tests dynamically, just a pain to work with // Don't build tests dynamically, just a pain to work with
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1"); cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
@@ -428,7 +442,9 @@ impl Step for Clippy {
}); });
if let Some(clippy) = clippy { if let Some(clippy) = clippy {
let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test"); let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
cargo.arg("--manifest-path").arg(builder.src.join("src/tools/clippy/Cargo.toml")); cargo
.arg("--manifest-path")
.arg(builder.src.join("src/tools/clippy/Cargo.toml"));
// Don't build tests dynamically, just a pain to work with // Don't build tests dynamically, just a pain to work with
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1"); cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
@@ -436,7 +452,9 @@ impl Step for Clippy {
cargo.env("SYSROOT", builder.sysroot(compiler)); cargo.env("SYSROOT", builder.sysroot(compiler));
cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler)); cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler)); cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
let host_libs = builder.stage_out(compiler, Mode::Tool).join(builder.cargo_dir()); let host_libs = builder
.stage_out(compiler, Mode::Tool)
.join(builder.cargo_dir());
cargo.env("HOST_LIBS", host_libs); cargo.env("HOST_LIBS", host_libs);
// clippy tests need to find the driver // clippy tests need to find the driver
cargo.env("CLIPPY_DRIVER_PATH", clippy); cargo.env("CLIPPY_DRIVER_PATH", clippy);
@@ -478,19 +496,26 @@ impl Step for RustdocTheme {
fn make_run(run: RunConfig) { fn make_run(run: RunConfig) {
let compiler = run.builder.compiler(run.builder.top_stage, run.host); let compiler = run.builder.compiler(run.builder.top_stage, run.host);
run.builder.ensure(RustdocTheme { run.builder.ensure(RustdocTheme { compiler: compiler });
compiler: compiler,
});
} }
fn run(self, builder: &Builder) { fn run(self, builder: &Builder) {
let rustdoc = builder.out.join("bootstrap/debug/rustdoc"); let rustdoc = builder.out.join("bootstrap/debug/rustdoc");
let mut cmd = builder.tool_cmd(Tool::RustdocTheme); let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
cmd.arg(rustdoc.to_str().unwrap()) cmd.arg(rustdoc.to_str().unwrap())
.arg(builder.src.join("src/librustdoc/html/static/themes").to_str().unwrap()) .arg(
builder
.src
.join("src/librustdoc/html/static/themes")
.to_str()
.unwrap(),
)
.env("RUSTC_STAGE", self.compiler.stage.to_string()) .env("RUSTC_STAGE", self.compiler.stage.to_string())
.env("RUSTC_SYSROOT", builder.sysroot(self.compiler)) .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
.env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host)) .env(
"RUSTDOC_LIBDIR",
builder.sysroot_libdir(self.compiler, self.compiler.host),
)
.env("CFG_RELEASE_CHANNEL", &builder.config.channel) .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
.env("RUSTDOC_REAL", builder.rustdoc(self.compiler.host)) .env("RUSTDOC_REAL", builder.rustdoc(self.compiler.host))
.env("RUSTDOC_CRATE_VERSION", builder.rust_version()) .env("RUSTDOC_CRATE_VERSION", builder.rust_version())
@@ -534,7 +559,9 @@ impl Step for RustdocJS {
}); });
builder.run(&mut command); builder.run(&mut command);
} else { } else {
builder.info(&format!("No nodejs found, skipping \"src/test/rustdoc-js\" tests")); builder.info(&format!(
"No nodejs found, skipping \"src/test/rustdoc-js\" tests"
));
} }
} }
} }
@@ -918,7 +945,7 @@ impl Step for Compiletest {
builder.ensure(dist::DebuggerScripts { builder.ensure(dist::DebuggerScripts {
sysroot: builder.sysroot(compiler), sysroot: builder.sysroot(compiler),
host: target host: target,
}); });
} }
@@ -926,7 +953,8 @@ impl Step for Compiletest {
// FIXME: Does pretty need librustc compiled? Note that there are // FIXME: Does pretty need librustc compiled? Note that there are
// fulldeps test suites with mode = pretty as well. // fulldeps test suites with mode = pretty as well.
mode == "pretty" || mode == "pretty" ||
mode == "rustdoc" { mode == "rustdoc"
{
builder.ensure(compile::Rustc { compiler, target }); builder.ensure(compile::Rustc { compiler, target });
} }
@@ -939,26 +967,34 @@ impl Step for Compiletest {
// compiletest currently has... a lot of arguments, so let's just pass all // compiletest currently has... a lot of arguments, so let's just pass all
// of them! // of them!
cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler)); cmd.arg("--compile-lib-path")
cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target)); .arg(builder.rustc_libdir(compiler));
cmd.arg("--run-lib-path")
.arg(builder.sysroot_libdir(compiler, target));
cmd.arg("--rustc-path").arg(builder.rustc(compiler)); cmd.arg("--rustc-path").arg(builder.rustc(compiler));
let is_rustdoc_ui = suite.ends_with("rustdoc-ui"); let is_rustdoc_ui = suite.ends_with("rustdoc-ui");
// Avoid depending on rustdoc when we don't need it. // Avoid depending on rustdoc when we don't need it.
if mode == "rustdoc" || if mode == "rustdoc"
(mode == "run-make" && suite.ends_with("fulldeps")) || || (mode == "run-make" && suite.ends_with("fulldeps"))
(mode == "ui" && is_rustdoc_ui) { || (mode == "ui" && is_rustdoc_ui)
cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host)); {
cmd.arg("--rustdoc-path")
.arg(builder.rustdoc(compiler.host));
} }
cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite)); cmd.arg("--src-base")
cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite)); .arg(builder.src.join("src/test").join(suite));
cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target)); cmd.arg("--build-base")
.arg(testdir(builder, compiler.host).join(suite));
cmd.arg("--stage-id")
.arg(format!("stage{}-{}", compiler.stage, target));
cmd.arg("--mode").arg(mode); cmd.arg("--mode").arg(mode);
cmd.arg("--target").arg(target); cmd.arg("--target").arg(target);
cmd.arg("--host").arg(&*compiler.host); cmd.arg("--host").arg(&*compiler.host);
cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build)); cmd.arg("--llvm-filecheck")
.arg(builder.llvm_filecheck(builder.config.build));
if builder.config.cmd.bless() { if builder.config.cmd.bless() {
cmd.arg("--bless"); cmd.arg("--bless");
@@ -994,8 +1030,10 @@ impl Step for Compiletest {
cmd.arg("--host-rustcflags").arg(hostflags.join(" ")); cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
let mut targetflags = flags.clone(); let mut targetflags = flags.clone();
targetflags.push(format!("-Lnative={}", targetflags.push(format!(
builder.test_helpers_out(target).display())); "-Lnative={}",
builder.test_helpers_out(target).display()
));
cmd.arg("--target-rustcflags").arg(targetflags.join(" ")); cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
cmd.arg("--docck-python").arg(builder.python()); cmd.arg("--docck-python").arg(builder.python());
@@ -1022,12 +1060,15 @@ impl Step for Compiletest {
// Get paths from cmd args // Get paths from cmd args
let paths = match &builder.config.cmd { let paths = match &builder.config.cmd {
Subcommand::Test { ref paths, .. } => &paths[..], Subcommand::Test { ref paths, .. } => &paths[..],
_ => &[] _ => &[],
}; };
// Get test-args by striping suite path // Get test-args by striping suite path
let mut test_args: Vec<&str> = paths.iter().filter(|p| p.starts_with(suite_path) && let mut test_args: Vec<&str> = paths
p.is_file()).map(|p| p.strip_prefix(suite_path).unwrap().to_str().unwrap()).collect(); .iter()
.filter(|p| p.starts_with(suite_path) && p.is_file())
.map(|p| p.strip_prefix(suite_path).unwrap().to_str().unwrap())
.collect();
test_args.append(&mut builder.config.cmd.test_args()); test_args.append(&mut builder.config.cmd.test_args());
@@ -1059,32 +1100,44 @@ impl Step for Compiletest {
if !builder.config.dry_run && suite == "run-make-fulldeps" { if !builder.config.dry_run && suite == "run-make-fulldeps" {
let llvm_components = output(Command::new(&llvm_config).arg("--components")); let llvm_components = output(Command::new(&llvm_config).arg("--components"));
let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags")); let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
cmd.arg("--cc").arg(builder.cc(target)) cmd.arg("--cc")
.arg("--cxx").arg(builder.cxx(target).unwrap()) .arg(builder.cc(target))
.arg("--cflags").arg(builder.cflags(target).join(" ")) .arg("--cxx")
.arg("--llvm-components").arg(llvm_components.trim()) .arg(builder.cxx(target).unwrap())
.arg("--llvm-cxxflags").arg(llvm_cxxflags.trim()); .arg("--cflags")
.arg(builder.cflags(target).join(" "))
.arg("--llvm-components")
.arg(llvm_components.trim())
.arg("--llvm-cxxflags")
.arg(llvm_cxxflags.trim());
if let Some(ar) = builder.ar(target) { if let Some(ar) = builder.ar(target) {
cmd.arg("--ar").arg(ar); cmd.arg("--ar").arg(ar);
} }
} }
} }
if suite == "run-make-fulldeps" && !builder.config.llvm_enabled { if suite == "run-make-fulldeps" && !builder.config.llvm_enabled {
builder.info( builder.info(&format!(
&format!("Ignoring run-make test suite as they generally don't work without LLVM")); "Ignoring run-make test suite as they generally don't work without LLVM"
));
return; return;
} }
if suite != "run-make-fulldeps" { if suite != "run-make-fulldeps" {
cmd.arg("--cc").arg("") cmd.arg("--cc")
.arg("--cxx").arg("") .arg("")
.arg("--cflags").arg("") .arg("--cxx")
.arg("--llvm-components").arg("") .arg("")
.arg("--llvm-cxxflags").arg(""); .arg("--cflags")
.arg("")
.arg("--llvm-components")
.arg("")
.arg("--llvm-cxxflags")
.arg("");
} }
if builder.remote_tested(target) { if builder.remote_tested(target) {
cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient)); cmd.arg("--remote-test-client")
.arg(builder.tool_exe(Tool::RemoteTestClient));
} }
// Running a C compiler on MSVC requires a few env vars to be set, to be // Running a C compiler on MSVC requires a few env vars to be set, to be
@@ -1125,16 +1178,20 @@ impl Step for Compiletest {
builder.ci_env.force_coloring_in_ci(&mut cmd); builder.ci_env.force_coloring_in_ci(&mut cmd);
let _folder = builder.fold_output(|| format!("test_{}", suite)); let _folder = builder.fold_output(|| format!("test_{}", suite));
builder.info(&format!("Check compiletest suite={} mode={} ({} -> {})", builder.info(&format!(
suite, mode, &compiler.host, target)); "Check compiletest suite={} mode={} ({} -> {})",
suite, mode, &compiler.host, target
));
let _time = util::timeit(&builder); let _time = util::timeit(&builder);
try_run(builder, &mut cmd); try_run(builder, &mut cmd);
if let Some(compare_mode) = compare_mode { if let Some(compare_mode) = compare_mode {
cmd.arg("--compare-mode").arg(compare_mode); cmd.arg("--compare-mode").arg(compare_mode);
let _folder = builder.fold_output(|| format!("test_{}_{}", suite, compare_mode)); let _folder = builder.fold_output(|| format!("test_{}_{}", suite, compare_mode));
builder.info(&format!("Check compiletest suite={} mode={} compare_mode={} ({} -> {})", builder.info(&format!(
suite, mode, compare_mode, &compiler.host, target)); "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
suite, mode, compare_mode, &compiler.host, target
));
let _time = util::timeit(&builder); let _time = util::timeit(&builder);
try_run(builder, &mut cmd); try_run(builder, &mut cmd);
} }
@@ -1165,7 +1222,10 @@ impl Step for DocTest {
fn run(self, builder: &Builder) { fn run(self, builder: &Builder) {
let compiler = self.compiler; let compiler = self.compiler;
builder.ensure(compile::Test { compiler, target: compiler.host }); builder.ensure(compile::Test {
compiler,
target: compiler.host,
});
// Do a breadth-first traversal of the `src/doc` directory and just run // Do a breadth-first traversal of the `src/doc` directory and just run
// tests for all files that end in `*.md` // tests for all files that end in `*.md`
@@ -1177,7 +1237,7 @@ impl Step for DocTest {
while let Some(p) = stack.pop() { while let Some(p) = stack.pop() {
if p.is_dir() { if p.is_dir() {
stack.extend(t!(p.read_dir()).map(|p| t!(p).path())); stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
continue continue;
} }
if p.extension().and_then(|s| s.to_str()) != Some("md") { if p.extension().and_then(|s| s.to_str()) != Some("md") {
@@ -1284,7 +1344,10 @@ impl Step for ErrorIndex {
fn run(self, builder: &Builder) { fn run(self, builder: &Builder) {
let compiler = self.compiler; let compiler = self.compiler;
builder.ensure(compile::Std { compiler, target: compiler.host }); builder.ensure(compile::Std {
compiler,
target: compiler.host,
});
let dir = testdir(builder, compiler.host); let dir = testdir(builder, compiler.host);
t!(fs::create_dir_all(&dir)); t!(fs::create_dir_all(&dir));
@@ -1296,7 +1359,6 @@ impl Step for ErrorIndex {
.env("CFG_BUILD", &builder.config.build) .env("CFG_BUILD", &builder.config.build)
.env("RUSTC_ERROR_METADATA_DST", builder.extended_error_dir()); .env("RUSTC_ERROR_METADATA_DST", builder.extended_error_dir());
let _folder = builder.fold_output(|| "test_error_index"); let _folder = builder.fold_output(|| "test_error_index");
builder.info(&format!("Testing error-index stage{}", compiler.stage)); builder.info(&format!("Testing error-index stage{}", compiler.stage));
let _time = util::timeit(&builder); let _time = util::timeit(&builder);
@@ -1314,7 +1376,7 @@ fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) -> bool
return true; return true;
} }
} }
Err(_) => {}, Err(_) => {}
} }
builder.info(&format!("doc tests for: {}", markdown.display())); builder.info(&format!("doc tests for: {}", markdown.display()));
@@ -1431,7 +1493,6 @@ impl Step for CrateNotDefault {
} }
} }
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Crate { pub struct Crate {
pub compiler: Compiler, pub compiler: Compiler,
@@ -1449,10 +1510,11 @@ impl Step for Crate {
let builder = run.builder; let builder = run.builder;
run = run.krate("test"); run = run.krate("test");
for krate in run.builder.in_tree_crates("std") { for krate in run.builder.in_tree_crates("std") {
if krate.is_local(&run.builder) && if krate.is_local(&run.builder)
!krate.name.contains("jemalloc") && && !krate.name.contains("jemalloc")
!(krate.name.starts_with("rustc_") && krate.name.ends_with("san")) && && !(krate.name.starts_with("rustc_") && krate.name.ends_with("san"))
krate.name != "dlmalloc" { && krate.name != "dlmalloc"
{
run = run.path(krate.local_path(&builder).to_str().unwrap()); run = run.path(krate.local_path(&builder).to_str().unwrap());
} }
} }
@@ -1567,38 +1629,59 @@ impl Step for Crate {
} }
if target.contains("emscripten") { if target.contains("emscripten") {
cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), cargo.env(
builder.config.nodejs.as_ref().expect("nodejs not configured")); format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
builder
.config
.nodejs
.as_ref()
.expect("nodejs not configured"),
);
} else if target.starts_with("wasm32") { } else if target.starts_with("wasm32") {
// Warn about running tests without the `wasm_syscall` feature enabled. // Warn about running tests without the `wasm_syscall` feature enabled.
// The javascript shim implements the syscall interface so that test // The javascript shim implements the syscall interface so that test
// output can be correctly reported. // output can be correctly reported.
if !builder.config.wasm_syscall { if !builder.config.wasm_syscall {
builder.info(&format!("Libstd was built without `wasm_syscall` feature enabled: \ builder.info(&format!(
test output may not be visible.")); "Libstd was built without `wasm_syscall` feature enabled: \
test output may not be visible."
));
} }
// On the wasm32-unknown-unknown target we're using LTO which is // On the wasm32-unknown-unknown target we're using LTO which is
// incompatible with `-C prefer-dynamic`, so disable that here // incompatible with `-C prefer-dynamic`, so disable that here
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1"); cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
let node = builder.config.nodejs.as_ref() let node = builder
.config
.nodejs
.as_ref()
.expect("nodejs not configured"); .expect("nodejs not configured");
let runner = format!("{} {}/src/etc/wasm32-shim.js", let runner = format!(
"{} {}/src/etc/wasm32-shim.js",
node.display(), node.display(),
builder.src.display()); builder.src.display()
);
cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner); cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
} else if builder.remote_tested(target) { } else if builder.remote_tested(target) {
cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), cargo.env(
format!("{} run", format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
builder.tool_exe(Tool::RemoteTestClient).display())); format!("{} run", builder.tool_exe(Tool::RemoteTestClient).display()),
);
} }
let _folder = builder.fold_output(|| { let _folder = builder.fold_output(|| {
format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, krate) format!(
"{}_stage{}-{}",
test_kind.subcommand(),
compiler.stage,
krate
)
}); });
builder.info(&format!("{} {} stage{} ({} -> {})", test_kind, krate, compiler.stage, builder.info(&format!(
&compiler.host, target)); "{} {} stage{} ({} -> {})",
test_kind, krate, compiler.stage, &compiler.host, target
));
let _time = util::timeit(&builder); let _time = util::timeit(&builder);
try_run(builder, &mut cargo); try_run(builder, &mut cargo);
} }
@@ -1636,11 +1719,13 @@ impl Step for CrateRustdoc {
let compiler = builder.compiler(builder.top_stage, self.host); let compiler = builder.compiler(builder.top_stage, self.host);
let target = compiler.host; let target = compiler.host;
let mut cargo = tool::prepare_tool_cargo(builder, let mut cargo = tool::prepare_tool_cargo(
builder,
compiler, compiler,
target, target,
test_kind.subcommand(), test_kind.subcommand(),
"src/tools/rustdoc"); "src/tools/rustdoc",
);
if test_kind.subcommand() == "test" && !builder.fail_fast { if test_kind.subcommand() == "test" && !builder.fail_fast {
cargo.arg("--no-fail-fast"); cargo.arg("--no-fail-fast");
} }
@@ -1654,11 +1739,12 @@ impl Step for CrateRustdoc {
cargo.arg("--quiet"); cargo.arg("--quiet");
} }
let _folder = builder.fold_output(|| { let _folder = builder
format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage) .fold_output(|| format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage));
}); builder.info(&format!(
builder.info(&format!("{} rustdoc stage{} ({} -> {})", test_kind, compiler.stage, "{} rustdoc stage{} ({} -> {})",
&compiler.host, target)); test_kind, compiler.stage, &compiler.host, target
));
let _time = util::timeit(&builder); let _time = util::timeit(&builder);
try_run(builder, &mut cargo); try_run(builder, &mut cargo);
@@ -1666,12 +1752,13 @@ impl Step for CrateRustdoc {
} }
fn envify(s: &str) -> String { fn envify(s: &str) -> String {
s.chars().map(|c| { s.chars()
match c { .map(|c| match c {
'-' => '_', '-' => '_',
c => c, c => c,
} })
}).flat_map(|c| c.to_uppercase()).collect() .flat_map(|c| c.to_uppercase())
.collect()
} }
/// Some test suites are run inside emulators or on remote devices, and most /// Some test suites are run inside emulators or on remote devices, and most
@@ -1700,7 +1787,7 @@ impl Step for RemoteCopyLibs {
let compiler = self.compiler; let compiler = self.compiler;
let target = self.target; let target = self.target;
if !builder.remote_tested(target) { if !builder.remote_tested(target) {
return return;
} }
builder.ensure(compile::Test { compiler, target }); builder.ensure(compile::Test { compiler, target });
@@ -1727,9 +1814,7 @@ impl Step for RemoteCopyLibs {
let f = t!(f); let f = t!(f);
let name = f.file_name().into_string().unwrap(); let name = f.file_name().into_string().unwrap();
if util::is_dylib(&name) { if util::is_dylib(&name) {
builder.run(Command::new(&tool) builder.run(Command::new(&tool).arg("push").arg(f.path()));
.arg("push")
.arg(f.path()));
} }
} }
} }
@@ -1766,13 +1851,17 @@ impl Step for Distcheck {
.arg("--strip-components=1") .arg("--strip-components=1")
.current_dir(&dir); .current_dir(&dir);
builder.run(&mut cmd); builder.run(&mut cmd);
builder.run(Command::new("./configure") builder.run(
Command::new("./configure")
.args(&builder.config.configure_args) .args(&builder.config.configure_args)
.arg("--enable-vendor") .arg("--enable-vendor")
.current_dir(&dir)); .current_dir(&dir),
builder.run(Command::new(build_helper::make(&builder.config.build)) );
builder.run(
Command::new(build_helper::make(&builder.config.build))
.arg("check") .arg("check")
.current_dir(&dir)); .current_dir(&dir),
);
// Now make sure that rust-src has all of libstd's dependencies // Now make sure that rust-src has all of libstd's dependencies
builder.info(&format!("Distcheck rust-src")); builder.info(&format!("Distcheck rust-src"));
@@ -1788,11 +1877,13 @@ impl Step for Distcheck {
builder.run(&mut cmd); builder.run(&mut cmd);
let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml"); let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
builder.run(Command::new(&builder.initial_cargo) builder.run(
Command::new(&builder.initial_cargo)
.arg("generate-lockfile") .arg("generate-lockfile")
.arg("--manifest-path") .arg("--manifest-path")
.arg(&toml) .arg(&toml)
.current_dir(&dir)); .current_dir(&dir),
);
} }
} }

View File

@@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
use common::CompareMode; use common::CompareMode;
use common::{expected_output_path, UI_STDERR, UI_STDOUT, UI_FIXED}; use common::{expected_output_path, UI_FIXED, UI_STDERR, UI_STDOUT};
use common::{output_base_dir, output_base_name, output_testname_unique}; use common::{output_base_dir, output_base_name, output_testname_unique};
use common::{Codegen, CodegenUnits, DebugInfoGdb, DebugInfoLldb, Rustdoc}; use common::{Codegen, CodegenUnits, DebugInfoGdb, DebugInfoLldb, Rustdoc};
use common::{CompileFail, ParseFail, Pretty, RunFail, RunPass, RunPassValgrind}; use common::{CompileFail, ParseFail, Pretty, RunFail, RunPass, RunPassValgrind};
@@ -24,8 +24,8 @@ use regex::Regex;
use rustfix::{apply_suggestions, get_suggestions_from_json}; use rustfix::{apply_suggestions, get_suggestions_from_json};
use util::{logv, PathBufExt}; use util::{logv, PathBufExt};
use std::collections::{HashMap, HashSet, VecDeque};
use std::collections::hash_map::DefaultHasher; use std::collections::hash_map::DefaultHasher;
use std::collections::{HashMap, HashSet, VecDeque};
use std::env; use std::env;
use std::ffi::OsString; use std::ffi::OsString;
use std::fmt; use std::fmt;
@@ -48,9 +48,7 @@ fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
} }
lazy_static! { lazy_static! {
static ref LOCK: Mutex<()> = { static ref LOCK: Mutex<()> = { Mutex::new(()) };
Mutex::new(())
};
} }
// Error mode is a global variable, so lock it so only one thread will change it // Error mode is a global variable, so lock it so only one thread will change it
let _lock = LOCK.lock().unwrap(); let _lock = LOCK.lock().unwrap();
@@ -743,7 +741,8 @@ impl<'test> TestCx<'test> {
} }
_ => { _ => {
let rust_src_root = self.config let rust_src_root = self
.config
.find_rust_src_root() .find_rust_src_root()
.expect("Could not find Rust source root"); .expect("Could not find Rust source root");
let rust_pp_module_rel_path = Path::new("./src/etc"); let rust_pp_module_rel_path = Path::new("./src/etc");
@@ -905,7 +904,8 @@ impl<'test> TestCx<'test> {
script_str.push_str("version\n"); script_str.push_str("version\n");
// Switch LLDB into "Rust mode" // Switch LLDB into "Rust mode"
let rust_src_root = self.config let rust_src_root = self
.config
.find_rust_src_root() .find_rust_src_root()
.expect("Could not find Rust source root"); .expect("Could not find Rust source root");
let rust_pp_module_rel_path = Path::new("./src/etc/lldb_rust_formatters.py"); let rust_pp_module_rel_path = Path::new("./src/etc/lldb_rust_formatters.py");
@@ -1052,7 +1052,8 @@ impl<'test> TestCx<'test> {
// Remove options that are either unwanted (-O) or may lead to duplicates due to RUSTFLAGS. // Remove options that are either unwanted (-O) or may lead to duplicates due to RUSTFLAGS.
let options_to_remove = ["-O".to_owned(), "-g".to_owned(), "--debuginfo".to_owned()]; let options_to_remove = ["-O".to_owned(), "-g".to_owned(), "--debuginfo".to_owned()];
let new_options = self.split_maybe_args(options) let new_options = self
.split_maybe_args(options)
.into_iter() .into_iter()
.filter(|x| !options_to_remove.contains(x)) .filter(|x| !options_to_remove.contains(x))
.collect::<Vec<String>>(); .collect::<Vec<String>>();
@@ -1351,7 +1352,8 @@ impl<'test> TestCx<'test> {
let aux_dir = self.aux_output_dir_name(); let aux_dir = self.aux_output_dir_name();
let rustdoc_path = self.config let rustdoc_path = self
.config
.rustdoc_path .rustdoc_path
.as_ref() .as_ref()
.expect("--rustdoc-path passed"); .expect("--rustdoc-path passed");
@@ -1449,7 +1451,8 @@ impl<'test> TestCx<'test> {
/// For each `aux-build: foo/bar` annotation, we check to find the /// For each `aux-build: foo/bar` annotation, we check to find the
/// file in a `auxiliary` directory relative to the test itself. /// file in a `auxiliary` directory relative to the test itself.
fn compute_aux_test_paths(&self, rel_ab: &str) -> TestPaths { fn compute_aux_test_paths(&self, rel_ab: &str) -> TestPaths {
let test_ab = self.testpaths let test_ab = self
.testpaths
.file .file
.parent() .parent()
.expect("test file path has no parent") .expect("test file path has no parent")
@@ -1464,7 +1467,8 @@ impl<'test> TestCx<'test> {
TestPaths { TestPaths {
file: test_ab, file: test_ab,
relative_dir: self.testpaths relative_dir: self
.testpaths
.relative_dir .relative_dir
.join(self.output_testname_unique()) .join(self.output_testname_unique())
.join("auxiliary") .join("auxiliary")
@@ -1617,16 +1621,20 @@ impl<'test> TestCx<'test> {
let mut rustc = if !is_rustdoc { let mut rustc = if !is_rustdoc {
Command::new(&self.config.rustc_path) Command::new(&self.config.rustc_path)
} else { } else {
Command::new(&self.config Command::new(
&self
.config
.rustdoc_path .rustdoc_path
.clone() .clone()
.expect("no rustdoc built yet")) .expect("no rustdoc built yet"),
)
}; };
// FIXME Why is -L here? // FIXME Why is -L here?
rustc.arg(input_file); //.arg("-L").arg(&self.config.build_base); rustc.arg(input_file); //.arg("-L").arg(&self.config.build_base);
// Optionally prevent default --target if specified in test compile-flags. // Optionally prevent default --target if specified in test compile-flags.
let custom_target = self.props let custom_target = self
.props
.compile_flags .compile_flags
.iter() .iter()
.any(|x| x.starts_with("--target")); .any(|x| x.starts_with("--target"));
@@ -1670,7 +1678,8 @@ impl<'test> TestCx<'test> {
} }
} }
Ui => { Ui => {
if !self.props if !self
.props
.compile_flags .compile_flags
.iter() .iter()
.any(|s| s.starts_with("--error-format")) .any(|s| s.starts_with("--error-format"))
@@ -1704,7 +1713,13 @@ impl<'test> TestCx<'test> {
} }
if self.props.skip_codegen { if self.props.skip_codegen {
assert!(!self.props.compile_flags.iter().any(|s| s.starts_with("--emit"))); assert!(
!self
.props
.compile_flags
.iter()
.any(|s| s.starts_with("--emit"))
);
rustc.args(&["--emit", "metadata"]); rustc.args(&["--emit", "metadata"]);
} }
@@ -1812,7 +1827,8 @@ impl<'test> TestCx<'test> {
fn split_maybe_args(&self, argstr: &Option<String>) -> Vec<String> { fn split_maybe_args(&self, argstr: &Option<String>) -> Vec<String> {
match *argstr { match *argstr {
Some(ref s) => s.split(' ') Some(ref s) => s
.split(' ')
.filter_map(|s| { .filter_map(|s| {
if s.chars().all(|c| c.is_whitespace()) { if s.chars().all(|c| c.is_whitespace()) {
None None
@@ -2125,7 +2141,8 @@ impl<'test> TestCx<'test> {
} }
let mut tested = 0; let mut tested = 0;
for _ in res.stdout for _ in res
.stdout
.split('\n') .split('\n')
.filter(|s| s.starts_with("test ")) .filter(|s| s.starts_with("test "))
.inspect(|s| { .inspect(|s| {
@@ -2136,7 +2153,8 @@ impl<'test> TestCx<'test> {
tested += 1; tested += 1;
let mut iter = tmp[1].split("(line "); let mut iter = tmp[1].split("(line ");
iter.next(); iter.next();
let line = iter.next() let line = iter
.next()
.unwrap_or(")") .unwrap_or(")")
.split(')') .split(')')
.next() .next()
@@ -2290,7 +2308,8 @@ impl<'test> TestCx<'test> {
let full_string = format!("{}{}", PREFIX, s.trim().to_owned()); let full_string = format!("{}{}", PREFIX, s.trim().to_owned());
let parts: Vec<&str> = s.split(CGU_MARKER) let parts: Vec<&str> = s
.split(CGU_MARKER)
.map(str::trim) .map(str::trim)
.filter(|s| !s.is_empty()) .filter(|s| !s.is_empty())
.collect(); .collect();
@@ -2375,7 +2394,8 @@ impl<'test> TestCx<'test> {
// FIXME -- use non-incremental mode as an oracle? That doesn't apply // FIXME -- use non-incremental mode as an oracle? That doesn't apply
// to #[rustc_dirty] and clean tests I guess // to #[rustc_dirty] and clean tests I guess
let revision = self.revision let revision = self
.revision
.expect("incremental tests require a list of revisions"); .expect("incremental tests require a list of revisions");
// Incremental workproduct directory should have already been created. // Incremental workproduct directory should have already been created.
@@ -2421,7 +2441,8 @@ impl<'test> TestCx<'test> {
fn run_rmake_test(&self) { fn run_rmake_test(&self) {
let cwd = env::current_dir().unwrap(); let cwd = env::current_dir().unwrap();
let src_root = self.config let src_root = self
.config
.src_base .src_base
.parent() .parent()
.unwrap() .unwrap()
@@ -2438,8 +2459,10 @@ impl<'test> TestCx<'test> {
create_dir_all(&tmpdir).unwrap(); create_dir_all(&tmpdir).unwrap();
let host = &self.config.host; let host = &self.config.host;
let make = if host.contains("bitrig") || host.contains("dragonfly") let make = if host.contains("bitrig")
|| host.contains("freebsd") || host.contains("netbsd") || host.contains("dragonfly")
|| host.contains("freebsd")
|| host.contains("netbsd")
|| host.contains("openbsd") || host.contains("openbsd")
{ {
"gmake" "gmake"
@@ -2494,7 +2517,8 @@ impl<'test> TestCx<'test> {
// MSYS doesn't like passing flags of the form `/foo` as it thinks it's // MSYS doesn't like passing flags of the form `/foo` as it thinks it's
// a path and instead passes `C:\msys64\foo`, so convert all // a path and instead passes `C:\msys64\foo`, so convert all
// `/`-arguments to MSVC here to `-` arguments. // `/`-arguments to MSVC here to `-` arguments.
let cflags = self.config let cflags = self
.config
.cflags .cflags
.split(' ') .split(' ')
.map(|s| s.replace("/", "-")) .map(|s| s.replace("/", "-"))
@@ -2516,7 +2540,8 @@ impl<'test> TestCx<'test> {
} }
} }
let output = cmd.spawn() let output = cmd
.spawn()
.and_then(read2_abbreviated) .and_then(read2_abbreviated)
.expect("failed to spawn `make`"); .expect("failed to spawn `make`");
if !output.status.success() { if !output.status.success() {
@@ -2557,7 +2582,8 @@ impl<'test> TestCx<'test> {
// if the user specified a format in the ui test // if the user specified a format in the ui test
// print the output to the stderr file, otherwise extract // print the output to the stderr file, otherwise extract
// the rendered error messages from json and print them // the rendered error messages from json and print them
let explicit = self.props let explicit = self
.props
.compile_flags .compile_flags
.iter() .iter()
.any(|s| s.contains("--error-format")); .any(|s| s.contains("--error-format"));
@@ -2587,22 +2613,27 @@ impl<'test> TestCx<'test> {
// don't test rustfix with nll right now // don't test rustfix with nll right now
} else if self.props.run_rustfix { } else if self.props.run_rustfix {
// Apply suggestions from rustc to the code itself // Apply suggestions from rustc to the code itself
let unfixed_code = self.load_expected_output_from_path(&self.testpaths.file) let unfixed_code = self
.load_expected_output_from_path(&self.testpaths.file)
.unwrap(); .unwrap();
let suggestions = get_suggestions_from_json(&proc_res.stderr, &HashSet::new()).unwrap(); let suggestions = get_suggestions_from_json(&proc_res.stderr, &HashSet::new()).unwrap();
let fixed_code = apply_suggestions(&unfixed_code, &suggestions).expect( let fixed_code = apply_suggestions(&unfixed_code, &suggestions).expect(&format!(
&format!("failed to apply suggestions for {:?} with rustfix", self.testpaths.file) "failed to apply suggestions for {:?} with rustfix",
); self.testpaths.file
));
errors += self.compare_output("fixed", &fixed_code, &expected_fixed); errors += self.compare_output("fixed", &fixed_code, &expected_fixed);
} else if !expected_fixed.is_empty() { } else if !expected_fixed.is_empty() {
panic!("the `// run-rustfix` directive wasn't found but a `*.fixed` \ panic!(
file was found"); "the `// run-rustfix` directive wasn't found but a `*.fixed` \
file was found"
);
} }
if errors > 0 { if errors > 0 {
println!("To update references, rerun the tests and pass the `--bless` flag"); println!("To update references, rerun the tests and pass the `--bless` flag");
let relative_path_to_file = self.testpaths let relative_path_to_file = self
.testpaths
.relative_dir .relative_dir
.join(self.testpaths.file.file_name().unwrap()); .join(self.testpaths.file.file_name().unwrap());
println!( println!(
@@ -2784,11 +2815,7 @@ impl<'test> TestCx<'test> {
Test Name: {}\n\ Test Name: {}\n\
Expected:\n{}\n\ Expected:\n{}\n\
Actual:\n{}", Actual:\n{}",
extra_msg, extra_msg, expected_line, test_name, expected_content, normalize_all
expected_line,
test_name,
expected_content,
normalize_all
); );
}; };
@@ -2904,7 +2931,12 @@ impl<'test> TestCx<'test> {
if !path.exists() { if !path.exists() {
if let Some(CompareMode::Polonius) = self.config.compare_mode { if let Some(CompareMode::Polonius) = self.config.compare_mode {
path = expected_output_path(&self.testpaths, self.revision, &Some(CompareMode::Nll), kind); path = expected_output_path(
&self.testpaths,
self.revision,
&Some(CompareMode::Nll),
kind,
);
} }
} }
@@ -2973,7 +3005,8 @@ impl<'test> TestCx<'test> {
} }
let mode = self.config.compare_mode.as_ref().map_or("", |m| m.to_str()); let mode = self.config.compare_mode.as_ref().map_or("", |m| m.to_str());
let output_file = self.output_base_name() let output_file = self
.output_base_name()
.with_extra_extension(self.revision.unwrap_or("")) .with_extra_extension(self.revision.unwrap_or(""))
.with_extra_extension(mode) .with_extra_extension(mode)
.with_extra_extension(kind); .with_extra_extension(kind);
@@ -3023,7 +3056,8 @@ impl<'test> TestCx<'test> {
fn create_stamp(&self) { fn create_stamp(&self) {
let mut f = File::create(::stamp(&self.config, self.testpaths, self.revision)).unwrap(); let mut f = File::create(::stamp(&self.config, self.testpaths, self.revision)).unwrap();
f.write_all(compute_stamp_hash(&self.config).as_bytes()).unwrap(); f.write_all(compute_stamp_hash(&self.config).as_bytes())
.unwrap();
} }
} }