blob: c86010379f495fe56e89a31ff1eed0106bd5a513 [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 Sekine3f00b1c2018-07-21 13:39:35978 if builder.no_std(target) != Some(true) {
Hideki Sekinebbc89b22018-07-17 15:40:55979 builder.ensure(compile::Test { compiler, target });
980 }
Mark Simulacrum6b3413d2017-07-05 12:41:27981 builder.ensure(native::TestHelpers { target });
Mark Simulacrumaa8b93b2017-07-07 18:31:29982 builder.ensure(RemoteCopyLibs { compiler, target });
Mark Simulacrum6b3413d2017-07-05 12:41:27983
Mark Simulacrum6b3413d2017-07-05 12:41:27984 let mut cmd = builder.tool_cmd(Tool::Compiletest);
Alex Crichtonb325baf2016-04-05 18:34:23985
Mark Simulacrum001e9f32017-07-05 01:41:43986 // compiletest currently has... a lot of arguments, so let's just pass all
987 // of them!
Brian Anderson8401e372016-09-15 19:42:26988
Santiago Pastorinob39a1d62018-05-30 17:33:43989 cmd.arg("--compile-lib-path")
990 .arg(builder.rustc_libdir(compiler));
991 cmd.arg("--run-lib-path")
992 .arg(builder.sysroot_libdir(compiler, target));
Mark Simulacrumc114fe52017-07-05 17:21:33993 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
Mark Simulacrum4e5333c2017-07-25 22:54:33994
Guillaume Gomezb2192ae2018-04-01 19:06:35995 let is_rustdoc_ui = suite.ends_with("rustdoc-ui");
996
Mark Simulacrum4e5333c2017-07-25 22:54:33997 // Avoid depending on rustdoc when we don't need it.
Santiago Pastorinob39a1d62018-05-30 17:33:43998 if mode == "rustdoc"
999 || (mode == "run-make" && suite.ends_with("fulldeps"))
1000 || (mode == "ui" && is_rustdoc_ui)
1001 {
1002 cmd.arg("--rustdoc-path")
1003 .arg(builder.rustdoc(compiler.host));
Mark Simulacrum4e5333c2017-07-25 22:54:331004 }
1005
Santiago Pastorinob39a1d62018-05-30 17:33:431006 cmd.arg("--src-base")
1007 .arg(builder.src.join("src/test").join(suite));
1008 cmd.arg("--build-base")
1009 .arg(testdir(builder, compiler.host).join(suite));
1010 cmd.arg("--stage-id")
1011 .arg(format!("stage{}-{}", compiler.stage, target));
Mark Simulacrum001e9f32017-07-05 01:41:431012 cmd.arg("--mode").arg(mode);
1013 cmd.arg("--target").arg(target);
Mark Simulacrum528646e2017-07-14 00:48:441014 cmd.arg("--host").arg(&*compiler.host);
Santiago Pastorinob39a1d62018-05-30 17:33:431015 cmd.arg("--llvm-filecheck")
1016 .arg(builder.llvm_filecheck(builder.config.build));
Alex Crichtonf4e4ec72016-05-13 22:26:411017
Oliver Schneiderceed8eb2018-05-16 16:17:291018 if builder.config.cmd.bless() {
Oliver Schneider37dee692018-05-16 15:18:191019 cmd.arg("--bless");
1020 }
1021
Santiago Pastorinob970fee2018-05-28 22:44:331022 let compare_mode = builder.config.cmd.compare_mode().or(self.compare_mode);
1023
Mark Simulacrumbe1e7892018-04-14 23:27:571024 if let Some(ref nodejs) = builder.config.nodejs {
Mark Simulacrum001e9f32017-07-05 01:41:431025 cmd.arg("--nodejs").arg(nodejs);
1026 }
Alex Crichtonf4e4ec72016-05-13 22:26:411027
Guillaume Gomezb2192ae2018-04-01 19:06:351028 let mut flags = if is_rustdoc_ui {
1029 Vec::new()
1030 } else {
1031 vec!["-Crpath".to_string()]
1032 };
1033 if !is_rustdoc_ui {
Mark Simulacrumbe1e7892018-04-14 23:27:571034 if builder.config.rust_optimize_tests {
Guillaume Gomezb2192ae2018-04-01 19:06:351035 flags.push("-O".to_string());
1036 }
Mark Simulacrumbe1e7892018-04-14 23:27:571037 if builder.config.rust_debuginfo_tests {
Guillaume Gomezb2192ae2018-04-01 19:06:351038 flags.push("-g".to_string());
1039 }
Mark Simulacrum001e9f32017-07-05 01:41:431040 }
Guillaume Gomeza3ed2ab2018-04-15 11:05:141041 flags.push("-Zunstable-options".to_string());
Mark Simulacrumbe1e7892018-04-14 23:27:571042 flags.push(builder.config.cmd.rustc_args().join(" "));
Alex Crichtoncbe62922016-04-19 16:44:191043
Mark Simulacrumbe1e7892018-04-14 23:27:571044 if let Some(linker) = builder.linker(target) {
Oliver Schneideracdf83f2017-12-06 08:25:291045 cmd.arg("--linker").arg(linker);
1046 }
1047
1048 let hostflags = flags.clone();
Mark Simulacrum001e9f32017-07-05 01:41:431049 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
Alex Crichtoncbe62922016-04-19 16:44:191050
Oliver Schneideracdf83f2017-12-06 08:25:291051 let mut targetflags = flags.clone();
Santiago Pastorinob39a1d62018-05-30 17:33:431052 targetflags.push(format!(
1053 "-Lnative={}",
1054 builder.test_helpers_out(target).display()
1055 ));
Mark Simulacrum001e9f32017-07-05 01:41:431056 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
Alex Crichtonb325baf2016-04-05 18:34:231057
Mark Simulacrumbe1e7892018-04-14 23:27:571058 cmd.arg("--docck-python").arg(builder.python());
Alex Crichtonb325baf2016-04-05 18:34:231059
Mark Simulacrumbe1e7892018-04-14 23:27:571060 if builder.config.build.ends_with("apple-darwin") {
Mark Simulacrum001e9f32017-07-05 01:41:431061 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
1062 // LLDB plugin's compiled module which only works with the system python
1063 // (namely not Homebrew-installed python)
1064 cmd.arg("--lldb-python").arg("/usr/bin/python");
1065 } else {
Mark Simulacrumbe1e7892018-04-14 23:27:571066 cmd.arg("--lldb-python").arg(builder.python());
Mark Simulacrum001e9f32017-07-05 01:41:431067 }
Alex Crichtonb325baf2016-04-05 18:34:231068
Mark Simulacrumbe1e7892018-04-14 23:27:571069 if let Some(ref gdb) = builder.config.gdb {
Mark Simulacrum001e9f32017-07-05 01:41:431070 cmd.arg("--gdb").arg(gdb);
1071 }
Mark Simulacrumbe1e7892018-04-14 23:27:571072 if let Some(ref vers) = builder.lldb_version {
Mark Simulacrum001e9f32017-07-05 01:41:431073 cmd.arg("--lldb-version").arg(vers);
1074 }
Mark Simulacrumbe1e7892018-04-14 23:27:571075 if let Some(ref dir) = builder.lldb_python_dir {
Mark Simulacrum001e9f32017-07-05 01:41:431076 cmd.arg("--lldb-python-dir").arg(dir);
1077 }
Alex Crichtonb325baf2016-04-05 18:34:231078
Collins Abitekaniza41ee6fe2018-04-12 11:49:311079 // Get paths from cmd args
1080 let paths = match &builder.config.cmd {
Santiago Pastorinob39a1d62018-05-30 17:33:431081 Subcommand::Test { ref paths, .. } => &paths[..],
1082 _ => &[],
Collins Abitekaniza41ee6fe2018-04-12 11:49:311083 };
1084
1085 // Get test-args by striping suite path
Santiago Pastorinob39a1d62018-05-30 17:33:431086 let mut test_args: Vec<&str> = paths
1087 .iter()
Steven Laabs475405b2018-06-22 04:57:061088 .map(|p| {
1089 match p.strip_prefix(".") {
1090 Ok(path) => path,
1091 Err(_) => p,
1092 }
1093 })
Santiago Pastorinob39a1d62018-05-30 17:33:431094 .filter(|p| p.starts_with(suite_path) && p.is_file())
1095 .map(|p| p.strip_prefix(suite_path).unwrap().to_str().unwrap())
1096 .collect();
Collins Abitekaniza41ee6fe2018-04-12 11:49:311097
1098 test_args.append(&mut builder.config.cmd.test_args());
1099
1100 cmd.args(&test_args);
Corey Farwellc8c6d2c2016-10-30 01:58:521101
Mark Simulacrumbe1e7892018-04-14 23:27:571102 if builder.is_verbose() {
Mark Simulacrum001e9f32017-07-05 01:41:431103 cmd.arg("--verbose");
1104 }
Alex Crichton126e09e2016-04-14 22:51:031105
Oliver Schneider0c1bcd32018-06-07 12:40:361106 if !builder.config.verbose_tests {
Mark Simulacrum001e9f32017-07-05 01:41:431107 cmd.arg("--quiet");
1108 }
Alex Crichton1747ce22017-01-28 21:38:061109
Mark Simulacrumbe1e7892018-04-14 23:27:571110 if builder.config.llvm_enabled {
Alex Crichtonbe902e72018-03-05 17:47:541111 let llvm_config = builder.ensure(native::Llvm {
Mark Simulacrumbe1e7892018-04-14 23:27:571112 target: builder.config.build,
Alex Crichtonbe902e72018-03-05 17:47:541113 emscripten: false,
1114 });
Mark Simulacrumbe1e7892018-04-14 23:27:571115 if !builder.config.dry_run {
Mark Simulacrum0ce5cf02018-04-01 01:21:141116 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1117 cmd.arg("--llvm-version").arg(llvm_version);
1118 }
Mark Simulacrumbe1e7892018-04-14 23:27:571119 if !builder.is_rust_llvm(target) {
bjorn30c97bbf2017-08-13 10:30:541120 cmd.arg("--system-llvm");
1121 }
1122
1123 // Only pass correct values for these flags for the `run-make` suite as it
1124 // requires that a C++ compiler was configured which isn't always the case.
Eric Hussa90a9632018-05-15 23:39:211125 if !builder.config.dry_run && suite == "run-make-fulldeps" {
bjorn30c97bbf2017-08-13 10:30:541126 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1127 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
Santiago Pastorinob39a1d62018-05-30 17:33:431128 cmd.arg("--cc")
1129 .arg(builder.cc(target))
1130 .arg("--cxx")
1131 .arg(builder.cxx(target).unwrap())
1132 .arg("--cflags")
1133 .arg(builder.cflags(target).join(" "))
1134 .arg("--llvm-components")
1135 .arg(llvm_components.trim())
1136 .arg("--llvm-cxxflags")
1137 .arg(llvm_cxxflags.trim());
Mark Simulacrumbe1e7892018-04-14 23:27:571138 if let Some(ar) = builder.ar(target) {
Oliver Schneideracdf83f2017-12-06 08:25:291139 cmd.arg("--ar").arg(ar);
1140 }
bjorn30c97bbf2017-08-13 10:30:541141 }
1142 }
Eric Hussa90a9632018-05-15 23:39:211143 if suite == "run-make-fulldeps" && !builder.config.llvm_enabled {
Santiago Pastorinob39a1d62018-05-30 17:33:431144 builder.info(&format!(
1145 "Ignoring run-make test suite as they generally don't work without LLVM"
1146 ));
bjorn30c97bbf2017-08-13 10:30:541147 return;
1148 }
1149
Eric Hussa90a9632018-05-15 23:39:211150 if suite != "run-make-fulldeps" {
Santiago Pastorinob39a1d62018-05-30 17:33:431151 cmd.arg("--cc")
1152 .arg("")
1153 .arg("--cxx")
1154 .arg("")
1155 .arg("--cflags")
1156 .arg("")
1157 .arg("--llvm-components")
1158 .arg("")
1159 .arg("--llvm-cxxflags")
1160 .arg("");
Mark Simulacrum001e9f32017-07-05 01:41:431161 }
1162
Mark Simulacrumbe1e7892018-04-14 23:27:571163 if builder.remote_tested(target) {
Santiago Pastorinob39a1d62018-05-30 17:33:431164 cmd.arg("--remote-test-client")
1165 .arg(builder.tool_exe(Tool::RemoteTestClient));
Mark Simulacrum001e9f32017-07-05 01:41:431166 }
1167
1168 // Running a C compiler on MSVC requires a few env vars to be set, to be
1169 // sure to set them here.
1170 //
1171 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1172 // rather than stomp over it.
1173 if target.contains("msvc") {
Mark Simulacrumbe1e7892018-04-14 23:27:571174 for &(ref k, ref v) in builder.cc[&target].env() {
Mark Simulacrum001e9f32017-07-05 01:41:431175 if k != "PATH" {
1176 cmd.env(k, v);
1177 }
Alex Crichton126e09e2016-04-14 22:51:031178 }
1179 }
Mark Simulacrum001e9f32017-07-05 01:41:431180 cmd.env("RUSTC_BOOTSTRAP", "1");
Mark Simulacrumbe1e7892018-04-14 23:27:571181 builder.add_rust_test_threads(&mut cmd);
Mark Simulacrum001e9f32017-07-05 01:41:431182
Mark Simulacrumbe1e7892018-04-14 23:27:571183 if builder.config.sanitizers {
Mark Simulacrum001e9f32017-07-05 01:41:431184 cmd.env("SANITIZER_SUPPORT", "1");
1185 }
1186
Mark Simulacrumbe1e7892018-04-14 23:27:571187 if builder.config.profiler {
Mark Simulacrum001e9f32017-07-05 01:41:431188 cmd.env("PROFILER_SUPPORT", "1");
1189 }
1190
Mark Simulacrumbe1e7892018-04-14 23:27:571191 cmd.env("RUST_TEST_TMPDIR", builder.out.join("tmp"));
Alex Crichton884715c2018-01-22 15:29:241192
Mark Simulacrum001e9f32017-07-05 01:41:431193 cmd.arg("--adb-path").arg("adb");
1194 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1195 if target.contains("android") {
1196 // Assume that cc for this target comes from the android sysroot
1197 cmd.arg("--android-cross-path")
Santiago Pastorinob39a1d62018-05-30 17:33:431198 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
Mark Simulacrum001e9f32017-07-05 01:41:431199 } else {
1200 cmd.arg("--android-cross-path").arg("");
1201 }
1202
Mark Simulacrumbe1e7892018-04-14 23:27:571203 builder.ci_env.force_coloring_in_ci(&mut cmd);
Mark Simulacrum001e9f32017-07-05 01:41:431204
Mark Simulacrumbe1e7892018-04-14 23:27:571205 let _folder = builder.fold_output(|| format!("test_{}", suite));
Santiago Pastorinob39a1d62018-05-30 17:33:431206 builder.info(&format!(
1207 "Check compiletest suite={} mode={} ({} -> {})",
1208 suite, mode, &compiler.host, target
1209 ));
Mark Simulacrumbe1e7892018-04-14 23:27:571210 let _time = util::timeit(&builder);
1211 try_run(builder, &mut cmd);
Felix S. Klock II55895502018-04-11 15:15:591212
1213 if let Some(compare_mode) = compare_mode {
1214 cmd.arg("--compare-mode").arg(compare_mode);
1215 let _folder = builder.fold_output(|| format!("test_{}_{}", suite, compare_mode));
Santiago Pastorinob39a1d62018-05-30 17:33:431216 builder.info(&format!(
1217 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1218 suite, mode, compare_mode, &compiler.host, target
1219 ));
Felix S. Klock II55895502018-04-11 15:15:591220 let _time = util::timeit(&builder);
1221 try_run(builder, &mut cmd);
1222 }
Alex Crichton126e09e2016-04-14 22:51:031223 }
Alex Crichtonb325baf2016-04-05 18:34:231224}
Alex Crichtonede89442016-04-15 01:00:351225
Mark Simulacrum528646e2017-07-14 00:48:441226#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
kennytm0d300d42018-02-21 19:13:341227struct DocTest {
Mark Simulacrum528646e2017-07-14 00:48:441228 compiler: Compiler,
kennytm0d300d42018-02-21 19:13:341229 path: &'static str,
1230 name: &'static str,
1231 is_ext_doc: bool,
Mark Simulacruma5ab2ce2017-07-12 15:15:001232}
1233
kennytm0d300d42018-02-21 19:13:341234impl Step for DocTest {
Mark Simulacruma5ab2ce2017-07-12 15:15:001235 type Output = ();
Mark Simulacruma5ab2ce2017-07-12 15:15:001236 const ONLY_HOSTS: bool = true;
Alex Crichtonede89442016-04-15 01:00:351237
Mark Simulacrum56128fb2017-07-19 00:03:381238 fn should_run(run: ShouldRun) -> ShouldRun {
kennytm0d300d42018-02-21 19:13:341239 run.never()
Mark Simulacruma5ab2ce2017-07-12 15:15:001240 }
1241
1242 /// Run `rustdoc --test` for all documentation in `src/doc`.
1243 ///
1244 /// This will run all tests in our markdown documentation (e.g. the book)
1245 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
1246 /// `compiler`.
1247 fn run(self, builder: &Builder) {
Mark Simulacruma5ab2ce2017-07-12 15:15:001248 let compiler = self.compiler;
Mark Simulacrumceecd622017-07-12 16:12:471249
Santiago Pastorinob39a1d62018-05-30 17:33:431250 builder.ensure(compile::Test {
1251 compiler,
1252 target: compiler.host,
1253 });
Mark Simulacrumceecd622017-07-12 16:12:471254
Mark Simulacruma5ab2ce2017-07-12 15:15:001255 // Do a breadth-first traversal of the `src/doc` directory and just run
1256 // tests for all files that end in `*.md`
Mark Simulacrumbe1e7892018-04-14 23:27:571257 let mut stack = vec![builder.src.join(self.path)];
1258 let _time = util::timeit(&builder);
1259 let _folder = builder.fold_output(|| format!("test_{}", self.name));
Mark Simulacruma5ab2ce2017-07-12 15:15:001260
Mark Simulacruma7274472018-03-27 14:06:471261 let mut files = Vec::new();
Mark Simulacruma5ab2ce2017-07-12 15:15:001262 while let Some(p) = stack.pop() {
1263 if p.is_dir() {
1264 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
Santiago Pastorinob39a1d62018-05-30 17:33:431265 continue;
Mark Simulacruma5ab2ce2017-07-12 15:15:001266 }
1267
1268 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1269 continue;
1270 }
1271
1272 // The nostarch directory in the book is for no starch, and so isn't
Mark Simulacrumbe1e7892018-04-14 23:27:571273 // guaranteed to builder. We don't care if it doesn't build, so skip it.
Mark Simulacruma5ab2ce2017-07-12 15:15:001274 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
1275 continue;
1276 }
1277
Mark Simulacruma7274472018-03-27 14:06:471278 files.push(p);
1279 }
1280
1281 files.sort();
1282
kennytm20231d72018-07-02 21:53:181283 let mut toolstate = ToolState::TestPass;
Mark Simulacruma7274472018-03-27 14:06:471284 for file in files {
kennytm20231d72018-07-02 21:53:181285 if !markdown_test(builder, compiler, &file) {
1286 toolstate = ToolState::TestFail;
kennytma9f940e2018-02-21 19:25:231287 }
Alex Crichtonede89442016-04-15 01:00:351288 }
kennytm20231d72018-07-02 21:53:181289 if self.is_ext_doc {
1290 builder.save_toolstate(self.name, toolstate);
1291 }
Alex Crichtonede89442016-04-15 01:00:351292 }
1293}
1294
kennytm0d300d42018-02-21 19:13:341295macro_rules! test_book {
1296 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1297 $(
1298 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1299 pub struct $name {
1300 compiler: Compiler,
1301 }
1302
1303 impl Step for $name {
1304 type Output = ();
1305 const DEFAULT: bool = $default;
1306 const ONLY_HOSTS: bool = true;
1307
1308 fn should_run(run: ShouldRun) -> ShouldRun {
1309 run.path($path)
1310 }
1311
1312 fn make_run(run: RunConfig) {
1313 run.builder.ensure($name {
1314 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1315 });
1316 }
1317
1318 fn run(self, builder: &Builder) {
1319 builder.ensure(DocTest {
1320 compiler: self.compiler,
1321 path: $path,
1322 name: $book_name,
1323 is_ext_doc: !$default,
1324 });
1325 }
1326 }
1327 )+
1328 }
1329}
1330
1331test_book!(
1332 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1333 Reference, "src/doc/reference", "reference", default=false;
1334 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
steveklabnikb99418d2018-04-05 18:41:481335 RustcBook, "src/doc/rustc", "rustc", default=true;
kennytm0d300d42018-02-21 19:13:341336 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1337 TheBook, "src/doc/book", "book", default=false;
1338 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1339);
1340
Mark Simulacrum528646e2017-07-14 00:48:441341#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1342pub struct ErrorIndex {
1343 compiler: Compiler,
Mark Simulacrum001e9f32017-07-05 01:41:431344}
Alex Crichton0e272de2016-11-16 20:31:191345
Mark Simulacrum528646e2017-07-14 00:48:441346impl Step for ErrorIndex {
Mark Simulacrum001e9f32017-07-05 01:41:431347 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271348 const DEFAULT: bool = true;
1349 const ONLY_HOSTS: bool = true;
1350
Mark Simulacrum56128fb2017-07-19 00:03:381351 fn should_run(run: ShouldRun) -> ShouldRun {
1352 run.path("src/tools/error_index_generator")
Mark Simulacrum6b3413d2017-07-05 12:41:271353 }
1354
Mark Simulacrum6a67a052017-07-20 23:51:071355 fn make_run(run: RunConfig) {
1356 run.builder.ensure(ErrorIndex {
1357 compiler: run.builder.compiler(run.builder.top_stage, run.host),
Mark Simulacrum6b3413d2017-07-05 12:41:271358 });
1359 }
Alex Crichtonede89442016-04-15 01:00:351360
Mark Simulacrum001e9f32017-07-05 01:41:431361 /// Run the error index generator tool to execute the tests located in the error
1362 /// index.
1363 ///
1364 /// The `error_index_generator` tool lives in `src/tools` and is used to
1365 /// generate a markdown file from the error indexes of the code base which is
1366 /// then passed to `rustdoc --test`.
1367 fn run(self, builder: &Builder) {
Mark Simulacrum001e9f32017-07-05 01:41:431368 let compiler = self.compiler;
1369
Santiago Pastorinob39a1d62018-05-30 17:33:431370 builder.ensure(compile::Std {
1371 compiler,
1372 target: compiler.host,
1373 });
Mark Simulacrum6b3413d2017-07-05 12:41:271374
Mark Simulacrumbe1e7892018-04-14 23:27:571375 let dir = testdir(builder, compiler.host);
Mark Simulacrum001e9f32017-07-05 01:41:431376 t!(fs::create_dir_all(&dir));
1377 let output = dir.join("error-index.md");
1378
Alex Crichton6fd4d672018-03-16 15:35:031379 let mut tool = builder.tool_cmd(Tool::ErrorIndex);
1380 tool.arg("markdown")
1381 .arg(&output)
Mark Simulacrumbe1e7892018-04-14 23:27:571382 .env("CFG_BUILD", &builder.config.build)
1383 .env("RUSTC_ERROR_METADATA_DST", builder.extended_error_dir());
Mark Simulacrum001e9f32017-07-05 01:41:431384
Mark Simulacrumbe1e7892018-04-14 23:27:571385 let _folder = builder.fold_output(|| "test_error_index");
1386 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1387 let _time = util::timeit(&builder);
1388 builder.run(&mut tool);
Mark Simulacrumc114fe52017-07-05 17:21:331389 markdown_test(builder, compiler, &output);
Mark Simulacrum001e9f32017-07-05 01:41:431390 }
Alex Crichtonede89442016-04-15 01:00:351391}
1392
kennytma9f940e2018-02-21 19:25:231393fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) -> bool {
Mark Simulacrum0ce5cf02018-04-01 01:21:141394 match File::open(markdown) {
1395 Ok(mut file) => {
1396 let mut contents = String::new();
1397 t!(file.read_to_string(&mut contents));
1398 if !contents.contains("```") {
1399 return true;
1400 }
1401 }
Santiago Pastorinob39a1d62018-05-30 17:33:431402 Err(_) => {}
Mark Simulacrumdd1d75e2017-06-04 23:55:501403 }
1404
Mark Simulacrumbe1e7892018-04-14 23:27:571405 builder.info(&format!("doc tests for: {}", markdown.display()));
Mark Simulacrumfacf5a92017-08-04 22:13:011406 let mut cmd = builder.rustdoc_cmd(compiler.host);
Mark Simulacrumbe1e7892018-04-14 23:27:571407 builder.add_rust_test_threads(&mut cmd);
Alex Crichtonede89442016-04-15 01:00:351408 cmd.arg("--test");
1409 cmd.arg(markdown);
Alex Crichton6f62fae2016-12-12 17:03:351410 cmd.env("RUSTC_BOOTSTRAP", "1");
Corey Farwellc8c6d2c2016-10-30 01:58:521411
Mark Simulacrumbe1e7892018-04-14 23:27:571412 let test_args = builder.config.cmd.test_args().join(" ");
Corey Farwellc8c6d2c2016-10-30 01:58:521413 cmd.arg("--test-args").arg(test_args);
1414
Oliver Schneider0c1bcd32018-06-07 12:40:361415 if builder.config.verbose_tests {
Mark Simulacrumbe1e7892018-04-14 23:27:571416 try_run(builder, &mut cmd)
Oliver Schneider0c1bcd32018-06-07 12:40:361417 } else {
1418 try_run_quiet(builder, &mut cmd)
kennytm6ac07872017-05-21 20:27:471419 }
Alex Crichtonede89442016-04-15 01:00:351420}
Alex Crichtonbb9062a2016-04-29 21:23:151421
Mark Simulacrum528646e2017-07-14 00:48:441422#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum981afa52017-07-18 21:28:531423pub struct CrateLibrustc {
Mark Simulacrum528646e2017-07-14 00:48:441424 compiler: Compiler,
1425 target: Interned<String>,
Mark Simulacrum6b3413d2017-07-05 12:41:271426 test_kind: TestKind,
Mark Simulacrumf104b122018-02-11 16:51:581427 krate: Interned<String>,
Mark Simulacrum6b3413d2017-07-05 12:41:271428}
1429
Mark Simulacrum981afa52017-07-18 21:28:531430impl Step for CrateLibrustc {
Mark Simulacrum6b3413d2017-07-05 12:41:271431 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271432 const DEFAULT: bool = true;
1433 const ONLY_HOSTS: bool = true;
1434
Mark Simulacrum56128fb2017-07-19 00:03:381435 fn should_run(run: ShouldRun) -> ShouldRun {
1436 run.krate("rustc-main")
Mark Simulacrum6b3413d2017-07-05 12:41:271437 }
1438
Mark Simulacrum6a67a052017-07-20 23:51:071439 fn make_run(run: RunConfig) {
1440 let builder = run.builder;
1441 let compiler = builder.compiler(builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:271442
Mark Simulacrumf104b122018-02-11 16:51:581443 for krate in builder.in_tree_crates("rustc-main") {
1444 if run.path.ends_with(&krate.path) {
Oliver Schneider37dee692018-05-16 15:18:191445 let test_kind = builder.kind.into();
Mark Simulacrum6b3413d2017-07-05 12:41:271446
Mark Simulacrumf104b122018-02-11 16:51:581447 builder.ensure(CrateLibrustc {
1448 compiler,
1449 target: run.target,
1450 test_kind,
1451 krate: krate.name,
1452 });
Mark Simulacrum6b3413d2017-07-05 12:41:271453 }
Mark Simulacrum6b3413d2017-07-05 12:41:271454 }
1455 }
1456
Mark Simulacrum6b3413d2017-07-05 12:41:271457 fn run(self, builder: &Builder) {
Mark Simulacrum981afa52017-07-18 21:28:531458 builder.ensure(Crate {
Mark Simulacrum6b3413d2017-07-05 12:41:271459 compiler: self.compiler,
1460 target: self.target,
Collins Abitekaniza42ee6d52018-05-19 20:04:411461 mode: Mode::Rustc,
Mark Simulacrum6b3413d2017-07-05 12:41:271462 test_kind: self.test_kind,
1463 krate: self.krate,
1464 });
1465 }
1466}
1467
Mark Simulacrum528646e2017-07-14 00:48:441468#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrumf104b122018-02-11 16:51:581469pub struct CrateNotDefault {
Mark Simulacrum528646e2017-07-14 00:48:441470 compiler: Compiler,
1471 target: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:431472 test_kind: TestKind,
Mark Simulacrumf104b122018-02-11 16:51:581473 krate: &'static str,
Mark Simulacrum001e9f32017-07-05 01:41:431474}
Alex Crichtonbb9062a2016-04-29 21:23:151475
Mark Simulacrumf104b122018-02-11 16:51:581476impl Step for CrateNotDefault {
Mark Simulacrum001e9f32017-07-05 01:41:431477 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271478
Mark Simulacrum56128fb2017-07-19 00:03:381479 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumf104b122018-02-11 16:51:581480 run.path("src/liballoc_jemalloc")
1481 .path("src/librustc_asan")
1482 .path("src/librustc_lsan")
1483 .path("src/librustc_msan")
1484 .path("src/librustc_tsan")
Mark Simulacrum6b3413d2017-07-05 12:41:271485 }
1486
Mark Simulacrum6a67a052017-07-20 23:51:071487 fn make_run(run: RunConfig) {
1488 let builder = run.builder;
1489 let compiler = builder.compiler(builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:271490
Oliver Schneider37dee692018-05-16 15:18:191491 let test_kind = builder.kind.into();
Mark Simulacrumf104b122018-02-11 16:51:581492
1493 builder.ensure(CrateNotDefault {
1494 compiler,
1495 target: run.target,
1496 test_kind,
1497 krate: match run.path {
1498 _ if run.path.ends_with("src/liballoc_jemalloc") => "alloc_jemalloc",
1499 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1500 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1501 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1502 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1503 _ => panic!("unexpected path {:?}", run.path),
1504 },
1505 });
1506 }
1507
1508 fn run(self, builder: &Builder) {
1509 builder.ensure(Crate {
1510 compiler: self.compiler,
1511 target: self.target,
Collins Abitekaniza42ee6d52018-05-19 20:04:411512 mode: Mode::Std,
Mark Simulacrumf104b122018-02-11 16:51:581513 test_kind: self.test_kind,
1514 krate: INTERNER.intern_str(self.krate),
1515 });
1516 }
1517}
1518
kennytmbe9d6692018-05-05 18:33:011519#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
Mark Simulacrumf104b122018-02-11 16:51:581520pub struct Crate {
kennytmbe9d6692018-05-05 18:33:011521 pub compiler: Compiler,
1522 pub target: Interned<String>,
1523 pub mode: Mode,
1524 pub test_kind: TestKind,
1525 pub krate: Interned<String>,
Mark Simulacrumf104b122018-02-11 16:51:581526}
1527
1528impl Step for Crate {
1529 type Output = ();
1530 const DEFAULT: bool = true;
1531
1532 fn should_run(mut run: ShouldRun) -> ShouldRun {
1533 let builder = run.builder;
1534 run = run.krate("test");
1535 for krate in run.builder.in_tree_crates("std") {
Santiago Pastorinob39a1d62018-05-30 17:33:431536 if krate.is_local(&run.builder)
1537 && !krate.name.contains("jemalloc")
1538 && !(krate.name.starts_with("rustc_") && krate.name.ends_with("san"))
1539 && krate.name != "dlmalloc"
1540 {
Mark Simulacrumf104b122018-02-11 16:51:581541 run = run.path(krate.local_path(&builder).to_str().unwrap());
1542 }
1543 }
1544 run
1545 }
1546
1547 fn make_run(run: RunConfig) {
1548 let builder = run.builder;
1549 let compiler = builder.compiler(builder.top_stage, run.host);
1550
1551 let make = |mode: Mode, krate: &CargoCrate| {
Oliver Schneider37dee692018-05-16 15:18:191552 let test_kind = builder.kind.into();
Mark Simulacrum6b3413d2017-07-05 12:41:271553
Mark Simulacrum981afa52017-07-18 21:28:531554 builder.ensure(Crate {
Mark Simulacrum6a67a052017-07-20 23:51:071555 compiler,
1556 target: run.target,
Zack M. Davis1b6c9602017-08-07 05:54:091557 mode,
1558 test_kind,
Mark Simulacrumf104b122018-02-11 16:51:581559 krate: krate.name,
Mark Simulacrum6b3413d2017-07-05 12:41:271560 });
1561 };
1562
Mark Simulacrumf104b122018-02-11 16:51:581563 for krate in builder.in_tree_crates("std") {
1564 if run.path.ends_with(&krate.local_path(&builder)) {
Collins Abitekaniza42ee6d52018-05-19 20:04:411565 make(Mode::Std, krate);
Mark Simulacrum6b3413d2017-07-05 12:41:271566 }
Mark Simulacrumf104b122018-02-11 16:51:581567 }
1568 for krate in builder.in_tree_crates("test") {
1569 if run.path.ends_with(&krate.local_path(&builder)) {
Collins Abitekaniza42ee6d52018-05-19 20:04:411570 make(Mode::Test, krate);
Mark Simulacrum6b3413d2017-07-05 12:41:271571 }
Mark Simulacrum6b3413d2017-07-05 12:41:271572 }
1573 }
Alex Crichton7046fea2016-12-25 23:20:331574
Mark Simulacrumf104b122018-02-11 16:51:581575 /// Run all unit tests plus documentation tests for a given crate defined
1576 /// by a `Cargo.toml` (single manifest)
Mark Simulacrum001e9f32017-07-05 01:41:431577 ///
1578 /// This is what runs tests for crates like the standard library, compiler, etc.
1579 /// It essentially is the driver for running `cargo test`.
1580 ///
1581 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1582 /// arguments, and those arguments are discovered from `cargo metadata`.
1583 fn run(self, builder: &Builder) {
Mark Simulacrum001e9f32017-07-05 01:41:431584 let compiler = self.compiler;
1585 let target = self.target;
1586 let mode = self.mode;
1587 let test_kind = self.test_kind;
1588 let krate = self.krate;
Alex Crichtonbb9062a2016-04-29 21:23:151589
Mark Simulacrum6b3413d2017-07-05 12:41:271590 builder.ensure(compile::Test { compiler, target });
1591 builder.ensure(RemoteCopyLibs { compiler, target });
Mark Simulacrum001e9f32017-07-05 01:41:431592
1593 // If we're not doing a full bootstrap but we're testing a stage2 version of
1594 // libstd, then what we're actually testing is the libstd produced in
1595 // stage1. Reflect that here by updating the compiler that we're working
1596 // with automatically.
Mark Simulacrumbe1e7892018-04-14 23:27:571597 let compiler = if builder.force_use_stage1(compiler, target) {
Mark Simulacrum6b3413d2017-07-05 12:41:271598 builder.compiler(1, compiler.host)
Mark Simulacrum001e9f32017-07-05 01:41:431599 } else {
1600 compiler.clone()
1601 };
1602
Alex Crichton90105672017-07-17 16:32:081603 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
Mark Simulacrumf104b122018-02-11 16:51:581604 match mode {
Collins Abitekaniza42ee6d52018-05-19 20:04:411605 Mode::Std => {
Alex Crichtonbe902e72018-03-05 17:47:541606 compile::std_cargo(builder, &compiler, target, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081607 }
Collins Abitekaniza42ee6d52018-05-19 20:04:411608 Mode::Test => {
Mark Simulacrumbe1e7892018-04-14 23:27:571609 compile::test_cargo(builder, &compiler, target, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081610 }
Collins Abitekaniza42ee6d52018-05-19 20:04:411611 Mode::Rustc => {
Alex Crichton90105672017-07-17 16:32:081612 builder.ensure(compile::Rustc { compiler, target });
Mark Simulacrumbe1e7892018-04-14 23:27:571613 compile::rustc_cargo(builder, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081614 }
1615 _ => panic!("can only test libraries"),
1616 };
Alex Crichton90105672017-07-17 16:32:081617
Mark Simulacrum001e9f32017-07-05 01:41:431618 // Build up the base `cargo test` command.
1619 //
1620 // Pass in some standard flags then iterate over the graph we've discovered
1621 // in `cargo metadata` with the maps above and figure out what `-p`
1622 // arguments need to get passed.
Mark Simulacrumbe1e7892018-04-14 23:27:571623 if test_kind.subcommand() == "test" && !builder.fail_fast {
Mark Simulacrum001e9f32017-07-05 01:41:431624 cargo.arg("--no-fail-fast");
Alex Crichtonbb9062a2016-04-29 21:23:151625 }
kennytm1733f5e2018-05-05 16:04:061626 match builder.doc_tests {
kennytm05af55b2018-05-05 19:30:421627 DocTests::Only => {
kennytm1733f5e2018-05-05 16:04:061628 cargo.arg("--doc");
1629 }
kennytm05af55b2018-05-05 19:30:421630 DocTests::No => {
kennytm1733f5e2018-05-05 16:04:061631 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
1632 }
kennytm05af55b2018-05-05 19:30:421633 DocTests::Yes => {}
Guillaume Gomez8e469272018-02-17 14:45:391634 }
Mark Simulacrum001e9f32017-07-05 01:41:431635
Mark Simulacrumf104b122018-02-11 16:51:581636 cargo.arg("-p").arg(krate);
Alex Crichtonbb9062a2016-04-29 21:23:151637
Mark Simulacrum001e9f32017-07-05 01:41:431638 // The tests are going to run with the *target* libraries, so we need to
1639 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1640 //
1641 // Note that to run the compiler we need to run with the *host* libraries,
1642 // but our wrapper scripts arrange for that to be the case anyway.
1643 let mut dylib_path = dylib_path();
Mark Simulacrum528646e2017-07-14 00:48:441644 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
Mark Simulacrum001e9f32017-07-05 01:41:431645 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
Alex Crichtonbb9062a2016-04-29 21:23:151646
Mark Simulacrum001e9f32017-07-05 01:41:431647 cargo.arg("--");
Mark Simulacrumbe1e7892018-04-14 23:27:571648 cargo.args(&builder.config.cmd.test_args());
Alex Crichton0e272de2016-11-16 20:31:191649
Oliver Schneider0c1bcd32018-06-07 12:40:361650 if !builder.config.verbose_tests {
Mark Simulacrum001e9f32017-07-05 01:41:431651 cargo.arg("--quiet");
1652 }
Corey Farwellc8c6d2c2016-10-30 01:58:521653
Mark Simulacrum001e9f32017-07-05 01:41:431654 if target.contains("emscripten") {
Santiago Pastorinob39a1d62018-05-30 17:33:431655 cargo.env(
1656 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1657 builder
1658 .config
1659 .nodejs
1660 .as_ref()
1661 .expect("nodejs not configured"),
1662 );
Oliver Schneideracdf83f2017-12-06 08:25:291663 } else if target.starts_with("wasm32") {
Diggory Blake0e6601f2018-01-11 17:51:491664 // Warn about running tests without the `wasm_syscall` feature enabled.
1665 // The javascript shim implements the syscall interface so that test
1666 // output can be correctly reported.
Mark Simulacrumbe1e7892018-04-14 23:27:571667 if !builder.config.wasm_syscall {
Santiago Pastorinob39a1d62018-05-30 17:33:431668 builder.info(&format!(
1669 "Libstd was built without `wasm_syscall` feature enabled: \
1670 test output may not be visible."
1671 ));
Diggory Blake0e6601f2018-01-11 17:51:491672 }
1673
Oliver Schneideracdf83f2017-12-06 08:25:291674 // On the wasm32-unknown-unknown target we're using LTO which is
1675 // incompatible with `-C prefer-dynamic`, so disable that here
1676 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
1677
Santiago Pastorinob39a1d62018-05-30 17:33:431678 let node = builder
1679 .config
1680 .nodejs
1681 .as_ref()
Oliver Schneideracdf83f2017-12-06 08:25:291682 .expect("nodejs not configured");
Santiago Pastorinob39a1d62018-05-30 17:33:431683 let runner = format!(
1684 "{} {}/src/etc/wasm32-shim.js",
1685 node.display(),
1686 builder.src.display()
1687 );
Oliver Schneideracdf83f2017-12-06 08:25:291688 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
Mark Simulacrumbe1e7892018-04-14 23:27:571689 } else if builder.remote_tested(target) {
Santiago Pastorinob39a1d62018-05-30 17:33:431690 cargo.env(
1691 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1692 format!("{} run", builder.tool_exe(Tool::RemoteTestClient).display()),
1693 );
Mark Simulacrum001e9f32017-07-05 01:41:431694 }
Alex Crichton6fd4d672018-03-16 15:35:031695
Mark Simulacrumbe1e7892018-04-14 23:27:571696 let _folder = builder.fold_output(|| {
Santiago Pastorinob39a1d62018-05-30 17:33:431697 format!(
1698 "{}_stage{}-{}",
1699 test_kind.subcommand(),
1700 compiler.stage,
1701 krate
1702 )
Alex Crichton6fd4d672018-03-16 15:35:031703 });
Santiago Pastorinob39a1d62018-05-30 17:33:431704 builder.info(&format!(
1705 "{} {} stage{} ({} -> {})",
1706 test_kind, krate, compiler.stage, &compiler.host, target
1707 ));
Mark Simulacrumbe1e7892018-04-14 23:27:571708 let _time = util::timeit(&builder);
1709 try_run(builder, &mut cargo);
Alex Crichton39a5d3f2016-06-28 20:31:301710 }
1711}
1712
Mark Simulacrumf87696b2017-09-02 14:02:321713#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrumf104b122018-02-11 16:51:581714pub struct CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321715 host: Interned<String>,
1716 test_kind: TestKind,
1717}
1718
Mark Simulacrumf104b122018-02-11 16:51:581719impl Step for CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321720 type Output = ();
1721 const DEFAULT: bool = true;
1722 const ONLY_HOSTS: bool = true;
1723
1724 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumf104b122018-02-11 16:51:581725 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
Mark Simulacrumf87696b2017-09-02 14:02:321726 }
1727
1728 fn make_run(run: RunConfig) {
1729 let builder = run.builder;
1730
Oliver Schneider37dee692018-05-16 15:18:191731 let test_kind = builder.kind.into();
Mark Simulacrumf87696b2017-09-02 14:02:321732
Mark Simulacrumf104b122018-02-11 16:51:581733 builder.ensure(CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321734 host: run.host,
1735 test_kind,
1736 });
1737 }
1738
1739 fn run(self, builder: &Builder) {
Mark Simulacrumf87696b2017-09-02 14:02:321740 let test_kind = self.test_kind;
1741
1742 let compiler = builder.compiler(builder.top_stage, self.host);
1743 let target = compiler.host;
Mark Rousskov814e6e62018-07-21 21:54:541744 builder.ensure(compile::Rustc { compiler, target });
Mark Simulacrumf87696b2017-09-02 14:02:321745
Collins Abitekanizafb949b52018-05-27 22:09:431746 let mut cargo = tool::prepare_tool_cargo(builder,
1747 compiler,
Collins Abitekaniza36eafe52018-05-27 23:56:331748 Mode::ToolRustc,
Collins Abitekanizafb949b52018-05-27 22:09:431749 target,
1750 test_kind.subcommand(),
Tatsuyuki Ishie0989852018-07-13 05:12:581751 "src/tools/rustdoc",
Tatsuyuki Ishi62f73dc2018-07-26 03:36:581752 SourceType::InTree);
Mark Simulacrumbe1e7892018-04-14 23:27:571753 if test_kind.subcommand() == "test" && !builder.fail_fast {
Mark Simulacrumf87696b2017-09-02 14:02:321754 cargo.arg("--no-fail-fast");
1755 }
1756
1757 cargo.arg("-p").arg("rustdoc:0.0.0");
1758
1759 cargo.arg("--");
Mark Simulacrumbe1e7892018-04-14 23:27:571760 cargo.args(&builder.config.cmd.test_args());
Mark Simulacrumf87696b2017-09-02 14:02:321761
Oliver Schneider0c1bcd32018-06-07 12:40:361762 if !builder.config.verbose_tests {
Mark Simulacrumf87696b2017-09-02 14:02:321763 cargo.arg("--quiet");
1764 }
1765
Santiago Pastorinob39a1d62018-05-30 17:33:431766 let _folder = builder
1767 .fold_output(|| format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage));
1768 builder.info(&format!(
1769 "{} rustdoc stage{} ({} -> {})",
1770 test_kind, compiler.stage, &compiler.host, target
1771 ));
Mark Simulacrumbe1e7892018-04-14 23:27:571772 let _time = util::timeit(&builder);
Mark Simulacrumf87696b2017-09-02 14:02:321773
Mark Simulacrumbe1e7892018-04-14 23:27:571774 try_run(builder, &mut cargo);
Mark Simulacrumf87696b2017-09-02 14:02:321775 }
1776}
1777
Alex Crichton8e7849e2017-07-29 00:52:441778fn envify(s: &str) -> String {
Santiago Pastorinob39a1d62018-05-30 17:33:431779 s.chars()
1780 .map(|c| match c {
Alex Crichton8e7849e2017-07-29 00:52:441781 '-' => '_',
1782 c => c,
Santiago Pastorinob39a1d62018-05-30 17:33:431783 })
1784 .flat_map(|c| c.to_uppercase())
1785 .collect()
Alex Crichton39a5d3f2016-06-28 20:31:301786}
1787
Mark Simulacrumceecd622017-07-12 16:12:471788/// Some test suites are run inside emulators or on remote devices, and most
1789/// of our test binaries are linked dynamically which means we need to ship
1790/// the standard library and such to the emulator ahead of time. This step
1791/// represents this and is a dependency of all test suites.
1792///
1793/// Most of the time this is a noop. For some steps such as shipping data to
1794/// QEMU we have to build our own tools so we've got conditional dependencies
1795/// on those programs as well. Note that the remote test client is built for
1796/// the build target (us) and the server is built for the target.
Mark Simulacrum528646e2017-07-14 00:48:441797#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1798pub struct RemoteCopyLibs {
1799 compiler: Compiler,
1800 target: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:431801}
Alex Crichton1747ce22017-01-28 21:38:061802
Mark Simulacrum528646e2017-07-14 00:48:441803impl Step for RemoteCopyLibs {
Mark Simulacrum001e9f32017-07-05 01:41:431804 type Output = ();
Alex Crichton1747ce22017-01-28 21:38:061805
Mark Simulacrum56128fb2017-07-19 00:03:381806 fn should_run(run: ShouldRun) -> ShouldRun {
1807 run.never()
Mark Simulacrum681b1232017-07-14 12:30:161808 }
1809
Mark Simulacrum001e9f32017-07-05 01:41:431810 fn run(self, builder: &Builder) {
Mark Simulacrum001e9f32017-07-05 01:41:431811 let compiler = self.compiler;
1812 let target = self.target;
Mark Simulacrumbe1e7892018-04-14 23:27:571813 if !builder.remote_tested(target) {
Santiago Pastorinob39a1d62018-05-30 17:33:431814 return;
Mark Simulacrum001e9f32017-07-05 01:41:431815 }
Alex Crichton1747ce22017-01-28 21:38:061816
Mark Simulacrum6b3413d2017-07-05 12:41:271817 builder.ensure(compile::Test { compiler, target });
1818
Mark Simulacrumbe1e7892018-04-14 23:27:571819 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
1820 t!(fs::create_dir_all(builder.out.join("tmp")));
Mark Simulacrum001e9f32017-07-05 01:41:431821
Alex Crichtonef41cf02018-06-29 21:35:101822 let server = builder.ensure(tool::RemoteTestServer {
1823 compiler: compiler.with_stage(0),
1824 target,
1825 });
Mark Simulacrum001e9f32017-07-05 01:41:431826
1827 // Spawn the emulator and wait for it to come online
Mark Simulacrum6b3413d2017-07-05 12:41:271828 let tool = builder.tool_exe(Tool::RemoteTestClient);
Mark Simulacrum001e9f32017-07-05 01:41:431829 let mut cmd = Command::new(&tool);
1830 cmd.arg("spawn-emulator")
Santiago Pastorinob39a1d62018-05-30 17:33:431831 .arg(target)
1832 .arg(&server)
1833 .arg(builder.out.join("tmp"));
Mark Simulacrumbe1e7892018-04-14 23:27:571834 if let Some(rootfs) = builder.qemu_rootfs(target) {
Mark Simulacrum001e9f32017-07-05 01:41:431835 cmd.arg(rootfs);
1836 }
Mark Simulacrumbe1e7892018-04-14 23:27:571837 builder.run(&mut cmd);
Mark Simulacrum001e9f32017-07-05 01:41:431838
1839 // Push all our dylibs to the emulator
Mark Simulacrum60388302017-07-05 16:46:411840 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
Mark Simulacrum001e9f32017-07-05 01:41:431841 let f = t!(f);
1842 let name = f.file_name().into_string().unwrap();
1843 if util::is_dylib(&name) {
Santiago Pastorinob39a1d62018-05-30 17:33:431844 builder.run(Command::new(&tool).arg("push").arg(f.path()));
Mark Simulacrum001e9f32017-07-05 01:41:431845 }
Alex Crichton1747ce22017-01-28 21:38:061846 }
1847 }
1848}
1849
Mark Simulacrum528646e2017-07-14 00:48:441850#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum001e9f32017-07-05 01:41:431851pub struct Distcheck;
1852
Mark Simulacrum528646e2017-07-14 00:48:441853impl Step for Distcheck {
Mark Simulacrum001e9f32017-07-05 01:41:431854 type Output = ();
1855
Mark Simulacrum56128fb2017-07-19 00:03:381856 fn should_run(run: ShouldRun) -> ShouldRun {
1857 run.path("distcheck")
Mark Simulacrum681b1232017-07-14 12:30:161858 }
1859
Mark Simulacrum8f2e5762017-07-22 13:35:421860 fn make_run(run: RunConfig) {
1861 run.builder.ensure(Distcheck);
1862 }
1863
Mark Simulacrum001e9f32017-07-05 01:41:431864 /// Run "distcheck", a 'make check' from a tarball
1865 fn run(self, builder: &Builder) {
Mark Simulacrumbe1e7892018-04-14 23:27:571866 builder.info(&format!("Distcheck"));
1867 let dir = builder.out.join("tmp").join("distcheck");
Mark Simulacrum001e9f32017-07-05 01:41:431868 let _ = fs::remove_dir_all(&dir);
1869 t!(fs::create_dir_all(&dir));
1870
Mark Simulacrum1c118232017-07-22 16:48:291871 // Guarantee that these are built before we begin running.
1872 builder.ensure(dist::PlainSourceTarball);
1873 builder.ensure(dist::Src);
1874
Mark Simulacrum001e9f32017-07-05 01:41:431875 let mut cmd = Command::new("tar");
1876 cmd.arg("-xzf")
Santiago Pastorinob39a1d62018-05-30 17:33:431877 .arg(builder.ensure(dist::PlainSourceTarball))
1878 .arg("--strip-components=1")
1879 .current_dir(&dir);
Mark Simulacrumbe1e7892018-04-14 23:27:571880 builder.run(&mut cmd);
Santiago Pastorinob39a1d62018-05-30 17:33:431881 builder.run(
1882 Command::new("./configure")
1883 .args(&builder.config.configure_args)
1884 .arg("--enable-vendor")
1885 .current_dir(&dir),
1886 );
1887 builder.run(
1888 Command::new(build_helper::make(&builder.config.build))
1889 .arg("check")
1890 .current_dir(&dir),
1891 );
Mark Simulacrum001e9f32017-07-05 01:41:431892
1893 // Now make sure that rust-src has all of libstd's dependencies
Mark Simulacrumbe1e7892018-04-14 23:27:571894 builder.info(&format!("Distcheck rust-src"));
1895 let dir = builder.out.join("tmp").join("distcheck-src");
Mark Simulacrum001e9f32017-07-05 01:41:431896 let _ = fs::remove_dir_all(&dir);
1897 t!(fs::create_dir_all(&dir));
1898
1899 let mut cmd = Command::new("tar");
1900 cmd.arg("-xzf")
Santiago Pastorinob39a1d62018-05-30 17:33:431901 .arg(builder.ensure(dist::Src))
1902 .arg("--strip-components=1")
1903 .current_dir(&dir);
Mark Simulacrumbe1e7892018-04-14 23:27:571904 builder.run(&mut cmd);
Mark Simulacrum001e9f32017-07-05 01:41:431905
1906 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
Santiago Pastorinob39a1d62018-05-30 17:33:431907 builder.run(
1908 Command::new(&builder.initial_cargo)
1909 .arg("generate-lockfile")
1910 .arg("--manifest-path")
1911 .arg(&toml)
1912 .current_dir(&dir),
1913 );
Alex Crichtond38db822016-12-09 01:13:551914 }
Alex Crichtond38db822016-12-09 01:13:551915}
Alex Crichton1a040b32016-12-31 03:50:571916
Mark Simulacrum528646e2017-07-14 00:48:441917#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum001e9f32017-07-05 01:41:431918pub struct Bootstrap;
1919
Mark Simulacrum528646e2017-07-14 00:48:441920impl Step for Bootstrap {
Mark Simulacrum001e9f32017-07-05 01:41:431921 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271922 const DEFAULT: bool = true;
1923 const ONLY_HOSTS: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:431924
1925 /// Test the build system itself
1926 fn run(self, builder: &Builder) {
Mark Simulacrumbe1e7892018-04-14 23:27:571927 let mut cmd = Command::new(&builder.initial_cargo);
Mark Simulacrum001e9f32017-07-05 01:41:431928 cmd.arg("test")
Santiago Pastorinob39a1d62018-05-30 17:33:431929 .current_dir(builder.src.join("src/bootstrap"))
1930 .env("RUSTFLAGS", "-Cdebuginfo=2")
1931 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
1932 .env("RUSTC_BOOTSTRAP", "1")
1933 .env("RUSTC", &builder.initial_rustc);
Simon Sapine993e622018-03-23 18:55:411934 if let Some(flags) = option_env!("RUSTFLAGS") {
1935 // Use the same rustc flags for testing as for "normal" compilation,
1936 // so that Cargo doesn’t recompile the entire dependency graph every time:
1937 // https://github.com/rust-lang/rust/issues/49215
1938 cmd.env("RUSTFLAGS", flags);
1939 }
Mark Simulacrumbe1e7892018-04-14 23:27:571940 if !builder.fail_fast {
Mark Simulacrum001e9f32017-07-05 01:41:431941 cmd.arg("--no-fail-fast");
1942 }
Mark Simulacrumbe1e7892018-04-14 23:27:571943 cmd.arg("--").args(&builder.config.cmd.test_args());
Mark Simulacrumb436dca2018-06-16 17:12:151944 // rustbuild tests are racy on directory creation so just run them one at a time.
1945 // Since there's not many this shouldn't be a problem.
1946 cmd.arg("--test-threads=1");
Mark Simulacrumbe1e7892018-04-14 23:27:571947 try_run(builder, &mut cmd);
Josh Stone617aea42017-06-02 16:27:441948 }
Mark Simulacrum6b3413d2017-07-05 12:41:271949
Mark Simulacrum56128fb2017-07-19 00:03:381950 fn should_run(run: ShouldRun) -> ShouldRun {
1951 run.path("src/bootstrap")
Mark Simulacrum6b3413d2017-07-05 12:41:271952 }
1953
Mark Simulacrum6a67a052017-07-20 23:51:071954 fn make_run(run: RunConfig) {
1955 run.builder.ensure(Bootstrap);
Mark Simulacrum6b3413d2017-07-05 12:41:271956 }
Alex Crichton1a040b32016-12-31 03:50:571957}