Skip to content

Commit 3147de8

Browse files
committed
Auto merge of #32755 - alexcrichton:rustbuild-start-test, r=brson
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.
2 parents a4f781e + 808116f commit 3147de8

23 files changed

+418
-53
lines changed

mk/crates.mk

+1-1
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

-1
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

+1-1
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

+55
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,55 @@ 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+
if let Some(ref vers) = build.gdb_version {
77+
cmd.arg("--gdb-version").arg(vers);
78+
}
79+
if let Some(ref vers) = build.lldb_version {
80+
cmd.arg("--lldb-version").arg(vers);
81+
}
82+
83+
cmd.args(&build.flags.args);
84+
85+
if build.config.verbose || build.flags.verbose {
86+
cmd.arg("--verbose");
87+
}
88+
89+
build.run(&mut cmd);
90+
}

src/bootstrap/build/compile.rs

+1-8
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/dist.rs

+30-23
Original file line numberDiff line numberDiff line change
@@ -195,29 +195,7 @@ pub fn rustc(build: &Build, stage: u32, host: &str) {
195195
cp_r(&build.src.join("man"), &image.join("share/man/man1"));
196196

197197
// Debugger scripts
198-
let cp_debugger_script = |file: &str| {
199-
let dst = image.join("lib/rustlib/etc");
200-
t!(fs::create_dir_all(&dst));
201-
install(&build.src.join("src/etc/").join(file), &dst, 0o644);
202-
};
203-
if host.contains("windows") {
204-
// no debugger scripts
205-
} else if host.contains("darwin") {
206-
// lldb debugger scripts
207-
install(&build.src.join("src/etc/rust-lldb"), &image.join("bin"),
208-
0o755);
209-
210-
cp_debugger_script("lldb_rust_formatters.py");
211-
cp_debugger_script("debugger_pretty_printers_common.py");
212-
} else {
213-
// gdb debugger scripts
214-
install(&build.src.join("src/etc/rust-gdb"), &image.join("bin"),
215-
0o755);
216-
217-
cp_debugger_script("gdb_load_rust_pretty_printers.py");
218-
cp_debugger_script("gdb_rust_pretty_printing.py");
219-
cp_debugger_script("debugger_pretty_printers_common.py");
220-
}
198+
debugger_scripts(build, &image, host);
221199

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

212+
pub fn debugger_scripts(build: &Build,
213+
sysroot: &Path,
214+
host: &str) {
215+
let cp_debugger_script = |file: &str| {
216+
let dst = sysroot.join("lib/rustlib/etc");
217+
t!(fs::create_dir_all(&dst));
218+
install(&build.src.join("src/etc/").join(file), &dst, 0o644);
219+
};
220+
if host.contains("windows") {
221+
// no debugger scripts
222+
} else if host.contains("darwin") {
223+
// lldb debugger scripts
224+
install(&build.src.join("src/etc/rust-lldb"), &sysroot.join("bin"),
225+
0o755);
226+
227+
cp_debugger_script("lldb_rust_formatters.py");
228+
cp_debugger_script("debugger_pretty_printers_common.py");
229+
} else {
230+
// gdb debugger scripts
231+
install(&build.src.join("src/etc/rust-gdb"), &sysroot.join("bin"),
232+
0o755);
233+
234+
cp_debugger_script("gdb_load_rust_pretty_printers.py");
235+
cp_debugger_script("gdb_rust_pretty_printing.py");
236+
cp_debugger_script("debugger_pretty_printers_common.py");
237+
}
238+
}
239+
240+
234241
pub fn std(build: &Build, compiler: &Compiler, target: &str) {
235242
println!("Dist std stage{} ({} -> {})", compiler.stage, compiler.host,
236243
target);

src/bootstrap/build/flags.rs

-5
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

+101-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ pub struct Build {
8080
package_vers: String,
8181
bootstrap_key: String,
8282

83+
// Probed tools at runtime
84+
gdb_version: Option<String>,
85+
lldb_version: Option<String>,
86+
8387
// Runtime state filled in later on
8488
cc: HashMap<String, (gcc::Tool, PathBuf)>,
8589
cxx: HashMap<String, gcc::Tool>,
@@ -128,6 +132,8 @@ impl Build {
128132
cc: HashMap::new(),
129133
cxx: HashMap::new(),
130134
compiler_rt_built: RefCell::new(HashMap::new()),
135+
gdb_version: None,
136+
lldb_version: None,
131137
}
132138
}
133139

@@ -160,6 +166,9 @@ impl Build {
160166
CompilerRt { _dummy } => {
161167
native::compiler_rt(self, target.target);
162168
}
169+
TestHelpers { _dummy } => {
170+
native::test_helpers(self, target.target);
171+
}
163172
Libstd { compiler } => {
164173
compile::std(self, target.target, &compiler);
165174
}
@@ -197,6 +206,9 @@ impl Build {
197206
ToolCargoTest { stage } => {
198207
compile::tool(self, stage, target.target, "cargotest");
199208
}
209+
ToolCompiletest { stage } => {
210+
compile::tool(self, stage, target.target, "compiletest");
211+
}
200212
DocBook { stage } => {
201213
doc::rustbook(self, stage, target.target, "book", &doc_out);
202214
}
@@ -230,12 +242,68 @@ impl Build {
230242
CheckCargoTest { stage } => {
231243
check::cargotest(self, stage, target.target);
232244
}
245+
CheckRPass { compiler } => {
246+
check::compiletest(self, &compiler, target.target,
247+
"run-pass", "run-pass");
248+
}
249+
CheckCFail { compiler } => {
250+
check::compiletest(self, &compiler, target.target,
251+
"compile-fail", "compile-fail");
252+
}
253+
CheckPFail { compiler } => {
254+
check::compiletest(self, &compiler, target.target,
255+
"parse-fail", "parse-fail");
256+
}
257+
CheckRFail { compiler } => {
258+
check::compiletest(self, &compiler, target.target,
259+
"run-fail", "run-fail");
260+
}
261+
CheckPretty { compiler } => {
262+
check::compiletest(self, &compiler, target.target,
263+
"pretty", "pretty");
264+
}
265+
CheckCodegen { compiler } => {
266+
check::compiletest(self, &compiler, target.target,
267+
"codegen", "codegen");
268+
}
269+
CheckCodegenUnits { compiler } => {
270+
check::compiletest(self, &compiler, target.target,
271+
"codegen-units", "codegen-units");
272+
}
273+
CheckDebuginfo { compiler } => {
274+
// TODO: select between gdb/lldb
275+
check::compiletest(self, &compiler, target.target,
276+
"debuginfo-gdb", "debuginfo");
277+
}
278+
CheckRustdoc { compiler } => {
279+
check::compiletest(self, &compiler, target.target,
280+
"rustdoc", "rustdoc");
281+
}
282+
CheckRPassValgrind { compiler } => {
283+
check::compiletest(self, &compiler, target.target,
284+
"run-pass-valgrind", "run-pass-valgrind");
285+
}
286+
CheckRPassFull { compiler } => {
287+
check::compiletest(self, &compiler, target.target,
288+
"run-pass", "run-pass-fulldeps");
289+
}
290+
CheckCFailFull { compiler } => {
291+
check::compiletest(self, &compiler, target.target,
292+
"compile-fail", "compile-fail-fulldeps")
293+
}
233294

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

300+
DebuggerScripts { stage } => {
301+
let compiler = Compiler::new(stage, target.target);
302+
dist::debugger_scripts(self,
303+
&self.sysroot(&compiler),
304+
target.target);
305+
}
306+
239307
Dist { .. } |
240308
Doc { .. } | // pseudo-steps
241309
Check { .. } => {}
@@ -436,7 +504,8 @@ impl Build {
436504
let suffix = match mode {
437505
Mode::Libstd => "-std",
438506
Mode::Libtest => "-test",
439-
Mode::Tool | Mode::Librustc => "-rustc",
507+
Mode::Tool => "-tools",
508+
Mode::Librustc => "-rustc",
440509
};
441510
self.out.join(compiler.host)
442511
.join(format!("stage{}{}", compiler.stage, suffix))
@@ -457,11 +526,39 @@ impl Build {
457526
self.out.join(target).join("llvm")
458527
}
459528

529+
/// Returns the path to `llvm-config` for the specified target
530+
fn llvm_config(&self, target: &str) -> PathBuf {
531+
let target_config = self.config.target_config.get(target);
532+
if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
533+
s.clone()
534+
} else {
535+
self.llvm_out(&self.config.build).join("bin")
536+
.join(exe("llvm-config", target))
537+
}
538+
}
539+
540+
/// Returns the path to `llvm-config` for the specified target
541+
fn llvm_filecheck(&self, target: &str) -> PathBuf {
542+
let target_config = self.config.target_config.get(target);
543+
if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
544+
s.parent().unwrap().join(exe("FileCheck", target))
545+
} else {
546+
self.llvm_out(&self.config.build).join("build/bin")
547+
.join(exe("FileCheck", target))
548+
}
549+
}
550+
460551
/// Root output directory for compiler-rt compiled for `target`
461552
fn compiler_rt_out(&self, target: &str) -> PathBuf {
462553
self.out.join(target).join("compiler-rt")
463554
}
464555

556+
/// Root output directory for rust_test_helpers library compiled for
557+
/// `target`
558+
fn test_helpers_out(&self, target: &str) -> PathBuf {
559+
self.out.join(target).join("rust-test-helpers")
560+
}
561+
465562
fn add_rustc_lib_path(&self, compiler: &Compiler, cmd: &mut Command) {
466563
// Windows doesn't need dylib path munging because the dlls for the
467564
// compiler live next to the compiler and the system will find them
@@ -504,8 +601,11 @@ impl Build {
504601
}
505602

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

511611
// If we're compiling on OSX then we add a few unconditional flags

0 commit comments

Comments
 (0)