Skip to content

Commit

Permalink
Auto merge of #32755 - alexcrichton:rustbuild-start-test, r=brson
Browse files Browse the repository at this point in the history
rustbuild: Add support for compiletest test suites

This commit adds support in rustbuild for running all of the compiletest test
suites as part of `make check`. The `compiletest` program was moved to
`src/tools` (like `rustbook` and others) and is now just compiled like any other
old tool. Each test suite has a pretty standard set of dependencies and just
tweaks various parameters to the final compiletest executable.

Note that full support is lacking in terms of:

* Once a test suite has passed, that's not remembered. When a test suite is
  requested to be run, it's always run.
* The arguments to compiletest probably don't work for every possible
  combination of platforms and testing environments just yet. There will likely
  need to be future updates to tweak various pieces here and there.
* Cross compiled test suites probably don't work just yet, support for that will
  come in a follow-up patch.
  • Loading branch information
bors committed Apr 12, 2016
2 parents a4f781e + 808116f commit 3147de8
Show file tree
Hide file tree
Showing 23 changed files with 418 additions and 53 deletions.
2 changes: 1 addition & 1 deletion mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ TOOL_DEPS_rustdoc := rustdoc
TOOL_DEPS_rustc := rustc_driver
TOOL_DEPS_rustbook := std rustdoc
TOOL_DEPS_error_index_generator := rustdoc syntax serialize
TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs
TOOL_SOURCE_compiletest := $(S)src/tools/compiletest/src/main.rs
TOOL_SOURCE_rustdoc := $(S)src/driver/driver.rs
TOOL_SOURCE_rustc := $(S)src/driver/driver.rs
TOOL_SOURCE_rustbook := $(S)src/tools/rustbook/main.rs
Expand Down
1 change: 0 additions & 1 deletion mk/dist.mk
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ PKG_FILES := \
$(addprefix $(S)src/, \
bootstrap \
build_helper \
compiletest \
doc \
driver \
etc \
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,11 @@ def build_triple(self):

# Run the bootstrap
args = [os.path.join(rb.build_dir, "bootstrap/debug/bootstrap")]
args.extend(sys.argv[1:])
args.append('--src')
args.append(rb.rust_root)
args.append('--build')
args.append(rb.build)
args.extend(sys.argv[1:])
env = os.environ.copy()
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
rb.run(args, env)
55 changes: 55 additions & 0 deletions src/bootstrap/build/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::path::PathBuf;
use std::process::Command;

use build::{Build, Compiler};

pub fn linkcheck(build: &Build, stage: u32, host: &str) {
Expand All @@ -33,3 +36,55 @@ pub fn cargotest(build: &Build, stage: u32, host: &str) {
.env("PATH", newpath)
.arg(&build.cargo));
}

fn testdir(build: &Build, host: &str) -> PathBuf {
build.out.join(host).join("test")
}

pub fn compiletest(build: &Build,
compiler: &Compiler,
target: &str,
mode: &str,
suite: &str) {
let compiletest = build.tool(compiler, "compiletest");
let mut cmd = Command::new(&compiletest);

cmd.arg("--compile-lib-path").arg(build.rustc_libdir(compiler));
cmd.arg("--run-lib-path").arg(build.sysroot_libdir(compiler, target));
cmd.arg("--rustc-path").arg(build.compiler_path(compiler));
cmd.arg("--rustdoc-path").arg(build.rustdoc(compiler));
cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
cmd.arg("--aux-base").arg(build.src.join("src/test/auxiliary"));
cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
cmd.arg("--mode").arg(mode);
cmd.arg("--target").arg(target);
cmd.arg("--host").arg(compiler.host);

let filecheck = build.llvm_filecheck(&build.config.build);
cmd.arg("--llvm-bin-path").arg(filecheck.parent().unwrap());

let linkflag = format!("-Lnative={}", build.test_helpers_out(target).display());
cmd.arg("--host-rustcflags").arg("-Crpath");
cmd.arg("--target-rustcflags").arg(format!("-Crpath {}", linkflag));

// FIXME: needs android support
cmd.arg("--android-cross-path").arg("");
// FIXME: CFG_PYTHON should probably be detected more robustly elsewhere
cmd.arg("--python").arg("python");

if let Some(ref vers) = build.gdb_version {
cmd.arg("--gdb-version").arg(vers);
}
if let Some(ref vers) = build.lldb_version {
cmd.arg("--lldb-version").arg(vers);
}

cmd.args(&build.flags.args);

if build.config.verbose || build.flags.verbose {
cmd.arg("--verbose");
}

build.run(&mut cmd);
}
9 changes: 1 addition & 8 deletions src/bootstrap/build/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,7 @@ pub fn rustc<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
if !build.unstable_features {
cargo.env("CFG_DISABLE_UNSTABLE_FEATURES", "1");
}
let target_config = build.config.target_config.get(target);
if let Some(ref s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
cargo.env("LLVM_CONFIG", s);
} else {
let llvm_config = build.llvm_out(&build.config.build).join("bin")
.join(exe("llvm-config", target));
cargo.env("LLVM_CONFIG", llvm_config);
}
cargo.env("LLVM_CONFIG", build.llvm_config(target));
if build.config.llvm_static_stdcpp {
cargo.env("LLVM_STATIC_STDCPP",
compiler_file(build.cxx(target), "libstdc++.a"));
Expand Down
53 changes: 30 additions & 23 deletions src/bootstrap/build/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,29 +195,7 @@ pub fn rustc(build: &Build, stage: u32, host: &str) {
cp_r(&build.src.join("man"), &image.join("share/man/man1"));

// Debugger scripts
let cp_debugger_script = |file: &str| {
let dst = image.join("lib/rustlib/etc");
t!(fs::create_dir_all(&dst));
install(&build.src.join("src/etc/").join(file), &dst, 0o644);
};
if host.contains("windows") {
// no debugger scripts
} else if host.contains("darwin") {
// lldb debugger scripts
install(&build.src.join("src/etc/rust-lldb"), &image.join("bin"),
0o755);

cp_debugger_script("lldb_rust_formatters.py");
cp_debugger_script("debugger_pretty_printers_common.py");
} else {
// gdb debugger scripts
install(&build.src.join("src/etc/rust-gdb"), &image.join("bin"),
0o755);

cp_debugger_script("gdb_load_rust_pretty_printers.py");
cp_debugger_script("gdb_rust_pretty_printing.py");
cp_debugger_script("debugger_pretty_printers_common.py");
}
debugger_scripts(build, &image, host);

// Misc license info
let cp = |file: &str| {
Expand All @@ -231,6 +209,35 @@ pub fn rustc(build: &Build, stage: u32, host: &str) {
}
}

pub fn debugger_scripts(build: &Build,
sysroot: &Path,
host: &str) {
let cp_debugger_script = |file: &str| {
let dst = sysroot.join("lib/rustlib/etc");
t!(fs::create_dir_all(&dst));
install(&build.src.join("src/etc/").join(file), &dst, 0o644);
};
if host.contains("windows") {
// no debugger scripts
} else if host.contains("darwin") {
// lldb debugger scripts
install(&build.src.join("src/etc/rust-lldb"), &sysroot.join("bin"),
0o755);

cp_debugger_script("lldb_rust_formatters.py");
cp_debugger_script("debugger_pretty_printers_common.py");
} else {
// gdb debugger scripts
install(&build.src.join("src/etc/rust-gdb"), &sysroot.join("bin"),
0o755);

cp_debugger_script("gdb_load_rust_pretty_printers.py");
cp_debugger_script("gdb_rust_pretty_printing.py");
cp_debugger_script("debugger_pretty_printers_common.py");
}
}


pub fn std(build: &Build, compiler: &Compiler, target: &str) {
println!("Dist std stage{} ({} -> {})", compiler.stage, compiler.host,
target);
Expand Down
5 changes: 0 additions & 5 deletions src/bootstrap/build/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ impl Flags {
usage(0);
}

if m.free.len() > 0 {
println!("free arguments are not currently accepted");
usage(1);
}

let cfg_file = m.opt_str("config").map(PathBuf::from).or_else(|| {
if fs::metadata("config.toml").is_ok() {
Some(PathBuf::from("config.toml"))
Expand Down
102 changes: 101 additions & 1 deletion src/bootstrap/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ pub struct Build {
package_vers: String,
bootstrap_key: String,

// Probed tools at runtime
gdb_version: Option<String>,
lldb_version: Option<String>,

// Runtime state filled in later on
cc: HashMap<String, (gcc::Tool, PathBuf)>,
cxx: HashMap<String, gcc::Tool>,
Expand Down Expand Up @@ -128,6 +132,8 @@ impl Build {
cc: HashMap::new(),
cxx: HashMap::new(),
compiler_rt_built: RefCell::new(HashMap::new()),
gdb_version: None,
lldb_version: None,
}
}

Expand Down Expand Up @@ -160,6 +166,9 @@ impl Build {
CompilerRt { _dummy } => {
native::compiler_rt(self, target.target);
}
TestHelpers { _dummy } => {
native::test_helpers(self, target.target);
}
Libstd { compiler } => {
compile::std(self, target.target, &compiler);
}
Expand Down Expand Up @@ -197,6 +206,9 @@ impl Build {
ToolCargoTest { stage } => {
compile::tool(self, stage, target.target, "cargotest");
}
ToolCompiletest { stage } => {
compile::tool(self, stage, target.target, "compiletest");
}
DocBook { stage } => {
doc::rustbook(self, stage, target.target, "book", &doc_out);
}
Expand Down Expand Up @@ -230,12 +242,68 @@ impl Build {
CheckCargoTest { stage } => {
check::cargotest(self, stage, target.target);
}
CheckRPass { compiler } => {
check::compiletest(self, &compiler, target.target,
"run-pass", "run-pass");
}
CheckCFail { compiler } => {
check::compiletest(self, &compiler, target.target,
"compile-fail", "compile-fail");
}
CheckPFail { compiler } => {
check::compiletest(self, &compiler, target.target,
"parse-fail", "parse-fail");
}
CheckRFail { compiler } => {
check::compiletest(self, &compiler, target.target,
"run-fail", "run-fail");
}
CheckPretty { compiler } => {
check::compiletest(self, &compiler, target.target,
"pretty", "pretty");
}
CheckCodegen { compiler } => {
check::compiletest(self, &compiler, target.target,
"codegen", "codegen");
}
CheckCodegenUnits { compiler } => {
check::compiletest(self, &compiler, target.target,
"codegen-units", "codegen-units");
}
CheckDebuginfo { compiler } => {
// TODO: select between gdb/lldb
check::compiletest(self, &compiler, target.target,
"debuginfo-gdb", "debuginfo");
}
CheckRustdoc { compiler } => {
check::compiletest(self, &compiler, target.target,
"rustdoc", "rustdoc");
}
CheckRPassValgrind { compiler } => {
check::compiletest(self, &compiler, target.target,
"run-pass-valgrind", "run-pass-valgrind");
}
CheckRPassFull { compiler } => {
check::compiletest(self, &compiler, target.target,
"run-pass", "run-pass-fulldeps");
}
CheckCFailFull { compiler } => {
check::compiletest(self, &compiler, target.target,
"compile-fail", "compile-fail-fulldeps")
}

DistDocs { stage } => dist::docs(self, stage, target.target),
DistMingw { _dummy } => dist::mingw(self, target.target),
DistRustc { stage } => dist::rustc(self, stage, target.target),
DistStd { compiler } => dist::std(self, &compiler, target.target),

DebuggerScripts { stage } => {
let compiler = Compiler::new(stage, target.target);
dist::debugger_scripts(self,
&self.sysroot(&compiler),
target.target);
}

Dist { .. } |
Doc { .. } | // pseudo-steps
Check { .. } => {}
Expand Down Expand Up @@ -436,7 +504,8 @@ impl Build {
let suffix = match mode {
Mode::Libstd => "-std",
Mode::Libtest => "-test",
Mode::Tool | Mode::Librustc => "-rustc",
Mode::Tool => "-tools",
Mode::Librustc => "-rustc",
};
self.out.join(compiler.host)
.join(format!("stage{}{}", compiler.stage, suffix))
Expand All @@ -457,11 +526,39 @@ impl Build {
self.out.join(target).join("llvm")
}

/// Returns the path to `llvm-config` for the specified target
fn llvm_config(&self, target: &str) -> PathBuf {
let target_config = self.config.target_config.get(target);
if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
s.clone()
} else {
self.llvm_out(&self.config.build).join("bin")
.join(exe("llvm-config", target))
}
}

/// Returns the path to `llvm-config` for the specified target
fn llvm_filecheck(&self, target: &str) -> PathBuf {
let target_config = self.config.target_config.get(target);
if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
s.parent().unwrap().join(exe("FileCheck", target))
} else {
self.llvm_out(&self.config.build).join("build/bin")
.join(exe("FileCheck", target))
}
}

/// Root output directory for compiler-rt compiled for `target`
fn compiler_rt_out(&self, target: &str) -> PathBuf {
self.out.join(target).join("compiler-rt")
}

/// Root output directory for rust_test_helpers library compiled for
/// `target`
fn test_helpers_out(&self, target: &str) -> PathBuf {
self.out.join(target).join("rust-test-helpers")
}

fn add_rustc_lib_path(&self, compiler: &Compiler, cmd: &mut Command) {
// Windows doesn't need dylib path munging because the dlls for the
// compiler live next to the compiler and the system will find them
Expand Down Expand Up @@ -504,8 +601,11 @@ impl Build {
}

fn cflags(&self, target: &str) -> Vec<String> {
// Filter out -O and /O (the optimization flags) that we picked up from
// gcc-rs because the build scripts will determine that for themselves.
let mut base = self.cc[target].0.args().iter()
.map(|s| s.to_string_lossy().into_owned())
.filter(|s| !s.starts_with("-O") && !s.starts_with("/O"))
.collect::<Vec<_>>();

// If we're compiling on OSX then we add a few unconditional flags
Expand Down
Loading

0 comments on commit 3147de8

Please sign in to comment.