blob: f762d9414cff383d0554c76d3f8f87ad994eb8dd [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;
Tatsuyuki Ishi62f73dc2018-07-26 03:36:5833use tool::{self, Tool, SourceType};
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 });
Tatsuyuki Ishia89f8e12018-07-25 05:46:47225 let mut cargo = tool::prepare_tool_cargo(builder,
226 compiler,
227 Mode::ToolRustc,
228 self.host,
229 "test",
230 "src/tools/cargo",
Tatsuyuki Ishi62f73dc2018-07-26 03:36:58231 SourceType::Submodule);
Tatsuyuki Ishia89f8e12018-07-25 05:46:47232
Mark Simulacrumbe1e7892018-04-14 23:27:57233 if !builder.fail_fast {
Mark Simulacrum001e9f32017-07-05 01:41:43234 cargo.arg("--no-fail-fast");
235 }
Nick Cameron04415dc2017-06-30 18:58:54236
Mark Simulacrum001e9f32017-07-05 01:41:43237 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
238 // available.
239 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
240
Santiago Pastorinob39a1d62018-05-30 17:33:43241 try_run(
242 builder,
243 cargo.env("PATH", &path_for_cargo(builder, compiler)),
244 );
Mark Simulacrum001e9f32017-07-05 01:41:43245 }
246}
247
Mark Simulacrumdec44b02017-07-17 15:52:05248#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
249pub struct Rls {
Mark Simulacrum001e9f32017-07-05 01:41:43250 stage: u32,
Mark Simulacrumdec44b02017-07-17 15:52:05251 host: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:43252}
253
Mark Simulacrumdec44b02017-07-17 15:52:05254impl Step for Rls {
Mark Simulacrum001e9f32017-07-05 01:41:43255 type Output = ();
Mark Simulacrumdec44b02017-07-17 15:52:05256 const ONLY_HOSTS: bool = true;
257
Mark Simulacrum56128fb2017-07-19 00:03:38258 fn should_run(run: ShouldRun) -> ShouldRun {
259 run.path("src/tools/rls")
Mark Simulacrumdec44b02017-07-17 15:52:05260 }
261
Mark Simulacrum6a67a052017-07-20 23:51:07262 fn make_run(run: RunConfig) {
263 run.builder.ensure(Rls {
264 stage: run.builder.top_stage,
265 host: run.target,
Mark Simulacrumdec44b02017-07-17 15:52:05266 });
267 }
Mark Simulacrum001e9f32017-07-05 01:41:43268
269 /// Runs `cargo test` for the rls.
270 fn run(self, builder: &Builder) {
Mark Simulacrum001e9f32017-07-05 01:41:43271 let stage = self.stage;
272 let host = self.host;
Mark Simulacrumdec44b02017-07-17 15:52:05273 let compiler = builder.compiler(stage, host);
Mark Simulacrum001e9f32017-07-05 01:41:43274
kennytm27d96912018-04-20 16:53:36275 let build_result = builder.ensure(tool::Rls {
276 compiler,
277 target: self.host,
278 extra_features: Vec::new(),
279 });
280 if build_result.is_none() {
281 eprintln!("failed to test rls: could not build");
282 return;
283 }
284
Collins Abitekanizafb949b52018-05-27 22:09:43285 let mut cargo = tool::prepare_tool_cargo(builder,
286 compiler,
Collins Abitekaniza11333972018-05-27 23:02:58287 Mode::ToolRustc,
Collins Abitekanizafb949b52018-05-27 22:09:43288 host,
289 "test",
Tatsuyuki Ishie0989852018-07-13 05:12:58290 "src/tools/rls",
Tatsuyuki Ishi62f73dc2018-07-26 03:36:58291 SourceType::Submodule);
Mark Simulacrum001e9f32017-07-05 01:41:43292
kennytma28e3d22018-07-28 19:36:18293 // Copy `src/tools/rls/test_data` to a writable drive.
294 let test_workspace_path = builder.out.join("rls-test-data");
295 let test_data_path = test_workspace_path.join("test_data");
296 builder.create_dir(&test_data_path);
297 builder.cp_r(&builder.src.join("src/tools/rls/test_data"), &test_data_path);
298 cargo.env("RLS_TEST_WORKSPACE_DIR", test_workspace_path);
299
Mark Simulacrumdec44b02017-07-17 15:52:05300 builder.add_rustc_lib_path(compiler, &mut cargo);
Alex Crichton0e034d12018-07-31 21:16:55301 cargo.arg("--")
302 .args(builder.config.cmd.test_args());
Mark Simulacrum001e9f32017-07-05 01:41:43303
Mark Simulacrumbe1e7892018-04-14 23:27:57304 if try_run(builder, &mut cargo) {
305 builder.save_toolstate("rls", ToolState::TestPass);
Oliver Schneideracdf83f2017-12-06 08:25:29306 }
Mark Simulacrum001e9f32017-07-05 01:41:43307 }
Nick Cameron04415dc2017-06-30 18:58:54308}
309
Nick Camerond0070e82017-09-01 06:43:00310#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
311pub struct Rustfmt {
312 stage: u32,
313 host: Interned<String>,
314}
315
316impl Step for Rustfmt {
317 type Output = ();
318 const ONLY_HOSTS: bool = true;
319
320 fn should_run(run: ShouldRun) -> ShouldRun {
321 run.path("src/tools/rustfmt")
322 }
323
324 fn make_run(run: RunConfig) {
325 run.builder.ensure(Rustfmt {
326 stage: run.builder.top_stage,
327 host: run.target,
328 });
329 }
330
331 /// Runs `cargo test` for rustfmt.
332 fn run(self, builder: &Builder) {
Nick Camerond0070e82017-09-01 06:43:00333 let stage = self.stage;
334 let host = self.host;
335 let compiler = builder.compiler(stage, host);
336
kennytm27d96912018-04-20 16:53:36337 let build_result = builder.ensure(tool::Rustfmt {
338 compiler,
339 target: self.host,
340 extra_features: Vec::new(),
341 });
342 if build_result.is_none() {
343 eprintln!("failed to test rustfmt: could not build");
344 return;
345 }
346
Collins Abitekanizafb949b52018-05-27 22:09:43347 let mut cargo = tool::prepare_tool_cargo(builder,
348 compiler,
Collins Abitekaniza11333972018-05-27 23:02:58349 Mode::ToolRustc,
Collins Abitekanizafb949b52018-05-27 22:09:43350 host,
351 "test",
Tatsuyuki Ishie0989852018-07-13 05:12:58352 "src/tools/rustfmt",
Tatsuyuki Ishi62f73dc2018-07-26 03:36:58353 SourceType::Submodule);
Nick Camerond0070e82017-09-01 06:43:00354
Nick Camerondf97dd12018-05-05 20:27:48355 let dir = testdir(builder, compiler.host);
356 t!(fs::create_dir_all(&dir));
357 cargo.env("RUSTFMT_TEST_DIR", dir);
Nick Camerond0070e82017-09-01 06:43:00358
359 builder.add_rustc_lib_path(compiler, &mut cargo);
360
Mark Simulacrumbe1e7892018-04-14 23:27:57361 if try_run(builder, &mut cargo) {
362 builder.save_toolstate("rustfmt", ToolState::TestPass);
Oliver Schneideracdf83f2017-12-06 08:25:29363 }
Nick Camerond0070e82017-09-01 06:43:00364 }
365}
Oliver Schneider01555b12017-09-17 19:45:54366
367#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Oliver Schneiderf3817442017-08-28 14:54:50368pub struct Miri {
Oliver Schneideracdf83f2017-12-06 08:25:29369 stage: u32,
Oliver Schneiderf3817442017-08-28 14:54:50370 host: Interned<String>,
371}
372
373impl Step for Miri {
374 type Output = ();
375 const ONLY_HOSTS: bool = true;
376 const DEFAULT: bool = true;
377
378 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumbe1e7892018-04-14 23:27:57379 let test_miri = run.builder.config.test_miri;
Oliver Schneiderf3817442017-08-28 14:54:50380 run.path("src/tools/miri").default_condition(test_miri)
381 }
382
383 fn make_run(run: RunConfig) {
384 run.builder.ensure(Miri {
Oliver Schneideracdf83f2017-12-06 08:25:29385 stage: run.builder.top_stage,
Oliver Schneiderf3817442017-08-28 14:54:50386 host: run.target,
387 });
388 }
389
390 /// Runs `cargo test` for miri.
391 fn run(self, builder: &Builder) {
Oliver Schneideracdf83f2017-12-06 08:25:29392 let stage = self.stage;
Oliver Schneiderf3817442017-08-28 14:54:50393 let host = self.host;
Oliver Schneideracdf83f2017-12-06 08:25:29394 let compiler = builder.compiler(stage, host);
Oliver Schneiderf3817442017-08-28 14:54:50395
Oliver Schneider02ac15c2018-02-09 17:53:41396 let miri = builder.ensure(tool::Miri {
397 compiler,
398 target: self.host,
399 extra_features: Vec::new(),
400 });
401 if let Some(miri) = miri {
Tatsuyuki Ishia89f8e12018-07-25 05:46:47402 let mut cargo = tool::prepare_tool_cargo(builder,
403 compiler,
404 Mode::ToolRustc,
405 host,
406 "test",
407 "src/tools/miri",
Tatsuyuki Ishi62f73dc2018-07-26 03:36:58408 SourceType::Submodule);
Oliver Schneiderf3817442017-08-28 14:54:50409
Oliver Schneideracdf83f2017-12-06 08:25:29410 // miri tests need to know about the stage sysroot
411 cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
412 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
413 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
414 cargo.env("MIRI_PATH", miri);
Oliver Schneiderf3817442017-08-28 14:54:50415
Oliver Schneideracdf83f2017-12-06 08:25:29416 builder.add_rustc_lib_path(compiler, &mut cargo);
Oliver Schneiderf3817442017-08-28 14:54:50417
Mark Simulacrumbe1e7892018-04-14 23:27:57418 if try_run(builder, &mut cargo) {
419 builder.save_toolstate("miri", ToolState::TestPass);
Oliver Schneideracdf83f2017-12-06 08:25:29420 }
421 } else {
422 eprintln!("failed to test miri: could not build");
423 }
Oliver Schneiderf3817442017-08-28 14:54:50424 }
425}
426
Oliver Schneiderd64a0672017-09-18 11:13:57427#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
428pub struct Clippy {
Oliver Schneideracdf83f2017-12-06 08:25:29429 stage: u32,
Oliver Schneiderd64a0672017-09-18 11:13:57430 host: Interned<String>,
431}
432
433impl Step for Clippy {
434 type Output = ();
435 const ONLY_HOSTS: bool = true;
436 const DEFAULT: bool = false;
437
438 fn should_run(run: ShouldRun) -> ShouldRun {
439 run.path("src/tools/clippy")
440 }
441
442 fn make_run(run: RunConfig) {
443 run.builder.ensure(Clippy {
Oliver Schneideracdf83f2017-12-06 08:25:29444 stage: run.builder.top_stage,
Oliver Schneiderd64a0672017-09-18 11:13:57445 host: run.target,
446 });
447 }
448
449 /// Runs `cargo test` for clippy.
450 fn run(self, builder: &Builder) {
Oliver Schneideracdf83f2017-12-06 08:25:29451 let stage = self.stage;
Oliver Schneiderd64a0672017-09-18 11:13:57452 let host = self.host;
Oliver Schneideracdf83f2017-12-06 08:25:29453 let compiler = builder.compiler(stage, host);
Oliver Schneiderd64a0672017-09-18 11:13:57454
Oliver Schneider02ac15c2018-02-09 17:53:41455 let clippy = builder.ensure(tool::Clippy {
456 compiler,
457 target: self.host,
458 extra_features: Vec::new(),
459 });
460 if let Some(clippy) = clippy {
Tatsuyuki Ishia89f8e12018-07-25 05:46:47461 let mut cargo = tool::prepare_tool_cargo(builder,
462 compiler,
463 Mode::ToolRustc,
464 host,
465 "test",
466 "src/tools/clippy",
Tatsuyuki Ishi62f73dc2018-07-26 03:36:58467 SourceType::Submodule);
Oliver Schneiderd64a0672017-09-18 11:13:57468
Oliver Schneideracdf83f2017-12-06 08:25:29469 // clippy tests need to know about the stage sysroot
470 cargo.env("SYSROOT", builder.sysroot(compiler));
471 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
472 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
Santiago Pastorinob39a1d62018-05-30 17:33:43473 let host_libs = builder
Collins Abitekaniza42ee6d52018-05-19 20:04:41474 .stage_out(compiler, Mode::ToolRustc)
Santiago Pastorinob39a1d62018-05-30 17:33:43475 .join(builder.cargo_dir());
Oliver Schneideracdf83f2017-12-06 08:25:29476 cargo.env("HOST_LIBS", host_libs);
477 // clippy tests need to find the driver
478 cargo.env("CLIPPY_DRIVER_PATH", clippy);
Oliver Schneiderd64a0672017-09-18 11:13:57479
Oliver Schneideracdf83f2017-12-06 08:25:29480 builder.add_rustc_lib_path(compiler, &mut cargo);
Oliver Schneiderd64a0672017-09-18 11:13:57481
Mark Simulacrumbe1e7892018-04-14 23:27:57482 if try_run(builder, &mut cargo) {
483 builder.save_toolstate("clippy-driver", ToolState::TestPass);
Oliver Schneideracdf83f2017-12-06 08:25:29484 }
485 } else {
486 eprintln!("failed to test clippy: could not build");
487 }
Oliver Schneiderd64a0672017-09-18 11:13:57488 }
489}
Nick Camerond0070e82017-09-01 06:43:00490
Mark Simulacrumdec44b02017-07-17 15:52:05491fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
Nick Cameron04415dc2017-06-30 18:58:54492 // Configure PATH to find the right rustc. NB. we have to use PATH
493 // and not RUSTC because the Cargo test suite has tests that will
494 // fail if rustc is not spelled `rustc`.
Mark Simulacrumdec44b02017-07-17 15:52:05495 let path = builder.sysroot(compiler).join("bin");
Nick Cameron04415dc2017-06-30 18:58:54496 let old_path = env::var_os("PATH").unwrap_or_default();
497 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
Brian Anderson3a790ac2016-03-18 20:54:31498}
Alex Crichton9dd3c542016-03-29 20:14:52499
Guillaume Gomezf18c52b2017-12-12 22:53:24500#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
Guillaume Gomez51580d42018-01-25 23:44:52501pub struct RustdocTheme {
502 pub compiler: Compiler,
Guillaume Gomez51580d42018-01-25 23:44:52503}
504
505impl Step for RustdocTheme {
506 type Output = ();
507 const DEFAULT: bool = true;
508 const ONLY_HOSTS: bool = true;
509
510 fn should_run(run: ShouldRun) -> ShouldRun {
511 run.path("src/tools/rustdoc-themes")
512 }
513
514 fn make_run(run: RunConfig) {
515 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
516
Santiago Pastorinob39a1d62018-05-30 17:33:43517 run.builder.ensure(RustdocTheme { compiler: compiler });
Guillaume Gomez51580d42018-01-25 23:44:52518 }
519
520 fn run(self, builder: &Builder) {
Chris Coulson6f101462018-04-12 14:01:49521 let rustdoc = builder.out.join("bootstrap/debug/rustdoc");
Guillaume Gomezdec9fab2018-02-05 22:43:53522 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
523 cmd.arg(rustdoc.to_str().unwrap())
Santiago Pastorinob39a1d62018-05-30 17:33:43524 .arg(
525 builder
526 .src
527 .join("src/librustdoc/html/static/themes")
528 .to_str()
529 .unwrap(),
530 )
531 .env("RUSTC_STAGE", self.compiler.stage.to_string())
532 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
533 .env(
534 "RUSTDOC_LIBDIR",
535 builder.sysroot_libdir(self.compiler, self.compiler.host),
536 )
537 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
538 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler.host))
539 .env("RUSTDOC_CRATE_VERSION", builder.rust_version())
540 .env("RUSTC_BOOTSTRAP", "1");
Mark Simulacrumbe1e7892018-04-14 23:27:57541 if let Some(linker) = builder.linker(self.compiler.host) {
Guillaume Gomez51580d42018-01-25 23:44:52542 cmd.env("RUSTC_TARGET_LINKER", linker);
543 }
Mark Simulacrumbe1e7892018-04-14 23:27:57544 try_run(builder, &mut cmd);
Guillaume Gomez51580d42018-01-25 23:44:52545 }
546}
547
548#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
Guillaume Gomezf18c52b2017-12-12 22:53:24549pub struct RustdocJS {
550 pub host: Interned<String>,
Guillaume Gomez69521992018-01-12 22:40:00551 pub target: Interned<String>,
Guillaume Gomezf18c52b2017-12-12 22:53:24552}
553
554impl Step for RustdocJS {
Guillaume Gomez50bb6ba2018-01-08 22:43:20555 type Output = ();
Guillaume Gomezf18c52b2017-12-12 22:53:24556 const DEFAULT: bool = true;
557 const ONLY_HOSTS: bool = true;
558
559 fn should_run(run: ShouldRun) -> ShouldRun {
Guillaume Gomez69521992018-01-12 22:40:00560 run.path("src/test/rustdoc-js")
Guillaume Gomezf18c52b2017-12-12 22:53:24561 }
562
563 fn make_run(run: RunConfig) {
564 run.builder.ensure(RustdocJS {
565 host: run.host,
Guillaume Gomez69521992018-01-12 22:40:00566 target: run.target,
Guillaume Gomezf18c52b2017-12-12 22:53:24567 });
568 }
569
Guillaume Gomez50bb6ba2018-01-08 22:43:20570 fn run(self, builder: &Builder) {
Guillaume Gomez026c7492018-01-13 21:35:41571 if let Some(ref nodejs) = builder.config.nodejs {
572 let mut command = Command::new(nodejs);
573 command.args(&["src/tools/rustdoc-js/tester.js", &*self.host]);
574 builder.ensure(::doc::Std {
575 target: self.target,
576 stage: builder.top_stage,
577 });
578 builder.run(&mut command);
579 } else {
Santiago Pastorinob39a1d62018-05-30 17:33:43580 builder.info(&format!(
581 "No nodejs found, skipping \"src/test/rustdoc-js\" tests"
582 ));
Guillaume Gomez026c7492018-01-13 21:35:41583 }
Guillaume Gomezf18c52b2017-12-12 22:53:24584 }
585}
586
Guillaume Gomez035ec5b2018-03-31 12:49:56587#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
588pub struct RustdocUi {
589 pub host: Interned<String>,
590 pub target: Interned<String>,
591 pub compiler: Compiler,
592}
593
594impl Step for RustdocUi {
595 type Output = ();
596 const DEFAULT: bool = true;
597 const ONLY_HOSTS: bool = true;
598
599 fn should_run(run: ShouldRun) -> ShouldRun {
600 run.path("src/test/rustdoc-ui")
601 }
602
603 fn make_run(run: RunConfig) {
604 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
605 run.builder.ensure(RustdocUi {
606 host: run.host,
607 target: run.target,
608 compiler,
609 });
610 }
611
612 fn run(self, builder: &Builder) {
613 builder.ensure(Compiletest {
614 compiler: self.compiler,
615 target: self.target,
616 mode: "ui",
617 suite: "rustdoc-ui",
Collins Abitekaniza41ee6fe2018-04-12 11:49:31618 path: None,
Felix S. Klock II55895502018-04-11 15:15:59619 compare_mode: None,
Guillaume Gomez035ec5b2018-03-31 12:49:56620 })
621 }
622}
623
Mark Simulacrum528646e2017-07-14 00:48:44624#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum1c8f3b02018-02-11 22:41:06625pub struct Tidy;
Mark Simulacrum001e9f32017-07-05 01:41:43626
Mark Simulacrum528646e2017-07-14 00:48:44627impl Step for Tidy {
Mark Simulacrum001e9f32017-07-05 01:41:43628 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27629 const DEFAULT: bool = true;
630 const ONLY_HOSTS: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:43631
Mark Simulacrum1c8f3b02018-02-11 22:41:06632 /// Runs the `tidy` tool.
Mark Simulacrum001e9f32017-07-05 01:41:43633 ///
634 /// This tool in `src/tools` checks up on various bits and pieces of style and
635 /// otherwise just implements a few lint-like checks that are specific to the
636 /// compiler itself.
637 fn run(self, builder: &Builder) {
Mark Simulacrum60388302017-07-05 16:46:41638 let mut cmd = builder.tool_cmd(Tool::Tidy);
Mark Simulacrumbe1e7892018-04-14 23:27:57639 cmd.arg(builder.src.join("src"));
640 cmd.arg(&builder.initial_cargo);
641 if !builder.config.vendor {
Mark Simulacrum001e9f32017-07-05 01:41:43642 cmd.arg("--no-vendor");
643 }
Oliver Schneider0c1bcd32018-06-07 12:40:36644 if !builder.config.verbose_tests {
Mark Simulacrum001e9f32017-07-05 01:41:43645 cmd.arg("--quiet");
646 }
Alex Crichton6fd4d672018-03-16 15:35:03647
Mark Simulacrumbe1e7892018-04-14 23:27:57648 let _folder = builder.fold_output(|| "tidy");
Mark Simulacrum545b92f2018-03-28 15:25:09649 builder.info(&format!("tidy check"));
Mark Simulacrumbe1e7892018-04-14 23:27:57650 try_run(builder, &mut cmd);
Eduard-Mihai Burtescud29f0bc2017-02-10 20:59:40651 }
Mark Simulacrum6b3413d2017-07-05 12:41:27652
Mark Simulacrum56128fb2017-07-19 00:03:38653 fn should_run(run: ShouldRun) -> ShouldRun {
654 run.path("src/tools/tidy")
Mark Simulacrum6b3413d2017-07-05 12:41:27655 }
656
Mark Simulacrum6a67a052017-07-20 23:51:07657 fn make_run(run: RunConfig) {
Mark Simulacrum1c8f3b02018-02-11 22:41:06658 run.builder.ensure(Tidy);
Mark Simulacrum6b3413d2017-07-05 12:41:27659 }
Alex Crichton9dd3c542016-03-29 20:14:52660}
Alex Crichtonb325baf2016-04-05 18:34:23661
Mark Simulacrumbe1e7892018-04-14 23:27:57662fn testdir(builder: &Builder, host: Interned<String>) -> PathBuf {
663 builder.out.join(host).join("test")
Alex Crichtonb325baf2016-04-05 18:34:23664}
665
Mark Simulacrumf104b122018-02-11 16:51:58666macro_rules! default_test {
667 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
668 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
669 }
Mark Simulacrum1ab89302017-07-07 17:51:57670}
671
Felix S. Klock II55895502018-04-11 15:15:59672macro_rules! default_test_with_compare_mode {
673 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
674 compare_mode: $compare_mode:expr }) => {
675 test_with_compare_mode!($name { path: $path, mode: $mode, suite: $suite, default: true,
676 host: false, compare_mode: $compare_mode });
677 }
678}
679
Mark Simulacrumf104b122018-02-11 16:51:58680macro_rules! host_test {
681 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
682 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
683 }
684}
Mark Simulacrum6b3413d2017-07-05 12:41:27685
Mark Simulacrumf104b122018-02-11 16:51:58686macro_rules! test {
Felix S. Klock II55895502018-04-11 15:15:59687 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
688 host: $host:expr }) => {
689 test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default,
690 host: $host, compare_mode: None });
691 }
692}
693
694macro_rules! test_with_compare_mode {
695 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
696 host: $host:expr, compare_mode: $compare_mode:expr }) => {
697 test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default,
698 host: $host, compare_mode: Some($compare_mode) });
699 }
700}
701
702macro_rules! test_definitions {
Mark Simulacrumf104b122018-02-11 16:51:58703 ($name:ident {
704 path: $path:expr,
705 mode: $mode:expr,
706 suite: $suite:expr,
707 default: $default:expr,
Felix S. Klock II55895502018-04-11 15:15:59708 host: $host:expr,
709 compare_mode: $compare_mode:expr
Mark Simulacrumf104b122018-02-11 16:51:58710 }) => {
711 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
712 pub struct $name {
713 pub compiler: Compiler,
714 pub target: Interned<String>,
715 }
716
717 impl Step for $name {
718 type Output = ();
719 const DEFAULT: bool = $default;
720 const ONLY_HOSTS: bool = $host;
721
722 fn should_run(run: ShouldRun) -> ShouldRun {
Collins Abitekaniza41ee6fe2018-04-12 11:49:31723 run.suite_path($path)
Mark Simulacrumf104b122018-02-11 16:51:58724 }
725
726 fn make_run(run: RunConfig) {
727 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
728
729 run.builder.ensure($name {
730 compiler,
731 target: run.target,
732 });
733 }
734
735 fn run(self, builder: &Builder) {
736 builder.ensure(Compiletest {
737 compiler: self.compiler,
738 target: self.target,
739 mode: $mode,
740 suite: $suite,
Collins Abitekaniza41ee6fe2018-04-12 11:49:31741 path: Some($path),
Felix S. Klock II55895502018-04-11 15:15:59742 compare_mode: $compare_mode,
Mark Simulacrumf104b122018-02-11 16:51:58743 })
744 }
745 }
746 }
747}
748
Felix S. Klock II55895502018-04-11 15:15:59749default_test_with_compare_mode!(Ui {
Mark Simulacrumf104b122018-02-11 16:51:58750 path: "src/test/ui",
751 mode: "ui",
Felix S. Klock II55895502018-04-11 15:15:59752 suite: "ui",
753 compare_mode: "nll"
Mark Simulacrumf104b122018-02-11 16:51:58754});
755
756default_test!(RunPass {
757 path: "src/test/run-pass",
758 mode: "run-pass",
759 suite: "run-pass"
760});
761
762default_test!(CompileFail {
763 path: "src/test/compile-fail",
764 mode: "compile-fail",
765 suite: "compile-fail"
766});
767
768default_test!(ParseFail {
769 path: "src/test/parse-fail",
770 mode: "parse-fail",
771 suite: "parse-fail"
772});
773
774default_test!(RunFail {
775 path: "src/test/run-fail",
776 mode: "run-fail",
777 suite: "run-fail"
778});
779
780default_test!(RunPassValgrind {
781 path: "src/test/run-pass-valgrind",
782 mode: "run-pass-valgrind",
783 suite: "run-pass-valgrind"
784});
785
786default_test!(MirOpt {
787 path: "src/test/mir-opt",
788 mode: "mir-opt",
789 suite: "mir-opt"
790});
791
792default_test!(Codegen {
793 path: "src/test/codegen",
794 mode: "codegen",
795 suite: "codegen"
796});
797
798default_test!(CodegenUnits {
799 path: "src/test/codegen-units",
800 mode: "codegen-units",
801 suite: "codegen-units"
802});
803
804default_test!(Incremental {
805 path: "src/test/incremental",
806 mode: "incremental",
807 suite: "incremental"
808});
809
810default_test!(Debuginfo {
811 path: "src/test/debuginfo",
Mark Simulacrumaa8b93b2017-07-07 18:31:29812 // What this runs varies depending on the native platform being apple
Mark Simulacrumf104b122018-02-11 16:51:58813 mode: "debuginfo-XXX",
814 suite: "debuginfo"
815});
Mark Simulacrum6b3413d2017-07-05 12:41:27816
Mark Simulacrumf104b122018-02-11 16:51:58817host_test!(UiFullDeps {
818 path: "src/test/ui-fulldeps",
819 mode: "ui",
820 suite: "ui-fulldeps"
821});
Mark Simulacrumf1d04a32017-07-20 15:42:18822
Mark Simulacrumf104b122018-02-11 16:51:58823host_test!(RunPassFullDeps {
824 path: "src/test/run-pass-fulldeps",
825 mode: "run-pass",
826 suite: "run-pass-fulldeps"
827});
Mark Simulacrumf1d04a32017-07-20 15:42:18828
Mark Simulacrumf104b122018-02-11 16:51:58829host_test!(RunFailFullDeps {
830 path: "src/test/run-fail-fulldeps",
831 mode: "run-fail",
832 suite: "run-fail-fulldeps"
833});
Mark Simulacrumf1d04a32017-07-20 15:42:18834
Mark Simulacrumf104b122018-02-11 16:51:58835host_test!(CompileFailFullDeps {
836 path: "src/test/compile-fail-fulldeps",
837 mode: "compile-fail",
838 suite: "compile-fail-fulldeps"
839});
Mark Simulacrumf1d04a32017-07-20 15:42:18840
Mark Simulacrumf104b122018-02-11 16:51:58841host_test!(IncrementalFullDeps {
842 path: "src/test/incremental-fulldeps",
843 mode: "incremental",
844 suite: "incremental-fulldeps"
845});
Mark Simulacrumf1d04a32017-07-20 15:42:18846
Mark Simulacrumf104b122018-02-11 16:51:58847host_test!(Rustdoc {
848 path: "src/test/rustdoc",
849 mode: "rustdoc",
850 suite: "rustdoc"
851});
Mark Simulacrumf1d04a32017-07-20 15:42:18852
Mark Simulacrumf104b122018-02-11 16:51:58853test!(Pretty {
854 path: "src/test/pretty",
855 mode: "pretty",
856 suite: "pretty",
857 default: false,
858 host: true
859});
860test!(RunPassPretty {
861 path: "src/test/run-pass/pretty",
862 mode: "pretty",
863 suite: "run-pass",
864 default: false,
865 host: true
866});
867test!(RunFailPretty {
868 path: "src/test/run-fail/pretty",
869 mode: "pretty",
870 suite: "run-fail",
871 default: false,
872 host: true
873});
874test!(RunPassValgrindPretty {
875 path: "src/test/run-pass-valgrind/pretty",
876 mode: "pretty",
877 suite: "run-pass-valgrind",
878 default: false,
879 host: true
880});
881test!(RunPassFullDepsPretty {
882 path: "src/test/run-pass-fulldeps/pretty",
883 mode: "pretty",
884 suite: "run-pass-fulldeps",
885 default: false,
886 host: true
887});
888test!(RunFailFullDepsPretty {
889 path: "src/test/run-fail-fulldeps/pretty",
890 mode: "pretty",
891 suite: "run-fail-fulldeps",
892 default: false,
893 host: true
894});
Mark Simulacrumf1d04a32017-07-20 15:42:18895
Eric Hussa90a9632018-05-15 23:39:21896default_test!(RunMake {
Mark Simulacrumf104b122018-02-11 16:51:58897 path: "src/test/run-make",
898 mode: "run-make",
899 suite: "run-make"
900});
Mark Simulacrumf1d04a32017-07-20 15:42:18901
Alex Crichton7df6f412018-03-09 17:26:15902host_test!(RunMakeFullDeps {
903 path: "src/test/run-make-fulldeps",
904 mode: "run-make",
905 suite: "run-make-fulldeps"
906});
907
Mark Simulacrumf1d04a32017-07-20 15:42:18908#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
909struct Compiletest {
910 compiler: Compiler,
911 target: Interned<String>,
912 mode: &'static str,
913 suite: &'static str,
Collins Abitekaniza41ee6fe2018-04-12 11:49:31914 path: Option<&'static str>,
Felix S. Klock II55895502018-04-11 15:15:59915 compare_mode: Option<&'static str>,
Mark Simulacrumf1d04a32017-07-20 15:42:18916}
917
918impl Step for Compiletest {
919 type Output = ();
920
921 fn should_run(run: ShouldRun) -> ShouldRun {
922 run.never()
923 }
924
Mark Simulacrum001e9f32017-07-05 01:41:43925 /// Executes the `compiletest` tool to run a suite of tests.
926 ///
927 /// Compiles all tests with `compiler` for `target` with the specified
928 /// compiletest `mode` and `suite` arguments. For example `mode` can be
929 /// "run-pass" or `suite` can be something like `debuginfo`.
930 fn run(self, builder: &Builder) {
Mark Simulacrum001e9f32017-07-05 01:41:43931 let compiler = self.compiler;
932 let target = self.target;
933 let mode = self.mode;
934 let suite = self.suite;
Mark Simulacrum6b3413d2017-07-05 12:41:27935
Collins Abitekaniza41ee6fe2018-04-12 11:49:31936 // Path for test suite
937 let suite_path = self.path.unwrap_or("");
938
Mark Simulacrum6b3413d2017-07-05 12:41:27939 // Skip codegen tests if they aren't enabled in configuration.
Mark Simulacrumbe1e7892018-04-14 23:27:57940 if !builder.config.codegen_tests && suite == "codegen" {
Mark Simulacrum6b3413d2017-07-05 12:41:27941 return;
942 }
943
944 if suite == "debuginfo" {
Mark Simulacrum951616c2017-07-20 17:23:29945 // Skip debuginfo tests on MSVC
Mark Simulacrumbe1e7892018-04-14 23:27:57946 if builder.config.build.contains("msvc") {
Mark Simulacrum951616c2017-07-20 17:23:29947 return;
948 }
949
Mark Simulacrum6b3413d2017-07-05 12:41:27950 if mode == "debuginfo-XXX" {
Mark Simulacrumbe1e7892018-04-14 23:27:57951 return if builder.config.build.contains("apple") {
Mark Simulacrum6b3413d2017-07-05 12:41:27952 builder.ensure(Compiletest {
953 mode: "debuginfo-lldb",
954 ..self
Mark Simulacrum528646e2017-07-14 00:48:44955 });
Mark Simulacrum6b3413d2017-07-05 12:41:27956 } else {
957 builder.ensure(Compiletest {
958 mode: "debuginfo-gdb",
959 ..self
Mark Simulacrum528646e2017-07-14 00:48:44960 });
Mark Simulacrum6b3413d2017-07-05 12:41:27961 };
962 }
963
Mark Simulacrum6b3413d2017-07-05 12:41:27964 builder.ensure(dist::DebuggerScripts {
Mark Simulacrum528646e2017-07-14 00:48:44965 sysroot: builder.sysroot(compiler),
Santiago Pastorinob39a1d62018-05-30 17:33:43966 host: target,
Mark Simulacrum6b3413d2017-07-05 12:41:27967 });
968 }
969
970 if suite.ends_with("fulldeps") ||
971 // FIXME: Does pretty need librustc compiled? Note that there are
972 // fulldeps test suites with mode = pretty as well.
Mark Simulacrumcf24a1d2018-06-02 13:50:35973 mode == "pretty"
Santiago Pastorinob39a1d62018-05-30 17:33:43974 {
Mark Simulacrum6b3413d2017-07-05 12:41:27975 builder.ensure(compile::Rustc { compiler, target });
976 }
977
Hideki Sekine7c438d42018-08-08 09:29:17978 if builder.no_std(target) == Some(true) {
979 // the `test` doesn't compile for no-std targets
980 builder.ensure(compile::Std { compiler, target });
981 } else {
Hideki Sekinebbc89b22018-07-17 15:40:55982 builder.ensure(compile::Test { compiler, target });
983 }
Hideki Sekine7c438d42018-08-08 09:29:17984
985 if builder.no_std(target) == Some(true) {
Hideki Sekine09854b02018-08-08 11:19:29986 // for no_std run-make (e.g. thumb*),
Hideki Sekine7c438d42018-08-08 09:29:17987 // we need a host compiler which is called by cargo.
988 builder.ensure(compile::Std { compiler, target: compiler.host });
989 }
990
Mark Simulacrum6b3413d2017-07-05 12:41:27991 builder.ensure(native::TestHelpers { target });
Mark Simulacrumaa8b93b2017-07-07 18:31:29992 builder.ensure(RemoteCopyLibs { compiler, target });
Mark Simulacrum6b3413d2017-07-05 12:41:27993
Mark Simulacrum6b3413d2017-07-05 12:41:27994 let mut cmd = builder.tool_cmd(Tool::Compiletest);
Alex Crichtonb325baf2016-04-05 18:34:23995
Mark Simulacrum001e9f32017-07-05 01:41:43996 // compiletest currently has... a lot of arguments, so let's just pass all
997 // of them!
Brian Anderson8401e372016-09-15 19:42:26998
Santiago Pastorinob39a1d62018-05-30 17:33:43999 cmd.arg("--compile-lib-path")
1000 .arg(builder.rustc_libdir(compiler));
1001 cmd.arg("--run-lib-path")
1002 .arg(builder.sysroot_libdir(compiler, target));
Mark Simulacrumc114fe52017-07-05 17:21:331003 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
Mark Simulacrum4e5333c2017-07-25 22:54:331004
Guillaume Gomezb2192ae2018-04-01 19:06:351005 let is_rustdoc_ui = suite.ends_with("rustdoc-ui");
1006
Mark Simulacrum4e5333c2017-07-25 22:54:331007 // Avoid depending on rustdoc when we don't need it.
Santiago Pastorinob39a1d62018-05-30 17:33:431008 if mode == "rustdoc"
1009 || (mode == "run-make" && suite.ends_with("fulldeps"))
1010 || (mode == "ui" && is_rustdoc_ui)
1011 {
1012 cmd.arg("--rustdoc-path")
1013 .arg(builder.rustdoc(compiler.host));
Mark Simulacrum4e5333c2017-07-25 22:54:331014 }
1015
Santiago Pastorinob39a1d62018-05-30 17:33:431016 cmd.arg("--src-base")
1017 .arg(builder.src.join("src/test").join(suite));
1018 cmd.arg("--build-base")
1019 .arg(testdir(builder, compiler.host).join(suite));
1020 cmd.arg("--stage-id")
1021 .arg(format!("stage{}-{}", compiler.stage, target));
Mark Simulacrum001e9f32017-07-05 01:41:431022 cmd.arg("--mode").arg(mode);
1023 cmd.arg("--target").arg(target);
Mark Simulacrum528646e2017-07-14 00:48:441024 cmd.arg("--host").arg(&*compiler.host);
Santiago Pastorinob39a1d62018-05-30 17:33:431025 cmd.arg("--llvm-filecheck")
1026 .arg(builder.llvm_filecheck(builder.config.build));
Alex Crichtonf4e4ec72016-05-13 22:26:411027
Oliver Schneiderceed8eb2018-05-16 16:17:291028 if builder.config.cmd.bless() {
Oliver Schneider37dee692018-05-16 15:18:191029 cmd.arg("--bless");
1030 }
1031
Santiago Pastorinob970fee2018-05-28 22:44:331032 let compare_mode = builder.config.cmd.compare_mode().or(self.compare_mode);
1033
Mark Simulacrumbe1e7892018-04-14 23:27:571034 if let Some(ref nodejs) = builder.config.nodejs {
Mark Simulacrum001e9f32017-07-05 01:41:431035 cmd.arg("--nodejs").arg(nodejs);
1036 }
Alex Crichtonf4e4ec72016-05-13 22:26:411037
Guillaume Gomezb2192ae2018-04-01 19:06:351038 let mut flags = if is_rustdoc_ui {
1039 Vec::new()
1040 } else {
1041 vec!["-Crpath".to_string()]
1042 };
1043 if !is_rustdoc_ui {
Mark Simulacrumbe1e7892018-04-14 23:27:571044 if builder.config.rust_optimize_tests {
Guillaume Gomezb2192ae2018-04-01 19:06:351045 flags.push("-O".to_string());
1046 }
Mark Simulacrumbe1e7892018-04-14 23:27:571047 if builder.config.rust_debuginfo_tests {
Guillaume Gomezb2192ae2018-04-01 19:06:351048 flags.push("-g".to_string());
1049 }
Mark Simulacrum001e9f32017-07-05 01:41:431050 }
Guillaume Gomeza3ed2ab2018-04-15 11:05:141051 flags.push("-Zunstable-options".to_string());
Mark Simulacrumbe1e7892018-04-14 23:27:571052 flags.push(builder.config.cmd.rustc_args().join(" "));
Alex Crichtoncbe62922016-04-19 16:44:191053
Mark Simulacrumbe1e7892018-04-14 23:27:571054 if let Some(linker) = builder.linker(target) {
Oliver Schneideracdf83f2017-12-06 08:25:291055 cmd.arg("--linker").arg(linker);
1056 }
1057
1058 let hostflags = flags.clone();
Mark Simulacrum001e9f32017-07-05 01:41:431059 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
Alex Crichtoncbe62922016-04-19 16:44:191060
Oliver Schneideracdf83f2017-12-06 08:25:291061 let mut targetflags = flags.clone();
Santiago Pastorinob39a1d62018-05-30 17:33:431062 targetflags.push(format!(
1063 "-Lnative={}",
1064 builder.test_helpers_out(target).display()
1065 ));
Mark Simulacrum001e9f32017-07-05 01:41:431066 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
Alex Crichtonb325baf2016-04-05 18:34:231067
Mark Simulacrumbe1e7892018-04-14 23:27:571068 cmd.arg("--docck-python").arg(builder.python());
Alex Crichtonb325baf2016-04-05 18:34:231069
Mark Simulacrumbe1e7892018-04-14 23:27:571070 if builder.config.build.ends_with("apple-darwin") {
Mark Simulacrum001e9f32017-07-05 01:41:431071 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
1072 // LLDB plugin's compiled module which only works with the system python
1073 // (namely not Homebrew-installed python)
1074 cmd.arg("--lldb-python").arg("/usr/bin/python");
1075 } else {
Mark Simulacrumbe1e7892018-04-14 23:27:571076 cmd.arg("--lldb-python").arg(builder.python());
Mark Simulacrum001e9f32017-07-05 01:41:431077 }
Alex Crichtonb325baf2016-04-05 18:34:231078
Mark Simulacrumbe1e7892018-04-14 23:27:571079 if let Some(ref gdb) = builder.config.gdb {
Mark Simulacrum001e9f32017-07-05 01:41:431080 cmd.arg("--gdb").arg(gdb);
1081 }
Mark Simulacrumbe1e7892018-04-14 23:27:571082 if let Some(ref vers) = builder.lldb_version {
Mark Simulacrum001e9f32017-07-05 01:41:431083 cmd.arg("--lldb-version").arg(vers);
1084 }
Mark Simulacrumbe1e7892018-04-14 23:27:571085 if let Some(ref dir) = builder.lldb_python_dir {
Mark Simulacrum001e9f32017-07-05 01:41:431086 cmd.arg("--lldb-python-dir").arg(dir);
1087 }
Alex Crichtonb325baf2016-04-05 18:34:231088
Collins Abitekaniza41ee6fe2018-04-12 11:49:311089 // Get paths from cmd args
1090 let paths = match &builder.config.cmd {
Santiago Pastorinob39a1d62018-05-30 17:33:431091 Subcommand::Test { ref paths, .. } => &paths[..],
1092 _ => &[],
Collins Abitekaniza41ee6fe2018-04-12 11:49:311093 };
1094
1095 // Get test-args by striping suite path
Santiago Pastorinob39a1d62018-05-30 17:33:431096 let mut test_args: Vec<&str> = paths
1097 .iter()
Steven Laabs475405b2018-06-22 04:57:061098 .map(|p| {
1099 match p.strip_prefix(".") {
1100 Ok(path) => path,
1101 Err(_) => p,
1102 }
1103 })
Santiago Pastorinob39a1d62018-05-30 17:33:431104 .filter(|p| p.starts_with(suite_path) && p.is_file())
1105 .map(|p| p.strip_prefix(suite_path).unwrap().to_str().unwrap())
1106 .collect();
Collins Abitekaniza41ee6fe2018-04-12 11:49:311107
1108 test_args.append(&mut builder.config.cmd.test_args());
1109
1110 cmd.args(&test_args);
Corey Farwellc8c6d2c2016-10-30 01:58:521111
Mark Simulacrumbe1e7892018-04-14 23:27:571112 if builder.is_verbose() {
Mark Simulacrum001e9f32017-07-05 01:41:431113 cmd.arg("--verbose");
1114 }
Alex Crichton126e09e2016-04-14 22:51:031115
Oliver Schneider0c1bcd32018-06-07 12:40:361116 if !builder.config.verbose_tests {
Mark Simulacrum001e9f32017-07-05 01:41:431117 cmd.arg("--quiet");
1118 }
Alex Crichton1747ce22017-01-28 21:38:061119
Mark Simulacrumbe1e7892018-04-14 23:27:571120 if builder.config.llvm_enabled {
Alex Crichtonbe902e72018-03-05 17:47:541121 let llvm_config = builder.ensure(native::Llvm {
Mark Simulacrumbe1e7892018-04-14 23:27:571122 target: builder.config.build,
Alex Crichtonbe902e72018-03-05 17:47:541123 emscripten: false,
1124 });
Mark Simulacrumbe1e7892018-04-14 23:27:571125 if !builder.config.dry_run {
Mark Simulacrum0ce5cf02018-04-01 01:21:141126 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1127 cmd.arg("--llvm-version").arg(llvm_version);
1128 }
Mark Simulacrumbe1e7892018-04-14 23:27:571129 if !builder.is_rust_llvm(target) {
bjorn30c97bbf2017-08-13 10:30:541130 cmd.arg("--system-llvm");
1131 }
1132
1133 // Only pass correct values for these flags for the `run-make` suite as it
1134 // requires that a C++ compiler was configured which isn't always the case.
Eric Hussa90a9632018-05-15 23:39:211135 if !builder.config.dry_run && suite == "run-make-fulldeps" {
bjorn30c97bbf2017-08-13 10:30:541136 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1137 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
Santiago Pastorinob39a1d62018-05-30 17:33:431138 cmd.arg("--cc")
1139 .arg(builder.cc(target))
1140 .arg("--cxx")
1141 .arg(builder.cxx(target).unwrap())
1142 .arg("--cflags")
1143 .arg(builder.cflags(target).join(" "))
1144 .arg("--llvm-components")
1145 .arg(llvm_components.trim())
1146 .arg("--llvm-cxxflags")
1147 .arg(llvm_cxxflags.trim());
Mark Simulacrumbe1e7892018-04-14 23:27:571148 if let Some(ar) = builder.ar(target) {
Oliver Schneideracdf83f2017-12-06 08:25:291149 cmd.arg("--ar").arg(ar);
1150 }
bjorn30c97bbf2017-08-13 10:30:541151 }
1152 }
Eric Hussa90a9632018-05-15 23:39:211153 if suite == "run-make-fulldeps" && !builder.config.llvm_enabled {
Santiago Pastorinob39a1d62018-05-30 17:33:431154 builder.info(&format!(
1155 "Ignoring run-make test suite as they generally don't work without LLVM"
1156 ));
bjorn30c97bbf2017-08-13 10:30:541157 return;
1158 }
1159
Eric Hussa90a9632018-05-15 23:39:211160 if suite != "run-make-fulldeps" {
Santiago Pastorinob39a1d62018-05-30 17:33:431161 cmd.arg("--cc")
1162 .arg("")
1163 .arg("--cxx")
1164 .arg("")
1165 .arg("--cflags")
1166 .arg("")
1167 .arg("--llvm-components")
1168 .arg("")
1169 .arg("--llvm-cxxflags")
1170 .arg("");
Mark Simulacrum001e9f32017-07-05 01:41:431171 }
1172
Mark Simulacrumbe1e7892018-04-14 23:27:571173 if builder.remote_tested(target) {
Santiago Pastorinob39a1d62018-05-30 17:33:431174 cmd.arg("--remote-test-client")
1175 .arg(builder.tool_exe(Tool::RemoteTestClient));
Mark Simulacrum001e9f32017-07-05 01:41:431176 }
1177
1178 // Running a C compiler on MSVC requires a few env vars to be set, to be
1179 // sure to set them here.
1180 //
1181 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1182 // rather than stomp over it.
1183 if target.contains("msvc") {
Mark Simulacrumbe1e7892018-04-14 23:27:571184 for &(ref k, ref v) in builder.cc[&target].env() {
Mark Simulacrum001e9f32017-07-05 01:41:431185 if k != "PATH" {
1186 cmd.env(k, v);
1187 }
Alex Crichton126e09e2016-04-14 22:51:031188 }
1189 }
Mark Simulacrum001e9f32017-07-05 01:41:431190 cmd.env("RUSTC_BOOTSTRAP", "1");
Mark Simulacrumbe1e7892018-04-14 23:27:571191 builder.add_rust_test_threads(&mut cmd);
Mark Simulacrum001e9f32017-07-05 01:41:431192
Mark Simulacrumbe1e7892018-04-14 23:27:571193 if builder.config.sanitizers {
Mark Simulacrum001e9f32017-07-05 01:41:431194 cmd.env("SANITIZER_SUPPORT", "1");
1195 }
1196
Mark Simulacrumbe1e7892018-04-14 23:27:571197 if builder.config.profiler {
Mark Simulacrum001e9f32017-07-05 01:41:431198 cmd.env("PROFILER_SUPPORT", "1");
1199 }
1200
Mark Simulacrumbe1e7892018-04-14 23:27:571201 cmd.env("RUST_TEST_TMPDIR", builder.out.join("tmp"));
Alex Crichton884715c2018-01-22 15:29:241202
Mark Simulacrum001e9f32017-07-05 01:41:431203 cmd.arg("--adb-path").arg("adb");
1204 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1205 if target.contains("android") {
1206 // Assume that cc for this target comes from the android sysroot
1207 cmd.arg("--android-cross-path")
Santiago Pastorinob39a1d62018-05-30 17:33:431208 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
Mark Simulacrum001e9f32017-07-05 01:41:431209 } else {
1210 cmd.arg("--android-cross-path").arg("");
1211 }
1212
Mark Simulacrumbe1e7892018-04-14 23:27:571213 builder.ci_env.force_coloring_in_ci(&mut cmd);
Mark Simulacrum001e9f32017-07-05 01:41:431214
Mark Simulacrumbe1e7892018-04-14 23:27:571215 let _folder = builder.fold_output(|| format!("test_{}", suite));
Santiago Pastorinob39a1d62018-05-30 17:33:431216 builder.info(&format!(
1217 "Check compiletest suite={} mode={} ({} -> {})",
1218 suite, mode, &compiler.host, target
1219 ));
Mark Simulacrumbe1e7892018-04-14 23:27:571220 let _time = util::timeit(&builder);
1221 try_run(builder, &mut cmd);
Felix S. Klock II55895502018-04-11 15:15:591222
1223 if let Some(compare_mode) = compare_mode {
1224 cmd.arg("--compare-mode").arg(compare_mode);
1225 let _folder = builder.fold_output(|| format!("test_{}_{}", suite, compare_mode));
Santiago Pastorinob39a1d62018-05-30 17:33:431226 builder.info(&format!(
1227 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1228 suite, mode, compare_mode, &compiler.host, target
1229 ));
Felix S. Klock II55895502018-04-11 15:15:591230 let _time = util::timeit(&builder);
1231 try_run(builder, &mut cmd);
1232 }
Alex Crichton126e09e2016-04-14 22:51:031233 }
Alex Crichtonb325baf2016-04-05 18:34:231234}
Alex Crichtonede89442016-04-15 01:00:351235
Mark Simulacrum528646e2017-07-14 00:48:441236#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
kennytm0d300d42018-02-21 19:13:341237struct DocTest {
Mark Simulacrum528646e2017-07-14 00:48:441238 compiler: Compiler,
kennytm0d300d42018-02-21 19:13:341239 path: &'static str,
1240 name: &'static str,
1241 is_ext_doc: bool,
Mark Simulacruma5ab2ce2017-07-12 15:15:001242}
1243
kennytm0d300d42018-02-21 19:13:341244impl Step for DocTest {
Mark Simulacruma5ab2ce2017-07-12 15:15:001245 type Output = ();
Mark Simulacruma5ab2ce2017-07-12 15:15:001246 const ONLY_HOSTS: bool = true;
Alex Crichtonede89442016-04-15 01:00:351247
Mark Simulacrum56128fb2017-07-19 00:03:381248 fn should_run(run: ShouldRun) -> ShouldRun {
kennytm0d300d42018-02-21 19:13:341249 run.never()
Mark Simulacruma5ab2ce2017-07-12 15:15:001250 }
1251
1252 /// Run `rustdoc --test` for all documentation in `src/doc`.
1253 ///
1254 /// This will run all tests in our markdown documentation (e.g. the book)
1255 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
1256 /// `compiler`.
1257 fn run(self, builder: &Builder) {
Mark Simulacruma5ab2ce2017-07-12 15:15:001258 let compiler = self.compiler;
Mark Simulacrumceecd622017-07-12 16:12:471259
Santiago Pastorinob39a1d62018-05-30 17:33:431260 builder.ensure(compile::Test {
1261 compiler,
1262 target: compiler.host,
1263 });
Mark Simulacrumceecd622017-07-12 16:12:471264
Mark Simulacruma5ab2ce2017-07-12 15:15:001265 // Do a breadth-first traversal of the `src/doc` directory and just run
1266 // tests for all files that end in `*.md`
Mark Simulacrumbe1e7892018-04-14 23:27:571267 let mut stack = vec![builder.src.join(self.path)];
1268 let _time = util::timeit(&builder);
1269 let _folder = builder.fold_output(|| format!("test_{}", self.name));
Mark Simulacruma5ab2ce2017-07-12 15:15:001270
Mark Simulacruma7274472018-03-27 14:06:471271 let mut files = Vec::new();
Mark Simulacruma5ab2ce2017-07-12 15:15:001272 while let Some(p) = stack.pop() {
1273 if p.is_dir() {
1274 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
Santiago Pastorinob39a1d62018-05-30 17:33:431275 continue;
Mark Simulacruma5ab2ce2017-07-12 15:15:001276 }
1277
1278 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1279 continue;
1280 }
1281
1282 // The nostarch directory in the book is for no starch, and so isn't
Mark Simulacrumbe1e7892018-04-14 23:27:571283 // guaranteed to builder. We don't care if it doesn't build, so skip it.
Mark Simulacruma5ab2ce2017-07-12 15:15:001284 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
1285 continue;
1286 }
1287
Mark Simulacruma7274472018-03-27 14:06:471288 files.push(p);
1289 }
1290
1291 files.sort();
1292
kennytm20231d72018-07-02 21:53:181293 let mut toolstate = ToolState::TestPass;
Mark Simulacruma7274472018-03-27 14:06:471294 for file in files {
kennytm20231d72018-07-02 21:53:181295 if !markdown_test(builder, compiler, &file) {
1296 toolstate = ToolState::TestFail;
kennytma9f940e2018-02-21 19:25:231297 }
Alex Crichtonede89442016-04-15 01:00:351298 }
kennytm20231d72018-07-02 21:53:181299 if self.is_ext_doc {
1300 builder.save_toolstate(self.name, toolstate);
1301 }
Alex Crichtonede89442016-04-15 01:00:351302 }
1303}
1304
kennytm0d300d42018-02-21 19:13:341305macro_rules! test_book {
1306 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1307 $(
1308 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1309 pub struct $name {
1310 compiler: Compiler,
1311 }
1312
1313 impl Step for $name {
1314 type Output = ();
1315 const DEFAULT: bool = $default;
1316 const ONLY_HOSTS: bool = true;
1317
1318 fn should_run(run: ShouldRun) -> ShouldRun {
1319 run.path($path)
1320 }
1321
1322 fn make_run(run: RunConfig) {
1323 run.builder.ensure($name {
1324 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1325 });
1326 }
1327
1328 fn run(self, builder: &Builder) {
1329 builder.ensure(DocTest {
1330 compiler: self.compiler,
1331 path: $path,
1332 name: $book_name,
1333 is_ext_doc: !$default,
1334 });
1335 }
1336 }
1337 )+
1338 }
1339}
1340
1341test_book!(
1342 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1343 Reference, "src/doc/reference", "reference", default=false;
1344 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
steveklabnikb99418d2018-04-05 18:41:481345 RustcBook, "src/doc/rustc", "rustc", default=true;
kennytm0d300d42018-02-21 19:13:341346 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1347 TheBook, "src/doc/book", "book", default=false;
1348 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1349);
1350
Mark Simulacrum528646e2017-07-14 00:48:441351#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1352pub struct ErrorIndex {
1353 compiler: Compiler,
Mark Simulacrum001e9f32017-07-05 01:41:431354}
Alex Crichton0e272de2016-11-16 20:31:191355
Mark Simulacrum528646e2017-07-14 00:48:441356impl Step for ErrorIndex {
Mark Simulacrum001e9f32017-07-05 01:41:431357 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271358 const DEFAULT: bool = true;
1359 const ONLY_HOSTS: bool = true;
1360
Mark Simulacrum56128fb2017-07-19 00:03:381361 fn should_run(run: ShouldRun) -> ShouldRun {
1362 run.path("src/tools/error_index_generator")
Mark Simulacrum6b3413d2017-07-05 12:41:271363 }
1364
Mark Simulacrum6a67a052017-07-20 23:51:071365 fn make_run(run: RunConfig) {
1366 run.builder.ensure(ErrorIndex {
1367 compiler: run.builder.compiler(run.builder.top_stage, run.host),
Mark Simulacrum6b3413d2017-07-05 12:41:271368 });
1369 }
Alex Crichtonede89442016-04-15 01:00:351370
Mark Simulacrum001e9f32017-07-05 01:41:431371 /// Run the error index generator tool to execute the tests located in the error
1372 /// index.
1373 ///
1374 /// The `error_index_generator` tool lives in `src/tools` and is used to
1375 /// generate a markdown file from the error indexes of the code base which is
1376 /// then passed to `rustdoc --test`.
1377 fn run(self, builder: &Builder) {
Mark Simulacrum001e9f32017-07-05 01:41:431378 let compiler = self.compiler;
1379
Santiago Pastorinob39a1d62018-05-30 17:33:431380 builder.ensure(compile::Std {
1381 compiler,
1382 target: compiler.host,
1383 });
Mark Simulacrum6b3413d2017-07-05 12:41:271384
Mark Simulacrumbe1e7892018-04-14 23:27:571385 let dir = testdir(builder, compiler.host);
Mark Simulacrum001e9f32017-07-05 01:41:431386 t!(fs::create_dir_all(&dir));
1387 let output = dir.join("error-index.md");
1388
Alex Crichton6fd4d672018-03-16 15:35:031389 let mut tool = builder.tool_cmd(Tool::ErrorIndex);
1390 tool.arg("markdown")
1391 .arg(&output)
Mark Simulacrumbe1e7892018-04-14 23:27:571392 .env("CFG_BUILD", &builder.config.build)
1393 .env("RUSTC_ERROR_METADATA_DST", builder.extended_error_dir());
Mark Simulacrum001e9f32017-07-05 01:41:431394
Mark Simulacrumbe1e7892018-04-14 23:27:571395 let _folder = builder.fold_output(|| "test_error_index");
1396 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1397 let _time = util::timeit(&builder);
1398 builder.run(&mut tool);
Mark Simulacrumc114fe52017-07-05 17:21:331399 markdown_test(builder, compiler, &output);
Mark Simulacrum001e9f32017-07-05 01:41:431400 }
Alex Crichtonede89442016-04-15 01:00:351401}
1402
kennytma9f940e2018-02-21 19:25:231403fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) -> bool {
Mark Simulacrum0ce5cf02018-04-01 01:21:141404 match File::open(markdown) {
1405 Ok(mut file) => {
1406 let mut contents = String::new();
1407 t!(file.read_to_string(&mut contents));
1408 if !contents.contains("```") {
1409 return true;
1410 }
1411 }
Santiago Pastorinob39a1d62018-05-30 17:33:431412 Err(_) => {}
Mark Simulacrumdd1d75e2017-06-04 23:55:501413 }
1414
Mark Simulacrumbe1e7892018-04-14 23:27:571415 builder.info(&format!("doc tests for: {}", markdown.display()));
Mark Simulacrumfacf5a92017-08-04 22:13:011416 let mut cmd = builder.rustdoc_cmd(compiler.host);
Mark Simulacrumbe1e7892018-04-14 23:27:571417 builder.add_rust_test_threads(&mut cmd);
Alex Crichtonede89442016-04-15 01:00:351418 cmd.arg("--test");
1419 cmd.arg(markdown);
Alex Crichton6f62fae2016-12-12 17:03:351420 cmd.env("RUSTC_BOOTSTRAP", "1");
Corey Farwellc8c6d2c2016-10-30 01:58:521421
Mark Simulacrumbe1e7892018-04-14 23:27:571422 let test_args = builder.config.cmd.test_args().join(" ");
Corey Farwellc8c6d2c2016-10-30 01:58:521423 cmd.arg("--test-args").arg(test_args);
1424
Oliver Schneider0c1bcd32018-06-07 12:40:361425 if builder.config.verbose_tests {
Mark Simulacrumbe1e7892018-04-14 23:27:571426 try_run(builder, &mut cmd)
Oliver Schneider0c1bcd32018-06-07 12:40:361427 } else {
1428 try_run_quiet(builder, &mut cmd)
kennytm6ac07872017-05-21 20:27:471429 }
Alex Crichtonede89442016-04-15 01:00:351430}
Alex Crichtonbb9062a2016-04-29 21:23:151431
Mark Simulacrum528646e2017-07-14 00:48:441432#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum981afa52017-07-18 21:28:531433pub struct CrateLibrustc {
Mark Simulacrum528646e2017-07-14 00:48:441434 compiler: Compiler,
1435 target: Interned<String>,
Mark Simulacrum6b3413d2017-07-05 12:41:271436 test_kind: TestKind,
Mark Simulacrumf104b122018-02-11 16:51:581437 krate: Interned<String>,
Mark Simulacrum6b3413d2017-07-05 12:41:271438}
1439
Mark Simulacrum981afa52017-07-18 21:28:531440impl Step for CrateLibrustc {
Mark Simulacrum6b3413d2017-07-05 12:41:271441 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271442 const DEFAULT: bool = true;
1443 const ONLY_HOSTS: bool = true;
1444
Mark Simulacrum56128fb2017-07-19 00:03:381445 fn should_run(run: ShouldRun) -> ShouldRun {
1446 run.krate("rustc-main")
Mark Simulacrum6b3413d2017-07-05 12:41:271447 }
1448
Mark Simulacrum6a67a052017-07-20 23:51:071449 fn make_run(run: RunConfig) {
1450 let builder = run.builder;
1451 let compiler = builder.compiler(builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:271452
Mark Simulacrumf104b122018-02-11 16:51:581453 for krate in builder.in_tree_crates("rustc-main") {
1454 if run.path.ends_with(&krate.path) {
Oliver Schneider37dee692018-05-16 15:18:191455 let test_kind = builder.kind.into();
Mark Simulacrum6b3413d2017-07-05 12:41:271456
Mark Simulacrumf104b122018-02-11 16:51:581457 builder.ensure(CrateLibrustc {
1458 compiler,
1459 target: run.target,
1460 test_kind,
1461 krate: krate.name,
1462 });
Mark Simulacrum6b3413d2017-07-05 12:41:271463 }
Mark Simulacrum6b3413d2017-07-05 12:41:271464 }
1465 }
1466
Mark Simulacrum6b3413d2017-07-05 12:41:271467 fn run(self, builder: &Builder) {
Mark Simulacrum981afa52017-07-18 21:28:531468 builder.ensure(Crate {
Mark Simulacrum6b3413d2017-07-05 12:41:271469 compiler: self.compiler,
1470 target: self.target,
Collins Abitekaniza42ee6d52018-05-19 20:04:411471 mode: Mode::Rustc,
Mark Simulacrum6b3413d2017-07-05 12:41:271472 test_kind: self.test_kind,
1473 krate: self.krate,
1474 });
1475 }
1476}
1477
Mark Simulacrum528646e2017-07-14 00:48:441478#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrumf104b122018-02-11 16:51:581479pub struct CrateNotDefault {
Mark Simulacrum528646e2017-07-14 00:48:441480 compiler: Compiler,
1481 target: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:431482 test_kind: TestKind,
Mark Simulacrumf104b122018-02-11 16:51:581483 krate: &'static str,
Mark Simulacrum001e9f32017-07-05 01:41:431484}
Alex Crichtonbb9062a2016-04-29 21:23:151485
Mark Simulacrumf104b122018-02-11 16:51:581486impl Step for CrateNotDefault {
Mark Simulacrum001e9f32017-07-05 01:41:431487 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271488
Mark Simulacrum56128fb2017-07-19 00:03:381489 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumf104b122018-02-11 16:51:581490 run.path("src/liballoc_jemalloc")
1491 .path("src/librustc_asan")
1492 .path("src/librustc_lsan")
1493 .path("src/librustc_msan")
1494 .path("src/librustc_tsan")
Mark Simulacrum6b3413d2017-07-05 12:41:271495 }
1496
Mark Simulacrum6a67a052017-07-20 23:51:071497 fn make_run(run: RunConfig) {
1498 let builder = run.builder;
1499 let compiler = builder.compiler(builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:271500
Oliver Schneider37dee692018-05-16 15:18:191501 let test_kind = builder.kind.into();
Mark Simulacrumf104b122018-02-11 16:51:581502
1503 builder.ensure(CrateNotDefault {
1504 compiler,
1505 target: run.target,
1506 test_kind,
1507 krate: match run.path {
1508 _ if run.path.ends_with("src/liballoc_jemalloc") => "alloc_jemalloc",
1509 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1510 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1511 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1512 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1513 _ => panic!("unexpected path {:?}", run.path),
1514 },
1515 });
1516 }
1517
1518 fn run(self, builder: &Builder) {
1519 builder.ensure(Crate {
1520 compiler: self.compiler,
1521 target: self.target,
Collins Abitekaniza42ee6d52018-05-19 20:04:411522 mode: Mode::Std,
Mark Simulacrumf104b122018-02-11 16:51:581523 test_kind: self.test_kind,
1524 krate: INTERNER.intern_str(self.krate),
1525 });
1526 }
1527}
1528
kennytmbe9d6692018-05-05 18:33:011529#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
Mark Simulacrumf104b122018-02-11 16:51:581530pub struct Crate {
kennytmbe9d6692018-05-05 18:33:011531 pub compiler: Compiler,
1532 pub target: Interned<String>,
1533 pub mode: Mode,
1534 pub test_kind: TestKind,
1535 pub krate: Interned<String>,
Mark Simulacrumf104b122018-02-11 16:51:581536}
1537
1538impl Step for Crate {
1539 type Output = ();
1540 const DEFAULT: bool = true;
1541
1542 fn should_run(mut run: ShouldRun) -> ShouldRun {
1543 let builder = run.builder;
1544 run = run.krate("test");
1545 for krate in run.builder.in_tree_crates("std") {
Santiago Pastorinob39a1d62018-05-30 17:33:431546 if krate.is_local(&run.builder)
1547 && !krate.name.contains("jemalloc")
1548 && !(krate.name.starts_with("rustc_") && krate.name.ends_with("san"))
1549 && krate.name != "dlmalloc"
1550 {
Mark Simulacrumf104b122018-02-11 16:51:581551 run = run.path(krate.local_path(&builder).to_str().unwrap());
1552 }
1553 }
1554 run
1555 }
1556
1557 fn make_run(run: RunConfig) {
1558 let builder = run.builder;
1559 let compiler = builder.compiler(builder.top_stage, run.host);
1560
1561 let make = |mode: Mode, krate: &CargoCrate| {
Oliver Schneider37dee692018-05-16 15:18:191562 let test_kind = builder.kind.into();
Mark Simulacrum6b3413d2017-07-05 12:41:271563
Mark Simulacrum981afa52017-07-18 21:28:531564 builder.ensure(Crate {
Mark Simulacrum6a67a052017-07-20 23:51:071565 compiler,
1566 target: run.target,
Zack M. Davis1b6c9602017-08-07 05:54:091567 mode,
1568 test_kind,
Mark Simulacrumf104b122018-02-11 16:51:581569 krate: krate.name,
Mark Simulacrum6b3413d2017-07-05 12:41:271570 });
1571 };
1572
Mark Simulacrumf104b122018-02-11 16:51:581573 for krate in builder.in_tree_crates("std") {
1574 if run.path.ends_with(&krate.local_path(&builder)) {
Collins Abitekaniza42ee6d52018-05-19 20:04:411575 make(Mode::Std, krate);
Mark Simulacrum6b3413d2017-07-05 12:41:271576 }
Mark Simulacrumf104b122018-02-11 16:51:581577 }
1578 for krate in builder.in_tree_crates("test") {
1579 if run.path.ends_with(&krate.local_path(&builder)) {
Collins Abitekaniza42ee6d52018-05-19 20:04:411580 make(Mode::Test, krate);
Mark Simulacrum6b3413d2017-07-05 12:41:271581 }
Mark Simulacrum6b3413d2017-07-05 12:41:271582 }
1583 }
Alex Crichton7046fea2016-12-25 23:20:331584
Mark Simulacrumf104b122018-02-11 16:51:581585 /// Run all unit tests plus documentation tests for a given crate defined
1586 /// by a `Cargo.toml` (single manifest)
Mark Simulacrum001e9f32017-07-05 01:41:431587 ///
1588 /// This is what runs tests for crates like the standard library, compiler, etc.
1589 /// It essentially is the driver for running `cargo test`.
1590 ///
1591 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1592 /// arguments, and those arguments are discovered from `cargo metadata`.
1593 fn run(self, builder: &Builder) {
Mark Simulacrum001e9f32017-07-05 01:41:431594 let compiler = self.compiler;
1595 let target = self.target;
1596 let mode = self.mode;
1597 let test_kind = self.test_kind;
1598 let krate = self.krate;
Alex Crichtonbb9062a2016-04-29 21:23:151599
Mark Simulacrum6b3413d2017-07-05 12:41:271600 builder.ensure(compile::Test { compiler, target });
1601 builder.ensure(RemoteCopyLibs { compiler, target });
Mark Simulacrum001e9f32017-07-05 01:41:431602
1603 // If we're not doing a full bootstrap but we're testing a stage2 version of
1604 // libstd, then what we're actually testing is the libstd produced in
1605 // stage1. Reflect that here by updating the compiler that we're working
1606 // with automatically.
Mark Simulacrumbe1e7892018-04-14 23:27:571607 let compiler = if builder.force_use_stage1(compiler, target) {
Mark Simulacrum6b3413d2017-07-05 12:41:271608 builder.compiler(1, compiler.host)
Mark Simulacrum001e9f32017-07-05 01:41:431609 } else {
1610 compiler.clone()
1611 };
1612
Alex Crichton90105672017-07-17 16:32:081613 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
Mark Simulacrumf104b122018-02-11 16:51:581614 match mode {
Collins Abitekaniza42ee6d52018-05-19 20:04:411615 Mode::Std => {
Alex Crichtonbe902e72018-03-05 17:47:541616 compile::std_cargo(builder, &compiler, target, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081617 }
Collins Abitekaniza42ee6d52018-05-19 20:04:411618 Mode::Test => {
Mark Simulacrumbe1e7892018-04-14 23:27:571619 compile::test_cargo(builder, &compiler, target, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081620 }
Collins Abitekaniza42ee6d52018-05-19 20:04:411621 Mode::Rustc => {
Alex Crichton90105672017-07-17 16:32:081622 builder.ensure(compile::Rustc { compiler, target });
Mark Simulacrumbe1e7892018-04-14 23:27:571623 compile::rustc_cargo(builder, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081624 }
1625 _ => panic!("can only test libraries"),
1626 };
Alex Crichton90105672017-07-17 16:32:081627
Mark Simulacrum001e9f32017-07-05 01:41:431628 // Build up the base `cargo test` command.
1629 //
1630 // Pass in some standard flags then iterate over the graph we've discovered
1631 // in `cargo metadata` with the maps above and figure out what `-p`
1632 // arguments need to get passed.
Mark Simulacrumbe1e7892018-04-14 23:27:571633 if test_kind.subcommand() == "test" && !builder.fail_fast {
Mark Simulacrum001e9f32017-07-05 01:41:431634 cargo.arg("--no-fail-fast");
Alex Crichtonbb9062a2016-04-29 21:23:151635 }
kennytm1733f5e2018-05-05 16:04:061636 match builder.doc_tests {
kennytm05af55b2018-05-05 19:30:421637 DocTests::Only => {
kennytm1733f5e2018-05-05 16:04:061638 cargo.arg("--doc");
1639 }
kennytm05af55b2018-05-05 19:30:421640 DocTests::No => {
kennytm1733f5e2018-05-05 16:04:061641 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
1642 }
kennytm05af55b2018-05-05 19:30:421643 DocTests::Yes => {}
Guillaume Gomez8e469272018-02-17 14:45:391644 }
Mark Simulacrum001e9f32017-07-05 01:41:431645
Mark Simulacrumf104b122018-02-11 16:51:581646 cargo.arg("-p").arg(krate);
Alex Crichtonbb9062a2016-04-29 21:23:151647
Mark Simulacrum001e9f32017-07-05 01:41:431648 // The tests are going to run with the *target* libraries, so we need to
1649 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1650 //
1651 // Note that to run the compiler we need to run with the *host* libraries,
1652 // but our wrapper scripts arrange for that to be the case anyway.
1653 let mut dylib_path = dylib_path();
Mark Simulacrum528646e2017-07-14 00:48:441654 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
Mark Simulacrum001e9f32017-07-05 01:41:431655 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
Alex Crichtonbb9062a2016-04-29 21:23:151656
Mark Simulacrum001e9f32017-07-05 01:41:431657 cargo.arg("--");
Mark Simulacrumbe1e7892018-04-14 23:27:571658 cargo.args(&builder.config.cmd.test_args());
Alex Crichton0e272de2016-11-16 20:31:191659
Oliver Schneider0c1bcd32018-06-07 12:40:361660 if !builder.config.verbose_tests {
Mark Simulacrum001e9f32017-07-05 01:41:431661 cargo.arg("--quiet");
1662 }
Corey Farwellc8c6d2c2016-10-30 01:58:521663
Mark Simulacrum001e9f32017-07-05 01:41:431664 if target.contains("emscripten") {
Santiago Pastorinob39a1d62018-05-30 17:33:431665 cargo.env(
1666 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1667 builder
1668 .config
1669 .nodejs
1670 .as_ref()
1671 .expect("nodejs not configured"),
1672 );
Oliver Schneideracdf83f2017-12-06 08:25:291673 } else if target.starts_with("wasm32") {
Diggory Blake0e6601f2018-01-11 17:51:491674 // Warn about running tests without the `wasm_syscall` feature enabled.
1675 // The javascript shim implements the syscall interface so that test
1676 // output can be correctly reported.
Mark Simulacrumbe1e7892018-04-14 23:27:571677 if !builder.config.wasm_syscall {
Santiago Pastorinob39a1d62018-05-30 17:33:431678 builder.info(&format!(
1679 "Libstd was built without `wasm_syscall` feature enabled: \
1680 test output may not be visible."
1681 ));
Diggory Blake0e6601f2018-01-11 17:51:491682 }
1683
Oliver Schneideracdf83f2017-12-06 08:25:291684 // On the wasm32-unknown-unknown target we're using LTO which is
1685 // incompatible with `-C prefer-dynamic`, so disable that here
1686 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
1687
Santiago Pastorinob39a1d62018-05-30 17:33:431688 let node = builder
1689 .config
1690 .nodejs
1691 .as_ref()
Oliver Schneideracdf83f2017-12-06 08:25:291692 .expect("nodejs not configured");
Santiago Pastorinob39a1d62018-05-30 17:33:431693 let runner = format!(
1694 "{} {}/src/etc/wasm32-shim.js",
1695 node.display(),
1696 builder.src.display()
1697 );
Oliver Schneideracdf83f2017-12-06 08:25:291698 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
Mark Simulacrumbe1e7892018-04-14 23:27:571699 } else if builder.remote_tested(target) {
Santiago Pastorinob39a1d62018-05-30 17:33:431700 cargo.env(
1701 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1702 format!("{} run", builder.tool_exe(Tool::RemoteTestClient).display()),
1703 );
Mark Simulacrum001e9f32017-07-05 01:41:431704 }
Alex Crichton6fd4d672018-03-16 15:35:031705
Mark Simulacrumbe1e7892018-04-14 23:27:571706 let _folder = builder.fold_output(|| {
Santiago Pastorinob39a1d62018-05-30 17:33:431707 format!(
1708 "{}_stage{}-{}",
1709 test_kind.subcommand(),
1710 compiler.stage,
1711 krate
1712 )
Alex Crichton6fd4d672018-03-16 15:35:031713 });
Santiago Pastorinob39a1d62018-05-30 17:33:431714 builder.info(&format!(
1715 "{} {} stage{} ({} -> {})",
1716 test_kind, krate, compiler.stage, &compiler.host, target
1717 ));
Mark Simulacrumbe1e7892018-04-14 23:27:571718 let _time = util::timeit(&builder);
1719 try_run(builder, &mut cargo);
Alex Crichton39a5d3f2016-06-28 20:31:301720 }
1721}
1722
Mark Simulacrumf87696b2017-09-02 14:02:321723#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrumf104b122018-02-11 16:51:581724pub struct CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321725 host: Interned<String>,
1726 test_kind: TestKind,
1727}
1728
Mark Simulacrumf104b122018-02-11 16:51:581729impl Step for CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321730 type Output = ();
1731 const DEFAULT: bool = true;
1732 const ONLY_HOSTS: bool = true;
1733
1734 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumf104b122018-02-11 16:51:581735 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
Mark Simulacrumf87696b2017-09-02 14:02:321736 }
1737
1738 fn make_run(run: RunConfig) {
1739 let builder = run.builder;
1740
Oliver Schneider37dee692018-05-16 15:18:191741 let test_kind = builder.kind.into();
Mark Simulacrumf87696b2017-09-02 14:02:321742
Mark Simulacrumf104b122018-02-11 16:51:581743 builder.ensure(CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321744 host: run.host,
1745 test_kind,
1746 });
1747 }
1748
1749 fn run(self, builder: &Builder) {
Mark Simulacrumf87696b2017-09-02 14:02:321750 let test_kind = self.test_kind;
1751
1752 let compiler = builder.compiler(builder.top_stage, self.host);
1753 let target = compiler.host;
Mark Rousskov814e6e62018-07-21 21:54:541754 builder.ensure(compile::Rustc { compiler, target });
Mark Simulacrumf87696b2017-09-02 14:02:321755
Collins Abitekanizafb949b52018-05-27 22:09:431756 let mut cargo = tool::prepare_tool_cargo(builder,
1757 compiler,
Collins Abitekaniza36eafe52018-05-27 23:56:331758 Mode::ToolRustc,
Collins Abitekanizafb949b52018-05-27 22:09:431759 target,
1760 test_kind.subcommand(),
Tatsuyuki Ishie0989852018-07-13 05:12:581761 "src/tools/rustdoc",
Tatsuyuki Ishi62f73dc2018-07-26 03:36:581762 SourceType::InTree);
Mark Simulacrumbe1e7892018-04-14 23:27:571763 if test_kind.subcommand() == "test" && !builder.fail_fast {
Mark Simulacrumf87696b2017-09-02 14:02:321764 cargo.arg("--no-fail-fast");
1765 }
1766
1767 cargo.arg("-p").arg("rustdoc:0.0.0");
1768
1769 cargo.arg("--");
Mark Simulacrumbe1e7892018-04-14 23:27:571770 cargo.args(&builder.config.cmd.test_args());
Mark Simulacrumf87696b2017-09-02 14:02:321771
Oliver Schneider0c1bcd32018-06-07 12:40:361772 if !builder.config.verbose_tests {
Mark Simulacrumf87696b2017-09-02 14:02:321773 cargo.arg("--quiet");
1774 }
1775
Santiago Pastorinob39a1d62018-05-30 17:33:431776 let _folder = builder
1777 .fold_output(|| format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage));
1778 builder.info(&format!(
1779 "{} rustdoc stage{} ({} -> {})",
1780 test_kind, compiler.stage, &compiler.host, target
1781 ));
Mark Simulacrumbe1e7892018-04-14 23:27:571782 let _time = util::timeit(&builder);
Mark Simulacrumf87696b2017-09-02 14:02:321783
Mark Simulacrumbe1e7892018-04-14 23:27:571784 try_run(builder, &mut cargo);
Mark Simulacrumf87696b2017-09-02 14:02:321785 }
1786}
1787
Alex Crichton8e7849e2017-07-29 00:52:441788fn envify(s: &str) -> String {
Santiago Pastorinob39a1d62018-05-30 17:33:431789 s.chars()
1790 .map(|c| match c {
Alex Crichton8e7849e2017-07-29 00:52:441791 '-' => '_',
1792 c => c,
Santiago Pastorinob39a1d62018-05-30 17:33:431793 })
1794 .flat_map(|c| c.to_uppercase())
1795 .collect()
Alex Crichton39a5d3f2016-06-28 20:31:301796}
1797
Mark Simulacrumceecd622017-07-12 16:12:471798/// Some test suites are run inside emulators or on remote devices, and most
1799/// of our test binaries are linked dynamically which means we need to ship
1800/// the standard library and such to the emulator ahead of time. This step
1801/// represents this and is a dependency of all test suites.
1802///
1803/// Most of the time this is a noop. For some steps such as shipping data to
1804/// QEMU we have to build our own tools so we've got conditional dependencies
1805/// on those programs as well. Note that the remote test client is built for
1806/// the build target (us) and the server is built for the target.
Mark Simulacrum528646e2017-07-14 00:48:441807#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1808pub struct RemoteCopyLibs {
1809 compiler: Compiler,
1810 target: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:431811}
Alex Crichton1747ce22017-01-28 21:38:061812
Mark Simulacrum528646e2017-07-14 00:48:441813impl Step for RemoteCopyLibs {
Mark Simulacrum001e9f32017-07-05 01:41:431814 type Output = ();
Alex Crichton1747ce22017-01-28 21:38:061815
Mark Simulacrum56128fb2017-07-19 00:03:381816 fn should_run(run: ShouldRun) -> ShouldRun {
1817 run.never()
Mark Simulacrum681b1232017-07-14 12:30:161818 }
1819
Mark Simulacrum001e9f32017-07-05 01:41:431820 fn run(self, builder: &Builder) {
Mark Simulacrum001e9f32017-07-05 01:41:431821 let compiler = self.compiler;
1822 let target = self.target;
Mark Simulacrumbe1e7892018-04-14 23:27:571823 if !builder.remote_tested(target) {
Santiago Pastorinob39a1d62018-05-30 17:33:431824 return;
Mark Simulacrum001e9f32017-07-05 01:41:431825 }
Alex Crichton1747ce22017-01-28 21:38:061826
Mark Simulacrum6b3413d2017-07-05 12:41:271827 builder.ensure(compile::Test { compiler, target });
1828
Mark Simulacrumbe1e7892018-04-14 23:27:571829 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
1830 t!(fs::create_dir_all(builder.out.join("tmp")));
Mark Simulacrum001e9f32017-07-05 01:41:431831
Alex Crichtonef41cf02018-06-29 21:35:101832 let server = builder.ensure(tool::RemoteTestServer {
1833 compiler: compiler.with_stage(0),
1834 target,
1835 });
Mark Simulacrum001e9f32017-07-05 01:41:431836
1837 // Spawn the emulator and wait for it to come online
Mark Simulacrum6b3413d2017-07-05 12:41:271838 let tool = builder.tool_exe(Tool::RemoteTestClient);
Mark Simulacrum001e9f32017-07-05 01:41:431839 let mut cmd = Command::new(&tool);
1840 cmd.arg("spawn-emulator")
Santiago Pastorinob39a1d62018-05-30 17:33:431841 .arg(target)
1842 .arg(&server)
1843 .arg(builder.out.join("tmp"));
Mark Simulacrumbe1e7892018-04-14 23:27:571844 if let Some(rootfs) = builder.qemu_rootfs(target) {
Mark Simulacrum001e9f32017-07-05 01:41:431845 cmd.arg(rootfs);
1846 }
Mark Simulacrumbe1e7892018-04-14 23:27:571847 builder.run(&mut cmd);
Mark Simulacrum001e9f32017-07-05 01:41:431848
1849 // Push all our dylibs to the emulator
Mark Simulacrum60388302017-07-05 16:46:411850 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
Mark Simulacrum001e9f32017-07-05 01:41:431851 let f = t!(f);
1852 let name = f.file_name().into_string().unwrap();
1853 if util::is_dylib(&name) {
Santiago Pastorinob39a1d62018-05-30 17:33:431854 builder.run(Command::new(&tool).arg("push").arg(f.path()));
Mark Simulacrum001e9f32017-07-05 01:41:431855 }
Alex Crichton1747ce22017-01-28 21:38:061856 }
1857 }
1858}
1859
Mark Simulacrum528646e2017-07-14 00:48:441860#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum001e9f32017-07-05 01:41:431861pub struct Distcheck;
1862
Mark Simulacrum528646e2017-07-14 00:48:441863impl Step for Distcheck {
Mark Simulacrum001e9f32017-07-05 01:41:431864 type Output = ();
1865
Mark Simulacrum56128fb2017-07-19 00:03:381866 fn should_run(run: ShouldRun) -> ShouldRun {
1867 run.path("distcheck")
Mark Simulacrum681b1232017-07-14 12:30:161868 }
1869
Mark Simulacrum8f2e5762017-07-22 13:35:421870 fn make_run(run: RunConfig) {
1871 run.builder.ensure(Distcheck);
1872 }
1873
Mark Simulacrum001e9f32017-07-05 01:41:431874 /// Run "distcheck", a 'make check' from a tarball
1875 fn run(self, builder: &Builder) {
Mark Simulacrumbe1e7892018-04-14 23:27:571876 builder.info(&format!("Distcheck"));
1877 let dir = builder.out.join("tmp").join("distcheck");
Mark Simulacrum001e9f32017-07-05 01:41:431878 let _ = fs::remove_dir_all(&dir);
1879 t!(fs::create_dir_all(&dir));
1880
Mark Simulacrum1c118232017-07-22 16:48:291881 // Guarantee that these are built before we begin running.
1882 builder.ensure(dist::PlainSourceTarball);
1883 builder.ensure(dist::Src);
1884
Mark Simulacrum001e9f32017-07-05 01:41:431885 let mut cmd = Command::new("tar");
1886 cmd.arg("-xzf")
Santiago Pastorinob39a1d62018-05-30 17:33:431887 .arg(builder.ensure(dist::PlainSourceTarball))
1888 .arg("--strip-components=1")
1889 .current_dir(&dir);
Mark Simulacrumbe1e7892018-04-14 23:27:571890 builder.run(&mut cmd);
Santiago Pastorinob39a1d62018-05-30 17:33:431891 builder.run(
1892 Command::new("./configure")
1893 .args(&builder.config.configure_args)
1894 .arg("--enable-vendor")
1895 .current_dir(&dir),
1896 );
1897 builder.run(
1898 Command::new(build_helper::make(&builder.config.build))
1899 .arg("check")
1900 .current_dir(&dir),
1901 );
Mark Simulacrum001e9f32017-07-05 01:41:431902
1903 // Now make sure that rust-src has all of libstd's dependencies
Mark Simulacrumbe1e7892018-04-14 23:27:571904 builder.info(&format!("Distcheck rust-src"));
1905 let dir = builder.out.join("tmp").join("distcheck-src");
Mark Simulacrum001e9f32017-07-05 01:41:431906 let _ = fs::remove_dir_all(&dir);
1907 t!(fs::create_dir_all(&dir));
1908
1909 let mut cmd = Command::new("tar");
1910 cmd.arg("-xzf")
Santiago Pastorinob39a1d62018-05-30 17:33:431911 .arg(builder.ensure(dist::Src))
1912 .arg("--strip-components=1")
1913 .current_dir(&dir);
Mark Simulacrumbe1e7892018-04-14 23:27:571914 builder.run(&mut cmd);
Mark Simulacrum001e9f32017-07-05 01:41:431915
1916 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
Santiago Pastorinob39a1d62018-05-30 17:33:431917 builder.run(
1918 Command::new(&builder.initial_cargo)
1919 .arg("generate-lockfile")
1920 .arg("--manifest-path")
1921 .arg(&toml)
1922 .current_dir(&dir),
1923 );
Alex Crichtond38db822016-12-09 01:13:551924 }
Alex Crichtond38db822016-12-09 01:13:551925}
Alex Crichton1a040b32016-12-31 03:50:571926
Mark Simulacrum528646e2017-07-14 00:48:441927#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum001e9f32017-07-05 01:41:431928pub struct Bootstrap;
1929
Mark Simulacrum528646e2017-07-14 00:48:441930impl Step for Bootstrap {
Mark Simulacrum001e9f32017-07-05 01:41:431931 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271932 const DEFAULT: bool = true;
1933 const ONLY_HOSTS: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:431934
1935 /// Test the build system itself
1936 fn run(self, builder: &Builder) {
Mark Simulacrumbe1e7892018-04-14 23:27:571937 let mut cmd = Command::new(&builder.initial_cargo);
Mark Simulacrum001e9f32017-07-05 01:41:431938 cmd.arg("test")
Santiago Pastorinob39a1d62018-05-30 17:33:431939 .current_dir(builder.src.join("src/bootstrap"))
1940 .env("RUSTFLAGS", "-Cdebuginfo=2")
1941 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
1942 .env("RUSTC_BOOTSTRAP", "1")
1943 .env("RUSTC", &builder.initial_rustc);
Simon Sapine993e622018-03-23 18:55:411944 if let Some(flags) = option_env!("RUSTFLAGS") {
1945 // Use the same rustc flags for testing as for "normal" compilation,
1946 // so that Cargo doesn’t recompile the entire dependency graph every time:
1947 // https://github.com/rust-lang/rust/issues/49215
1948 cmd.env("RUSTFLAGS", flags);
1949 }
Mark Simulacrumbe1e7892018-04-14 23:27:571950 if !builder.fail_fast {
Mark Simulacrum001e9f32017-07-05 01:41:431951 cmd.arg("--no-fail-fast");
1952 }
Mark Simulacrumbe1e7892018-04-14 23:27:571953 cmd.arg("--").args(&builder.config.cmd.test_args());
Mark Simulacrumb436dca2018-06-16 17:12:151954 // rustbuild tests are racy on directory creation so just run them one at a time.
1955 // Since there's not many this shouldn't be a problem.
1956 cmd.arg("--test-threads=1");
Mark Simulacrumbe1e7892018-04-14 23:27:571957 try_run(builder, &mut cmd);
Josh Stone617aea42017-06-02 16:27:441958 }
Mark Simulacrum6b3413d2017-07-05 12:41:271959
Mark Simulacrum56128fb2017-07-19 00:03:381960 fn should_run(run: ShouldRun) -> ShouldRun {
1961 run.path("src/bootstrap")
Mark Simulacrum6b3413d2017-07-05 12:41:271962 }
1963
Mark Simulacrum6a67a052017-07-20 23:51:071964 fn make_run(run: RunConfig) {
1965 run.builder.ensure(Bootstrap);
Mark Simulacrum6b3413d2017-07-05 12:41:271966 }
Alex Crichton1a040b32016-12-31 03:50:571967}