blob: 3adfbb5e36b51d2088ba4f6aa7f18b11b21fc7b7 [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 Crichtonbb9062a2016-04-29 21:23:1516use std::env;
Nick Cameron04415dc2017-06-30 18:58:5417use std::ffi::OsString;
Ulrik Sverdrupb1566ba2016-11-25 21:13:5918use std::fmt;
Mark Simulacrumdd1d75e2017-06-04 23:55:5019use std::fs::{self, File};
Mark Simulacrumdd1d75e2017-06-04 23:55:5020use std::io::Read;
Santiago Pastorinob39a1d62018-05-30 17:33:4321use std::iter;
22use std::path::{Path, PathBuf};
23use std::process::Command;
Alex Crichton73c2d2a2016-04-14 21:27:5124
kennytm2566fa22017-12-06 21:06:4825use build_helper::{self, output};
Alex Crichton126e09e2016-04-14 22:51:0326
Santiago Pastorinob39a1d62018-05-30 17:33:4327use builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
28use cache::{Interned, INTERNER};
Alex Crichton90105672017-07-17 16:32:0829use compile;
30use dist;
Santiago Pastorinob39a1d62018-05-30 17:33:4331use flags::Subcommand;
Alex Crichton90105672017-07-17 16:32:0832use native;
33use tool::{self, Tool};
Oliver Schneiderab018c72017-08-30 16:59:2634use toolstate::ToolState;
Santiago Pastorinob39a1d62018-05-30 17:33:4335use util::{self, dylib_path, dylib_path_var};
36use Crate as CargoCrate;
37use {DocTests, Mode};
Alex Crichton39a5d3f2016-06-28 20:31:3038
Mark Simulacrum5b44cbc2017-06-26 16:23:5039const ADB_TEST_DIR: &str = "/data/tmp/work";
Alex Crichtondefd1b32016-03-08 07:15:5540
Ulrik Sverdrupb1566ba2016-11-25 21:13:5941/// The two modes of the test runner; tests or benchmarks.
kennytmbe9d6692018-05-05 18:33:0142#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord)]
Ulrik Sverdrupb1566ba2016-11-25 21:13:5943pub enum TestKind {
44 /// Run `cargo test`
45 Test,
46 /// Run `cargo bench`
47 Bench,
48}
49
Oliver Schneider37dee692018-05-16 15:18:1950impl From<Kind> for TestKind {
51 fn from(kind: Kind) -> Self {
52 match kind {
53 Kind::Test => TestKind::Test,
Oliver Schneider37dee692018-05-16 15:18:1954 Kind::Bench => TestKind::Bench,
Santiago Pastorinob39a1d62018-05-30 17:33:4355 _ => panic!("unexpected kind in crate: {:?}", kind),
Oliver Schneider37dee692018-05-16 15:18:1956 }
57 }
58}
59
Ulrik Sverdrupb1566ba2016-11-25 21:13:5960impl TestKind {
61 // Return the cargo subcommand for this test kind
62 fn subcommand(self) -> &'static str {
63 match self {
64 TestKind::Test => "test",
65 TestKind::Bench => "bench",
66 }
67 }
68}
69
70impl fmt::Display for TestKind {
71 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
72 f.write_str(match *self {
73 TestKind::Test => "Testing",
74 TestKind::Bench => "Benchmarking",
75 })
76 }
77}
78
Mark Simulacrumbe1e7892018-04-14 23:27:5779fn try_run(builder: &Builder, cmd: &mut Command) -> bool {
80 if !builder.fail_fast {
81 if !builder.try_run(cmd) {
82 let mut failures = builder.delayed_failures.borrow_mut();
Ximin Luo8f254972017-09-18 19:21:2483 failures.push(format!("{:?}", cmd));
Oliver Schneideracdf83f2017-12-06 08:25:2984 return false;
Josh Stone617aea42017-06-02 16:27:4485 }
86 } else {
Mark Simulacrumbe1e7892018-04-14 23:27:5787 builder.run(cmd);
Josh Stone617aea42017-06-02 16:27:4488 }
Oliver Schneideracdf83f2017-12-06 08:25:2989 true
Josh Stone617aea42017-06-02 16:27:4490}
91
Mark Simulacrumbe1e7892018-04-14 23:27:5792fn try_run_quiet(builder: &Builder, cmd: &mut Command) -> bool {
93 if !builder.fail_fast {
94 if !builder.try_run_quiet(cmd) {
95 let mut failures = builder.delayed_failures.borrow_mut();
Ximin Luo8f254972017-09-18 19:21:2496 failures.push(format!("{:?}", cmd));
kennytma9f940e2018-02-21 19:25:2397 return false;
Josh Stone617aea42017-06-02 16:27:4498 }
99 } else {
Mark Simulacrumbe1e7892018-04-14 23:27:57100 builder.run_quiet(cmd);
Josh Stone617aea42017-06-02 16:27:44101 }
kennytma9f940e2018-02-21 19:25:23102 true
Josh Stone617aea42017-06-02 16:27:44103}
104
Mark Simulacrum528646e2017-07-14 00:48:44105#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
106pub struct Linkcheck {
107 host: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:43108}
109
Mark Simulacrum528646e2017-07-14 00:48:44110impl Step for Linkcheck {
Mark Simulacrum001e9f32017-07-05 01:41:43111 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27112 const ONLY_HOSTS: bool = true;
113 const DEFAULT: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:43114
115 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
116 ///
117 /// This tool in `src/tools` will verify the validity of all our links in the
118 /// documentation to ensure we don't have a bunch of dead ones.
119 fn run(self, builder: &Builder) {
Mark Simulacrum001e9f32017-07-05 01:41:43120 let host = self.host;
121
Mark Simulacrumbe1e7892018-04-14 23:27:57122 builder.info(&format!("Linkcheck ({})", host));
Mark Simulacrum6b3413d2017-07-05 12:41:27123
124 builder.default_doc(None);
Mark Simulacrum001e9f32017-07-05 01:41:43125
Mark Simulacrumbe1e7892018-04-14 23:27:57126 let _time = util::timeit(&builder);
Santiago Pastorinob39a1d62018-05-30 17:33:43127 try_run(
128 builder,
129 builder
130 .tool_cmd(Tool::Linkchecker)
131 .arg(builder.out.join(host).join("doc")),
132 );
Mark Simulacrum001e9f32017-07-05 01:41:43133 }
Mark Simulacrum6b3413d2017-07-05 12:41:27134
Mark Simulacrum56128fb2017-07-19 00:03:38135 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumb05af492017-07-20 23:24:11136 let builder = run.builder;
Santiago Pastorinob39a1d62018-05-30 17:33:43137 run.path("src/tools/linkchecker")
138 .default_condition(builder.config.docs)
Mark Simulacrum6b3413d2017-07-05 12:41:27139 }
140
Mark Simulacrum6a67a052017-07-20 23:51:07141 fn make_run(run: RunConfig) {
Mark Simulacrum9ee877b2017-07-27 12:50:43142 run.builder.ensure(Linkcheck { host: run.target });
Mark Simulacrum6b3413d2017-07-05 12:41:27143 }
Alex Crichtondefd1b32016-03-08 07:15:55144}
Brian Anderson3a790ac2016-03-18 20:54:31145
Mark Simulacrum528646e2017-07-14 00:48:44146#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
147pub struct Cargotest {
Mark Simulacrum001e9f32017-07-05 01:41:43148 stage: u32,
Mark Simulacrum528646e2017-07-14 00:48:44149 host: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:43150}
Alex Crichton73c2d2a2016-04-14 21:27:51151
Mark Simulacrum528646e2017-07-14 00:48:44152impl Step for Cargotest {
Mark Simulacrum001e9f32017-07-05 01:41:43153 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27154 const ONLY_HOSTS: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:43155
Mark Simulacrum56128fb2017-07-19 00:03:38156 fn should_run(run: ShouldRun) -> ShouldRun {
157 run.path("src/tools/cargotest")
Mark Simulacrumceecd622017-07-12 16:12:47158 }
159
Mark Simulacrum6a67a052017-07-20 23:51:07160 fn make_run(run: RunConfig) {
161 run.builder.ensure(Cargotest {
162 stage: run.builder.top_stage,
Mark Simulacrum9ee877b2017-07-27 12:50:43163 host: run.target,
Mark Simulacrumceecd622017-07-12 16:12:47164 });
165 }
166
Mark Simulacrum001e9f32017-07-05 01:41:43167 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
168 ///
169 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
170 /// test` to ensure that we don't regress the test suites there.
171 fn run(self, builder: &Builder) {
Mark Simulacrum60388302017-07-05 16:46:41172 let compiler = builder.compiler(self.stage, self.host);
Santiago Pastorinob39a1d62018-05-30 17:33:43173 builder.ensure(compile::Rustc {
174 compiler,
175 target: compiler.host,
176 });
Mark Simulacrum001e9f32017-07-05 01:41:43177
178 // Note that this is a short, cryptic, and not scoped directory name. This
179 // is currently to minimize the length of path on Windows where we otherwise
180 // quickly run into path name limit constraints.
Mark Simulacrumbe1e7892018-04-14 23:27:57181 let out_dir = builder.out.join("ct");
Mark Simulacrum001e9f32017-07-05 01:41:43182 t!(fs::create_dir_all(&out_dir));
183
Mark Simulacrumbe1e7892018-04-14 23:27:57184 let _time = util::timeit(&builder);
Mark Simulacrum6b3413d2017-07-05 12:41:27185 let mut cmd = builder.tool_cmd(Tool::CargoTest);
Santiago Pastorinob39a1d62018-05-30 17:33:43186 try_run(
187 builder,
188 cmd.arg(&builder.initial_cargo)
189 .arg(&out_dir)
190 .env("RUSTC", builder.rustc(compiler))
191 .env("RUSTDOC", builder.rustdoc(compiler.host)),
192 );
Mark Simulacrum001e9f32017-07-05 01:41:43193 }
Alex Crichton009f45f2017-04-18 00:24:05194}
195
Mark Simulacrum528646e2017-07-14 00:48:44196#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
197pub struct Cargo {
Mark Simulacrum001e9f32017-07-05 01:41:43198 stage: u32,
Mark Simulacrum528646e2017-07-14 00:48:44199 host: Interned<String>,
Nick Cameron04415dc2017-06-30 18:58:54200}
201
Mark Simulacrum528646e2017-07-14 00:48:44202impl Step for Cargo {
Mark Simulacrum001e9f32017-07-05 01:41:43203 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27204 const ONLY_HOSTS: bool = true;
205
Mark Simulacrum56128fb2017-07-19 00:03:38206 fn should_run(run: ShouldRun) -> ShouldRun {
207 run.path("src/tools/cargo")
Mark Simulacrum6b3413d2017-07-05 12:41:27208 }
209
Mark Simulacrum6a67a052017-07-20 23:51:07210 fn make_run(run: RunConfig) {
211 run.builder.ensure(Cargo {
212 stage: run.builder.top_stage,
213 host: run.target,
Mark Simulacrum6b3413d2017-07-05 12:41:27214 });
215 }
Nick Cameron04415dc2017-06-30 18:58:54216
Mark Simulacrum001e9f32017-07-05 01:41:43217 /// Runs `cargo test` for `cargo` packaged with Rust.
218 fn run(self, builder: &Builder) {
Mark Simulacrum6b3413d2017-07-05 12:41:27219 let compiler = builder.compiler(self.stage, self.host);
Nick Cameron04415dc2017-06-30 18:58:54220
Santiago Pastorinob39a1d62018-05-30 17:33:43221 builder.ensure(tool::Cargo {
222 compiler,
223 target: self.host,
224 });
Collins Abitekaniza42ee6d52018-05-19 20:04:41225 let mut cargo = builder.cargo(compiler, Mode::ToolRustc, self.host, "test");
Santiago Pastorinob39a1d62018-05-30 17:33:43226 cargo
227 .arg("--manifest-path")
228 .arg(builder.src.join("src/tools/cargo/Cargo.toml"));
Mark Simulacrumbe1e7892018-04-14 23:27:57229 if !builder.fail_fast {
Mark Simulacrum001e9f32017-07-05 01:41:43230 cargo.arg("--no-fail-fast");
231 }
Nick Cameron04415dc2017-06-30 18:58:54232
Mark Simulacrum001e9f32017-07-05 01:41:43233 // Don't build tests dynamically, just a pain to work with
234 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
235
236 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
237 // available.
238 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
239
Santiago Pastorinob39a1d62018-05-30 17:33:43240 try_run(
241 builder,
242 cargo.env("PATH", &path_for_cargo(builder, compiler)),
243 );
Mark Simulacrum001e9f32017-07-05 01:41:43244 }
245}
246
Mark Simulacrumdec44b02017-07-17 15:52:05247#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
248pub struct Rls {
Mark Simulacrum001e9f32017-07-05 01:41:43249 stage: u32,
Mark Simulacrumdec44b02017-07-17 15:52:05250 host: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:43251}
252
Mark Simulacrumdec44b02017-07-17 15:52:05253impl Step for Rls {
Mark Simulacrum001e9f32017-07-05 01:41:43254 type Output = ();
Mark Simulacrumdec44b02017-07-17 15:52:05255 const ONLY_HOSTS: bool = true;
256
Mark Simulacrum56128fb2017-07-19 00:03:38257 fn should_run(run: ShouldRun) -> ShouldRun {
258 run.path("src/tools/rls")
Mark Simulacrumdec44b02017-07-17 15:52:05259 }
260
Mark Simulacrum6a67a052017-07-20 23:51:07261 fn make_run(run: RunConfig) {
262 run.builder.ensure(Rls {
263 stage: run.builder.top_stage,
264 host: run.target,
Mark Simulacrumdec44b02017-07-17 15:52:05265 });
266 }
Mark Simulacrum001e9f32017-07-05 01:41:43267
268 /// Runs `cargo test` for the rls.
269 fn run(self, builder: &Builder) {
Mark Simulacrum001e9f32017-07-05 01:41:43270 let stage = self.stage;
271 let host = self.host;
Mark Simulacrumdec44b02017-07-17 15:52:05272 let compiler = builder.compiler(stage, host);
Mark Simulacrum001e9f32017-07-05 01:41:43273
kennytm27d96912018-04-20 16:53:36274 let build_result = builder.ensure(tool::Rls {
275 compiler,
276 target: self.host,
277 extra_features: Vec::new(),
278 });
279 if build_result.is_none() {
280 eprintln!("failed to test rls: could not build");
281 return;
282 }
283
Collins Abitekanizafb949b52018-05-27 22:09:43284 let mut cargo = tool::prepare_tool_cargo(builder,
285 compiler,
Collins Abitekaniza11333972018-05-27 23:02:58286 Mode::ToolRustc,
Collins Abitekanizafb949b52018-05-27 22:09:43287 host,
288 "test",
289 "src/tools/rls");
Mark Simulacrum001e9f32017-07-05 01:41:43290
291 // Don't build tests dynamically, just a pain to work with
292 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
293
Mark Simulacrumdec44b02017-07-17 15:52:05294 builder.add_rustc_lib_path(compiler, &mut cargo);
Mark Simulacrum001e9f32017-07-05 01:41:43295
Mark Simulacrumbe1e7892018-04-14 23:27:57296 if try_run(builder, &mut cargo) {
297 builder.save_toolstate("rls", ToolState::TestPass);
Oliver Schneideracdf83f2017-12-06 08:25:29298 }
Mark Simulacrum001e9f32017-07-05 01:41:43299 }
Nick Cameron04415dc2017-06-30 18:58:54300}
301
Nick Camerond0070e82017-09-01 06:43:00302#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
303pub struct Rustfmt {
304 stage: u32,
305 host: Interned<String>,
306}
307
308impl Step for Rustfmt {
309 type Output = ();
310 const ONLY_HOSTS: bool = true;
311
312 fn should_run(run: ShouldRun) -> ShouldRun {
313 run.path("src/tools/rustfmt")
314 }
315
316 fn make_run(run: RunConfig) {
317 run.builder.ensure(Rustfmt {
318 stage: run.builder.top_stage,
319 host: run.target,
320 });
321 }
322
323 /// Runs `cargo test` for rustfmt.
324 fn run(self, builder: &Builder) {
Nick Camerond0070e82017-09-01 06:43:00325 let stage = self.stage;
326 let host = self.host;
327 let compiler = builder.compiler(stage, host);
328
kennytm27d96912018-04-20 16:53:36329 let build_result = builder.ensure(tool::Rustfmt {
330 compiler,
331 target: self.host,
332 extra_features: Vec::new(),
333 });
334 if build_result.is_none() {
335 eprintln!("failed to test rustfmt: could not build");
336 return;
337 }
338
Collins Abitekanizafb949b52018-05-27 22:09:43339 let mut cargo = tool::prepare_tool_cargo(builder,
340 compiler,
Collins Abitekaniza11333972018-05-27 23:02:58341 Mode::ToolRustc,
Collins Abitekanizafb949b52018-05-27 22:09:43342 host,
343 "test",
344 "src/tools/rustfmt");
Nick Camerond0070e82017-09-01 06:43:00345
346 // Don't build tests dynamically, just a pain to work with
347 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
Nick Camerondf97dd12018-05-05 20:27:48348 let dir = testdir(builder, compiler.host);
349 t!(fs::create_dir_all(&dir));
350 cargo.env("RUSTFMT_TEST_DIR", dir);
Nick Camerond0070e82017-09-01 06:43:00351
352 builder.add_rustc_lib_path(compiler, &mut cargo);
353
Mark Simulacrumbe1e7892018-04-14 23:27:57354 if try_run(builder, &mut cargo) {
355 builder.save_toolstate("rustfmt", ToolState::TestPass);
Oliver Schneideracdf83f2017-12-06 08:25:29356 }
Nick Camerond0070e82017-09-01 06:43:00357 }
358}
Oliver Schneider01555b12017-09-17 19:45:54359
360#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Oliver Schneiderf3817442017-08-28 14:54:50361pub struct Miri {
Oliver Schneideracdf83f2017-12-06 08:25:29362 stage: u32,
Oliver Schneiderf3817442017-08-28 14:54:50363 host: Interned<String>,
364}
365
366impl Step for Miri {
367 type Output = ();
368 const ONLY_HOSTS: bool = true;
369 const DEFAULT: bool = true;
370
371 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumbe1e7892018-04-14 23:27:57372 let test_miri = run.builder.config.test_miri;
Oliver Schneiderf3817442017-08-28 14:54:50373 run.path("src/tools/miri").default_condition(test_miri)
374 }
375
376 fn make_run(run: RunConfig) {
377 run.builder.ensure(Miri {
Oliver Schneideracdf83f2017-12-06 08:25:29378 stage: run.builder.top_stage,
Oliver Schneiderf3817442017-08-28 14:54:50379 host: run.target,
380 });
381 }
382
383 /// Runs `cargo test` for miri.
384 fn run(self, builder: &Builder) {
Oliver Schneideracdf83f2017-12-06 08:25:29385 let stage = self.stage;
Oliver Schneiderf3817442017-08-28 14:54:50386 let host = self.host;
Oliver Schneideracdf83f2017-12-06 08:25:29387 let compiler = builder.compiler(stage, host);
Oliver Schneiderf3817442017-08-28 14:54:50388
Oliver Schneider02ac15c2018-02-09 17:53:41389 let miri = builder.ensure(tool::Miri {
390 compiler,
391 target: self.host,
392 extra_features: Vec::new(),
393 });
394 if let Some(miri) = miri {
Collins Abitekaniza42ee6d52018-05-19 20:04:41395 let mut cargo = builder.cargo(compiler, Mode::ToolRustc, host, "test");
Santiago Pastorinob39a1d62018-05-30 17:33:43396 cargo
397 .arg("--manifest-path")
398 .arg(builder.src.join("src/tools/miri/Cargo.toml"));
Oliver Schneiderf3817442017-08-28 14:54:50399
Oliver Schneideracdf83f2017-12-06 08:25:29400 // Don't build tests dynamically, just a pain to work with
401 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
402 // miri tests need to know about the stage sysroot
403 cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
404 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
405 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
406 cargo.env("MIRI_PATH", miri);
Oliver Schneiderf3817442017-08-28 14:54:50407
Oliver Schneideracdf83f2017-12-06 08:25:29408 builder.add_rustc_lib_path(compiler, &mut cargo);
Oliver Schneiderf3817442017-08-28 14:54:50409
Mark Simulacrumbe1e7892018-04-14 23:27:57410 if try_run(builder, &mut cargo) {
411 builder.save_toolstate("miri", ToolState::TestPass);
Oliver Schneideracdf83f2017-12-06 08:25:29412 }
413 } else {
414 eprintln!("failed to test miri: could not build");
415 }
Oliver Schneiderf3817442017-08-28 14:54:50416 }
417}
418
Oliver Schneiderd64a0672017-09-18 11:13:57419#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
420pub struct Clippy {
Oliver Schneideracdf83f2017-12-06 08:25:29421 stage: u32,
Oliver Schneiderd64a0672017-09-18 11:13:57422 host: Interned<String>,
423}
424
425impl Step for Clippy {
426 type Output = ();
427 const ONLY_HOSTS: bool = true;
428 const DEFAULT: bool = false;
429
430 fn should_run(run: ShouldRun) -> ShouldRun {
431 run.path("src/tools/clippy")
432 }
433
434 fn make_run(run: RunConfig) {
435 run.builder.ensure(Clippy {
Oliver Schneideracdf83f2017-12-06 08:25:29436 stage: run.builder.top_stage,
Oliver Schneiderd64a0672017-09-18 11:13:57437 host: run.target,
438 });
439 }
440
441 /// Runs `cargo test` for clippy.
442 fn run(self, builder: &Builder) {
Oliver Schneideracdf83f2017-12-06 08:25:29443 let stage = self.stage;
Oliver Schneiderd64a0672017-09-18 11:13:57444 let host = self.host;
Oliver Schneideracdf83f2017-12-06 08:25:29445 let compiler = builder.compiler(stage, host);
Oliver Schneiderd64a0672017-09-18 11:13:57446
Oliver Schneider02ac15c2018-02-09 17:53:41447 let clippy = builder.ensure(tool::Clippy {
448 compiler,
449 target: self.host,
450 extra_features: Vec::new(),
451 });
452 if let Some(clippy) = clippy {
Collins Abitekaniza42ee6d52018-05-19 20:04:41453 let mut cargo = builder.cargo(compiler, Mode::ToolRustc, host, "test");
Santiago Pastorinob39a1d62018-05-30 17:33:43454 cargo
455 .arg("--manifest-path")
456 .arg(builder.src.join("src/tools/clippy/Cargo.toml"));
Oliver Schneiderd64a0672017-09-18 11:13:57457
Oliver Schneideracdf83f2017-12-06 08:25:29458 // Don't build tests dynamically, just a pain to work with
459 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
460 // clippy tests need to know about the stage sysroot
461 cargo.env("SYSROOT", builder.sysroot(compiler));
462 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
463 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
Santiago Pastorinob39a1d62018-05-30 17:33:43464 let host_libs = builder
Collins Abitekaniza42ee6d52018-05-19 20:04:41465 .stage_out(compiler, Mode::ToolRustc)
Santiago Pastorinob39a1d62018-05-30 17:33:43466 .join(builder.cargo_dir());
Oliver Schneideracdf83f2017-12-06 08:25:29467 cargo.env("HOST_LIBS", host_libs);
468 // clippy tests need to find the driver
469 cargo.env("CLIPPY_DRIVER_PATH", clippy);
Oliver Schneiderd64a0672017-09-18 11:13:57470
Oliver Schneideracdf83f2017-12-06 08:25:29471 builder.add_rustc_lib_path(compiler, &mut cargo);
Oliver Schneiderd64a0672017-09-18 11:13:57472
Mark Simulacrumbe1e7892018-04-14 23:27:57473 if try_run(builder, &mut cargo) {
474 builder.save_toolstate("clippy-driver", ToolState::TestPass);
Oliver Schneideracdf83f2017-12-06 08:25:29475 }
476 } else {
477 eprintln!("failed to test clippy: could not build");
478 }
Oliver Schneiderd64a0672017-09-18 11:13:57479 }
480}
Nick Camerond0070e82017-09-01 06:43:00481
Mark Simulacrumdec44b02017-07-17 15:52:05482fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
Nick Cameron04415dc2017-06-30 18:58:54483 // Configure PATH to find the right rustc. NB. we have to use PATH
484 // and not RUSTC because the Cargo test suite has tests that will
485 // fail if rustc is not spelled `rustc`.
Mark Simulacrumdec44b02017-07-17 15:52:05486 let path = builder.sysroot(compiler).join("bin");
Nick Cameron04415dc2017-06-30 18:58:54487 let old_path = env::var_os("PATH").unwrap_or_default();
488 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
Brian Anderson3a790ac2016-03-18 20:54:31489}
Alex Crichton9dd3c542016-03-29 20:14:52490
Guillaume Gomezf18c52b2017-12-12 22:53:24491#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
Guillaume Gomez51580d42018-01-25 23:44:52492pub struct RustdocTheme {
493 pub compiler: Compiler,
Guillaume Gomez51580d42018-01-25 23:44:52494}
495
496impl Step for RustdocTheme {
497 type Output = ();
498 const DEFAULT: bool = true;
499 const ONLY_HOSTS: bool = true;
500
501 fn should_run(run: ShouldRun) -> ShouldRun {
502 run.path("src/tools/rustdoc-themes")
503 }
504
505 fn make_run(run: RunConfig) {
506 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
507
Santiago Pastorinob39a1d62018-05-30 17:33:43508 run.builder.ensure(RustdocTheme { compiler: compiler });
Guillaume Gomez51580d42018-01-25 23:44:52509 }
510
511 fn run(self, builder: &Builder) {
Chris Coulson6f101462018-04-12 14:01:49512 let rustdoc = builder.out.join("bootstrap/debug/rustdoc");
Guillaume Gomezdec9fab2018-02-05 22:43:53513 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
514 cmd.arg(rustdoc.to_str().unwrap())
Santiago Pastorinob39a1d62018-05-30 17:33:43515 .arg(
516 builder
517 .src
518 .join("src/librustdoc/html/static/themes")
519 .to_str()
520 .unwrap(),
521 )
522 .env("RUSTC_STAGE", self.compiler.stage.to_string())
523 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
524 .env(
525 "RUSTDOC_LIBDIR",
526 builder.sysroot_libdir(self.compiler, self.compiler.host),
527 )
528 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
529 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler.host))
530 .env("RUSTDOC_CRATE_VERSION", builder.rust_version())
531 .env("RUSTC_BOOTSTRAP", "1");
Mark Simulacrumbe1e7892018-04-14 23:27:57532 if let Some(linker) = builder.linker(self.compiler.host) {
Guillaume Gomez51580d42018-01-25 23:44:52533 cmd.env("RUSTC_TARGET_LINKER", linker);
534 }
Mark Simulacrumbe1e7892018-04-14 23:27:57535 try_run(builder, &mut cmd);
Guillaume Gomez51580d42018-01-25 23:44:52536 }
537}
538
539#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
Guillaume Gomezf18c52b2017-12-12 22:53:24540pub struct RustdocJS {
541 pub host: Interned<String>,
Guillaume Gomez69521992018-01-12 22:40:00542 pub target: Interned<String>,
Guillaume Gomezf18c52b2017-12-12 22:53:24543}
544
545impl Step for RustdocJS {
Guillaume Gomez50bb6ba2018-01-08 22:43:20546 type Output = ();
Guillaume Gomezf18c52b2017-12-12 22:53:24547 const DEFAULT: bool = true;
548 const ONLY_HOSTS: bool = true;
549
550 fn should_run(run: ShouldRun) -> ShouldRun {
Guillaume Gomez69521992018-01-12 22:40:00551 run.path("src/test/rustdoc-js")
Guillaume Gomezf18c52b2017-12-12 22:53:24552 }
553
554 fn make_run(run: RunConfig) {
555 run.builder.ensure(RustdocJS {
556 host: run.host,
Guillaume Gomez69521992018-01-12 22:40:00557 target: run.target,
Guillaume Gomezf18c52b2017-12-12 22:53:24558 });
559 }
560
Guillaume Gomez50bb6ba2018-01-08 22:43:20561 fn run(self, builder: &Builder) {
Guillaume Gomez026c7492018-01-13 21:35:41562 if let Some(ref nodejs) = builder.config.nodejs {
563 let mut command = Command::new(nodejs);
564 command.args(&["src/tools/rustdoc-js/tester.js", &*self.host]);
565 builder.ensure(::doc::Std {
566 target: self.target,
567 stage: builder.top_stage,
568 });
569 builder.run(&mut command);
570 } else {
Santiago Pastorinob39a1d62018-05-30 17:33:43571 builder.info(&format!(
572 "No nodejs found, skipping \"src/test/rustdoc-js\" tests"
573 ));
Guillaume Gomez026c7492018-01-13 21:35:41574 }
Guillaume Gomezf18c52b2017-12-12 22:53:24575 }
576}
577
Guillaume Gomez035ec5b2018-03-31 12:49:56578#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
579pub struct RustdocUi {
580 pub host: Interned<String>,
581 pub target: Interned<String>,
582 pub compiler: Compiler,
583}
584
585impl Step for RustdocUi {
586 type Output = ();
587 const DEFAULT: bool = true;
588 const ONLY_HOSTS: bool = true;
589
590 fn should_run(run: ShouldRun) -> ShouldRun {
591 run.path("src/test/rustdoc-ui")
592 }
593
594 fn make_run(run: RunConfig) {
595 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
596 run.builder.ensure(RustdocUi {
597 host: run.host,
598 target: run.target,
599 compiler,
600 });
601 }
602
603 fn run(self, builder: &Builder) {
604 builder.ensure(Compiletest {
605 compiler: self.compiler,
606 target: self.target,
607 mode: "ui",
608 suite: "rustdoc-ui",
Collins Abitekaniza41ee6fe2018-04-12 11:49:31609 path: None,
Felix S. Klock II55895502018-04-11 15:15:59610 compare_mode: None,
Guillaume Gomez035ec5b2018-03-31 12:49:56611 })
612 }
613}
614
Mark Simulacrum528646e2017-07-14 00:48:44615#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum1c8f3b02018-02-11 22:41:06616pub struct Tidy;
Mark Simulacrum001e9f32017-07-05 01:41:43617
Mark Simulacrum528646e2017-07-14 00:48:44618impl Step for Tidy {
Mark Simulacrum001e9f32017-07-05 01:41:43619 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27620 const DEFAULT: bool = true;
621 const ONLY_HOSTS: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:43622
Mark Simulacrum1c8f3b02018-02-11 22:41:06623 /// Runs the `tidy` tool.
Mark Simulacrum001e9f32017-07-05 01:41:43624 ///
625 /// This tool in `src/tools` checks up on various bits and pieces of style and
626 /// otherwise just implements a few lint-like checks that are specific to the
627 /// compiler itself.
628 fn run(self, builder: &Builder) {
Mark Simulacrum60388302017-07-05 16:46:41629 let mut cmd = builder.tool_cmd(Tool::Tidy);
Mark Simulacrumbe1e7892018-04-14 23:27:57630 cmd.arg(builder.src.join("src"));
631 cmd.arg(&builder.initial_cargo);
632 if !builder.config.vendor {
Mark Simulacrum001e9f32017-07-05 01:41:43633 cmd.arg("--no-vendor");
634 }
Oliver Schneider0c1bcd32018-06-07 12:40:36635 if !builder.config.verbose_tests {
Mark Simulacrum001e9f32017-07-05 01:41:43636 cmd.arg("--quiet");
637 }
Alex Crichton6fd4d672018-03-16 15:35:03638
Mark Simulacrumbe1e7892018-04-14 23:27:57639 let _folder = builder.fold_output(|| "tidy");
Mark Simulacrum545b92f2018-03-28 15:25:09640 builder.info(&format!("tidy check"));
Mark Simulacrumbe1e7892018-04-14 23:27:57641 try_run(builder, &mut cmd);
Eduard-Mihai Burtescud29f0bc2017-02-10 20:59:40642 }
Mark Simulacrum6b3413d2017-07-05 12:41:27643
Mark Simulacrum56128fb2017-07-19 00:03:38644 fn should_run(run: ShouldRun) -> ShouldRun {
645 run.path("src/tools/tidy")
Mark Simulacrum6b3413d2017-07-05 12:41:27646 }
647
Mark Simulacrum6a67a052017-07-20 23:51:07648 fn make_run(run: RunConfig) {
Mark Simulacrum1c8f3b02018-02-11 22:41:06649 run.builder.ensure(Tidy);
Mark Simulacrum6b3413d2017-07-05 12:41:27650 }
Alex Crichton9dd3c542016-03-29 20:14:52651}
Alex Crichtonb325baf2016-04-05 18:34:23652
Mark Simulacrumbe1e7892018-04-14 23:27:57653fn testdir(builder: &Builder, host: Interned<String>) -> PathBuf {
654 builder.out.join(host).join("test")
Alex Crichtonb325baf2016-04-05 18:34:23655}
656
Mark Simulacrumf104b122018-02-11 16:51:58657macro_rules! default_test {
658 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
659 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
660 }
Mark Simulacrum1ab89302017-07-07 17:51:57661}
662
Felix S. Klock II55895502018-04-11 15:15:59663macro_rules! default_test_with_compare_mode {
664 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
665 compare_mode: $compare_mode:expr }) => {
666 test_with_compare_mode!($name { path: $path, mode: $mode, suite: $suite, default: true,
667 host: false, compare_mode: $compare_mode });
668 }
669}
670
Mark Simulacrumf104b122018-02-11 16:51:58671macro_rules! host_test {
672 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
673 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
674 }
675}
Mark Simulacrum6b3413d2017-07-05 12:41:27676
Mark Simulacrumf104b122018-02-11 16:51:58677macro_rules! test {
Felix S. Klock II55895502018-04-11 15:15:59678 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
679 host: $host:expr }) => {
680 test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default,
681 host: $host, compare_mode: None });
682 }
683}
684
685macro_rules! test_with_compare_mode {
686 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
687 host: $host:expr, compare_mode: $compare_mode:expr }) => {
688 test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default,
689 host: $host, compare_mode: Some($compare_mode) });
690 }
691}
692
693macro_rules! test_definitions {
Mark Simulacrumf104b122018-02-11 16:51:58694 ($name:ident {
695 path: $path:expr,
696 mode: $mode:expr,
697 suite: $suite:expr,
698 default: $default:expr,
Felix S. Klock II55895502018-04-11 15:15:59699 host: $host:expr,
700 compare_mode: $compare_mode:expr
Mark Simulacrumf104b122018-02-11 16:51:58701 }) => {
702 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
703 pub struct $name {
704 pub compiler: Compiler,
705 pub target: Interned<String>,
706 }
707
708 impl Step for $name {
709 type Output = ();
710 const DEFAULT: bool = $default;
711 const ONLY_HOSTS: bool = $host;
712
713 fn should_run(run: ShouldRun) -> ShouldRun {
Collins Abitekaniza41ee6fe2018-04-12 11:49:31714 run.suite_path($path)
Mark Simulacrumf104b122018-02-11 16:51:58715 }
716
717 fn make_run(run: RunConfig) {
718 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
719
720 run.builder.ensure($name {
721 compiler,
722 target: run.target,
723 });
724 }
725
726 fn run(self, builder: &Builder) {
727 builder.ensure(Compiletest {
728 compiler: self.compiler,
729 target: self.target,
730 mode: $mode,
731 suite: $suite,
Collins Abitekaniza41ee6fe2018-04-12 11:49:31732 path: Some($path),
Felix S. Klock II55895502018-04-11 15:15:59733 compare_mode: $compare_mode,
Mark Simulacrumf104b122018-02-11 16:51:58734 })
735 }
736 }
737 }
738}
739
Felix S. Klock II55895502018-04-11 15:15:59740default_test_with_compare_mode!(Ui {
Mark Simulacrumf104b122018-02-11 16:51:58741 path: "src/test/ui",
742 mode: "ui",
Felix S. Klock II55895502018-04-11 15:15:59743 suite: "ui",
744 compare_mode: "nll"
Mark Simulacrumf104b122018-02-11 16:51:58745});
746
747default_test!(RunPass {
748 path: "src/test/run-pass",
749 mode: "run-pass",
750 suite: "run-pass"
751});
752
753default_test!(CompileFail {
754 path: "src/test/compile-fail",
755 mode: "compile-fail",
756 suite: "compile-fail"
757});
758
759default_test!(ParseFail {
760 path: "src/test/parse-fail",
761 mode: "parse-fail",
762 suite: "parse-fail"
763});
764
765default_test!(RunFail {
766 path: "src/test/run-fail",
767 mode: "run-fail",
768 suite: "run-fail"
769});
770
771default_test!(RunPassValgrind {
772 path: "src/test/run-pass-valgrind",
773 mode: "run-pass-valgrind",
774 suite: "run-pass-valgrind"
775});
776
777default_test!(MirOpt {
778 path: "src/test/mir-opt",
779 mode: "mir-opt",
780 suite: "mir-opt"
781});
782
783default_test!(Codegen {
784 path: "src/test/codegen",
785 mode: "codegen",
786 suite: "codegen"
787});
788
789default_test!(CodegenUnits {
790 path: "src/test/codegen-units",
791 mode: "codegen-units",
792 suite: "codegen-units"
793});
794
795default_test!(Incremental {
796 path: "src/test/incremental",
797 mode: "incremental",
798 suite: "incremental"
799});
800
801default_test!(Debuginfo {
802 path: "src/test/debuginfo",
Mark Simulacrumaa8b93b2017-07-07 18:31:29803 // What this runs varies depending on the native platform being apple
Mark Simulacrumf104b122018-02-11 16:51:58804 mode: "debuginfo-XXX",
805 suite: "debuginfo"
806});
Mark Simulacrum6b3413d2017-07-05 12:41:27807
Mark Simulacrumf104b122018-02-11 16:51:58808host_test!(UiFullDeps {
809 path: "src/test/ui-fulldeps",
810 mode: "ui",
811 suite: "ui-fulldeps"
812});
Mark Simulacrumf1d04a32017-07-20 15:42:18813
Mark Simulacrumf104b122018-02-11 16:51:58814host_test!(RunPassFullDeps {
815 path: "src/test/run-pass-fulldeps",
816 mode: "run-pass",
817 suite: "run-pass-fulldeps"
818});
Mark Simulacrumf1d04a32017-07-20 15:42:18819
Mark Simulacrumf104b122018-02-11 16:51:58820host_test!(RunFailFullDeps {
821 path: "src/test/run-fail-fulldeps",
822 mode: "run-fail",
823 suite: "run-fail-fulldeps"
824});
Mark Simulacrumf1d04a32017-07-20 15:42:18825
Mark Simulacrumf104b122018-02-11 16:51:58826host_test!(CompileFailFullDeps {
827 path: "src/test/compile-fail-fulldeps",
828 mode: "compile-fail",
829 suite: "compile-fail-fulldeps"
830});
Mark Simulacrumf1d04a32017-07-20 15:42:18831
Mark Simulacrumf104b122018-02-11 16:51:58832host_test!(IncrementalFullDeps {
833 path: "src/test/incremental-fulldeps",
834 mode: "incremental",
835 suite: "incremental-fulldeps"
836});
Mark Simulacrumf1d04a32017-07-20 15:42:18837
Mark Simulacrumf104b122018-02-11 16:51:58838host_test!(Rustdoc {
839 path: "src/test/rustdoc",
840 mode: "rustdoc",
841 suite: "rustdoc"
842});
Mark Simulacrumf1d04a32017-07-20 15:42:18843
Mark Simulacrumf104b122018-02-11 16:51:58844test!(Pretty {
845 path: "src/test/pretty",
846 mode: "pretty",
847 suite: "pretty",
848 default: false,
849 host: true
850});
851test!(RunPassPretty {
852 path: "src/test/run-pass/pretty",
853 mode: "pretty",
854 suite: "run-pass",
855 default: false,
856 host: true
857});
858test!(RunFailPretty {
859 path: "src/test/run-fail/pretty",
860 mode: "pretty",
861 suite: "run-fail",
862 default: false,
863 host: true
864});
865test!(RunPassValgrindPretty {
866 path: "src/test/run-pass-valgrind/pretty",
867 mode: "pretty",
868 suite: "run-pass-valgrind",
869 default: false,
870 host: true
871});
872test!(RunPassFullDepsPretty {
873 path: "src/test/run-pass-fulldeps/pretty",
874 mode: "pretty",
875 suite: "run-pass-fulldeps",
876 default: false,
877 host: true
878});
879test!(RunFailFullDepsPretty {
880 path: "src/test/run-fail-fulldeps/pretty",
881 mode: "pretty",
882 suite: "run-fail-fulldeps",
883 default: false,
884 host: true
885});
Mark Simulacrumf1d04a32017-07-20 15:42:18886
Eric Hussa90a9632018-05-15 23:39:21887default_test!(RunMake {
Mark Simulacrumf104b122018-02-11 16:51:58888 path: "src/test/run-make",
889 mode: "run-make",
890 suite: "run-make"
891});
Mark Simulacrumf1d04a32017-07-20 15:42:18892
Alex Crichton7df6f412018-03-09 17:26:15893host_test!(RunMakeFullDeps {
894 path: "src/test/run-make-fulldeps",
895 mode: "run-make",
896 suite: "run-make-fulldeps"
897});
898
Mark Simulacrumf1d04a32017-07-20 15:42:18899#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
900struct Compiletest {
901 compiler: Compiler,
902 target: Interned<String>,
903 mode: &'static str,
904 suite: &'static str,
Collins Abitekaniza41ee6fe2018-04-12 11:49:31905 path: Option<&'static str>,
Felix S. Klock II55895502018-04-11 15:15:59906 compare_mode: Option<&'static str>,
Mark Simulacrumf1d04a32017-07-20 15:42:18907}
908
909impl Step for Compiletest {
910 type Output = ();
911
912 fn should_run(run: ShouldRun) -> ShouldRun {
913 run.never()
914 }
915
Mark Simulacrum001e9f32017-07-05 01:41:43916 /// Executes the `compiletest` tool to run a suite of tests.
917 ///
918 /// Compiles all tests with `compiler` for `target` with the specified
919 /// compiletest `mode` and `suite` arguments. For example `mode` can be
920 /// "run-pass" or `suite` can be something like `debuginfo`.
921 fn run(self, builder: &Builder) {
Mark Simulacrum001e9f32017-07-05 01:41:43922 let compiler = self.compiler;
923 let target = self.target;
924 let mode = self.mode;
925 let suite = self.suite;
Mark Simulacrum6b3413d2017-07-05 12:41:27926
Collins Abitekaniza41ee6fe2018-04-12 11:49:31927 // Path for test suite
928 let suite_path = self.path.unwrap_or("");
929
Mark Simulacrum6b3413d2017-07-05 12:41:27930 // Skip codegen tests if they aren't enabled in configuration.
Mark Simulacrumbe1e7892018-04-14 23:27:57931 if !builder.config.codegen_tests && suite == "codegen" {
Mark Simulacrum6b3413d2017-07-05 12:41:27932 return;
933 }
934
935 if suite == "debuginfo" {
Mark Simulacrum951616c2017-07-20 17:23:29936 // Skip debuginfo tests on MSVC
Mark Simulacrumbe1e7892018-04-14 23:27:57937 if builder.config.build.contains("msvc") {
Mark Simulacrum951616c2017-07-20 17:23:29938 return;
939 }
940
Mark Simulacrum6b3413d2017-07-05 12:41:27941 if mode == "debuginfo-XXX" {
Mark Simulacrumbe1e7892018-04-14 23:27:57942 return if builder.config.build.contains("apple") {
Mark Simulacrum6b3413d2017-07-05 12:41:27943 builder.ensure(Compiletest {
944 mode: "debuginfo-lldb",
945 ..self
Mark Simulacrum528646e2017-07-14 00:48:44946 });
Mark Simulacrum6b3413d2017-07-05 12:41:27947 } else {
948 builder.ensure(Compiletest {
949 mode: "debuginfo-gdb",
950 ..self
Mark Simulacrum528646e2017-07-14 00:48:44951 });
Mark Simulacrum6b3413d2017-07-05 12:41:27952 };
953 }
954
Mark Simulacrum6b3413d2017-07-05 12:41:27955 builder.ensure(dist::DebuggerScripts {
Mark Simulacrum528646e2017-07-14 00:48:44956 sysroot: builder.sysroot(compiler),
Santiago Pastorinob39a1d62018-05-30 17:33:43957 host: target,
Mark Simulacrum6b3413d2017-07-05 12:41:27958 });
959 }
960
961 if suite.ends_with("fulldeps") ||
962 // FIXME: Does pretty need librustc compiled? Note that there are
963 // fulldeps test suites with mode = pretty as well.
Mark Simulacrumcf24a1d2018-06-02 13:50:35964 mode == "pretty"
Santiago Pastorinob39a1d62018-05-30 17:33:43965 {
Mark Simulacrum6b3413d2017-07-05 12:41:27966 builder.ensure(compile::Rustc { compiler, target });
967 }
968
969 builder.ensure(compile::Test { compiler, target });
970 builder.ensure(native::TestHelpers { target });
Mark Simulacrumaa8b93b2017-07-07 18:31:29971 builder.ensure(RemoteCopyLibs { compiler, target });
Mark Simulacrum6b3413d2017-07-05 12:41:27972
Mark Simulacrum6b3413d2017-07-05 12:41:27973 let mut cmd = builder.tool_cmd(Tool::Compiletest);
Alex Crichtonb325baf2016-04-05 18:34:23974
Mark Simulacrum001e9f32017-07-05 01:41:43975 // compiletest currently has... a lot of arguments, so let's just pass all
976 // of them!
Brian Anderson8401e372016-09-15 19:42:26977
Santiago Pastorinob39a1d62018-05-30 17:33:43978 cmd.arg("--compile-lib-path")
979 .arg(builder.rustc_libdir(compiler));
980 cmd.arg("--run-lib-path")
981 .arg(builder.sysroot_libdir(compiler, target));
Mark Simulacrumc114fe52017-07-05 17:21:33982 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
Mark Simulacrum4e5333c2017-07-25 22:54:33983
Guillaume Gomezb2192ae2018-04-01 19:06:35984 let is_rustdoc_ui = suite.ends_with("rustdoc-ui");
985
Mark Simulacrum4e5333c2017-07-25 22:54:33986 // Avoid depending on rustdoc when we don't need it.
Santiago Pastorinob39a1d62018-05-30 17:33:43987 if mode == "rustdoc"
988 || (mode == "run-make" && suite.ends_with("fulldeps"))
989 || (mode == "ui" && is_rustdoc_ui)
990 {
991 cmd.arg("--rustdoc-path")
992 .arg(builder.rustdoc(compiler.host));
Mark Simulacrum4e5333c2017-07-25 22:54:33993 }
994
Santiago Pastorinob39a1d62018-05-30 17:33:43995 cmd.arg("--src-base")
996 .arg(builder.src.join("src/test").join(suite));
997 cmd.arg("--build-base")
998 .arg(testdir(builder, compiler.host).join(suite));
999 cmd.arg("--stage-id")
1000 .arg(format!("stage{}-{}", compiler.stage, target));
Mark Simulacrum001e9f32017-07-05 01:41:431001 cmd.arg("--mode").arg(mode);
1002 cmd.arg("--target").arg(target);
Mark Simulacrum528646e2017-07-14 00:48:441003 cmd.arg("--host").arg(&*compiler.host);
Santiago Pastorinob39a1d62018-05-30 17:33:431004 cmd.arg("--llvm-filecheck")
1005 .arg(builder.llvm_filecheck(builder.config.build));
Alex Crichtonf4e4ec72016-05-13 22:26:411006
Oliver Schneiderceed8eb2018-05-16 16:17:291007 if builder.config.cmd.bless() {
Oliver Schneider37dee692018-05-16 15:18:191008 cmd.arg("--bless");
1009 }
1010
Santiago Pastorinob970fee2018-05-28 22:44:331011 let compare_mode = builder.config.cmd.compare_mode().or(self.compare_mode);
1012
Mark Simulacrumbe1e7892018-04-14 23:27:571013 if let Some(ref nodejs) = builder.config.nodejs {
Mark Simulacrum001e9f32017-07-05 01:41:431014 cmd.arg("--nodejs").arg(nodejs);
1015 }
Alex Crichtonf4e4ec72016-05-13 22:26:411016
Guillaume Gomezb2192ae2018-04-01 19:06:351017 let mut flags = if is_rustdoc_ui {
1018 Vec::new()
1019 } else {
1020 vec!["-Crpath".to_string()]
1021 };
1022 if !is_rustdoc_ui {
Mark Simulacrumbe1e7892018-04-14 23:27:571023 if builder.config.rust_optimize_tests {
Guillaume Gomezb2192ae2018-04-01 19:06:351024 flags.push("-O".to_string());
1025 }
Mark Simulacrumbe1e7892018-04-14 23:27:571026 if builder.config.rust_debuginfo_tests {
Guillaume Gomezb2192ae2018-04-01 19:06:351027 flags.push("-g".to_string());
1028 }
Mark Simulacrum001e9f32017-07-05 01:41:431029 }
Guillaume Gomeza3ed2ab2018-04-15 11:05:141030 flags.push("-Zunstable-options".to_string());
Mark Simulacrumbe1e7892018-04-14 23:27:571031 flags.push(builder.config.cmd.rustc_args().join(" "));
Alex Crichtoncbe62922016-04-19 16:44:191032
Mark Simulacrumbe1e7892018-04-14 23:27:571033 if let Some(linker) = builder.linker(target) {
Oliver Schneideracdf83f2017-12-06 08:25:291034 cmd.arg("--linker").arg(linker);
1035 }
1036
1037 let hostflags = flags.clone();
Mark Simulacrum001e9f32017-07-05 01:41:431038 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
Alex Crichtoncbe62922016-04-19 16:44:191039
Oliver Schneideracdf83f2017-12-06 08:25:291040 let mut targetflags = flags.clone();
Santiago Pastorinob39a1d62018-05-30 17:33:431041 targetflags.push(format!(
1042 "-Lnative={}",
1043 builder.test_helpers_out(target).display()
1044 ));
Mark Simulacrum001e9f32017-07-05 01:41:431045 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
Alex Crichtonb325baf2016-04-05 18:34:231046
Mark Simulacrumbe1e7892018-04-14 23:27:571047 cmd.arg("--docck-python").arg(builder.python());
Alex Crichtonb325baf2016-04-05 18:34:231048
Mark Simulacrumbe1e7892018-04-14 23:27:571049 if builder.config.build.ends_with("apple-darwin") {
Mark Simulacrum001e9f32017-07-05 01:41:431050 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
1051 // LLDB plugin's compiled module which only works with the system python
1052 // (namely not Homebrew-installed python)
1053 cmd.arg("--lldb-python").arg("/usr/bin/python");
1054 } else {
Mark Simulacrumbe1e7892018-04-14 23:27:571055 cmd.arg("--lldb-python").arg(builder.python());
Mark Simulacrum001e9f32017-07-05 01:41:431056 }
Alex Crichtonb325baf2016-04-05 18:34:231057
Mark Simulacrumbe1e7892018-04-14 23:27:571058 if let Some(ref gdb) = builder.config.gdb {
Mark Simulacrum001e9f32017-07-05 01:41:431059 cmd.arg("--gdb").arg(gdb);
1060 }
Mark Simulacrumbe1e7892018-04-14 23:27:571061 if let Some(ref vers) = builder.lldb_version {
Mark Simulacrum001e9f32017-07-05 01:41:431062 cmd.arg("--lldb-version").arg(vers);
1063 }
Mark Simulacrumbe1e7892018-04-14 23:27:571064 if let Some(ref dir) = builder.lldb_python_dir {
Mark Simulacrum001e9f32017-07-05 01:41:431065 cmd.arg("--lldb-python-dir").arg(dir);
1066 }
Alex Crichtonb325baf2016-04-05 18:34:231067
Collins Abitekaniza41ee6fe2018-04-12 11:49:311068 // Get paths from cmd args
1069 let paths = match &builder.config.cmd {
Santiago Pastorinob39a1d62018-05-30 17:33:431070 Subcommand::Test { ref paths, .. } => &paths[..],
1071 _ => &[],
Collins Abitekaniza41ee6fe2018-04-12 11:49:311072 };
1073
1074 // Get test-args by striping suite path
Santiago Pastorinob39a1d62018-05-30 17:33:431075 let mut test_args: Vec<&str> = paths
1076 .iter()
Steven Laabs475405b2018-06-22 04:57:061077 .map(|p| {
1078 match p.strip_prefix(".") {
1079 Ok(path) => path,
1080 Err(_) => p,
1081 }
1082 })
Santiago Pastorinob39a1d62018-05-30 17:33:431083 .filter(|p| p.starts_with(suite_path) && p.is_file())
1084 .map(|p| p.strip_prefix(suite_path).unwrap().to_str().unwrap())
1085 .collect();
Collins Abitekaniza41ee6fe2018-04-12 11:49:311086
1087 test_args.append(&mut builder.config.cmd.test_args());
1088
1089 cmd.args(&test_args);
Corey Farwellc8c6d2c2016-10-30 01:58:521090
Mark Simulacrumbe1e7892018-04-14 23:27:571091 if builder.is_verbose() {
Mark Simulacrum001e9f32017-07-05 01:41:431092 cmd.arg("--verbose");
1093 }
Alex Crichton126e09e2016-04-14 22:51:031094
Oliver Schneider0c1bcd32018-06-07 12:40:361095 if !builder.config.verbose_tests {
Mark Simulacrum001e9f32017-07-05 01:41:431096 cmd.arg("--quiet");
1097 }
Alex Crichton1747ce22017-01-28 21:38:061098
Mark Simulacrumbe1e7892018-04-14 23:27:571099 if builder.config.llvm_enabled {
Alex Crichtonbe902e72018-03-05 17:47:541100 let llvm_config = builder.ensure(native::Llvm {
Mark Simulacrumbe1e7892018-04-14 23:27:571101 target: builder.config.build,
Alex Crichtonbe902e72018-03-05 17:47:541102 emscripten: false,
1103 });
Mark Simulacrumbe1e7892018-04-14 23:27:571104 if !builder.config.dry_run {
Mark Simulacrum0ce5cf02018-04-01 01:21:141105 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1106 cmd.arg("--llvm-version").arg(llvm_version);
1107 }
Mark Simulacrumbe1e7892018-04-14 23:27:571108 if !builder.is_rust_llvm(target) {
bjorn30c97bbf2017-08-13 10:30:541109 cmd.arg("--system-llvm");
1110 }
1111
1112 // Only pass correct values for these flags for the `run-make` suite as it
1113 // requires that a C++ compiler was configured which isn't always the case.
Eric Hussa90a9632018-05-15 23:39:211114 if !builder.config.dry_run && suite == "run-make-fulldeps" {
bjorn30c97bbf2017-08-13 10:30:541115 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1116 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
Santiago Pastorinob39a1d62018-05-30 17:33:431117 cmd.arg("--cc")
1118 .arg(builder.cc(target))
1119 .arg("--cxx")
1120 .arg(builder.cxx(target).unwrap())
1121 .arg("--cflags")
1122 .arg(builder.cflags(target).join(" "))
1123 .arg("--llvm-components")
1124 .arg(llvm_components.trim())
1125 .arg("--llvm-cxxflags")
1126 .arg(llvm_cxxflags.trim());
Mark Simulacrumbe1e7892018-04-14 23:27:571127 if let Some(ar) = builder.ar(target) {
Oliver Schneideracdf83f2017-12-06 08:25:291128 cmd.arg("--ar").arg(ar);
1129 }
bjorn30c97bbf2017-08-13 10:30:541130 }
1131 }
Eric Hussa90a9632018-05-15 23:39:211132 if suite == "run-make-fulldeps" && !builder.config.llvm_enabled {
Santiago Pastorinob39a1d62018-05-30 17:33:431133 builder.info(&format!(
1134 "Ignoring run-make test suite as they generally don't work without LLVM"
1135 ));
bjorn30c97bbf2017-08-13 10:30:541136 return;
1137 }
1138
Eric Hussa90a9632018-05-15 23:39:211139 if suite != "run-make-fulldeps" {
Santiago Pastorinob39a1d62018-05-30 17:33:431140 cmd.arg("--cc")
1141 .arg("")
1142 .arg("--cxx")
1143 .arg("")
1144 .arg("--cflags")
1145 .arg("")
1146 .arg("--llvm-components")
1147 .arg("")
1148 .arg("--llvm-cxxflags")
1149 .arg("");
Mark Simulacrum001e9f32017-07-05 01:41:431150 }
1151
Mark Simulacrumbe1e7892018-04-14 23:27:571152 if builder.remote_tested(target) {
Santiago Pastorinob39a1d62018-05-30 17:33:431153 cmd.arg("--remote-test-client")
1154 .arg(builder.tool_exe(Tool::RemoteTestClient));
Mark Simulacrum001e9f32017-07-05 01:41:431155 }
1156
1157 // Running a C compiler on MSVC requires a few env vars to be set, to be
1158 // sure to set them here.
1159 //
1160 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1161 // rather than stomp over it.
1162 if target.contains("msvc") {
Mark Simulacrumbe1e7892018-04-14 23:27:571163 for &(ref k, ref v) in builder.cc[&target].env() {
Mark Simulacrum001e9f32017-07-05 01:41:431164 if k != "PATH" {
1165 cmd.env(k, v);
1166 }
Alex Crichton126e09e2016-04-14 22:51:031167 }
1168 }
Mark Simulacrum001e9f32017-07-05 01:41:431169 cmd.env("RUSTC_BOOTSTRAP", "1");
Mark Simulacrumbe1e7892018-04-14 23:27:571170 builder.add_rust_test_threads(&mut cmd);
Mark Simulacrum001e9f32017-07-05 01:41:431171
Mark Simulacrumbe1e7892018-04-14 23:27:571172 if builder.config.sanitizers {
Mark Simulacrum001e9f32017-07-05 01:41:431173 cmd.env("SANITIZER_SUPPORT", "1");
1174 }
1175
Mark Simulacrumbe1e7892018-04-14 23:27:571176 if builder.config.profiler {
Mark Simulacrum001e9f32017-07-05 01:41:431177 cmd.env("PROFILER_SUPPORT", "1");
1178 }
1179
Mark Simulacrumbe1e7892018-04-14 23:27:571180 cmd.env("RUST_TEST_TMPDIR", builder.out.join("tmp"));
Alex Crichton884715c2018-01-22 15:29:241181
Mark Simulacrum001e9f32017-07-05 01:41:431182 cmd.arg("--adb-path").arg("adb");
1183 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1184 if target.contains("android") {
1185 // Assume that cc for this target comes from the android sysroot
1186 cmd.arg("--android-cross-path")
Santiago Pastorinob39a1d62018-05-30 17:33:431187 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
Mark Simulacrum001e9f32017-07-05 01:41:431188 } else {
1189 cmd.arg("--android-cross-path").arg("");
1190 }
1191
Mark Simulacrumbe1e7892018-04-14 23:27:571192 builder.ci_env.force_coloring_in_ci(&mut cmd);
Mark Simulacrum001e9f32017-07-05 01:41:431193
Mark Simulacrumbe1e7892018-04-14 23:27:571194 let _folder = builder.fold_output(|| format!("test_{}", suite));
Santiago Pastorinob39a1d62018-05-30 17:33:431195 builder.info(&format!(
1196 "Check compiletest suite={} mode={} ({} -> {})",
1197 suite, mode, &compiler.host, target
1198 ));
Mark Simulacrumbe1e7892018-04-14 23:27:571199 let _time = util::timeit(&builder);
1200 try_run(builder, &mut cmd);
Felix S. Klock II55895502018-04-11 15:15:591201
1202 if let Some(compare_mode) = compare_mode {
1203 cmd.arg("--compare-mode").arg(compare_mode);
1204 let _folder = builder.fold_output(|| format!("test_{}_{}", suite, compare_mode));
Santiago Pastorinob39a1d62018-05-30 17:33:431205 builder.info(&format!(
1206 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1207 suite, mode, compare_mode, &compiler.host, target
1208 ));
Felix S. Klock II55895502018-04-11 15:15:591209 let _time = util::timeit(&builder);
1210 try_run(builder, &mut cmd);
1211 }
Alex Crichton126e09e2016-04-14 22:51:031212 }
Alex Crichtonb325baf2016-04-05 18:34:231213}
Alex Crichtonede89442016-04-15 01:00:351214
Mark Simulacrum528646e2017-07-14 00:48:441215#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
kennytm0d300d42018-02-21 19:13:341216struct DocTest {
Mark Simulacrum528646e2017-07-14 00:48:441217 compiler: Compiler,
kennytm0d300d42018-02-21 19:13:341218 path: &'static str,
1219 name: &'static str,
1220 is_ext_doc: bool,
Mark Simulacruma5ab2ce2017-07-12 15:15:001221}
1222
kennytm0d300d42018-02-21 19:13:341223impl Step for DocTest {
Mark Simulacruma5ab2ce2017-07-12 15:15:001224 type Output = ();
Mark Simulacruma5ab2ce2017-07-12 15:15:001225 const ONLY_HOSTS: bool = true;
Alex Crichtonede89442016-04-15 01:00:351226
Mark Simulacrum56128fb2017-07-19 00:03:381227 fn should_run(run: ShouldRun) -> ShouldRun {
kennytm0d300d42018-02-21 19:13:341228 run.never()
Mark Simulacruma5ab2ce2017-07-12 15:15:001229 }
1230
1231 /// Run `rustdoc --test` for all documentation in `src/doc`.
1232 ///
1233 /// This will run all tests in our markdown documentation (e.g. the book)
1234 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
1235 /// `compiler`.
1236 fn run(self, builder: &Builder) {
Mark Simulacruma5ab2ce2017-07-12 15:15:001237 let compiler = self.compiler;
Mark Simulacrumceecd622017-07-12 16:12:471238
Santiago Pastorinob39a1d62018-05-30 17:33:431239 builder.ensure(compile::Test {
1240 compiler,
1241 target: compiler.host,
1242 });
Mark Simulacrumceecd622017-07-12 16:12:471243
Mark Simulacruma5ab2ce2017-07-12 15:15:001244 // Do a breadth-first traversal of the `src/doc` directory and just run
1245 // tests for all files that end in `*.md`
Mark Simulacrumbe1e7892018-04-14 23:27:571246 let mut stack = vec![builder.src.join(self.path)];
1247 let _time = util::timeit(&builder);
1248 let _folder = builder.fold_output(|| format!("test_{}", self.name));
Mark Simulacruma5ab2ce2017-07-12 15:15:001249
Mark Simulacruma7274472018-03-27 14:06:471250 let mut files = Vec::new();
Mark Simulacruma5ab2ce2017-07-12 15:15:001251 while let Some(p) = stack.pop() {
1252 if p.is_dir() {
1253 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
Santiago Pastorinob39a1d62018-05-30 17:33:431254 continue;
Mark Simulacruma5ab2ce2017-07-12 15:15:001255 }
1256
1257 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1258 continue;
1259 }
1260
1261 // The nostarch directory in the book is for no starch, and so isn't
Mark Simulacrumbe1e7892018-04-14 23:27:571262 // guaranteed to builder. We don't care if it doesn't build, so skip it.
Mark Simulacruma5ab2ce2017-07-12 15:15:001263 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
1264 continue;
1265 }
1266
Mark Simulacruma7274472018-03-27 14:06:471267 files.push(p);
1268 }
1269
1270 files.sort();
1271
kennytm20231d72018-07-02 21:53:181272 let mut toolstate = ToolState::TestPass;
Mark Simulacruma7274472018-03-27 14:06:471273 for file in files {
kennytm20231d72018-07-02 21:53:181274 if !markdown_test(builder, compiler, &file) {
1275 toolstate = ToolState::TestFail;
kennytma9f940e2018-02-21 19:25:231276 }
Alex Crichtonede89442016-04-15 01:00:351277 }
kennytm20231d72018-07-02 21:53:181278 if self.is_ext_doc {
1279 builder.save_toolstate(self.name, toolstate);
1280 }
Alex Crichtonede89442016-04-15 01:00:351281 }
1282}
1283
kennytm0d300d42018-02-21 19:13:341284macro_rules! test_book {
1285 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1286 $(
1287 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1288 pub struct $name {
1289 compiler: Compiler,
1290 }
1291
1292 impl Step for $name {
1293 type Output = ();
1294 const DEFAULT: bool = $default;
1295 const ONLY_HOSTS: bool = true;
1296
1297 fn should_run(run: ShouldRun) -> ShouldRun {
1298 run.path($path)
1299 }
1300
1301 fn make_run(run: RunConfig) {
1302 run.builder.ensure($name {
1303 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1304 });
1305 }
1306
1307 fn run(self, builder: &Builder) {
1308 builder.ensure(DocTest {
1309 compiler: self.compiler,
1310 path: $path,
1311 name: $book_name,
1312 is_ext_doc: !$default,
1313 });
1314 }
1315 }
1316 )+
1317 }
1318}
1319
1320test_book!(
1321 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1322 Reference, "src/doc/reference", "reference", default=false;
1323 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
steveklabnikb99418d2018-04-05 18:41:481324 RustcBook, "src/doc/rustc", "rustc", default=true;
kennytm0d300d42018-02-21 19:13:341325 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1326 TheBook, "src/doc/book", "book", default=false;
1327 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1328);
1329
Mark Simulacrum528646e2017-07-14 00:48:441330#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1331pub struct ErrorIndex {
1332 compiler: Compiler,
Mark Simulacrum001e9f32017-07-05 01:41:431333}
Alex Crichton0e272de2016-11-16 20:31:191334
Mark Simulacrum528646e2017-07-14 00:48:441335impl Step for ErrorIndex {
Mark Simulacrum001e9f32017-07-05 01:41:431336 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271337 const DEFAULT: bool = true;
1338 const ONLY_HOSTS: bool = true;
1339
Mark Simulacrum56128fb2017-07-19 00:03:381340 fn should_run(run: ShouldRun) -> ShouldRun {
1341 run.path("src/tools/error_index_generator")
Mark Simulacrum6b3413d2017-07-05 12:41:271342 }
1343
Mark Simulacrum6a67a052017-07-20 23:51:071344 fn make_run(run: RunConfig) {
1345 run.builder.ensure(ErrorIndex {
1346 compiler: run.builder.compiler(run.builder.top_stage, run.host),
Mark Simulacrum6b3413d2017-07-05 12:41:271347 });
1348 }
Alex Crichtonede89442016-04-15 01:00:351349
Mark Simulacrum001e9f32017-07-05 01:41:431350 /// Run the error index generator tool to execute the tests located in the error
1351 /// index.
1352 ///
1353 /// The `error_index_generator` tool lives in `src/tools` and is used to
1354 /// generate a markdown file from the error indexes of the code base which is
1355 /// then passed to `rustdoc --test`.
1356 fn run(self, builder: &Builder) {
Mark Simulacrum001e9f32017-07-05 01:41:431357 let compiler = self.compiler;
1358
Santiago Pastorinob39a1d62018-05-30 17:33:431359 builder.ensure(compile::Std {
1360 compiler,
1361 target: compiler.host,
1362 });
Mark Simulacrum6b3413d2017-07-05 12:41:271363
Mark Simulacrumbe1e7892018-04-14 23:27:571364 let dir = testdir(builder, compiler.host);
Mark Simulacrum001e9f32017-07-05 01:41:431365 t!(fs::create_dir_all(&dir));
1366 let output = dir.join("error-index.md");
1367
Alex Crichton6fd4d672018-03-16 15:35:031368 let mut tool = builder.tool_cmd(Tool::ErrorIndex);
1369 tool.arg("markdown")
1370 .arg(&output)
Mark Simulacrumbe1e7892018-04-14 23:27:571371 .env("CFG_BUILD", &builder.config.build)
1372 .env("RUSTC_ERROR_METADATA_DST", builder.extended_error_dir());
Mark Simulacrum001e9f32017-07-05 01:41:431373
Mark Simulacrumbe1e7892018-04-14 23:27:571374 let _folder = builder.fold_output(|| "test_error_index");
1375 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1376 let _time = util::timeit(&builder);
1377 builder.run(&mut tool);
Mark Simulacrumc114fe52017-07-05 17:21:331378 markdown_test(builder, compiler, &output);
Mark Simulacrum001e9f32017-07-05 01:41:431379 }
Alex Crichtonede89442016-04-15 01:00:351380}
1381
kennytma9f940e2018-02-21 19:25:231382fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) -> bool {
Mark Simulacrum0ce5cf02018-04-01 01:21:141383 match File::open(markdown) {
1384 Ok(mut file) => {
1385 let mut contents = String::new();
1386 t!(file.read_to_string(&mut contents));
1387 if !contents.contains("```") {
1388 return true;
1389 }
1390 }
Santiago Pastorinob39a1d62018-05-30 17:33:431391 Err(_) => {}
Mark Simulacrumdd1d75e2017-06-04 23:55:501392 }
1393
Mark Simulacrumbe1e7892018-04-14 23:27:571394 builder.info(&format!("doc tests for: {}", markdown.display()));
Mark Simulacrumfacf5a92017-08-04 22:13:011395 let mut cmd = builder.rustdoc_cmd(compiler.host);
Mark Simulacrumbe1e7892018-04-14 23:27:571396 builder.add_rust_test_threads(&mut cmd);
Alex Crichtonede89442016-04-15 01:00:351397 cmd.arg("--test");
1398 cmd.arg(markdown);
Alex Crichton6f62fae2016-12-12 17:03:351399 cmd.env("RUSTC_BOOTSTRAP", "1");
Corey Farwellc8c6d2c2016-10-30 01:58:521400
Mark Simulacrumbe1e7892018-04-14 23:27:571401 let test_args = builder.config.cmd.test_args().join(" ");
Corey Farwellc8c6d2c2016-10-30 01:58:521402 cmd.arg("--test-args").arg(test_args);
1403
Oliver Schneider0c1bcd32018-06-07 12:40:361404 if builder.config.verbose_tests {
Mark Simulacrumbe1e7892018-04-14 23:27:571405 try_run(builder, &mut cmd)
Oliver Schneider0c1bcd32018-06-07 12:40:361406 } else {
1407 try_run_quiet(builder, &mut cmd)
kennytm6ac07872017-05-21 20:27:471408 }
Alex Crichtonede89442016-04-15 01:00:351409}
Alex Crichtonbb9062a2016-04-29 21:23:151410
Mark Simulacrum528646e2017-07-14 00:48:441411#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum981afa52017-07-18 21:28:531412pub struct CrateLibrustc {
Mark Simulacrum528646e2017-07-14 00:48:441413 compiler: Compiler,
1414 target: Interned<String>,
Mark Simulacrum6b3413d2017-07-05 12:41:271415 test_kind: TestKind,
Mark Simulacrumf104b122018-02-11 16:51:581416 krate: Interned<String>,
Mark Simulacrum6b3413d2017-07-05 12:41:271417}
1418
Mark Simulacrum981afa52017-07-18 21:28:531419impl Step for CrateLibrustc {
Mark Simulacrum6b3413d2017-07-05 12:41:271420 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271421 const DEFAULT: bool = true;
1422 const ONLY_HOSTS: bool = true;
1423
Mark Simulacrum56128fb2017-07-19 00:03:381424 fn should_run(run: ShouldRun) -> ShouldRun {
1425 run.krate("rustc-main")
Mark Simulacrum6b3413d2017-07-05 12:41:271426 }
1427
Mark Simulacrum6a67a052017-07-20 23:51:071428 fn make_run(run: RunConfig) {
1429 let builder = run.builder;
1430 let compiler = builder.compiler(builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:271431
Mark Simulacrumf104b122018-02-11 16:51:581432 for krate in builder.in_tree_crates("rustc-main") {
1433 if run.path.ends_with(&krate.path) {
Oliver Schneider37dee692018-05-16 15:18:191434 let test_kind = builder.kind.into();
Mark Simulacrum6b3413d2017-07-05 12:41:271435
Mark Simulacrumf104b122018-02-11 16:51:581436 builder.ensure(CrateLibrustc {
1437 compiler,
1438 target: run.target,
1439 test_kind,
1440 krate: krate.name,
1441 });
Mark Simulacrum6b3413d2017-07-05 12:41:271442 }
Mark Simulacrum6b3413d2017-07-05 12:41:271443 }
1444 }
1445
Mark Simulacrum6b3413d2017-07-05 12:41:271446 fn run(self, builder: &Builder) {
Mark Simulacrum981afa52017-07-18 21:28:531447 builder.ensure(Crate {
Mark Simulacrum6b3413d2017-07-05 12:41:271448 compiler: self.compiler,
1449 target: self.target,
Collins Abitekaniza42ee6d52018-05-19 20:04:411450 mode: Mode::Rustc,
Mark Simulacrum6b3413d2017-07-05 12:41:271451 test_kind: self.test_kind,
1452 krate: self.krate,
1453 });
1454 }
1455}
1456
Mark Simulacrum528646e2017-07-14 00:48:441457#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrumf104b122018-02-11 16:51:581458pub struct CrateNotDefault {
Mark Simulacrum528646e2017-07-14 00:48:441459 compiler: Compiler,
1460 target: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:431461 test_kind: TestKind,
Mark Simulacrumf104b122018-02-11 16:51:581462 krate: &'static str,
Mark Simulacrum001e9f32017-07-05 01:41:431463}
Alex Crichtonbb9062a2016-04-29 21:23:151464
Mark Simulacrumf104b122018-02-11 16:51:581465impl Step for CrateNotDefault {
Mark Simulacrum001e9f32017-07-05 01:41:431466 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271467
Mark Simulacrum56128fb2017-07-19 00:03:381468 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumf104b122018-02-11 16:51:581469 run.path("src/liballoc_jemalloc")
1470 .path("src/librustc_asan")
1471 .path("src/librustc_lsan")
1472 .path("src/librustc_msan")
1473 .path("src/librustc_tsan")
Mark Simulacrum6b3413d2017-07-05 12:41:271474 }
1475
Mark Simulacrum6a67a052017-07-20 23:51:071476 fn make_run(run: RunConfig) {
1477 let builder = run.builder;
1478 let compiler = builder.compiler(builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:271479
Oliver Schneider37dee692018-05-16 15:18:191480 let test_kind = builder.kind.into();
Mark Simulacrumf104b122018-02-11 16:51:581481
1482 builder.ensure(CrateNotDefault {
1483 compiler,
1484 target: run.target,
1485 test_kind,
1486 krate: match run.path {
1487 _ if run.path.ends_with("src/liballoc_jemalloc") => "alloc_jemalloc",
1488 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1489 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1490 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1491 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1492 _ => panic!("unexpected path {:?}", run.path),
1493 },
1494 });
1495 }
1496
1497 fn run(self, builder: &Builder) {
1498 builder.ensure(Crate {
1499 compiler: self.compiler,
1500 target: self.target,
Collins Abitekaniza42ee6d52018-05-19 20:04:411501 mode: Mode::Std,
Mark Simulacrumf104b122018-02-11 16:51:581502 test_kind: self.test_kind,
1503 krate: INTERNER.intern_str(self.krate),
1504 });
1505 }
1506}
1507
kennytmbe9d6692018-05-05 18:33:011508#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
Mark Simulacrumf104b122018-02-11 16:51:581509pub struct Crate {
kennytmbe9d6692018-05-05 18:33:011510 pub compiler: Compiler,
1511 pub target: Interned<String>,
1512 pub mode: Mode,
1513 pub test_kind: TestKind,
1514 pub krate: Interned<String>,
Mark Simulacrumf104b122018-02-11 16:51:581515}
1516
1517impl Step for Crate {
1518 type Output = ();
1519 const DEFAULT: bool = true;
1520
1521 fn should_run(mut run: ShouldRun) -> ShouldRun {
1522 let builder = run.builder;
1523 run = run.krate("test");
1524 for krate in run.builder.in_tree_crates("std") {
Santiago Pastorinob39a1d62018-05-30 17:33:431525 if krate.is_local(&run.builder)
1526 && !krate.name.contains("jemalloc")
1527 && !(krate.name.starts_with("rustc_") && krate.name.ends_with("san"))
1528 && krate.name != "dlmalloc"
1529 {
Mark Simulacrumf104b122018-02-11 16:51:581530 run = run.path(krate.local_path(&builder).to_str().unwrap());
1531 }
1532 }
1533 run
1534 }
1535
1536 fn make_run(run: RunConfig) {
1537 let builder = run.builder;
1538 let compiler = builder.compiler(builder.top_stage, run.host);
1539
1540 let make = |mode: Mode, krate: &CargoCrate| {
Oliver Schneider37dee692018-05-16 15:18:191541 let test_kind = builder.kind.into();
Mark Simulacrum6b3413d2017-07-05 12:41:271542
Mark Simulacrum981afa52017-07-18 21:28:531543 builder.ensure(Crate {
Mark Simulacrum6a67a052017-07-20 23:51:071544 compiler,
1545 target: run.target,
Zack M. Davis1b6c9602017-08-07 05:54:091546 mode,
1547 test_kind,
Mark Simulacrumf104b122018-02-11 16:51:581548 krate: krate.name,
Mark Simulacrum6b3413d2017-07-05 12:41:271549 });
1550 };
1551
Mark Simulacrumf104b122018-02-11 16:51:581552 for krate in builder.in_tree_crates("std") {
1553 if run.path.ends_with(&krate.local_path(&builder)) {
Collins Abitekaniza42ee6d52018-05-19 20:04:411554 make(Mode::Std, krate);
Mark Simulacrum6b3413d2017-07-05 12:41:271555 }
Mark Simulacrumf104b122018-02-11 16:51:581556 }
1557 for krate in builder.in_tree_crates("test") {
1558 if run.path.ends_with(&krate.local_path(&builder)) {
Collins Abitekaniza42ee6d52018-05-19 20:04:411559 make(Mode::Test, krate);
Mark Simulacrum6b3413d2017-07-05 12:41:271560 }
Mark Simulacrum6b3413d2017-07-05 12:41:271561 }
1562 }
Alex Crichton7046fea2016-12-25 23:20:331563
Mark Simulacrumf104b122018-02-11 16:51:581564 /// Run all unit tests plus documentation tests for a given crate defined
1565 /// by a `Cargo.toml` (single manifest)
Mark Simulacrum001e9f32017-07-05 01:41:431566 ///
1567 /// This is what runs tests for crates like the standard library, compiler, etc.
1568 /// It essentially is the driver for running `cargo test`.
1569 ///
1570 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1571 /// arguments, and those arguments are discovered from `cargo metadata`.
1572 fn run(self, builder: &Builder) {
Mark Simulacrum001e9f32017-07-05 01:41:431573 let compiler = self.compiler;
1574 let target = self.target;
1575 let mode = self.mode;
1576 let test_kind = self.test_kind;
1577 let krate = self.krate;
Alex Crichtonbb9062a2016-04-29 21:23:151578
Mark Simulacrum6b3413d2017-07-05 12:41:271579 builder.ensure(compile::Test { compiler, target });
1580 builder.ensure(RemoteCopyLibs { compiler, target });
Mark Simulacrum001e9f32017-07-05 01:41:431581
1582 // If we're not doing a full bootstrap but we're testing a stage2 version of
1583 // libstd, then what we're actually testing is the libstd produced in
1584 // stage1. Reflect that here by updating the compiler that we're working
1585 // with automatically.
Mark Simulacrumbe1e7892018-04-14 23:27:571586 let compiler = if builder.force_use_stage1(compiler, target) {
Mark Simulacrum6b3413d2017-07-05 12:41:271587 builder.compiler(1, compiler.host)
Mark Simulacrum001e9f32017-07-05 01:41:431588 } else {
1589 compiler.clone()
1590 };
1591
Alex Crichton90105672017-07-17 16:32:081592 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
Mark Simulacrumf104b122018-02-11 16:51:581593 match mode {
Collins Abitekaniza42ee6d52018-05-19 20:04:411594 Mode::Std => {
Alex Crichtonbe902e72018-03-05 17:47:541595 compile::std_cargo(builder, &compiler, target, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081596 }
Collins Abitekaniza42ee6d52018-05-19 20:04:411597 Mode::Test => {
Mark Simulacrumbe1e7892018-04-14 23:27:571598 compile::test_cargo(builder, &compiler, target, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081599 }
Collins Abitekaniza42ee6d52018-05-19 20:04:411600 Mode::Rustc => {
Alex Crichton90105672017-07-17 16:32:081601 builder.ensure(compile::Rustc { compiler, target });
Mark Simulacrumbe1e7892018-04-14 23:27:571602 compile::rustc_cargo(builder, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081603 }
1604 _ => panic!("can only test libraries"),
1605 };
Alex Crichton90105672017-07-17 16:32:081606
Mark Simulacrum001e9f32017-07-05 01:41:431607 // Build up the base `cargo test` command.
1608 //
1609 // Pass in some standard flags then iterate over the graph we've discovered
1610 // in `cargo metadata` with the maps above and figure out what `-p`
1611 // arguments need to get passed.
Mark Simulacrumbe1e7892018-04-14 23:27:571612 if test_kind.subcommand() == "test" && !builder.fail_fast {
Mark Simulacrum001e9f32017-07-05 01:41:431613 cargo.arg("--no-fail-fast");
Alex Crichtonbb9062a2016-04-29 21:23:151614 }
kennytm1733f5e2018-05-05 16:04:061615 match builder.doc_tests {
kennytm05af55b2018-05-05 19:30:421616 DocTests::Only => {
kennytm1733f5e2018-05-05 16:04:061617 cargo.arg("--doc");
1618 }
kennytm05af55b2018-05-05 19:30:421619 DocTests::No => {
kennytm1733f5e2018-05-05 16:04:061620 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
1621 }
kennytm05af55b2018-05-05 19:30:421622 DocTests::Yes => {}
Guillaume Gomez8e469272018-02-17 14:45:391623 }
Mark Simulacrum001e9f32017-07-05 01:41:431624
Mark Simulacrumf104b122018-02-11 16:51:581625 cargo.arg("-p").arg(krate);
Alex Crichtonbb9062a2016-04-29 21:23:151626
Mark Simulacrum001e9f32017-07-05 01:41:431627 // The tests are going to run with the *target* libraries, so we need to
1628 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1629 //
1630 // Note that to run the compiler we need to run with the *host* libraries,
1631 // but our wrapper scripts arrange for that to be the case anyway.
1632 let mut dylib_path = dylib_path();
Mark Simulacrum528646e2017-07-14 00:48:441633 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
Mark Simulacrum001e9f32017-07-05 01:41:431634 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
Alex Crichtonbb9062a2016-04-29 21:23:151635
Mark Simulacrum001e9f32017-07-05 01:41:431636 cargo.arg("--");
Mark Simulacrumbe1e7892018-04-14 23:27:571637 cargo.args(&builder.config.cmd.test_args());
Alex Crichton0e272de2016-11-16 20:31:191638
Oliver Schneider0c1bcd32018-06-07 12:40:361639 if !builder.config.verbose_tests {
Mark Simulacrum001e9f32017-07-05 01:41:431640 cargo.arg("--quiet");
1641 }
Corey Farwellc8c6d2c2016-10-30 01:58:521642
Mark Simulacrum001e9f32017-07-05 01:41:431643 if target.contains("emscripten") {
Santiago Pastorinob39a1d62018-05-30 17:33:431644 cargo.env(
1645 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1646 builder
1647 .config
1648 .nodejs
1649 .as_ref()
1650 .expect("nodejs not configured"),
1651 );
Oliver Schneideracdf83f2017-12-06 08:25:291652 } else if target.starts_with("wasm32") {
Diggory Blake0e6601f2018-01-11 17:51:491653 // Warn about running tests without the `wasm_syscall` feature enabled.
1654 // The javascript shim implements the syscall interface so that test
1655 // output can be correctly reported.
Mark Simulacrumbe1e7892018-04-14 23:27:571656 if !builder.config.wasm_syscall {
Santiago Pastorinob39a1d62018-05-30 17:33:431657 builder.info(&format!(
1658 "Libstd was built without `wasm_syscall` feature enabled: \
1659 test output may not be visible."
1660 ));
Diggory Blake0e6601f2018-01-11 17:51:491661 }
1662
Oliver Schneideracdf83f2017-12-06 08:25:291663 // On the wasm32-unknown-unknown target we're using LTO which is
1664 // incompatible with `-C prefer-dynamic`, so disable that here
1665 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
1666
Santiago Pastorinob39a1d62018-05-30 17:33:431667 let node = builder
1668 .config
1669 .nodejs
1670 .as_ref()
Oliver Schneideracdf83f2017-12-06 08:25:291671 .expect("nodejs not configured");
Santiago Pastorinob39a1d62018-05-30 17:33:431672 let runner = format!(
1673 "{} {}/src/etc/wasm32-shim.js",
1674 node.display(),
1675 builder.src.display()
1676 );
Oliver Schneideracdf83f2017-12-06 08:25:291677 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
Mark Simulacrumbe1e7892018-04-14 23:27:571678 } else if builder.remote_tested(target) {
Santiago Pastorinob39a1d62018-05-30 17:33:431679 cargo.env(
1680 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1681 format!("{} run", builder.tool_exe(Tool::RemoteTestClient).display()),
1682 );
Mark Simulacrum001e9f32017-07-05 01:41:431683 }
Alex Crichton6fd4d672018-03-16 15:35:031684
Mark Simulacrumbe1e7892018-04-14 23:27:571685 let _folder = builder.fold_output(|| {
Santiago Pastorinob39a1d62018-05-30 17:33:431686 format!(
1687 "{}_stage{}-{}",
1688 test_kind.subcommand(),
1689 compiler.stage,
1690 krate
1691 )
Alex Crichton6fd4d672018-03-16 15:35:031692 });
Santiago Pastorinob39a1d62018-05-30 17:33:431693 builder.info(&format!(
1694 "{} {} stage{} ({} -> {})",
1695 test_kind, krate, compiler.stage, &compiler.host, target
1696 ));
Mark Simulacrumbe1e7892018-04-14 23:27:571697 let _time = util::timeit(&builder);
1698 try_run(builder, &mut cargo);
Alex Crichton39a5d3f2016-06-28 20:31:301699 }
1700}
1701
Mark Simulacrumf87696b2017-09-02 14:02:321702#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrumf104b122018-02-11 16:51:581703pub struct CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321704 host: Interned<String>,
1705 test_kind: TestKind,
1706}
1707
Mark Simulacrumf104b122018-02-11 16:51:581708impl Step for CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321709 type Output = ();
1710 const DEFAULT: bool = true;
1711 const ONLY_HOSTS: bool = true;
1712
1713 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumf104b122018-02-11 16:51:581714 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
Mark Simulacrumf87696b2017-09-02 14:02:321715 }
1716
1717 fn make_run(run: RunConfig) {
1718 let builder = run.builder;
1719
Oliver Schneider37dee692018-05-16 15:18:191720 let test_kind = builder.kind.into();
Mark Simulacrumf87696b2017-09-02 14:02:321721
Mark Simulacrumf104b122018-02-11 16:51:581722 builder.ensure(CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321723 host: run.host,
1724 test_kind,
1725 });
1726 }
1727
1728 fn run(self, builder: &Builder) {
Mark Simulacrumf87696b2017-09-02 14:02:321729 let test_kind = self.test_kind;
1730
1731 let compiler = builder.compiler(builder.top_stage, self.host);
1732 let target = compiler.host;
1733
Collins Abitekanizafb949b52018-05-27 22:09:431734 let mut cargo = tool::prepare_tool_cargo(builder,
1735 compiler,
Collins Abitekaniza36eafe52018-05-27 23:56:331736 Mode::ToolRustc,
Collins Abitekanizafb949b52018-05-27 22:09:431737 target,
1738 test_kind.subcommand(),
1739 "src/tools/rustdoc");
Mark Simulacrumbe1e7892018-04-14 23:27:571740 if test_kind.subcommand() == "test" && !builder.fail_fast {
Mark Simulacrumf87696b2017-09-02 14:02:321741 cargo.arg("--no-fail-fast");
1742 }
1743
1744 cargo.arg("-p").arg("rustdoc:0.0.0");
1745
1746 cargo.arg("--");
Mark Simulacrumbe1e7892018-04-14 23:27:571747 cargo.args(&builder.config.cmd.test_args());
Mark Simulacrumf87696b2017-09-02 14:02:321748
Oliver Schneider0c1bcd32018-06-07 12:40:361749 if !builder.config.verbose_tests {
Mark Simulacrumf87696b2017-09-02 14:02:321750 cargo.arg("--quiet");
1751 }
1752
Santiago Pastorinob39a1d62018-05-30 17:33:431753 let _folder = builder
1754 .fold_output(|| format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage));
1755 builder.info(&format!(
1756 "{} rustdoc stage{} ({} -> {})",
1757 test_kind, compiler.stage, &compiler.host, target
1758 ));
Mark Simulacrumbe1e7892018-04-14 23:27:571759 let _time = util::timeit(&builder);
Mark Simulacrumf87696b2017-09-02 14:02:321760
Mark Simulacrumbe1e7892018-04-14 23:27:571761 try_run(builder, &mut cargo);
Mark Simulacrumf87696b2017-09-02 14:02:321762 }
1763}
1764
Alex Crichton8e7849e2017-07-29 00:52:441765fn envify(s: &str) -> String {
Santiago Pastorinob39a1d62018-05-30 17:33:431766 s.chars()
1767 .map(|c| match c {
Alex Crichton8e7849e2017-07-29 00:52:441768 '-' => '_',
1769 c => c,
Santiago Pastorinob39a1d62018-05-30 17:33:431770 })
1771 .flat_map(|c| c.to_uppercase())
1772 .collect()
Alex Crichton39a5d3f2016-06-28 20:31:301773}
1774
Mark Simulacrumceecd622017-07-12 16:12:471775/// Some test suites are run inside emulators or on remote devices, and most
1776/// of our test binaries are linked dynamically which means we need to ship
1777/// the standard library and such to the emulator ahead of time. This step
1778/// represents this and is a dependency of all test suites.
1779///
1780/// Most of the time this is a noop. For some steps such as shipping data to
1781/// QEMU we have to build our own tools so we've got conditional dependencies
1782/// on those programs as well. Note that the remote test client is built for
1783/// the build target (us) and the server is built for the target.
Mark Simulacrum528646e2017-07-14 00:48:441784#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1785pub struct RemoteCopyLibs {
1786 compiler: Compiler,
1787 target: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:431788}
Alex Crichton1747ce22017-01-28 21:38:061789
Mark Simulacrum528646e2017-07-14 00:48:441790impl Step for RemoteCopyLibs {
Mark Simulacrum001e9f32017-07-05 01:41:431791 type Output = ();
Alex Crichton1747ce22017-01-28 21:38:061792
Mark Simulacrum56128fb2017-07-19 00:03:381793 fn should_run(run: ShouldRun) -> ShouldRun {
1794 run.never()
Mark Simulacrum681b1232017-07-14 12:30:161795 }
1796
Mark Simulacrum001e9f32017-07-05 01:41:431797 fn run(self, builder: &Builder) {
Mark Simulacrum001e9f32017-07-05 01:41:431798 let compiler = self.compiler;
1799 let target = self.target;
Mark Simulacrumbe1e7892018-04-14 23:27:571800 if !builder.remote_tested(target) {
Santiago Pastorinob39a1d62018-05-30 17:33:431801 return;
Mark Simulacrum001e9f32017-07-05 01:41:431802 }
Alex Crichton1747ce22017-01-28 21:38:061803
Mark Simulacrum6b3413d2017-07-05 12:41:271804 builder.ensure(compile::Test { compiler, target });
1805
Mark Simulacrumbe1e7892018-04-14 23:27:571806 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
1807 t!(fs::create_dir_all(builder.out.join("tmp")));
Mark Simulacrum001e9f32017-07-05 01:41:431808
Mark Simulacrumfe0eca02017-07-23 01:29:081809 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
Mark Simulacrum001e9f32017-07-05 01:41:431810
1811 // Spawn the emulator and wait for it to come online
Mark Simulacrum6b3413d2017-07-05 12:41:271812 let tool = builder.tool_exe(Tool::RemoteTestClient);
Mark Simulacrum001e9f32017-07-05 01:41:431813 let mut cmd = Command::new(&tool);
1814 cmd.arg("spawn-emulator")
Santiago Pastorinob39a1d62018-05-30 17:33:431815 .arg(target)
1816 .arg(&server)
1817 .arg(builder.out.join("tmp"));
Mark Simulacrumbe1e7892018-04-14 23:27:571818 if let Some(rootfs) = builder.qemu_rootfs(target) {
Mark Simulacrum001e9f32017-07-05 01:41:431819 cmd.arg(rootfs);
1820 }
Mark Simulacrumbe1e7892018-04-14 23:27:571821 builder.run(&mut cmd);
Mark Simulacrum001e9f32017-07-05 01:41:431822
1823 // Push all our dylibs to the emulator
Mark Simulacrum60388302017-07-05 16:46:411824 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
Mark Simulacrum001e9f32017-07-05 01:41:431825 let f = t!(f);
1826 let name = f.file_name().into_string().unwrap();
1827 if util::is_dylib(&name) {
Santiago Pastorinob39a1d62018-05-30 17:33:431828 builder.run(Command::new(&tool).arg("push").arg(f.path()));
Mark Simulacrum001e9f32017-07-05 01:41:431829 }
Alex Crichton1747ce22017-01-28 21:38:061830 }
1831 }
1832}
1833
Mark Simulacrum528646e2017-07-14 00:48:441834#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum001e9f32017-07-05 01:41:431835pub struct Distcheck;
1836
Mark Simulacrum528646e2017-07-14 00:48:441837impl Step for Distcheck {
Mark Simulacrum001e9f32017-07-05 01:41:431838 type Output = ();
1839
Mark Simulacrum56128fb2017-07-19 00:03:381840 fn should_run(run: ShouldRun) -> ShouldRun {
1841 run.path("distcheck")
Mark Simulacrum681b1232017-07-14 12:30:161842 }
1843
Mark Simulacrum8f2e5762017-07-22 13:35:421844 fn make_run(run: RunConfig) {
1845 run.builder.ensure(Distcheck);
1846 }
1847
Mark Simulacrum001e9f32017-07-05 01:41:431848 /// Run "distcheck", a 'make check' from a tarball
1849 fn run(self, builder: &Builder) {
Mark Simulacrumbe1e7892018-04-14 23:27:571850 builder.info(&format!("Distcheck"));
1851 let dir = builder.out.join("tmp").join("distcheck");
Mark Simulacrum001e9f32017-07-05 01:41:431852 let _ = fs::remove_dir_all(&dir);
1853 t!(fs::create_dir_all(&dir));
1854
Mark Simulacrum1c118232017-07-22 16:48:291855 // Guarantee that these are built before we begin running.
1856 builder.ensure(dist::PlainSourceTarball);
1857 builder.ensure(dist::Src);
1858
Mark Simulacrum001e9f32017-07-05 01:41:431859 let mut cmd = Command::new("tar");
1860 cmd.arg("-xzf")
Santiago Pastorinob39a1d62018-05-30 17:33:431861 .arg(builder.ensure(dist::PlainSourceTarball))
1862 .arg("--strip-components=1")
1863 .current_dir(&dir);
Mark Simulacrumbe1e7892018-04-14 23:27:571864 builder.run(&mut cmd);
Santiago Pastorinob39a1d62018-05-30 17:33:431865 builder.run(
1866 Command::new("./configure")
1867 .args(&builder.config.configure_args)
1868 .arg("--enable-vendor")
1869 .current_dir(&dir),
1870 );
1871 builder.run(
1872 Command::new(build_helper::make(&builder.config.build))
1873 .arg("check")
1874 .current_dir(&dir),
1875 );
Mark Simulacrum001e9f32017-07-05 01:41:431876
1877 // Now make sure that rust-src has all of libstd's dependencies
Mark Simulacrumbe1e7892018-04-14 23:27:571878 builder.info(&format!("Distcheck rust-src"));
1879 let dir = builder.out.join("tmp").join("distcheck-src");
Mark Simulacrum001e9f32017-07-05 01:41:431880 let _ = fs::remove_dir_all(&dir);
1881 t!(fs::create_dir_all(&dir));
1882
1883 let mut cmd = Command::new("tar");
1884 cmd.arg("-xzf")
Santiago Pastorinob39a1d62018-05-30 17:33:431885 .arg(builder.ensure(dist::Src))
1886 .arg("--strip-components=1")
1887 .current_dir(&dir);
Mark Simulacrumbe1e7892018-04-14 23:27:571888 builder.run(&mut cmd);
Mark Simulacrum001e9f32017-07-05 01:41:431889
1890 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
Santiago Pastorinob39a1d62018-05-30 17:33:431891 builder.run(
1892 Command::new(&builder.initial_cargo)
1893 .arg("generate-lockfile")
1894 .arg("--manifest-path")
1895 .arg(&toml)
1896 .current_dir(&dir),
1897 );
Alex Crichtond38db822016-12-09 01:13:551898 }
Alex Crichtond38db822016-12-09 01:13:551899}
Alex Crichton1a040b32016-12-31 03:50:571900
Mark Simulacrum528646e2017-07-14 00:48:441901#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum001e9f32017-07-05 01:41:431902pub struct Bootstrap;
1903
Mark Simulacrum528646e2017-07-14 00:48:441904impl Step for Bootstrap {
Mark Simulacrum001e9f32017-07-05 01:41:431905 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271906 const DEFAULT: bool = true;
1907 const ONLY_HOSTS: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:431908
1909 /// Test the build system itself
1910 fn run(self, builder: &Builder) {
Mark Simulacrumbe1e7892018-04-14 23:27:571911 let mut cmd = Command::new(&builder.initial_cargo);
Mark Simulacrum001e9f32017-07-05 01:41:431912 cmd.arg("test")
Santiago Pastorinob39a1d62018-05-30 17:33:431913 .current_dir(builder.src.join("src/bootstrap"))
1914 .env("RUSTFLAGS", "-Cdebuginfo=2")
1915 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
1916 .env("RUSTC_BOOTSTRAP", "1")
1917 .env("RUSTC", &builder.initial_rustc);
Simon Sapine993e622018-03-23 18:55:411918 if let Some(flags) = option_env!("RUSTFLAGS") {
1919 // Use the same rustc flags for testing as for "normal" compilation,
1920 // so that Cargo doesn’t recompile the entire dependency graph every time:
1921 // https://github.com/rust-lang/rust/issues/49215
1922 cmd.env("RUSTFLAGS", flags);
1923 }
Mark Simulacrumbe1e7892018-04-14 23:27:571924 if !builder.fail_fast {
Mark Simulacrum001e9f32017-07-05 01:41:431925 cmd.arg("--no-fail-fast");
1926 }
Mark Simulacrumbe1e7892018-04-14 23:27:571927 cmd.arg("--").args(&builder.config.cmd.test_args());
Mark Simulacrumb436dca2018-06-16 17:12:151928 // rustbuild tests are racy on directory creation so just run them one at a time.
1929 // Since there's not many this shouldn't be a problem.
1930 cmd.arg("--test-threads=1");
Mark Simulacrumbe1e7892018-04-14 23:27:571931 try_run(builder, &mut cmd);
Josh Stone617aea42017-06-02 16:27:441932 }
Mark Simulacrum6b3413d2017-07-05 12:41:271933
Mark Simulacrum56128fb2017-07-19 00:03:381934 fn should_run(run: ShouldRun) -> ShouldRun {
1935 run.path("src/bootstrap")
Mark Simulacrum6b3413d2017-07-05 12:41:271936 }
1937
Mark Simulacrum6a67a052017-07-20 23:51:071938 fn make_run(run: RunConfig) {
1939 run.builder.ensure(Bootstrap);
Mark Simulacrum6b3413d2017-07-05 12:41:271940 }
Alex Crichton1a040b32016-12-31 03:50:571941}