blob: a07505edc2eb8724b9889b8cfc0eee15f007def5 [file] [log] [blame]
Alex Crichtondefd1b32016-03-08 07:15:551// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
Alex Crichton0e272de2016-11-16 20:31:1911//! Implementation of the test-related targets of the build system.
Alex Crichtonf72bfe62016-05-02 22:16:1512//!
13//! This file implements the various regression test suites that we execute on
14//! our CI.
15
Alex Crichtona270b802016-10-21 20:18:0916use std::collections::HashSet;
Alex Crichtonbb9062a2016-04-29 21:23:1517use std::env;
Nick Cameron04415dc2017-06-30 18:58:5418use std::ffi::OsString;
Mark Simulacrum5b44cbc2017-06-26 16:23:5019use std::iter;
Ulrik Sverdrupb1566ba2016-11-25 21:13:5920use std::fmt;
Mark Simulacrumdd1d75e2017-06-04 23:55:5021use std::fs::{self, File};
Alex Crichtonede89442016-04-15 01:00:3522use std::path::{PathBuf, Path};
23use std::process::Command;
Mark Simulacrumdd1d75e2017-06-04 23:55:5024use std::io::Read;
Alex Crichton73c2d2a2016-04-14 21:27:5125
Mark Simulacrum5b44cbc2017-06-26 16:23:5026use build_helper::{self, output};
Alex Crichton126e09e2016-04-14 22:51:0327
Mark Simulacrum001e9f32017-07-05 01:41:4328use {Build, Mode};
Alex Crichtond38db822016-12-09 01:13:5529use dist;
Mark Simulacrum001e9f32017-07-05 01:41:4330use util::{self, dylib_path, dylib_path_var};
31
32use compile;
33use native;
Mark Simulacrum6a67a052017-07-20 23:51:0734use builder::{Kind, RunConfig, ShouldRun, Builder, Compiler, Step};
Mark Simulacrumceecd622017-07-12 16:12:4735use tool::{self, Tool};
Mark Simulacrum528646e2017-07-14 00:48:4436use cache::{INTERNER, Interned};
Alex Crichton39a5d3f2016-06-28 20:31:3037
Mark Simulacrum5b44cbc2017-06-26 16:23:5038const ADB_TEST_DIR: &str = "/data/tmp/work";
Alex Crichtondefd1b32016-03-08 07:15:5539
Ulrik Sverdrupb1566ba2016-11-25 21:13:5940/// The two modes of the test runner; tests or benchmarks.
Mark Simulacrum528646e2017-07-14 00:48:4441#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone)]
Ulrik Sverdrupb1566ba2016-11-25 21:13:5942pub enum TestKind {
43 /// Run `cargo test`
44 Test,
45 /// Run `cargo bench`
46 Bench,
47}
48
49impl TestKind {
50 // Return the cargo subcommand for this test kind
51 fn subcommand(self) -> &'static str {
52 match self {
53 TestKind::Test => "test",
54 TestKind::Bench => "bench",
55 }
56 }
57}
58
59impl fmt::Display for TestKind {
60 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
61 f.write_str(match *self {
62 TestKind::Test => "Testing",
63 TestKind::Bench => "Benchmarking",
64 })
65 }
66}
67
Josh Stone617aea42017-06-02 16:27:4468fn try_run(build: &Build, cmd: &mut Command) {
Mark Simulacrum4dc8fe92017-06-27 19:37:2469 if !build.fail_fast {
Josh Stone617aea42017-06-02 16:27:4470 if !build.try_run(cmd) {
71 let failures = build.delayed_failures.get();
72 build.delayed_failures.set(failures + 1);
73 }
74 } else {
75 build.run(cmd);
76 }
77}
78
79fn try_run_quiet(build: &Build, cmd: &mut Command) {
Mark Simulacrum4dc8fe92017-06-27 19:37:2480 if !build.fail_fast {
Josh Stone617aea42017-06-02 16:27:4481 if !build.try_run_quiet(cmd) {
82 let failures = build.delayed_failures.get();
83 build.delayed_failures.set(failures + 1);
84 }
85 } else {
86 build.run_quiet(cmd);
87 }
88}
89
Mark Simulacrum528646e2017-07-14 00:48:4490#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
91pub struct Linkcheck {
92 host: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:4393}
94
Mark Simulacrum528646e2017-07-14 00:48:4495impl Step for Linkcheck {
Mark Simulacrum001e9f32017-07-05 01:41:4396 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:2797 const ONLY_HOSTS: bool = true;
98 const DEFAULT: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:4399
100 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
101 ///
102 /// This tool in `src/tools` will verify the validity of all our links in the
103 /// documentation to ensure we don't have a bunch of dead ones.
104 fn run(self, builder: &Builder) {
105 let build = builder.build;
106 let host = self.host;
107
108 println!("Linkcheck ({})", host);
Mark Simulacrum6b3413d2017-07-05 12:41:27109
110 builder.default_doc(None);
Mark Simulacrum001e9f32017-07-05 01:41:43111
112 let _time = util::timeit();
Mark Simulacrum6b3413d2017-07-05 12:41:27113 try_run(build, builder.tool_cmd(Tool::Linkchecker)
Mark Simulacrum001e9f32017-07-05 01:41:43114 .arg(build.out.join(host).join("doc")));
115 }
Mark Simulacrum6b3413d2017-07-05 12:41:27116
Mark Simulacrum56128fb2017-07-19 00:03:38117 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumb05af492017-07-20 23:24:11118 let builder = run.builder;
119 run.path("src/tools/linkchecker").default_condition(builder.build.config.docs)
Mark Simulacrum6b3413d2017-07-05 12:41:27120 }
121
Mark Simulacrum6a67a052017-07-20 23:51:07122 fn make_run(run: RunConfig) {
123 run.builder.ensure(Linkcheck { host: run.host });
Mark Simulacrum6b3413d2017-07-05 12:41:27124 }
Alex Crichtondefd1b32016-03-08 07:15:55125}
Brian Anderson3a790ac2016-03-18 20:54:31126
Mark Simulacrum528646e2017-07-14 00:48:44127#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
128pub struct Cargotest {
Mark Simulacrum001e9f32017-07-05 01:41:43129 stage: u32,
Mark Simulacrum528646e2017-07-14 00:48:44130 host: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:43131}
Alex Crichton73c2d2a2016-04-14 21:27:51132
Mark Simulacrum528646e2017-07-14 00:48:44133impl Step for Cargotest {
Mark Simulacrum001e9f32017-07-05 01:41:43134 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27135 const ONLY_HOSTS: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:43136
Mark Simulacrum56128fb2017-07-19 00:03:38137 fn should_run(run: ShouldRun) -> ShouldRun {
138 run.path("src/tools/cargotest")
Mark Simulacrumceecd622017-07-12 16:12:47139 }
140
Mark Simulacrum6a67a052017-07-20 23:51:07141 fn make_run(run: RunConfig) {
142 run.builder.ensure(Cargotest {
143 stage: run.builder.top_stage,
144 host: run.host,
Mark Simulacrumceecd622017-07-12 16:12:47145 });
146 }
147
Mark Simulacrum001e9f32017-07-05 01:41:43148 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
149 ///
150 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
151 /// test` to ensure that we don't regress the test suites there.
152 fn run(self, builder: &Builder) {
153 let build = builder.build;
Mark Simulacrum60388302017-07-05 16:46:41154 let compiler = builder.compiler(self.stage, self.host);
Mark Simulacrum6b3413d2017-07-05 12:41:27155 builder.ensure(compile::Rustc { compiler, target: compiler.host });
Mark Simulacrum001e9f32017-07-05 01:41:43156
157 // Note that this is a short, cryptic, and not scoped directory name. This
158 // is currently to minimize the length of path on Windows where we otherwise
159 // quickly run into path name limit constraints.
160 let out_dir = build.out.join("ct");
161 t!(fs::create_dir_all(&out_dir));
162
163 let _time = util::timeit();
Mark Simulacrum6b3413d2017-07-05 12:41:27164 let mut cmd = builder.tool_cmd(Tool::CargoTest);
Mark Simulacrum001e9f32017-07-05 01:41:43165 try_run(build, cmd.arg(&build.initial_cargo)
166 .arg(&out_dir)
Mark Simulacrumc114fe52017-07-05 17:21:33167 .env("RUSTC", builder.rustc(compiler))
168 .env("RUSTDOC", builder.rustdoc(compiler)));
Mark Simulacrum001e9f32017-07-05 01:41:43169 }
Alex Crichton009f45f2017-04-18 00:24:05170}
171
Mark Simulacrum528646e2017-07-14 00:48:44172#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
173pub struct Cargo {
Mark Simulacrum001e9f32017-07-05 01:41:43174 stage: u32,
Mark Simulacrum528646e2017-07-14 00:48:44175 host: Interned<String>,
Nick Cameron04415dc2017-06-30 18:58:54176}
177
Mark Simulacrum528646e2017-07-14 00:48:44178impl Step for Cargo {
Mark Simulacrum001e9f32017-07-05 01:41:43179 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27180 const ONLY_HOSTS: bool = true;
181
Mark Simulacrum56128fb2017-07-19 00:03:38182 fn should_run(run: ShouldRun) -> ShouldRun {
183 run.path("src/tools/cargo")
Mark Simulacrum6b3413d2017-07-05 12:41:27184 }
185
Mark Simulacrum6a67a052017-07-20 23:51:07186 fn make_run(run: RunConfig) {
187 run.builder.ensure(Cargo {
188 stage: run.builder.top_stage,
189 host: run.target,
Mark Simulacrum6b3413d2017-07-05 12:41:27190 });
191 }
Nick Cameron04415dc2017-06-30 18:58:54192
Mark Simulacrum001e9f32017-07-05 01:41:43193 /// Runs `cargo test` for `cargo` packaged with Rust.
194 fn run(self, builder: &Builder) {
195 let build = builder.build;
Mark Simulacrum6b3413d2017-07-05 12:41:27196 let compiler = builder.compiler(self.stage, self.host);
Nick Cameron04415dc2017-06-30 18:58:54197
Mark Simulacrum4a21c722017-07-20 12:27:13198 builder.ensure(tool::Cargo { stage: self.stage, target: self.host });
Mark Simulacrumc114fe52017-07-05 17:21:33199 let mut cargo = builder.cargo(compiler, Mode::Tool, self.host, "test");
Mark Simulacrum001e9f32017-07-05 01:41:43200 cargo.arg("--manifest-path").arg(build.src.join("src/tools/cargo/Cargo.toml"));
201 if !build.fail_fast {
202 cargo.arg("--no-fail-fast");
203 }
Nick Cameron04415dc2017-06-30 18:58:54204
Mark Simulacrum001e9f32017-07-05 01:41:43205 // Don't build tests dynamically, just a pain to work with
206 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
207
208 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
209 // available.
210 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
211
Mark Simulacrumdec44b02017-07-17 15:52:05212 try_run(build, cargo.env("PATH", &path_for_cargo(builder, compiler)));
Mark Simulacrum001e9f32017-07-05 01:41:43213 }
214}
215
Mark Simulacrumdec44b02017-07-17 15:52:05216#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
217pub struct Rls {
Mark Simulacrum001e9f32017-07-05 01:41:43218 stage: u32,
Mark Simulacrumdec44b02017-07-17 15:52:05219 host: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:43220}
221
Mark Simulacrumdec44b02017-07-17 15:52:05222impl Step for Rls {
Mark Simulacrum001e9f32017-07-05 01:41:43223 type Output = ();
Mark Simulacrumdec44b02017-07-17 15:52:05224 const ONLY_HOSTS: bool = true;
225
Mark Simulacrum56128fb2017-07-19 00:03:38226 fn should_run(run: ShouldRun) -> ShouldRun {
227 run.path("src/tools/rls")
Mark Simulacrumdec44b02017-07-17 15:52:05228 }
229
Mark Simulacrum6a67a052017-07-20 23:51:07230 fn make_run(run: RunConfig) {
231 run.builder.ensure(Rls {
232 stage: run.builder.top_stage,
233 host: run.target,
Mark Simulacrumdec44b02017-07-17 15:52:05234 });
235 }
Mark Simulacrum001e9f32017-07-05 01:41:43236
237 /// Runs `cargo test` for the rls.
238 fn run(self, builder: &Builder) {
239 let build = builder.build;
240 let stage = self.stage;
241 let host = self.host;
Mark Simulacrumdec44b02017-07-17 15:52:05242 let compiler = builder.compiler(stage, host);
Mark Simulacrum001e9f32017-07-05 01:41:43243
Mark Simulacrum4a21c722017-07-20 12:27:13244 builder.ensure(tool::Rls { stage: self.stage, target: self.host });
Mark Simulacrumdec44b02017-07-17 15:52:05245 let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
Mark Simulacrum001e9f32017-07-05 01:41:43246 cargo.arg("--manifest-path").arg(build.src.join("src/tools/rls/Cargo.toml"));
247
248 // Don't build tests dynamically, just a pain to work with
249 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
250
Mark Simulacrumdec44b02017-07-17 15:52:05251 builder.add_rustc_lib_path(compiler, &mut cargo);
Mark Simulacrum001e9f32017-07-05 01:41:43252
253 try_run(build, &mut cargo);
254 }
Nick Cameron04415dc2017-06-30 18:58:54255}
256
Mark Simulacrumdec44b02017-07-17 15:52:05257fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
Nick Cameron04415dc2017-06-30 18:58:54258 // Configure PATH to find the right rustc. NB. we have to use PATH
259 // and not RUSTC because the Cargo test suite has tests that will
260 // fail if rustc is not spelled `rustc`.
Mark Simulacrumdec44b02017-07-17 15:52:05261 let path = builder.sysroot(compiler).join("bin");
Nick Cameron04415dc2017-06-30 18:58:54262 let old_path = env::var_os("PATH").unwrap_or_default();
263 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
Brian Anderson3a790ac2016-03-18 20:54:31264}
Alex Crichton9dd3c542016-03-29 20:14:52265
Mark Simulacrum528646e2017-07-14 00:48:44266#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
267pub struct Tidy {
268 host: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:43269}
270
Mark Simulacrum528646e2017-07-14 00:48:44271impl Step for Tidy {
Mark Simulacrum001e9f32017-07-05 01:41:43272 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27273 const DEFAULT: bool = true;
274 const ONLY_HOSTS: bool = true;
275 const ONLY_BUILD: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:43276
277 /// Runs the `tidy` tool as compiled in `stage` by the `host` compiler.
278 ///
279 /// This tool in `src/tools` checks up on various bits and pieces of style and
280 /// otherwise just implements a few lint-like checks that are specific to the
281 /// compiler itself.
282 fn run(self, builder: &Builder) {
283 let build = builder.build;
284 let host = self.host;
285
286 let _folder = build.fold_output(|| "tidy");
287 println!("tidy check ({})", host);
Mark Simulacrum60388302017-07-05 16:46:41288 let mut cmd = builder.tool_cmd(Tool::Tidy);
Mark Simulacrum001e9f32017-07-05 01:41:43289 cmd.arg(build.src.join("src"));
290 if !build.config.vendor {
291 cmd.arg("--no-vendor");
292 }
293 if build.config.quiet_tests {
294 cmd.arg("--quiet");
295 }
296 try_run(build, &mut cmd);
Eduard-Mihai Burtescud29f0bc2017-02-10 20:59:40297 }
Mark Simulacrum6b3413d2017-07-05 12:41:27298
Mark Simulacrum56128fb2017-07-19 00:03:38299 fn should_run(run: ShouldRun) -> ShouldRun {
300 run.path("src/tools/tidy")
Mark Simulacrum6b3413d2017-07-05 12:41:27301 }
302
Mark Simulacrum6a67a052017-07-20 23:51:07303 fn make_run(run: RunConfig) {
304 run.builder.ensure(Tidy {
305 host: run.builder.build.build,
Mark Simulacrum6b3413d2017-07-05 12:41:27306 });
307 }
Alex Crichton9dd3c542016-03-29 20:14:52308}
Alex Crichtonb325baf2016-04-05 18:34:23309
Mark Simulacrum528646e2017-07-14 00:48:44310fn testdir(build: &Build, host: Interned<String>) -> PathBuf {
Alex Crichtonb325baf2016-04-05 18:34:23311 build.out.join(host).join("test")
312}
313
Mark Simulacrum528646e2017-07-14 00:48:44314#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum1ab89302017-07-07 17:51:57315struct Test {
Mark Simulacrum1ab89302017-07-07 17:51:57316 path: &'static str,
317 mode: &'static str,
318 suite: &'static str,
319}
320
Mark Simulacrumaa8b93b2017-07-07 18:31:29321static DEFAULT_COMPILETESTS: &[Test] = &[
322 Test { path: "src/test/ui", mode: "ui", suite: "ui" },
323 Test { path: "src/test/run-pass", mode: "run-pass", suite: "run-pass" },
324 Test { path: "src/test/compile-fail", mode: "compile-fail", suite: "compile-fail" },
325 Test { path: "src/test/parse-fail", mode: "parse-fail", suite: "parse-fail" },
326 Test { path: "src/test/run-fail", mode: "run-fail", suite: "run-fail" },
Mark Simulacrum1ab89302017-07-07 17:51:57327 Test {
Mark Simulacrum1ab89302017-07-07 17:51:57328 path: "src/test/run-pass-valgrind",
329 mode: "run-pass-valgrind",
330 suite: "run-pass-valgrind"
331 },
Mark Simulacrumaa8b93b2017-07-07 18:31:29332 Test { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" },
333 Test { path: "src/test/codegen", mode: "codegen", suite: "codegen" },
334 Test { path: "src/test/codegen-units", mode: "codegen-units", suite: "codegen-units" },
335 Test { path: "src/test/incremental", mode: "incremental", suite: "incremental" },
Mark Simulacrum6b3413d2017-07-05 12:41:27336
Mark Simulacrumaa8b93b2017-07-07 18:31:29337 // What this runs varies depending on the native platform being apple
338 Test { path: "src/test/debuginfo", mode: "debuginfo-XXX", suite: "debuginfo" },
Mark Simulacrumaa8b93b2017-07-07 18:31:29339];
Mark Simulacrum6b3413d2017-07-05 12:41:27340
Mark Simulacrumf1d04a32017-07-20 15:42:18341#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
342pub struct DefaultCompiletest {
343 compiler: Compiler,
344 target: Interned<String>,
345 mode: &'static str,
346 suite: &'static str,
347}
348
349impl Step for DefaultCompiletest {
350 type Output = ();
351 const DEFAULT: bool = true;
352
353 fn should_run(mut run: ShouldRun) -> ShouldRun {
354 for test in DEFAULT_COMPILETESTS {
355 run = run.path(test.path);
356 }
357 run
358 }
359
Mark Simulacrum6a67a052017-07-20 23:51:07360 fn make_run(run: RunConfig) {
361 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
Mark Simulacrumf1d04a32017-07-20 15:42:18362
Mark Simulacrum6a67a052017-07-20 23:51:07363 let test = run.path.map(|path| {
Mark Simulacrumf1d04a32017-07-20 15:42:18364 DEFAULT_COMPILETESTS.iter().find(|&&test| {
365 path.ends_with(test.path)
366 }).unwrap_or_else(|| {
367 panic!("make_run in compile test to receive test path, received {:?}", path);
368 })
369 });
370
371 if let Some(test) = test {
Mark Simulacrum6a67a052017-07-20 23:51:07372 run.builder.ensure(DefaultCompiletest {
Mark Simulacrumf1d04a32017-07-20 15:42:18373 compiler,
Mark Simulacrum6a67a052017-07-20 23:51:07374 target: run.target,
Mark Simulacrumf1d04a32017-07-20 15:42:18375 mode: test.mode,
376 suite: test.suite,
377 });
378 } else {
379 for test in DEFAULT_COMPILETESTS {
Mark Simulacrum6a67a052017-07-20 23:51:07380 run.builder.ensure(DefaultCompiletest {
Mark Simulacrumf1d04a32017-07-20 15:42:18381 compiler,
Mark Simulacrum6a67a052017-07-20 23:51:07382 target: run.target,
Mark Simulacrumf1d04a32017-07-20 15:42:18383 mode: test.mode,
384 suite: test.suite
385 });
386 }
387 }
388 }
389
390 fn run(self, builder: &Builder) {
391 builder.ensure(Compiletest {
392 compiler: self.compiler,
393 target: self.target,
394 mode: self.mode,
395 suite: self.suite,
396 })
397 }
398}
399
Mark Simulacrumaa8b93b2017-07-07 18:31:29400// Also default, but host-only.
401static HOST_COMPILETESTS: &[Test] = &[
402 Test { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" },
403 Test { path: "src/test/run-pass-fulldeps", mode: "run-pass", suite: "run-pass-fulldeps" },
404 Test { path: "src/test/run-fail-fulldeps", mode: "run-fail", suite: "run-fail-fulldeps" },
Mark Simulacrum1ab89302017-07-07 17:51:57405 Test {
Mark Simulacrum1ab89302017-07-07 17:51:57406 path: "src/test/compile-fail-fulldeps",
407 mode: "compile-fail",
408 suite: "compile-fail-fulldeps",
409 },
Mark Simulacrumaa8b93b2017-07-07 18:31:29410 Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
411 Test { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" },
Mark Simulacrum6b3413d2017-07-05 12:41:27412
Mark Simulacrumaa8b93b2017-07-07 18:31:29413 Test { path: "src/test/pretty", mode: "pretty", suite: "pretty" },
414 Test { path: "src/test/run-pass/pretty", mode: "pretty", suite: "run-pass" },
415 Test { path: "src/test/run-fail/pretty", mode: "pretty", suite: "run-fail" },
416 Test { path: "src/test/run-pass-valgrind/pretty", mode: "pretty", suite: "run-pass-valgrind" },
417 Test { path: "src/test/run-pass-fulldeps/pretty", mode: "pretty", suite: "run-pass-fulldeps" },
418 Test { path: "src/test/run-fail-fulldeps/pretty", mode: "pretty", suite: "run-fail-fulldeps" },
Mark Simulacrum6b3413d2017-07-05 12:41:27419];
420
Mark Simulacrumf1d04a32017-07-20 15:42:18421#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
422pub struct HostCompiletest {
423 compiler: Compiler,
424 target: Interned<String>,
425 mode: &'static str,
426 suite: &'static str,
427}
Mark Simulacrum6b3413d2017-07-05 12:41:27428
Mark Simulacrumf1d04a32017-07-20 15:42:18429impl Step for HostCompiletest {
Mark Simulacrum001e9f32017-07-05 01:41:43430 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27431 const DEFAULT: bool = true;
Mark Simulacrumf1d04a32017-07-20 15:42:18432 const ONLY_HOSTS: bool = true;
Mark Simulacrum6b3413d2017-07-05 12:41:27433
Mark Simulacrum56128fb2017-07-19 00:03:38434 fn should_run(mut run: ShouldRun) -> ShouldRun {
Mark Simulacrumf1d04a32017-07-20 15:42:18435 for test in HOST_COMPILETESTS {
Mark Simulacrum56128fb2017-07-19 00:03:38436 run = run.path(test.path);
437 }
438 run
Mark Simulacrum6b3413d2017-07-05 12:41:27439 }
440
Mark Simulacrum6a67a052017-07-20 23:51:07441 fn make_run(run: RunConfig) {
442 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:27443
Mark Simulacrum6a67a052017-07-20 23:51:07444 let test = run.path.map(|path| {
Mark Simulacrumf1d04a32017-07-20 15:42:18445 HOST_COMPILETESTS.iter().find(|&&test| {
Mark Simulacrum1ab89302017-07-07 17:51:57446 path.ends_with(test.path)
Mark Simulacrum6b3413d2017-07-05 12:41:27447 }).unwrap_or_else(|| {
448 panic!("make_run in compile test to receive test path, received {:?}", path);
449 })
450 });
451
Mark Simulacrumf1d04a32017-07-20 15:42:18452 if let Some(test) = test {
Mark Simulacrum6a67a052017-07-20 23:51:07453 run.builder.ensure(HostCompiletest {
Mark Simulacrumf1d04a32017-07-20 15:42:18454 compiler,
Mark Simulacrum6a67a052017-07-20 23:51:07455 target: run.target,
Mark Simulacrumf1d04a32017-07-20 15:42:18456 mode: test.mode,
457 suite: test.suite,
Mark Simulacrum6b3413d2017-07-05 12:41:27458 });
Mark Simulacrumf1d04a32017-07-20 15:42:18459 } else {
460 for test in HOST_COMPILETESTS {
Mark Simulacrum6a67a052017-07-20 23:51:07461 run.builder.ensure(HostCompiletest {
Mark Simulacrumaa8b93b2017-07-07 18:31:29462 compiler,
Mark Simulacrum6a67a052017-07-20 23:51:07463 target: run.target,
Mark Simulacrumaa8b93b2017-07-07 18:31:29464 mode: test.mode,
465 suite: test.suite
466 });
467 }
Mark Simulacrum6b3413d2017-07-05 12:41:27468 }
469 }
Alex Crichtonf72bfe62016-05-02 22:16:15470
Mark Simulacrumf1d04a32017-07-20 15:42:18471 fn run(self, builder: &Builder) {
472 builder.ensure(Compiletest {
473 compiler: self.compiler,
474 target: self.target,
475 mode: self.mode,
476 suite: self.suite,
477 })
478 }
479}
480
481#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
482struct Compiletest {
483 compiler: Compiler,
484 target: Interned<String>,
485 mode: &'static str,
486 suite: &'static str,
487}
488
489impl Step for Compiletest {
490 type Output = ();
491
492 fn should_run(run: ShouldRun) -> ShouldRun {
493 run.never()
494 }
495
Mark Simulacrum001e9f32017-07-05 01:41:43496 /// Executes the `compiletest` tool to run a suite of tests.
497 ///
498 /// Compiles all tests with `compiler` for `target` with the specified
499 /// compiletest `mode` and `suite` arguments. For example `mode` can be
500 /// "run-pass" or `suite` can be something like `debuginfo`.
501 fn run(self, builder: &Builder) {
502 let build = builder.build;
503 let compiler = self.compiler;
504 let target = self.target;
505 let mode = self.mode;
506 let suite = self.suite;
Mark Simulacrum6b3413d2017-07-05 12:41:27507
508 // Skip codegen tests if they aren't enabled in configuration.
509 if !build.config.codegen_tests && suite == "codegen" {
510 return;
511 }
512
513 if suite == "debuginfo" {
Mark Simulacrum951616c2017-07-20 17:23:29514 // Skip debuginfo tests on MSVC
515 if build.build.contains("msvc") {
516 return;
517 }
518
Mark Simulacrum6b3413d2017-07-05 12:41:27519 if mode == "debuginfo-XXX" {
520 return if build.build.contains("apple") {
521 builder.ensure(Compiletest {
522 mode: "debuginfo-lldb",
523 ..self
Mark Simulacrum528646e2017-07-14 00:48:44524 });
Mark Simulacrum6b3413d2017-07-05 12:41:27525 } else {
526 builder.ensure(Compiletest {
527 mode: "debuginfo-gdb",
528 ..self
Mark Simulacrum528646e2017-07-14 00:48:44529 });
Mark Simulacrum6b3413d2017-07-05 12:41:27530 };
531 }
532
Mark Simulacrum6b3413d2017-07-05 12:41:27533 builder.ensure(dist::DebuggerScripts {
Mark Simulacrum528646e2017-07-14 00:48:44534 sysroot: builder.sysroot(compiler),
Mark Simulacrum5984e702017-07-13 00:52:31535 target: target
Mark Simulacrum6b3413d2017-07-05 12:41:27536 });
537 }
538
539 if suite.ends_with("fulldeps") ||
540 // FIXME: Does pretty need librustc compiled? Note that there are
541 // fulldeps test suites with mode = pretty as well.
542 mode == "pretty" ||
543 mode == "rustdoc" ||
544 mode == "run-make" {
545 builder.ensure(compile::Rustc { compiler, target });
546 }
547
548 builder.ensure(compile::Test { compiler, target });
549 builder.ensure(native::TestHelpers { target });
Mark Simulacrumaa8b93b2017-07-07 18:31:29550 builder.ensure(RemoteCopyLibs { compiler, target });
Mark Simulacrum6b3413d2017-07-05 12:41:27551
Mark Simulacrum001e9f32017-07-05 01:41:43552 let _folder = build.fold_output(|| format!("test_{}", suite));
553 println!("Check compiletest suite={} mode={} ({} -> {})",
Mark Simulacrum528646e2017-07-14 00:48:44554 suite, mode, &compiler.host, target);
Mark Simulacrum6b3413d2017-07-05 12:41:27555 let mut cmd = builder.tool_cmd(Tool::Compiletest);
Alex Crichtonb325baf2016-04-05 18:34:23556
Mark Simulacrum001e9f32017-07-05 01:41:43557 // compiletest currently has... a lot of arguments, so let's just pass all
558 // of them!
Brian Anderson8401e372016-09-15 19:42:26559
Mark Simulacrumc114fe52017-07-05 17:21:33560 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
Mark Simulacrum60388302017-07-05 16:46:41561 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
Mark Simulacrumc114fe52017-07-05 17:21:33562 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
563 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
Mark Simulacrum001e9f32017-07-05 01:41:43564 cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
565 cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
566 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
567 cmd.arg("--mode").arg(mode);
568 cmd.arg("--target").arg(target);
Mark Simulacrum528646e2017-07-14 00:48:44569 cmd.arg("--host").arg(&*compiler.host);
570 cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(build.build));
Alex Crichtonf4e4ec72016-05-13 22:26:41571
Mark Simulacrum001e9f32017-07-05 01:41:43572 if let Some(ref nodejs) = build.config.nodejs {
573 cmd.arg("--nodejs").arg(nodejs);
574 }
Alex Crichtonf4e4ec72016-05-13 22:26:41575
Mark Simulacrum001e9f32017-07-05 01:41:43576 let mut flags = vec!["-Crpath".to_string()];
577 if build.config.rust_optimize_tests {
578 flags.push("-O".to_string());
579 }
580 if build.config.rust_debuginfo_tests {
581 flags.push("-g".to_string());
582 }
Alex Crichtoncbe62922016-04-19 16:44:19583
Mark Simulacrum60388302017-07-05 16:46:41584 let mut hostflags = build.rustc_flags(compiler.host);
Mark Simulacrum001e9f32017-07-05 01:41:43585 hostflags.extend(flags.clone());
586 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
Alex Crichtoncbe62922016-04-19 16:44:19587
Mark Simulacrum528646e2017-07-14 00:48:44588 let mut targetflags = build.rustc_flags(target);
Mark Simulacrum001e9f32017-07-05 01:41:43589 targetflags.extend(flags);
590 targetflags.push(format!("-Lnative={}",
591 build.test_helpers_out(target).display()));
592 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
Alex Crichtonb325baf2016-04-05 18:34:23593
Mark Simulacrum001e9f32017-07-05 01:41:43594 cmd.arg("--docck-python").arg(build.python());
Alex Crichtonb325baf2016-04-05 18:34:23595
Mark Simulacrum001e9f32017-07-05 01:41:43596 if build.build.ends_with("apple-darwin") {
597 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
598 // LLDB plugin's compiled module which only works with the system python
599 // (namely not Homebrew-installed python)
600 cmd.arg("--lldb-python").arg("/usr/bin/python");
601 } else {
602 cmd.arg("--lldb-python").arg(build.python());
603 }
Alex Crichtonb325baf2016-04-05 18:34:23604
Mark Simulacrum001e9f32017-07-05 01:41:43605 if let Some(ref gdb) = build.config.gdb {
606 cmd.arg("--gdb").arg(gdb);
607 }
608 if let Some(ref vers) = build.lldb_version {
609 cmd.arg("--lldb-version").arg(vers);
610 }
611 if let Some(ref dir) = build.lldb_python_dir {
612 cmd.arg("--lldb-python-dir").arg(dir);
613 }
614 let llvm_config = build.llvm_config(target);
615 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
616 cmd.arg("--llvm-version").arg(llvm_version);
617 if !build.is_rust_llvm(target) {
618 cmd.arg("--system-llvm");
619 }
Alex Crichtonb325baf2016-04-05 18:34:23620
Mark Simulacrum001e9f32017-07-05 01:41:43621 cmd.args(&build.flags.cmd.test_args());
Corey Farwellc8c6d2c2016-10-30 01:58:52622
Mark Simulacrum001e9f32017-07-05 01:41:43623 if build.is_verbose() {
624 cmd.arg("--verbose");
625 }
Alex Crichton126e09e2016-04-14 22:51:03626
Mark Simulacrum001e9f32017-07-05 01:41:43627 if build.config.quiet_tests {
628 cmd.arg("--quiet");
629 }
Alex Crichton1747ce22017-01-28 21:38:06630
Mark Simulacrum001e9f32017-07-05 01:41:43631 // Only pass correct values for these flags for the `run-make` suite as it
632 // requires that a C++ compiler was configured which isn't always the case.
633 if suite == "run-make" {
634 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
635 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
636 cmd.arg("--cc").arg(build.cc(target))
637 .arg("--cxx").arg(build.cxx(target).unwrap())
638 .arg("--cflags").arg(build.cflags(target).join(" "))
639 .arg("--llvm-components").arg(llvm_components.trim())
640 .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
641 } else {
642 cmd.arg("--cc").arg("")
643 .arg("--cxx").arg("")
644 .arg("--cflags").arg("")
645 .arg("--llvm-components").arg("")
646 .arg("--llvm-cxxflags").arg("");
647 }
648
649 if build.remote_tested(target) {
Mark Simulacrum6b3413d2017-07-05 12:41:27650 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
Mark Simulacrum001e9f32017-07-05 01:41:43651 }
652
653 // Running a C compiler on MSVC requires a few env vars to be set, to be
654 // sure to set them here.
655 //
656 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
657 // rather than stomp over it.
658 if target.contains("msvc") {
Mark Simulacrum528646e2017-07-14 00:48:44659 for &(ref k, ref v) in build.cc[&target].0.env() {
Mark Simulacrum001e9f32017-07-05 01:41:43660 if k != "PATH" {
661 cmd.env(k, v);
662 }
Alex Crichton126e09e2016-04-14 22:51:03663 }
664 }
Mark Simulacrum001e9f32017-07-05 01:41:43665 cmd.env("RUSTC_BOOTSTRAP", "1");
666 build.add_rust_test_threads(&mut cmd);
667
668 if build.config.sanitizers {
669 cmd.env("SANITIZER_SUPPORT", "1");
670 }
671
672 if build.config.profiler {
673 cmd.env("PROFILER_SUPPORT", "1");
674 }
675
676 cmd.arg("--adb-path").arg("adb");
677 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
678 if target.contains("android") {
679 // Assume that cc for this target comes from the android sysroot
680 cmd.arg("--android-cross-path")
681 .arg(build.cc(target).parent().unwrap().parent().unwrap());
682 } else {
683 cmd.arg("--android-cross-path").arg("");
684 }
685
686 build.ci_env.force_coloring_in_ci(&mut cmd);
687
688 let _time = util::timeit();
689 try_run(build, &mut cmd);
Alex Crichton126e09e2016-04-14 22:51:03690 }
Alex Crichtonb325baf2016-04-05 18:34:23691}
Alex Crichtonede89442016-04-15 01:00:35692
Mark Simulacrum528646e2017-07-14 00:48:44693#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
694pub struct Docs {
695 compiler: Compiler,
Mark Simulacruma5ab2ce2017-07-12 15:15:00696}
697
Mark Simulacrum528646e2017-07-14 00:48:44698impl Step for Docs {
Mark Simulacruma5ab2ce2017-07-12 15:15:00699 type Output = ();
700 const DEFAULT: bool = true;
701 const ONLY_HOSTS: bool = true;
Alex Crichtonede89442016-04-15 01:00:35702
Mark Simulacrum56128fb2017-07-19 00:03:38703 fn should_run(run: ShouldRun) -> ShouldRun {
704 run.path("src/doc")
Mark Simulacruma5ab2ce2017-07-12 15:15:00705 }
706
Mark Simulacrum6a67a052017-07-20 23:51:07707 fn make_run(run: RunConfig) {
708 run.builder.ensure(Docs {
709 compiler: run.builder.compiler(run.builder.top_stage, run.host),
Mark Simulacruma5ab2ce2017-07-12 15:15:00710 });
711 }
712
713 /// Run `rustdoc --test` for all documentation in `src/doc`.
714 ///
715 /// This will run all tests in our markdown documentation (e.g. the book)
716 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
717 /// `compiler`.
718 fn run(self, builder: &Builder) {
719 let build = builder.build;
720 let compiler = self.compiler;
Mark Simulacrumceecd622017-07-12 16:12:47721
722 builder.ensure(compile::Test { compiler, target: compiler.host });
723
Mark Simulacruma5ab2ce2017-07-12 15:15:00724 // Do a breadth-first traversal of the `src/doc` directory and just run
725 // tests for all files that end in `*.md`
726 let mut stack = vec![build.src.join("src/doc")];
727 let _time = util::timeit();
728 let _folder = build.fold_output(|| "test_docs");
729
730 while let Some(p) = stack.pop() {
731 if p.is_dir() {
732 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
733 continue
734 }
735
736 if p.extension().and_then(|s| s.to_str()) != Some("md") {
737 continue;
738 }
739
740 // The nostarch directory in the book is for no starch, and so isn't
741 // guaranteed to build. We don't care if it doesn't build, so skip it.
742 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
743 continue;
744 }
745
746 markdown_test(builder, compiler, &p);
Alex Crichtonede89442016-04-15 01:00:35747 }
Alex Crichtonede89442016-04-15 01:00:35748 }
749}
750
Mark Simulacrum528646e2017-07-14 00:48:44751#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
752pub struct ErrorIndex {
753 compiler: Compiler,
Mark Simulacrum001e9f32017-07-05 01:41:43754}
Alex Crichton0e272de2016-11-16 20:31:19755
Mark Simulacrum528646e2017-07-14 00:48:44756impl Step for ErrorIndex {
Mark Simulacrum001e9f32017-07-05 01:41:43757 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27758 const DEFAULT: bool = true;
759 const ONLY_HOSTS: bool = true;
760
Mark Simulacrum56128fb2017-07-19 00:03:38761 fn should_run(run: ShouldRun) -> ShouldRun {
762 run.path("src/tools/error_index_generator")
Mark Simulacrum6b3413d2017-07-05 12:41:27763 }
764
Mark Simulacrum6a67a052017-07-20 23:51:07765 fn make_run(run: RunConfig) {
766 run.builder.ensure(ErrorIndex {
767 compiler: run.builder.compiler(run.builder.top_stage, run.host),
Mark Simulacrum6b3413d2017-07-05 12:41:27768 });
769 }
Alex Crichtonede89442016-04-15 01:00:35770
Mark Simulacrum001e9f32017-07-05 01:41:43771 /// Run the error index generator tool to execute the tests located in the error
772 /// index.
773 ///
774 /// The `error_index_generator` tool lives in `src/tools` and is used to
775 /// generate a markdown file from the error indexes of the code base which is
776 /// then passed to `rustdoc --test`.
777 fn run(self, builder: &Builder) {
778 let build = builder.build;
779 let compiler = self.compiler;
780
Mark Simulacrum6b3413d2017-07-05 12:41:27781 builder.ensure(compile::Std { compiler, target: compiler.host });
782
Mark Simulacrum001e9f32017-07-05 01:41:43783 let _folder = build.fold_output(|| "test_error_index");
784 println!("Testing error-index stage{}", compiler.stage);
785
786 let dir = testdir(build, compiler.host);
787 t!(fs::create_dir_all(&dir));
788 let output = dir.join("error-index.md");
789
790 let _time = util::timeit();
Mark Simulacrum60388302017-07-05 16:46:41791 build.run(builder.tool_cmd(Tool::ErrorIndex)
Mark Simulacrum001e9f32017-07-05 01:41:43792 .arg("markdown")
793 .arg(&output)
794 .env("CFG_BUILD", &build.build));
795
Mark Simulacrumc114fe52017-07-05 17:21:33796 markdown_test(builder, compiler, &output);
Mark Simulacrum001e9f32017-07-05 01:41:43797 }
Alex Crichtonede89442016-04-15 01:00:35798}
799
Mark Simulacrumc114fe52017-07-05 17:21:33800fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
801 let build = builder.build;
Mark Simulacrumdd1d75e2017-06-04 23:55:50802 let mut file = t!(File::open(markdown));
803 let mut contents = String::new();
804 t!(file.read_to_string(&mut contents));
805 if !contents.contains("```") {
806 return;
807 }
808
Mark Simulacrumbc8fabb2017-06-06 18:00:22809 println!("doc tests for: {}", markdown.display());
Mark Simulacrumc114fe52017-07-05 17:21:33810 let mut cmd = Command::new(builder.rustdoc(compiler));
811 builder.add_rustc_lib_path(compiler, &mut cmd);
Alex Crichton0e272de2016-11-16 20:31:19812 build.add_rust_test_threads(&mut cmd);
Alex Crichtonede89442016-04-15 01:00:35813 cmd.arg("--test");
814 cmd.arg(markdown);
Alex Crichton6f62fae2016-12-12 17:03:35815 cmd.env("RUSTC_BOOTSTRAP", "1");
Corey Farwellc8c6d2c2016-10-30 01:58:52816
kennytm6ac07872017-05-21 20:27:47817 let test_args = build.flags.cmd.test_args().join(" ");
Corey Farwellc8c6d2c2016-10-30 01:58:52818 cmd.arg("--test-args").arg(test_args);
819
kennytm6ac07872017-05-21 20:27:47820 if build.config.quiet_tests {
Josh Stone617aea42017-06-02 16:27:44821 try_run_quiet(build, &mut cmd);
kennytm6ac07872017-05-21 20:27:47822 } else {
Josh Stone617aea42017-06-02 16:27:44823 try_run(build, &mut cmd);
kennytm6ac07872017-05-21 20:27:47824 }
Alex Crichtonede89442016-04-15 01:00:35825}
Alex Crichtonbb9062a2016-04-29 21:23:15826
Mark Simulacrum528646e2017-07-14 00:48:44827#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum981afa52017-07-18 21:28:53828pub struct CrateLibrustc {
Mark Simulacrum528646e2017-07-14 00:48:44829 compiler: Compiler,
830 target: Interned<String>,
Mark Simulacrum6b3413d2017-07-05 12:41:27831 test_kind: TestKind,
Mark Simulacrum528646e2017-07-14 00:48:44832 krate: Option<Interned<String>>,
Mark Simulacrum6b3413d2017-07-05 12:41:27833}
834
Mark Simulacrum981afa52017-07-18 21:28:53835impl Step for CrateLibrustc {
Mark Simulacrum6b3413d2017-07-05 12:41:27836 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27837 const DEFAULT: bool = true;
838 const ONLY_HOSTS: bool = true;
839
Mark Simulacrum56128fb2017-07-19 00:03:38840 fn should_run(run: ShouldRun) -> ShouldRun {
841 run.krate("rustc-main")
Mark Simulacrum6b3413d2017-07-05 12:41:27842 }
843
Mark Simulacrum6a67a052017-07-20 23:51:07844 fn make_run(run: RunConfig) {
845 let builder = run.builder;
846 let compiler = builder.compiler(builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:27847
Mark Simulacrum6a67a052017-07-20 23:51:07848 let make = |name: Option<Interned<String>>| {
Mark Simulacrum6b3413d2017-07-05 12:41:27849 let test_kind = if builder.kind == Kind::Test {
850 TestKind::Test
851 } else if builder.kind == Kind::Bench {
852 TestKind::Bench
853 } else {
Mark Simulacrum981afa52017-07-18 21:28:53854 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
Mark Simulacrum6b3413d2017-07-05 12:41:27855 };
856
Mark Simulacrum981afa52017-07-18 21:28:53857 builder.ensure(CrateLibrustc {
Mark Simulacrum6b3413d2017-07-05 12:41:27858 compiler,
Mark Simulacrum6a67a052017-07-20 23:51:07859 target: run.target,
Mark Simulacrum6b3413d2017-07-05 12:41:27860 test_kind: test_kind,
861 krate: name,
862 });
863 };
864
Mark Simulacrum6a67a052017-07-20 23:51:07865 if let Some(path) = run.path {
Mark Simulacrum6b3413d2017-07-05 12:41:27866 for (name, krate_path) in builder.crates("rustc-main") {
867 if path.ends_with(krate_path) {
Mark Simulacrum6a67a052017-07-20 23:51:07868 make(Some(name));
Mark Simulacrum6b3413d2017-07-05 12:41:27869 }
870 }
871 } else {
Mark Simulacrum6a67a052017-07-20 23:51:07872 make(None);
Mark Simulacrum6b3413d2017-07-05 12:41:27873 }
874 }
875
876
877 fn run(self, builder: &Builder) {
Mark Simulacrum981afa52017-07-18 21:28:53878 builder.ensure(Crate {
Mark Simulacrum6b3413d2017-07-05 12:41:27879 compiler: self.compiler,
880 target: self.target,
881 mode: Mode::Librustc,
882 test_kind: self.test_kind,
883 krate: self.krate,
884 });
885 }
886}
887
888
Mark Simulacrum528646e2017-07-14 00:48:44889#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum981afa52017-07-18 21:28:53890pub struct Crate {
Mark Simulacrum528646e2017-07-14 00:48:44891 compiler: Compiler,
892 target: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:43893 mode: Mode,
894 test_kind: TestKind,
Mark Simulacrum528646e2017-07-14 00:48:44895 krate: Option<Interned<String>>,
Mark Simulacrum001e9f32017-07-05 01:41:43896}
Alex Crichtonbb9062a2016-04-29 21:23:15897
Mark Simulacrum981afa52017-07-18 21:28:53898impl Step for Crate {
Mark Simulacrum001e9f32017-07-05 01:41:43899 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27900 const DEFAULT: bool = true;
901
Mark Simulacrum56128fb2017-07-19 00:03:38902 fn should_run(run: ShouldRun) -> ShouldRun {
903 run.krate("std").krate("test")
Mark Simulacrum6b3413d2017-07-05 12:41:27904 }
905
Mark Simulacrum6a67a052017-07-20 23:51:07906 fn make_run(run: RunConfig) {
907 let builder = run.builder;
908 let compiler = builder.compiler(builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:27909
Mark Simulacrum6a67a052017-07-20 23:51:07910 let make = |mode: Mode, name: Option<Interned<String>>| {
Mark Simulacrum6b3413d2017-07-05 12:41:27911 let test_kind = if builder.kind == Kind::Test {
912 TestKind::Test
913 } else if builder.kind == Kind::Bench {
914 TestKind::Bench
915 } else {
Mark Simulacrum981afa52017-07-18 21:28:53916 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
Mark Simulacrum6b3413d2017-07-05 12:41:27917 };
918
Mark Simulacrum981afa52017-07-18 21:28:53919 builder.ensure(Crate {
Mark Simulacrum6a67a052017-07-20 23:51:07920 compiler,
921 target: run.target,
Mark Simulacrum6b3413d2017-07-05 12:41:27922 mode: mode,
923 test_kind: test_kind,
924 krate: name,
925 });
926 };
927
Mark Simulacrum6a67a052017-07-20 23:51:07928 if let Some(path) = run.path {
Mark Simulacrum6b3413d2017-07-05 12:41:27929 for (name, krate_path) in builder.crates("std") {
930 if path.ends_with(krate_path) {
Mark Simulacrum6a67a052017-07-20 23:51:07931 make(Mode::Libstd, Some(name));
Mark Simulacrum6b3413d2017-07-05 12:41:27932 }
933 }
934 for (name, krate_path) in builder.crates("test") {
935 if path.ends_with(krate_path) {
Mark Simulacrum6a67a052017-07-20 23:51:07936 make(Mode::Libtest, Some(name));
Mark Simulacrum6b3413d2017-07-05 12:41:27937 }
938 }
939 } else {
Mark Simulacrum6a67a052017-07-20 23:51:07940 make(Mode::Libstd, None);
941 make(Mode::Libtest, None);
Mark Simulacrum6b3413d2017-07-05 12:41:27942 }
943 }
Alex Crichton7046fea2016-12-25 23:20:33944
Mark Simulacrum001e9f32017-07-05 01:41:43945 /// Run all unit tests plus documentation tests for an entire crate DAG defined
946 /// by a `Cargo.toml`
947 ///
948 /// This is what runs tests for crates like the standard library, compiler, etc.
949 /// It essentially is the driver for running `cargo test`.
950 ///
951 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
952 /// arguments, and those arguments are discovered from `cargo metadata`.
953 fn run(self, builder: &Builder) {
954 let build = builder.build;
955 let compiler = self.compiler;
956 let target = self.target;
957 let mode = self.mode;
958 let test_kind = self.test_kind;
959 let krate = self.krate;
Alex Crichtonbb9062a2016-04-29 21:23:15960
Mark Simulacrum6b3413d2017-07-05 12:41:27961 builder.ensure(compile::Test { compiler, target });
962 builder.ensure(RemoteCopyLibs { compiler, target });
Mark Simulacrum001e9f32017-07-05 01:41:43963 let (name, path, features, root) = match mode {
964 Mode::Libstd => {
965 ("libstd", "src/libstd", build.std_features(), "std")
966 }
967 Mode::Libtest => {
968 ("libtest", "src/libtest", String::new(), "test")
969 }
970 Mode::Librustc => {
Mark Simulacrumceecd622017-07-12 16:12:47971 builder.ensure(compile::Rustc { compiler, target });
Mark Simulacrum001e9f32017-07-05 01:41:43972 ("librustc", "src/rustc", build.rustc_features(), "rustc-main")
973 }
974 _ => panic!("can only test libraries"),
975 };
Mark Simulacrum528646e2017-07-14 00:48:44976 let root = INTERNER.intern_string(String::from(root));
Mark Simulacrum001e9f32017-07-05 01:41:43977 let _folder = build.fold_output(|| {
978 format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, name)
979 });
980 println!("{} {} stage{} ({} -> {})", test_kind, name, compiler.stage,
Mark Simulacrum528646e2017-07-14 00:48:44981 &compiler.host, target);
Mark Simulacrum001e9f32017-07-05 01:41:43982
983 // If we're not doing a full bootstrap but we're testing a stage2 version of
984 // libstd, then what we're actually testing is the libstd produced in
985 // stage1. Reflect that here by updating the compiler that we're working
986 // with automatically.
987 let compiler = if build.force_use_stage1(compiler, target) {
Mark Simulacrum6b3413d2017-07-05 12:41:27988 builder.compiler(1, compiler.host)
Mark Simulacrum001e9f32017-07-05 01:41:43989 } else {
990 compiler.clone()
991 };
992
993 // Build up the base `cargo test` command.
994 //
995 // Pass in some standard flags then iterate over the graph we've discovered
996 // in `cargo metadata` with the maps above and figure out what `-p`
997 // arguments need to get passed.
Mark Simulacrumc114fe52017-07-05 17:21:33998 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
Mark Simulacrum001e9f32017-07-05 01:41:43999 cargo.arg("--manifest-path")
1000 .arg(build.src.join(path).join("Cargo.toml"))
1001 .arg("--features").arg(features);
1002 if test_kind.subcommand() == "test" && !build.fail_fast {
1003 cargo.arg("--no-fail-fast");
Alex Crichtonbb9062a2016-04-29 21:23:151004 }
Mark Simulacrum001e9f32017-07-05 01:41:431005
1006 match krate {
1007 Some(krate) => {
1008 cargo.arg("-p").arg(krate);
1009 }
1010 None => {
1011 let mut visited = HashSet::new();
1012 let mut next = vec![root];
1013 while let Some(name) = next.pop() {
1014 // Right now jemalloc is our only target-specific crate in the
1015 // sense that it's not present on all platforms. Custom skip it
1016 // here for now, but if we add more this probably wants to get
1017 // more generalized.
1018 //
1019 // Also skip `build_helper` as it's not compiled normally for
1020 // target during the bootstrap and it's just meant to be a
1021 // helper crate, not tested. If it leaks through then it ends up
1022 // messing with various mtime calculations and such.
Mark Simulacrum528646e2017-07-14 00:48:441023 if !name.contains("jemalloc") && *name != *"build_helper" {
Mark Simulacrum001e9f32017-07-05 01:41:431024 cargo.arg("-p").arg(&format!("{}:0.0.0", name));
1025 }
Mark Simulacrum528646e2017-07-14 00:48:441026 for dep in build.crates[&name].deps.iter() {
Mark Simulacrum001e9f32017-07-05 01:41:431027 if visited.insert(dep) {
Mark Simulacrum528646e2017-07-14 00:48:441028 next.push(*dep);
Mark Simulacrum001e9f32017-07-05 01:41:431029 }
Alex Crichtona270b802016-10-21 20:18:091030 }
1031 }
Alex Crichtonbb9062a2016-04-29 21:23:151032 }
1033 }
Alex Crichtonbb9062a2016-04-29 21:23:151034
Mark Simulacrum001e9f32017-07-05 01:41:431035 // The tests are going to run with the *target* libraries, so we need to
1036 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1037 //
1038 // Note that to run the compiler we need to run with the *host* libraries,
1039 // but our wrapper scripts arrange for that to be the case anyway.
1040 let mut dylib_path = dylib_path();
Mark Simulacrum528646e2017-07-14 00:48:441041 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
Mark Simulacrum001e9f32017-07-05 01:41:431042 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
Alex Crichtonbb9062a2016-04-29 21:23:151043
Mark Simulacrum001e9f32017-07-05 01:41:431044 if target.contains("emscripten") || build.remote_tested(target) {
1045 cargo.arg("--no-run");
1046 }
Alex Crichton0e272de2016-11-16 20:31:191047
Mark Simulacrum001e9f32017-07-05 01:41:431048 cargo.arg("--");
Alex Crichton0e272de2016-11-16 20:31:191049
Mark Simulacrum001e9f32017-07-05 01:41:431050 if build.config.quiet_tests {
1051 cargo.arg("--quiet");
1052 }
Corey Farwellc8c6d2c2016-10-30 01:58:521053
Mark Simulacrum001e9f32017-07-05 01:41:431054 let _time = util::timeit();
Alex Crichton0e272de2016-11-16 20:31:191055
Mark Simulacrum001e9f32017-07-05 01:41:431056 if target.contains("emscripten") {
1057 build.run(&mut cargo);
Mark Simulacrum60388302017-07-05 16:46:411058 krate_emscripten(build, compiler, target, mode);
Mark Simulacrum001e9f32017-07-05 01:41:431059 } else if build.remote_tested(target) {
1060 build.run(&mut cargo);
Mark Simulacrum60388302017-07-05 16:46:411061 krate_remote(builder, compiler, target, mode);
Mark Simulacrum001e9f32017-07-05 01:41:431062 } else {
1063 cargo.args(&build.flags.cmd.test_args());
1064 try_run(build, &mut cargo);
1065 }
Alex Crichton39a5d3f2016-06-28 20:31:301066 }
1067}
1068
Brian Andersonb8b50f02016-09-06 00:41:501069fn krate_emscripten(build: &Build,
Mark Simulacrum60388302017-07-05 16:46:411070 compiler: Compiler,
Mark Simulacrum528646e2017-07-14 00:48:441071 target: Interned<String>,
Brian Andersonb8b50f02016-09-06 00:41:501072 mode: Mode) {
Alex Crichton1747ce22017-01-28 21:38:061073 let out_dir = build.cargo_out(compiler, mode, target);
Mark Simulacrum5b44cbc2017-06-26 16:23:501074 let tests = find_tests(&out_dir.join("deps"), target);
Ross Schulmanad9184c2016-09-05 23:56:481075
Mark Simulacrum5b44cbc2017-06-26 16:23:501076 let nodejs = build.config.nodejs.as_ref().expect("nodejs not configured");
Alex Crichton1747ce22017-01-28 21:38:061077 for test in tests {
Mark Simulacrum5b44cbc2017-06-26 16:23:501078 println!("running {}", test.display());
Alex Crichton1747ce22017-01-28 21:38:061079 let mut cmd = Command::new(nodejs);
Mark Simulacrum5b44cbc2017-06-26 16:23:501080 cmd.arg(&test);
Alex Crichton1747ce22017-01-28 21:38:061081 if build.config.quiet_tests {
1082 cmd.arg("--quiet");
1083 }
Josh Stone617aea42017-06-02 16:27:441084 try_run(build, &mut cmd);
Alex Crichton1747ce22017-01-28 21:38:061085 }
1086}
1087
Mark Simulacrum60388302017-07-05 16:46:411088fn krate_remote(builder: &Builder,
1089 compiler: Compiler,
Mark Simulacrum528646e2017-07-14 00:48:441090 target: Interned<String>,
Alex Crichton7bc2cbf2017-04-26 15:52:191091 mode: Mode) {
Mark Simulacrum60388302017-07-05 16:46:411092 let build = builder.build;
Alex Crichton1747ce22017-01-28 21:38:061093 let out_dir = build.cargo_out(compiler, mode, target);
Mark Simulacrum5b44cbc2017-06-26 16:23:501094 let tests = find_tests(&out_dir.join("deps"), target);
Alex Crichton1747ce22017-01-28 21:38:061095
Mark Simulacrum6b3413d2017-07-05 12:41:271096 let tool = builder.tool_exe(Tool::RemoteTestClient);
Alex Crichton1747ce22017-01-28 21:38:061097 for test in tests {
1098 let mut cmd = Command::new(&tool);
1099 cmd.arg("run")
1100 .arg(&test);
1101 if build.config.quiet_tests {
1102 cmd.arg("--quiet");
1103 }
1104 cmd.args(&build.flags.cmd.test_args());
Josh Stone617aea42017-06-02 16:27:441105 try_run(build, &mut cmd);
Alex Crichton1747ce22017-01-28 21:38:061106 }
1107}
Ross Schulmanad9184c2016-09-05 23:56:481108
Mark Simulacrum528646e2017-07-14 00:48:441109fn find_tests(dir: &Path, target: Interned<String>) -> Vec<PathBuf> {
Mark Simulacrum5b44cbc2017-06-26 16:23:501110 let mut dst = Vec::new();
Alex Crichton39a5d3f2016-06-28 20:31:301111 for e in t!(dir.read_dir()).map(|e| t!(e)) {
1112 let file_type = t!(e.file_type());
1113 if !file_type.is_file() {
1114 continue
1115 }
1116 let filename = e.file_name().into_string().unwrap();
1117 if (target.contains("windows") && filename.ends_with(".exe")) ||
Ross Schulmanad9184c2016-09-05 23:56:481118 (!target.contains("windows") && !filename.contains(".")) ||
Marco A L Barbosa554f21b2017-06-13 12:32:491119 (target.contains("emscripten") &&
1120 filename.ends_with(".js") &&
1121 !filename.ends_with(".asm.js")) {
Alex Crichton39a5d3f2016-06-28 20:31:301122 dst.push(e.path());
1123 }
1124 }
Mark Simulacrum5b44cbc2017-06-26 16:23:501125 dst
Alex Crichton39a5d3f2016-06-28 20:31:301126}
1127
Mark Simulacrumceecd622017-07-12 16:12:471128/// Some test suites are run inside emulators or on remote devices, and most
1129/// of our test binaries are linked dynamically which means we need to ship
1130/// the standard library and such to the emulator ahead of time. This step
1131/// represents this and is a dependency of all test suites.
1132///
1133/// Most of the time this is a noop. For some steps such as shipping data to
1134/// QEMU we have to build our own tools so we've got conditional dependencies
1135/// on those programs as well. Note that the remote test client is built for
1136/// the build target (us) and the server is built for the target.
Mark Simulacrum528646e2017-07-14 00:48:441137#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1138pub struct RemoteCopyLibs {
1139 compiler: Compiler,
1140 target: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:431141}
Alex Crichton1747ce22017-01-28 21:38:061142
Mark Simulacrum528646e2017-07-14 00:48:441143impl Step for RemoteCopyLibs {
Mark Simulacrum001e9f32017-07-05 01:41:431144 type Output = ();
Alex Crichton1747ce22017-01-28 21:38:061145
Mark Simulacrum56128fb2017-07-19 00:03:381146 fn should_run(run: ShouldRun) -> ShouldRun {
1147 run.never()
Mark Simulacrum681b1232017-07-14 12:30:161148 }
1149
Mark Simulacrum001e9f32017-07-05 01:41:431150 fn run(self, builder: &Builder) {
1151 let build = builder.build;
1152 let compiler = self.compiler;
1153 let target = self.target;
1154 if !build.remote_tested(target) {
1155 return
1156 }
Alex Crichton1747ce22017-01-28 21:38:061157
Mark Simulacrum6b3413d2017-07-05 12:41:271158 builder.ensure(compile::Test { compiler, target });
1159
Mark Simulacrum001e9f32017-07-05 01:41:431160 println!("REMOTE copy libs to emulator ({})", target);
1161 t!(fs::create_dir_all(build.out.join("tmp")));
1162
Mark Simulacrum5984e702017-07-13 00:52:311163 let server = builder.ensure(tool::RemoteTestServer { stage: compiler.stage, target });
Mark Simulacrum001e9f32017-07-05 01:41:431164
1165 // Spawn the emulator and wait for it to come online
Mark Simulacrum6b3413d2017-07-05 12:41:271166 let tool = builder.tool_exe(Tool::RemoteTestClient);
Mark Simulacrum001e9f32017-07-05 01:41:431167 let mut cmd = Command::new(&tool);
1168 cmd.arg("spawn-emulator")
1169 .arg(target)
1170 .arg(&server)
1171 .arg(build.out.join("tmp"));
1172 if let Some(rootfs) = build.qemu_rootfs(target) {
1173 cmd.arg(rootfs);
1174 }
1175 build.run(&mut cmd);
1176
1177 // Push all our dylibs to the emulator
Mark Simulacrum60388302017-07-05 16:46:411178 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
Mark Simulacrum001e9f32017-07-05 01:41:431179 let f = t!(f);
1180 let name = f.file_name().into_string().unwrap();
1181 if util::is_dylib(&name) {
1182 build.run(Command::new(&tool)
1183 .arg("push")
1184 .arg(f.path()));
1185 }
Alex Crichton1747ce22017-01-28 21:38:061186 }
1187 }
1188}
1189
Mark Simulacrum528646e2017-07-14 00:48:441190#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum001e9f32017-07-05 01:41:431191pub struct Distcheck;
1192
Mark Simulacrum528646e2017-07-14 00:48:441193impl Step for Distcheck {
Mark Simulacrum001e9f32017-07-05 01:41:431194 type Output = ();
1195
Mark Simulacrum56128fb2017-07-19 00:03:381196 fn should_run(run: ShouldRun) -> ShouldRun {
1197 run.path("distcheck")
Mark Simulacrum681b1232017-07-14 12:30:161198 }
1199
Mark Simulacrum001e9f32017-07-05 01:41:431200 /// Run "distcheck", a 'make check' from a tarball
1201 fn run(self, builder: &Builder) {
1202 let build = builder.build;
1203
Mark Simulacrum528646e2017-07-14 00:48:441204 if *build.build != *"x86_64-unknown-linux-gnu" {
Mark Simulacrum001e9f32017-07-05 01:41:431205 return
1206 }
1207 if !build.config.host.iter().any(|s| s == "x86_64-unknown-linux-gnu") {
1208 return
1209 }
1210 if !build.config.target.iter().any(|s| s == "x86_64-unknown-linux-gnu") {
1211 return
1212 }
1213
1214 println!("Distcheck");
1215 let dir = build.out.join("tmp").join("distcheck");
1216 let _ = fs::remove_dir_all(&dir);
1217 t!(fs::create_dir_all(&dir));
1218
1219 let mut cmd = Command::new("tar");
1220 cmd.arg("-xzf")
Mark Simulacrum5984e702017-07-13 00:52:311221 .arg(builder.ensure(dist::PlainSourceTarball))
Mark Simulacrum001e9f32017-07-05 01:41:431222 .arg("--strip-components=1")
1223 .current_dir(&dir);
1224 build.run(&mut cmd);
1225 build.run(Command::new("./configure")
1226 .args(&build.config.configure_args)
1227 .arg("--enable-vendor")
1228 .current_dir(&dir));
1229 build.run(Command::new(build_helper::make(&build.build))
1230 .arg("check")
1231 .current_dir(&dir));
1232
1233 // Now make sure that rust-src has all of libstd's dependencies
1234 println!("Distcheck rust-src");
1235 let dir = build.out.join("tmp").join("distcheck-src");
1236 let _ = fs::remove_dir_all(&dir);
1237 t!(fs::create_dir_all(&dir));
1238
1239 let mut cmd = Command::new("tar");
1240 cmd.arg("-xzf")
Mark Simulacrum5984e702017-07-13 00:52:311241 .arg(builder.ensure(dist::Src))
Mark Simulacrum001e9f32017-07-05 01:41:431242 .arg("--strip-components=1")
1243 .current_dir(&dir);
1244 build.run(&mut cmd);
1245
1246 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
1247 build.run(Command::new(&build.initial_cargo)
1248 .arg("generate-lockfile")
1249 .arg("--manifest-path")
1250 .arg(&toml)
1251 .current_dir(&dir));
Alex Crichtond38db822016-12-09 01:13:551252 }
Alex Crichtond38db822016-12-09 01:13:551253}
Alex Crichton1a040b32016-12-31 03:50:571254
Mark Simulacrum528646e2017-07-14 00:48:441255#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum001e9f32017-07-05 01:41:431256pub struct Bootstrap;
1257
Mark Simulacrum528646e2017-07-14 00:48:441258impl Step for Bootstrap {
Mark Simulacrum001e9f32017-07-05 01:41:431259 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271260 const DEFAULT: bool = true;
1261 const ONLY_HOSTS: bool = true;
1262 const ONLY_BUILD: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:431263
1264 /// Test the build system itself
1265 fn run(self, builder: &Builder) {
1266 let build = builder.build;
1267 let mut cmd = Command::new(&build.initial_cargo);
1268 cmd.arg("test")
1269 .current_dir(build.src.join("src/bootstrap"))
1270 .env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
1271 .env("RUSTC_BOOTSTRAP", "1")
1272 .env("RUSTC", &build.initial_rustc);
1273 if !build.fail_fast {
1274 cmd.arg("--no-fail-fast");
1275 }
1276 cmd.arg("--").args(&build.flags.cmd.test_args());
1277 try_run(build, &mut cmd);
Josh Stone617aea42017-06-02 16:27:441278 }
Mark Simulacrum6b3413d2017-07-05 12:41:271279
Mark Simulacrum56128fb2017-07-19 00:03:381280 fn should_run(run: ShouldRun) -> ShouldRun {
1281 run.path("src/bootstrap")
Mark Simulacrum6b3413d2017-07-05 12:41:271282 }
1283
Mark Simulacrum6a67a052017-07-20 23:51:071284 fn make_run(run: RunConfig) {
1285 run.builder.ensure(Bootstrap);
Mark Simulacrum6b3413d2017-07-05 12:41:271286 }
Alex Crichton1a040b32016-12-31 03:50:571287}