Skip to content

Commit 023dcd3

Browse files
committed
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.
1 parent bed32d8 commit 023dcd3

21 files changed

+313
-27
lines changed

mk/crates.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ TOOL_DEPS_rustdoc := rustdoc
133133
TOOL_DEPS_rustc := rustc_driver
134134
TOOL_DEPS_rustbook := std rustdoc
135135
TOOL_DEPS_error_index_generator := rustdoc syntax serialize
136-
TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs
136+
TOOL_SOURCE_compiletest := $(S)src/tools/compiletest/src/main.rs
137137
TOOL_SOURCE_rustdoc := $(S)src/driver/driver.rs
138138
TOOL_SOURCE_rustc := $(S)src/driver/driver.rs
139139
TOOL_SOURCE_rustbook := $(S)src/tools/rustbook/main.rs

mk/dist.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ PKG_FILES := \
5050
$(addprefix $(S)src/, \
5151
bootstrap \
5252
build_helper \
53-
compiletest \
5453
doc \
5554
driver \
5655
etc \

src/bootstrap/bootstrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,11 @@ def build_triple(self):
308308

309309
# Run the bootstrap
310310
args = [os.path.join(rb.build_dir, "bootstrap/debug/bootstrap")]
311-
args.extend(sys.argv[1:])
312311
args.append('--src')
313312
args.append(rb.rust_root)
314313
args.append('--build')
315314
args.append(rb.build)
315+
args.extend(sys.argv[1:])
316316
env = os.environ.copy()
317317
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
318318
rb.run(args, env)

src/bootstrap/build/check.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use std::path::PathBuf;
12+
use std::process::Command;
13+
1114
use build::{Build, Compiler};
1215

1316
pub fn linkcheck(build: &Build, stage: u32, host: &str) {
@@ -33,3 +36,48 @@ pub fn cargotest(build: &Build, stage: u32, host: &str) {
3336
.env("PATH", newpath)
3437
.arg(&build.cargo));
3538
}
39+
40+
fn testdir(build: &Build, host: &str) -> PathBuf {
41+
build.out.join(host).join("test")
42+
}
43+
44+
pub fn compiletest(build: &Build,
45+
compiler: &Compiler,
46+
target: &str,
47+
mode: &str,
48+
suite: &str) {
49+
let compiletest = build.tool(compiler, "compiletest");
50+
let mut cmd = Command::new(&compiletest);
51+
52+
cmd.arg("--compile-lib-path").arg(build.rustc_libdir(compiler));
53+
cmd.arg("--run-lib-path").arg(build.sysroot_libdir(compiler, target));
54+
cmd.arg("--rustc-path").arg(build.compiler_path(compiler));
55+
cmd.arg("--rustdoc-path").arg(build.rustdoc(compiler));
56+
cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
57+
cmd.arg("--aux-base").arg(build.src.join("src/test/auxiliary"));
58+
cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
59+
cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
60+
cmd.arg("--mode").arg(mode);
61+
cmd.arg("--target").arg(target);
62+
cmd.arg("--host").arg(compiler.host);
63+
64+
let filecheck = build.llvm_filecheck(&build.config.build);
65+
cmd.arg("--llvm-bin-path").arg(filecheck.parent().unwrap());
66+
67+
let linkflag = format!("-Lnative={}", build.test_helpers_out(target).display());
68+
cmd.arg("--host-rustcflags").arg("-Crpath");
69+
cmd.arg("--target-rustcflags").arg(format!("-Crpath {}", linkflag));
70+
71+
// FIXME: needs android support
72+
cmd.arg("--android-cross-path").arg("");
73+
// FIXME: CFG_PYTHON should probably be detected more robustly elsewhere
74+
cmd.arg("--python").arg("python");
75+
76+
cmd.args(&build.flags.args);
77+
78+
if build.config.verbose || build.flags.verbose {
79+
cmd.arg("--verbose");
80+
}
81+
82+
build.run(&mut cmd);
83+
}

src/bootstrap/build/compile.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,7 @@ pub fn rustc<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
191191
if !build.unstable_features {
192192
cargo.env("CFG_DISABLE_UNSTABLE_FEATURES", "1");
193193
}
194-
let target_config = build.config.target_config.get(target);
195-
if let Some(ref s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
196-
cargo.env("LLVM_CONFIG", s);
197-
} else {
198-
let llvm_config = build.llvm_out(&build.config.build).join("bin")
199-
.join(exe("llvm-config", target));
200-
cargo.env("LLVM_CONFIG", llvm_config);
201-
}
194+
cargo.env("LLVM_CONFIG", build.llvm_config(target));
202195
if build.config.llvm_static_stdcpp {
203196
cargo.env("LLVM_STATIC_STDCPP",
204197
compiler_file(build.cxx(target), "libstdc++.a"));

src/bootstrap/build/flags.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ impl Flags {
6262
usage(0);
6363
}
6464

65-
if m.free.len() > 0 {
66-
println!("free arguments are not currently accepted");
67-
usage(1);
68-
}
69-
7065
let cfg_file = m.opt_str("config").map(PathBuf::from).or_else(|| {
7166
if fs::metadata("config.toml").is_ok() {
7267
Some(PathBuf::from("config.toml"))

src/bootstrap/build/mod.rs

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ impl Build {
160160
CompilerRt { _dummy } => {
161161
native::compiler_rt(self, target.target);
162162
}
163+
TestHelpers { _dummy } => {
164+
native::test_helpers(self, target.target);
165+
}
163166
Libstd { compiler } => {
164167
compile::std(self, target.target, &compiler);
165168
}
@@ -197,6 +200,9 @@ impl Build {
197200
ToolCargoTest { stage } => {
198201
compile::tool(self, stage, target.target, "cargotest");
199202
}
203+
ToolCompiletest { stage } => {
204+
compile::tool(self, stage, target.target, "compiletest");
205+
}
200206
DocBook { stage } => {
201207
doc::rustbook(self, stage, target.target, "book", &doc_out);
202208
}
@@ -230,6 +236,55 @@ impl Build {
230236
CheckCargoTest { stage } => {
231237
check::cargotest(self, stage, target.target);
232238
}
239+
CheckRPass { compiler } => {
240+
check::compiletest(self, &compiler, target.target,
241+
"run-pass", "run-pass");
242+
}
243+
CheckCFail { compiler } => {
244+
check::compiletest(self, &compiler, target.target,
245+
"compile-fail", "compile-fail");
246+
}
247+
CheckPFail { compiler } => {
248+
check::compiletest(self, &compiler, target.target,
249+
"parse-fail", "parse-fail");
250+
}
251+
CheckRFail { compiler } => {
252+
check::compiletest(self, &compiler, target.target,
253+
"run-fail", "run-fail");
254+
}
255+
CheckPretty { compiler } => {
256+
check::compiletest(self, &compiler, target.target,
257+
"pretty", "pretty");
258+
}
259+
CheckCodegen { compiler } => {
260+
check::compiletest(self, &compiler, target.target,
261+
"codegen", "codegen");
262+
}
263+
CheckCodegenUnits { compiler } => {
264+
check::compiletest(self, &compiler, target.target,
265+
"codegen-units", "codegen-units");
266+
}
267+
CheckDebuginfo { compiler } => {
268+
// TODO: select between gdb/lldb
269+
check::compiletest(self, &compiler, target.target,
270+
"debuginfo-gdb", "debuginfo");
271+
}
272+
CheckRustdoc { compiler } => {
273+
check::compiletest(self, &compiler, target.target,
274+
"rustdoc", "rustdoc");
275+
}
276+
CheckRPassValgrind { compiler } => {
277+
check::compiletest(self, &compiler, target.target,
278+
"run-pass-valgrind", "run-pass-valgrind");
279+
}
280+
CheckRPassFull { compiler } => {
281+
check::compiletest(self, &compiler, target.target,
282+
"run-pass", "run-pass-fulldeps");
283+
}
284+
CheckCFailFull { compiler } => {
285+
check::compiletest(self, &compiler, target.target,
286+
"compile-fail", "compile-fail-fulldeps")
287+
}
233288

234289
DistDocs { stage } => dist::docs(self, stage, target.target),
235290
DistMingw { _dummy } => dist::mingw(self, target.target),
@@ -436,7 +491,8 @@ impl Build {
436491
let suffix = match mode {
437492
Mode::Libstd => "-std",
438493
Mode::Libtest => "-test",
439-
Mode::Tool | Mode::Librustc => "-rustc",
494+
Mode::Tool => "-tools",
495+
Mode::Librustc => "-rustc",
440496
};
441497
self.out.join(compiler.host)
442498
.join(format!("stage{}{}", compiler.stage, suffix))
@@ -457,11 +513,39 @@ impl Build {
457513
self.out.join(target).join("llvm")
458514
}
459515

516+
/// Returns the path to `llvm-config` for the specified target
517+
fn llvm_config(&self, target: &str) -> PathBuf {
518+
let target_config = self.config.target_config.get(target);
519+
if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
520+
s.clone()
521+
} else {
522+
self.llvm_out(&self.config.build).join("bin")
523+
.join(exe("llvm-config", target))
524+
}
525+
}
526+
527+
/// Returns the path to `llvm-config` for the specified target
528+
fn llvm_filecheck(&self, target: &str) -> PathBuf {
529+
let target_config = self.config.target_config.get(target);
530+
if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
531+
s.parent().unwrap().join(exe("FileCheck", target))
532+
} else {
533+
self.llvm_out(&self.config.build).join("build/bin")
534+
.join(exe("FileCheck", target))
535+
}
536+
}
537+
460538
/// Root output directory for compiler-rt compiled for `target`
461539
fn compiler_rt_out(&self, target: &str) -> PathBuf {
462540
self.out.join(target).join("compiler-rt")
463541
}
464542

543+
/// Root output directory for rust_test_helpers library compiled for
544+
/// `target`
545+
fn test_helpers_out(&self, target: &str) -> PathBuf {
546+
self.out.join(target).join("rust-test-helpers")
547+
}
548+
465549
fn add_rustc_lib_path(&self, compiler: &Compiler, cmd: &mut Command) {
466550
// Windows doesn't need dylib path munging because the dlls for the
467551
// compiler live next to the compiler and the system will find them

src/bootstrap/build/native.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ use std::fs;
1414

1515
use build_helper::output;
1616
use cmake;
17+
use gcc;
1718

1819
use build::Build;
19-
use build::util::{exe, staticlib};
20+
use build::util::{exe, staticlib, up_to_date};
2021

2122
pub fn llvm(build: &Build, target: &str) {
2223
// If we're using a custom LLVM bail out here, but we can only use a
@@ -149,9 +150,7 @@ pub fn compiler_rt(build: &Build, target: &str) {
149150
}
150151
let _ = fs::remove_dir_all(&dst);
151152
t!(fs::create_dir_all(&dst));
152-
let build_llvm_config = build.llvm_out(&build.config.build)
153-
.join("bin")
154-
.join(exe("llvm-config", &build.config.build));
153+
let build_llvm_config = build.llvm_config(&build.config.build);
155154
let mut cfg = cmake::Config::new(build.src.join("src/compiler-rt"));
156155
cfg.target(target)
157156
.host(&build.config.build)
@@ -168,3 +167,23 @@ pub fn compiler_rt(build: &Build, target: &str) {
168167
.build_target(&build_target);
169168
cfg.build();
170169
}
170+
171+
pub fn test_helpers(build: &Build, target: &str) {
172+
let dst = build.test_helpers_out(target);
173+
let src = build.src.join("src/rt/rust_test_helpers.c");
174+
if up_to_date(&src, &dst.join("librust_test_helpers.a")) {
175+
return
176+
}
177+
178+
println!("Building test helpers");
179+
t!(fs::create_dir_all(&dst));
180+
let mut cfg = gcc::Config::new();
181+
cfg.cargo_metadata(false)
182+
.out_dir(&dst)
183+
.target(target)
184+
.host(&build.config.build)
185+
.opt_level(0)
186+
.debug(false)
187+
.file(build.src.join("src/rt/rust_test_helpers.c"))
188+
.compile("librust_test_helpers.a");
189+
}

src/bootstrap/build/sanity.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ pub fn check(build: &mut Build) {
6363
need_cmd(build.cxx(host).as_ref());
6464
}
6565

66+
// Externally configured LLVM requires FileCheck to exist
67+
let filecheck = build.llvm_filecheck(&build.config.build);
68+
if !filecheck.starts_with(&build.out) && !filecheck.exists() {
69+
panic!("filecheck executable {:?} does not exist", filecheck);
70+
}
71+
6672
for target in build.config.target.iter() {
6773
// Either can't build or don't want to run jemalloc on these targets
6874
if target.contains("rumprun") ||

0 commit comments

Comments
 (0)