blob: e7610976f8e35a2eee09d4470a2c3022669151a9 [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;
Mark Simulacrum5b44cbc2017-06-26 16:23:5018use std::iter;
Ulrik Sverdrupb1566ba2016-11-25 21:13:5919use std::fmt;
Mark Simulacrumdd1d75e2017-06-04 23:55:5020use std::fs::{self, File};
Alex Crichtonede89442016-04-15 01:00:3521use std::path::{PathBuf, Path};
22use std::process::Command;
Mark Simulacrumdd1d75e2017-06-04 23:55:5023use std::io::Read;
Alex Crichton73c2d2a2016-04-14 21:27:5124
kennytm2566fa22017-12-06 21:06:4825use build_helper::{self, output};
Alex Crichton126e09e2016-04-14 22:51:0326
Mark Simulacrum6a67a052017-07-20 23:51:0727use builder::{Kind, RunConfig, ShouldRun, Builder, Compiler, Step};
Mark Simulacrumf104b122018-02-11 16:51:5828use Crate as CargoCrate;
Mark Simulacrum528646e2017-07-14 00:48:4429use cache::{INTERNER, Interned};
Alex Crichton90105672017-07-17 16:32:0830use compile;
31use dist;
32use native;
33use tool::{self, Tool};
34use util::{self, dylib_path, dylib_path_var};
35use {Build, Mode};
Oliver Schneiderab018c72017-08-30 16:59:2636use toolstate::ToolState;
Alex Crichton39a5d3f2016-06-28 20:31:3037
Mark Simulacrum5b44cbc2017-06-26 16:23:5038const ADB_TEST_DIR: &str = "/data/tmp/work";
Alex Crichtondefd1b32016-03-08 07:15:5539
Ulrik Sverdrupb1566ba2016-11-25 21:13:5940/// The two modes of the test runner; tests or benchmarks.
Mark Simulacrum528646e2017-07-14 00:48:4441#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone)]
Ulrik Sverdrupb1566ba2016-11-25 21:13:5942pub enum TestKind {
43 /// Run `cargo test`
44 Test,
45 /// Run `cargo bench`
46 Bench,
47}
48
49impl TestKind {
50 // Return the cargo subcommand for this test kind
51 fn subcommand(self) -> &'static str {
52 match self {
53 TestKind::Test => "test",
54 TestKind::Bench => "bench",
55 }
56 }
57}
58
59impl fmt::Display for TestKind {
60 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
61 f.write_str(match *self {
62 TestKind::Test => "Testing",
63 TestKind::Bench => "Benchmarking",
64 })
65 }
66}
67
kennytm2566fa22017-12-06 21:06:4868fn try_run(build: &Build, cmd: &mut Command) -> bool {
Mark Simulacrum4dc8fe92017-06-27 19:37:2469 if !build.fail_fast {
kennytm2566fa22017-12-06 21:06:4870 if !build.try_run(cmd) {
Ximin Luo8f254972017-09-18 19:21:2471 let mut failures = build.delayed_failures.borrow_mut();
72 failures.push(format!("{:?}", cmd));
Oliver Schneideracdf83f2017-12-06 08:25:2973 return false;
Josh Stone617aea42017-06-02 16:27:4474 }
75 } else {
kennytm2566fa22017-12-06 21:06:4876 build.run(cmd);
Josh Stone617aea42017-06-02 16:27:4477 }
Oliver Schneideracdf83f2017-12-06 08:25:2978 true
Josh Stone617aea42017-06-02 16:27:4479}
80
kennytma9f940e2018-02-21 19:25:2381fn try_run_quiet(build: &Build, cmd: &mut Command) -> bool {
Mark Simulacrum4dc8fe92017-06-27 19:37:2482 if !build.fail_fast {
Josh Stone617aea42017-06-02 16:27:4483 if !build.try_run_quiet(cmd) {
Ximin Luo8f254972017-09-18 19:21:2484 let mut failures = build.delayed_failures.borrow_mut();
85 failures.push(format!("{:?}", cmd));
kennytma9f940e2018-02-21 19:25:2386 return false;
Josh Stone617aea42017-06-02 16:27:4487 }
88 } else {
89 build.run_quiet(cmd);
90 }
kennytma9f940e2018-02-21 19:25:2391 true
Josh Stone617aea42017-06-02 16:27:4492}
93
Mark Simulacrum528646e2017-07-14 00:48:4494#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
95pub struct Linkcheck {
96 host: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:4397}
98
Mark Simulacrum528646e2017-07-14 00:48:4499impl Step for Linkcheck {
Mark Simulacrum001e9f32017-07-05 01:41:43100 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27101 const ONLY_HOSTS: bool = true;
102 const DEFAULT: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:43103
104 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
105 ///
106 /// This tool in `src/tools` will verify the validity of all our links in the
107 /// documentation to ensure we don't have a bunch of dead ones.
108 fn run(self, builder: &Builder) {
109 let build = builder.build;
110 let host = self.host;
111
Mark Simulacrum545b92f2018-03-28 15:25:09112 build.info(&format!("Linkcheck ({})", host));
Mark Simulacrum6b3413d2017-07-05 12:41:27113
114 builder.default_doc(None);
Mark Simulacrum001e9f32017-07-05 01:41:43115
Mark Simulacrum545b92f2018-03-28 15:25:09116 let _time = util::timeit(&build);
Mark Simulacrum6b3413d2017-07-05 12:41:27117 try_run(build, builder.tool_cmd(Tool::Linkchecker)
Guillaume Gomezdec9fab2018-02-05 22:43:53118 .arg(build.out.join(host).join("doc")));
Mark Simulacrum001e9f32017-07-05 01:41:43119 }
Mark Simulacrum6b3413d2017-07-05 12:41:27120
Mark Simulacrum56128fb2017-07-19 00:03:38121 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumb05af492017-07-20 23:24:11122 let builder = run.builder;
123 run.path("src/tools/linkchecker").default_condition(builder.build.config.docs)
Mark Simulacrum6b3413d2017-07-05 12:41:27124 }
125
Mark Simulacrum6a67a052017-07-20 23:51:07126 fn make_run(run: RunConfig) {
Mark Simulacrum9ee877b2017-07-27 12:50:43127 run.builder.ensure(Linkcheck { host: run.target });
Mark Simulacrum6b3413d2017-07-05 12:41:27128 }
Alex Crichtondefd1b32016-03-08 07:15:55129}
Brian Anderson3a790ac2016-03-18 20:54:31130
Mark Simulacrum528646e2017-07-14 00:48:44131#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
132pub struct Cargotest {
Mark Simulacrum001e9f32017-07-05 01:41:43133 stage: u32,
Mark Simulacrum528646e2017-07-14 00:48:44134 host: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:43135}
Alex Crichton73c2d2a2016-04-14 21:27:51136
Mark Simulacrum528646e2017-07-14 00:48:44137impl Step for Cargotest {
Mark Simulacrum001e9f32017-07-05 01:41:43138 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27139 const ONLY_HOSTS: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:43140
Mark Simulacrum56128fb2017-07-19 00:03:38141 fn should_run(run: ShouldRun) -> ShouldRun {
142 run.path("src/tools/cargotest")
Mark Simulacrumceecd622017-07-12 16:12:47143 }
144
Mark Simulacrum6a67a052017-07-20 23:51:07145 fn make_run(run: RunConfig) {
146 run.builder.ensure(Cargotest {
147 stage: run.builder.top_stage,
Mark Simulacrum9ee877b2017-07-27 12:50:43148 host: run.target,
Mark Simulacrumceecd622017-07-12 16:12:47149 });
150 }
151
Mark Simulacrum001e9f32017-07-05 01:41:43152 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
153 ///
154 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
155 /// test` to ensure that we don't regress the test suites there.
156 fn run(self, builder: &Builder) {
157 let build = builder.build;
Mark Simulacrum60388302017-07-05 16:46:41158 let compiler = builder.compiler(self.stage, self.host);
Mark Simulacrum6b3413d2017-07-05 12:41:27159 builder.ensure(compile::Rustc { compiler, target: compiler.host });
Mark Simulacrum001e9f32017-07-05 01:41:43160
161 // Note that this is a short, cryptic, and not scoped directory name. This
162 // is currently to minimize the length of path on Windows where we otherwise
163 // quickly run into path name limit constraints.
164 let out_dir = build.out.join("ct");
165 t!(fs::create_dir_all(&out_dir));
166
Mark Simulacrum545b92f2018-03-28 15:25:09167 let _time = util::timeit(&build);
Mark Simulacrum6b3413d2017-07-05 12:41:27168 let mut cmd = builder.tool_cmd(Tool::CargoTest);
Mark Simulacrum001e9f32017-07-05 01:41:43169 try_run(build, cmd.arg(&build.initial_cargo)
170 .arg(&out_dir)
Mark Simulacrumc114fe52017-07-05 17:21:33171 .env("RUSTC", builder.rustc(compiler))
Mark Simulacrumfacf5a92017-08-04 22:13:01172 .env("RUSTDOC", builder.rustdoc(compiler.host)));
Mark Simulacrum001e9f32017-07-05 01:41:43173 }
Alex Crichton009f45f2017-04-18 00:24:05174}
175
Mark Simulacrum528646e2017-07-14 00:48:44176#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
177pub struct Cargo {
Mark Simulacrum001e9f32017-07-05 01:41:43178 stage: u32,
Mark Simulacrum528646e2017-07-14 00:48:44179 host: Interned<String>,
Nick Cameron04415dc2017-06-30 18:58:54180}
181
Mark Simulacrum528646e2017-07-14 00:48:44182impl Step for Cargo {
Mark Simulacrum001e9f32017-07-05 01:41:43183 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27184 const ONLY_HOSTS: bool = true;
185
Mark Simulacrum56128fb2017-07-19 00:03:38186 fn should_run(run: ShouldRun) -> ShouldRun {
187 run.path("src/tools/cargo")
Mark Simulacrum6b3413d2017-07-05 12:41:27188 }
189
Mark Simulacrum6a67a052017-07-20 23:51:07190 fn make_run(run: RunConfig) {
191 run.builder.ensure(Cargo {
192 stage: run.builder.top_stage,
193 host: run.target,
Mark Simulacrum6b3413d2017-07-05 12:41:27194 });
195 }
Nick Cameron04415dc2017-06-30 18:58:54196
Mark Simulacrum001e9f32017-07-05 01:41:43197 /// Runs `cargo test` for `cargo` packaged with Rust.
198 fn run(self, builder: &Builder) {
199 let build = builder.build;
Mark Simulacrum6b3413d2017-07-05 12:41:27200 let compiler = builder.compiler(self.stage, self.host);
Nick Cameron04415dc2017-06-30 18:58:54201
Mark Simulacrumfe0eca02017-07-23 01:29:08202 builder.ensure(tool::Cargo { compiler, target: self.host });
Mark Simulacrumc114fe52017-07-05 17:21:33203 let mut cargo = builder.cargo(compiler, Mode::Tool, self.host, "test");
Mark Simulacrum001e9f32017-07-05 01:41:43204 cargo.arg("--manifest-path").arg(build.src.join("src/tools/cargo/Cargo.toml"));
205 if !build.fail_fast {
206 cargo.arg("--no-fail-fast");
207 }
Nick Cameron04415dc2017-06-30 18:58:54208
Mark Simulacrum001e9f32017-07-05 01:41:43209 // Don't build tests dynamically, just a pain to work with
210 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
211
212 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
213 // available.
214 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
215
Mark Simulacrumdec44b02017-07-17 15:52:05216 try_run(build, cargo.env("PATH", &path_for_cargo(builder, compiler)));
Mark Simulacrum001e9f32017-07-05 01:41:43217 }
218}
219
Mark Simulacrumdec44b02017-07-17 15:52:05220#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
221pub struct Rls {
Mark Simulacrum001e9f32017-07-05 01:41:43222 stage: u32,
Mark Simulacrumdec44b02017-07-17 15:52:05223 host: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:43224}
225
Mark Simulacrumdec44b02017-07-17 15:52:05226impl Step for Rls {
Mark Simulacrum001e9f32017-07-05 01:41:43227 type Output = ();
Mark Simulacrumdec44b02017-07-17 15:52:05228 const ONLY_HOSTS: bool = true;
229
Mark Simulacrum56128fb2017-07-19 00:03:38230 fn should_run(run: ShouldRun) -> ShouldRun {
231 run.path("src/tools/rls")
Mark Simulacrumdec44b02017-07-17 15:52:05232 }
233
Mark Simulacrum6a67a052017-07-20 23:51:07234 fn make_run(run: RunConfig) {
235 run.builder.ensure(Rls {
236 stage: run.builder.top_stage,
237 host: run.target,
Mark Simulacrumdec44b02017-07-17 15:52:05238 });
239 }
Mark Simulacrum001e9f32017-07-05 01:41:43240
241 /// Runs `cargo test` for the rls.
242 fn run(self, builder: &Builder) {
243 let build = builder.build;
244 let stage = self.stage;
245 let host = self.host;
Mark Simulacrumdec44b02017-07-17 15:52:05246 let compiler = builder.compiler(stage, host);
Mark Simulacrum001e9f32017-07-05 01:41:43247
Oliver Schneider02ac15c2018-02-09 17:53:41248 builder.ensure(tool::Rls { compiler, target: self.host, extra_features: Vec::new() });
Oliver Schneideracdf83f2017-12-06 08:25:29249 let mut cargo = tool::prepare_tool_cargo(builder,
250 compiler,
251 host,
252 "test",
253 "src/tools/rls");
Mark Simulacrum001e9f32017-07-05 01:41:43254
255 // Don't build tests dynamically, just a pain to work with
256 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
257
Mark Simulacrumdec44b02017-07-17 15:52:05258 builder.add_rustc_lib_path(compiler, &mut cargo);
Mark Simulacrum001e9f32017-07-05 01:41:43259
kennytm2566fa22017-12-06 21:06:48260 if try_run(build, &mut cargo) {
kennytm44954ab2017-12-21 17:16:21261 build.save_toolstate("rls", ToolState::TestPass);
Oliver Schneideracdf83f2017-12-06 08:25:29262 }
Mark Simulacrum001e9f32017-07-05 01:41:43263 }
Nick Cameron04415dc2017-06-30 18:58:54264}
265
Nick Camerond0070e82017-09-01 06:43:00266#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
267pub struct Rustfmt {
268 stage: u32,
269 host: Interned<String>,
270}
271
272impl Step for Rustfmt {
273 type Output = ();
274 const ONLY_HOSTS: bool = true;
275
276 fn should_run(run: ShouldRun) -> ShouldRun {
277 run.path("src/tools/rustfmt")
278 }
279
280 fn make_run(run: RunConfig) {
281 run.builder.ensure(Rustfmt {
282 stage: run.builder.top_stage,
283 host: run.target,
284 });
285 }
286
287 /// Runs `cargo test` for rustfmt.
288 fn run(self, builder: &Builder) {
289 let build = builder.build;
290 let stage = self.stage;
291 let host = self.host;
292 let compiler = builder.compiler(stage, host);
293
Oliver Schneider02ac15c2018-02-09 17:53:41294 builder.ensure(tool::Rustfmt { compiler, target: self.host, extra_features: Vec::new() });
Oliver Schneideracdf83f2017-12-06 08:25:29295 let mut cargo = tool::prepare_tool_cargo(builder,
296 compiler,
297 host,
298 "test",
299 "src/tools/rustfmt");
Nick Camerond0070e82017-09-01 06:43:00300
301 // Don't build tests dynamically, just a pain to work with
302 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
303
304 builder.add_rustc_lib_path(compiler, &mut cargo);
305
kennytm2566fa22017-12-06 21:06:48306 if try_run(build, &mut cargo) {
kennytm44954ab2017-12-21 17:16:21307 build.save_toolstate("rustfmt", ToolState::TestPass);
Oliver Schneideracdf83f2017-12-06 08:25:29308 }
Nick Camerond0070e82017-09-01 06:43:00309 }
310}
Oliver Schneider01555b12017-09-17 19:45:54311
312#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Oliver Schneiderf3817442017-08-28 14:54:50313pub struct Miri {
Oliver Schneideracdf83f2017-12-06 08:25:29314 stage: u32,
Oliver Schneiderf3817442017-08-28 14:54:50315 host: Interned<String>,
316}
317
318impl Step for Miri {
319 type Output = ();
320 const ONLY_HOSTS: bool = true;
321 const DEFAULT: bool = true;
322
323 fn should_run(run: ShouldRun) -> ShouldRun {
324 let test_miri = run.builder.build.config.test_miri;
325 run.path("src/tools/miri").default_condition(test_miri)
326 }
327
328 fn make_run(run: RunConfig) {
329 run.builder.ensure(Miri {
Oliver Schneideracdf83f2017-12-06 08:25:29330 stage: run.builder.top_stage,
Oliver Schneiderf3817442017-08-28 14:54:50331 host: run.target,
332 });
333 }
334
335 /// Runs `cargo test` for miri.
336 fn run(self, builder: &Builder) {
337 let build = builder.build;
Oliver Schneideracdf83f2017-12-06 08:25:29338 let stage = self.stage;
Oliver Schneiderf3817442017-08-28 14:54:50339 let host = self.host;
Oliver Schneideracdf83f2017-12-06 08:25:29340 let compiler = builder.compiler(stage, host);
Oliver Schneiderf3817442017-08-28 14:54:50341
Oliver Schneider02ac15c2018-02-09 17:53:41342 let miri = builder.ensure(tool::Miri {
343 compiler,
344 target: self.host,
345 extra_features: Vec::new(),
346 });
347 if let Some(miri) = miri {
Oliver Schneideracdf83f2017-12-06 08:25:29348 let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
349 cargo.arg("--manifest-path").arg(build.src.join("src/tools/miri/Cargo.toml"));
Oliver Schneiderf3817442017-08-28 14:54:50350
Oliver Schneideracdf83f2017-12-06 08:25:29351 // Don't build tests dynamically, just a pain to work with
352 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
353 // miri tests need to know about the stage sysroot
354 cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
355 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
356 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
357 cargo.env("MIRI_PATH", miri);
Oliver Schneiderf3817442017-08-28 14:54:50358
Oliver Schneideracdf83f2017-12-06 08:25:29359 builder.add_rustc_lib_path(compiler, &mut cargo);
Oliver Schneiderf3817442017-08-28 14:54:50360
kennytm2566fa22017-12-06 21:06:48361 if try_run(build, &mut cargo) {
kennytm44954ab2017-12-21 17:16:21362 build.save_toolstate("miri", ToolState::TestPass);
Oliver Schneideracdf83f2017-12-06 08:25:29363 }
364 } else {
365 eprintln!("failed to test miri: could not build");
366 }
Oliver Schneiderf3817442017-08-28 14:54:50367 }
368}
369
Oliver Schneiderd64a0672017-09-18 11:13:57370#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
371pub struct Clippy {
Oliver Schneideracdf83f2017-12-06 08:25:29372 stage: u32,
Oliver Schneiderd64a0672017-09-18 11:13:57373 host: Interned<String>,
374}
375
376impl Step for Clippy {
377 type Output = ();
378 const ONLY_HOSTS: bool = true;
379 const DEFAULT: bool = false;
380
381 fn should_run(run: ShouldRun) -> ShouldRun {
382 run.path("src/tools/clippy")
383 }
384
385 fn make_run(run: RunConfig) {
386 run.builder.ensure(Clippy {
Oliver Schneideracdf83f2017-12-06 08:25:29387 stage: run.builder.top_stage,
Oliver Schneiderd64a0672017-09-18 11:13:57388 host: run.target,
389 });
390 }
391
392 /// Runs `cargo test` for clippy.
393 fn run(self, builder: &Builder) {
394 let build = builder.build;
Oliver Schneideracdf83f2017-12-06 08:25:29395 let stage = self.stage;
Oliver Schneiderd64a0672017-09-18 11:13:57396 let host = self.host;
Oliver Schneideracdf83f2017-12-06 08:25:29397 let compiler = builder.compiler(stage, host);
Oliver Schneiderd64a0672017-09-18 11:13:57398
Oliver Schneider02ac15c2018-02-09 17:53:41399 let clippy = builder.ensure(tool::Clippy {
400 compiler,
401 target: self.host,
402 extra_features: Vec::new(),
403 });
404 if let Some(clippy) = clippy {
Oliver Schneideracdf83f2017-12-06 08:25:29405 let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
406 cargo.arg("--manifest-path").arg(build.src.join("src/tools/clippy/Cargo.toml"));
Oliver Schneiderd64a0672017-09-18 11:13:57407
Oliver Schneideracdf83f2017-12-06 08:25:29408 // Don't build tests dynamically, just a pain to work with
409 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
410 // clippy tests need to know about the stage sysroot
411 cargo.env("SYSROOT", builder.sysroot(compiler));
412 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
413 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
414 let host_libs = builder.stage_out(compiler, Mode::Tool).join(builder.cargo_dir());
415 cargo.env("HOST_LIBS", host_libs);
416 // clippy tests need to find the driver
417 cargo.env("CLIPPY_DRIVER_PATH", clippy);
Oliver Schneiderd64a0672017-09-18 11:13:57418
Oliver Schneideracdf83f2017-12-06 08:25:29419 builder.add_rustc_lib_path(compiler, &mut cargo);
Oliver Schneiderd64a0672017-09-18 11:13:57420
kennytm2566fa22017-12-06 21:06:48421 if try_run(build, &mut cargo) {
kennytm44954ab2017-12-21 17:16:21422 build.save_toolstate("clippy-driver", ToolState::TestPass);
Oliver Schneideracdf83f2017-12-06 08:25:29423 }
424 } else {
425 eprintln!("failed to test clippy: could not build");
426 }
Oliver Schneiderd64a0672017-09-18 11:13:57427 }
428}
Nick Camerond0070e82017-09-01 06:43:00429
Mark Simulacrumdec44b02017-07-17 15:52:05430fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
Nick Cameron04415dc2017-06-30 18:58:54431 // Configure PATH to find the right rustc. NB. we have to use PATH
432 // and not RUSTC because the Cargo test suite has tests that will
433 // fail if rustc is not spelled `rustc`.
Mark Simulacrumdec44b02017-07-17 15:52:05434 let path = builder.sysroot(compiler).join("bin");
Nick Cameron04415dc2017-06-30 18:58:54435 let old_path = env::var_os("PATH").unwrap_or_default();
436 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
Brian Anderson3a790ac2016-03-18 20:54:31437}
Alex Crichton9dd3c542016-03-29 20:14:52438
Guillaume Gomezf18c52b2017-12-12 22:53:24439#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
Guillaume Gomez51580d42018-01-25 23:44:52440pub struct RustdocTheme {
441 pub compiler: Compiler,
Guillaume Gomez51580d42018-01-25 23:44:52442}
443
444impl Step for RustdocTheme {
445 type Output = ();
446 const DEFAULT: bool = true;
447 const ONLY_HOSTS: bool = true;
448
449 fn should_run(run: ShouldRun) -> ShouldRun {
450 run.path("src/tools/rustdoc-themes")
451 }
452
453 fn make_run(run: RunConfig) {
454 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
455
456 run.builder.ensure(RustdocTheme {
457 compiler: compiler,
Guillaume Gomez51580d42018-01-25 23:44:52458 });
459 }
460
461 fn run(self, builder: &Builder) {
Chris Coulson6f101462018-04-12 14:01:49462 let rustdoc = builder.out.join("bootstrap/debug/rustdoc");
Guillaume Gomezdec9fab2018-02-05 22:43:53463 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
464 cmd.arg(rustdoc.to_str().unwrap())
465 .arg(builder.src.join("src/librustdoc/html/static/themes").to_str().unwrap())
466 .env("RUSTC_STAGE", self.compiler.stage.to_string())
Guillaume Gomez51580d42018-01-25 23:44:52467 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
468 .env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
469 .env("CFG_RELEASE_CHANNEL", &builder.build.config.channel)
Guillaume Gomezdec9fab2018-02-05 22:43:53470 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler.host))
Guillaume Gomez51580d42018-01-25 23:44:52471 .env("RUSTDOC_CRATE_VERSION", builder.build.rust_version())
472 .env("RUSTC_BOOTSTRAP", "1");
Guillaume Gomezdec9fab2018-02-05 22:43:53473 if let Some(linker) = builder.build.linker(self.compiler.host) {
Guillaume Gomez51580d42018-01-25 23:44:52474 cmd.env("RUSTC_TARGET_LINKER", linker);
475 }
Guillaume Gomezdec9fab2018-02-05 22:43:53476 try_run(builder.build, &mut cmd);
Guillaume Gomez51580d42018-01-25 23:44:52477 }
478}
479
480#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
Guillaume Gomezf18c52b2017-12-12 22:53:24481pub struct RustdocJS {
482 pub host: Interned<String>,
Guillaume Gomez69521992018-01-12 22:40:00483 pub target: Interned<String>,
Guillaume Gomezf18c52b2017-12-12 22:53:24484}
485
486impl Step for RustdocJS {
Guillaume Gomez50bb6ba2018-01-08 22:43:20487 type Output = ();
Guillaume Gomezf18c52b2017-12-12 22:53:24488 const DEFAULT: bool = true;
489 const ONLY_HOSTS: bool = true;
490
491 fn should_run(run: ShouldRun) -> ShouldRun {
Guillaume Gomez69521992018-01-12 22:40:00492 run.path("src/test/rustdoc-js")
Guillaume Gomezf18c52b2017-12-12 22:53:24493 }
494
495 fn make_run(run: RunConfig) {
496 run.builder.ensure(RustdocJS {
497 host: run.host,
Guillaume Gomez69521992018-01-12 22:40:00498 target: run.target,
Guillaume Gomezf18c52b2017-12-12 22:53:24499 });
500 }
501
Guillaume Gomez50bb6ba2018-01-08 22:43:20502 fn run(self, builder: &Builder) {
Guillaume Gomez026c7492018-01-13 21:35:41503 if let Some(ref nodejs) = builder.config.nodejs {
504 let mut command = Command::new(nodejs);
505 command.args(&["src/tools/rustdoc-js/tester.js", &*self.host]);
506 builder.ensure(::doc::Std {
507 target: self.target,
508 stage: builder.top_stage,
509 });
510 builder.run(&mut command);
511 } else {
Mark Simulacrum545b92f2018-03-28 15:25:09512 builder.info(&format!("No nodejs found, skipping \"src/test/rustdoc-js\" tests"));
Guillaume Gomez026c7492018-01-13 21:35:41513 }
Guillaume Gomezf18c52b2017-12-12 22:53:24514 }
515}
516
Guillaume Gomez035ec5b2018-03-31 12:49:56517#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
518pub struct RustdocUi {
519 pub host: Interned<String>,
520 pub target: Interned<String>,
521 pub compiler: Compiler,
522}
523
524impl Step for RustdocUi {
525 type Output = ();
526 const DEFAULT: bool = true;
527 const ONLY_HOSTS: bool = true;
528
529 fn should_run(run: ShouldRun) -> ShouldRun {
530 run.path("src/test/rustdoc-ui")
531 }
532
533 fn make_run(run: RunConfig) {
534 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
535 run.builder.ensure(RustdocUi {
536 host: run.host,
537 target: run.target,
538 compiler,
539 });
540 }
541
542 fn run(self, builder: &Builder) {
543 builder.ensure(Compiletest {
544 compiler: self.compiler,
545 target: self.target,
546 mode: "ui",
547 suite: "rustdoc-ui",
548 })
549 }
550}
551
Mark Simulacrum528646e2017-07-14 00:48:44552#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum1c8f3b02018-02-11 22:41:06553pub struct Tidy;
Mark Simulacrum001e9f32017-07-05 01:41:43554
Mark Simulacrum528646e2017-07-14 00:48:44555impl Step for Tidy {
Mark Simulacrum001e9f32017-07-05 01:41:43556 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27557 const DEFAULT: bool = true;
558 const ONLY_HOSTS: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:43559
Mark Simulacrum1c8f3b02018-02-11 22:41:06560 /// Runs the `tidy` tool.
Mark Simulacrum001e9f32017-07-05 01:41:43561 ///
562 /// This tool in `src/tools` checks up on various bits and pieces of style and
563 /// otherwise just implements a few lint-like checks that are specific to the
564 /// compiler itself.
565 fn run(self, builder: &Builder) {
566 let build = builder.build;
Mark Simulacrum001e9f32017-07-05 01:41:43567
Mark Simulacrum60388302017-07-05 16:46:41568 let mut cmd = builder.tool_cmd(Tool::Tidy);
Mark Simulacrum001e9f32017-07-05 01:41:43569 cmd.arg(build.src.join("src"));
Mark Mansib9b1c372018-02-26 17:05:43570 cmd.arg(&build.initial_cargo);
Mark Simulacrum001e9f32017-07-05 01:41:43571 if !build.config.vendor {
572 cmd.arg("--no-vendor");
573 }
574 if build.config.quiet_tests {
575 cmd.arg("--quiet");
576 }
Alex Crichton6fd4d672018-03-16 15:35:03577
578 let _folder = build.fold_output(|| "tidy");
Mark Simulacrum545b92f2018-03-28 15:25:09579 builder.info(&format!("tidy check"));
Mark Simulacrum001e9f32017-07-05 01:41:43580 try_run(build, &mut cmd);
Eduard-Mihai Burtescud29f0bc2017-02-10 20:59:40581 }
Mark Simulacrum6b3413d2017-07-05 12:41:27582
Mark Simulacrum56128fb2017-07-19 00:03:38583 fn should_run(run: ShouldRun) -> ShouldRun {
584 run.path("src/tools/tidy")
Mark Simulacrum6b3413d2017-07-05 12:41:27585 }
586
Mark Simulacrum6a67a052017-07-20 23:51:07587 fn make_run(run: RunConfig) {
Mark Simulacrum1c8f3b02018-02-11 22:41:06588 run.builder.ensure(Tidy);
Mark Simulacrum6b3413d2017-07-05 12:41:27589 }
Alex Crichton9dd3c542016-03-29 20:14:52590}
Alex Crichtonb325baf2016-04-05 18:34:23591
Mark Simulacrum528646e2017-07-14 00:48:44592fn testdir(build: &Build, host: Interned<String>) -> PathBuf {
Alex Crichtonb325baf2016-04-05 18:34:23593 build.out.join(host).join("test")
594}
595
Mark Simulacrumf104b122018-02-11 16:51:58596macro_rules! default_test {
597 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
598 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
599 }
Mark Simulacrum1ab89302017-07-07 17:51:57600}
601
Mark Simulacrumf104b122018-02-11 16:51:58602macro_rules! host_test {
603 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
604 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
605 }
606}
Mark Simulacrum6b3413d2017-07-05 12:41:27607
Mark Simulacrumf104b122018-02-11 16:51:58608macro_rules! test {
609 ($name:ident {
610 path: $path:expr,
611 mode: $mode:expr,
612 suite: $suite:expr,
613 default: $default:expr,
614 host: $host:expr
615 }) => {
616 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
617 pub struct $name {
618 pub compiler: Compiler,
619 pub target: Interned<String>,
620 }
621
622 impl Step for $name {
623 type Output = ();
624 const DEFAULT: bool = $default;
625 const ONLY_HOSTS: bool = $host;
626
627 fn should_run(run: ShouldRun) -> ShouldRun {
628 run.path($path)
629 }
630
631 fn make_run(run: RunConfig) {
632 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
633
634 run.builder.ensure($name {
635 compiler,
636 target: run.target,
637 });
638 }
639
640 fn run(self, builder: &Builder) {
641 builder.ensure(Compiletest {
642 compiler: self.compiler,
643 target: self.target,
644 mode: $mode,
645 suite: $suite,
646 })
647 }
648 }
649 }
650}
651
652default_test!(Ui {
653 path: "src/test/ui",
654 mode: "ui",
655 suite: "ui"
656});
657
658default_test!(RunPass {
659 path: "src/test/run-pass",
660 mode: "run-pass",
661 suite: "run-pass"
662});
663
664default_test!(CompileFail {
665 path: "src/test/compile-fail",
666 mode: "compile-fail",
667 suite: "compile-fail"
668});
669
670default_test!(ParseFail {
671 path: "src/test/parse-fail",
672 mode: "parse-fail",
673 suite: "parse-fail"
674});
675
676default_test!(RunFail {
677 path: "src/test/run-fail",
678 mode: "run-fail",
679 suite: "run-fail"
680});
681
682default_test!(RunPassValgrind {
683 path: "src/test/run-pass-valgrind",
684 mode: "run-pass-valgrind",
685 suite: "run-pass-valgrind"
686});
687
688default_test!(MirOpt {
689 path: "src/test/mir-opt",
690 mode: "mir-opt",
691 suite: "mir-opt"
692});
693
694default_test!(Codegen {
695 path: "src/test/codegen",
696 mode: "codegen",
697 suite: "codegen"
698});
699
700default_test!(CodegenUnits {
701 path: "src/test/codegen-units",
702 mode: "codegen-units",
703 suite: "codegen-units"
704});
705
706default_test!(Incremental {
707 path: "src/test/incremental",
708 mode: "incremental",
709 suite: "incremental"
710});
711
712default_test!(Debuginfo {
713 path: "src/test/debuginfo",
Mark Simulacrumaa8b93b2017-07-07 18:31:29714 // What this runs varies depending on the native platform being apple
Mark Simulacrumf104b122018-02-11 16:51:58715 mode: "debuginfo-XXX",
716 suite: "debuginfo"
717});
Mark Simulacrum6b3413d2017-07-05 12:41:27718
Mark Simulacrumf104b122018-02-11 16:51:58719host_test!(UiFullDeps {
720 path: "src/test/ui-fulldeps",
721 mode: "ui",
722 suite: "ui-fulldeps"
723});
Mark Simulacrumf1d04a32017-07-20 15:42:18724
Mark Simulacrumf104b122018-02-11 16:51:58725host_test!(RunPassFullDeps {
726 path: "src/test/run-pass-fulldeps",
727 mode: "run-pass",
728 suite: "run-pass-fulldeps"
729});
Mark Simulacrumf1d04a32017-07-20 15:42:18730
Mark Simulacrumf104b122018-02-11 16:51:58731host_test!(RunFailFullDeps {
732 path: "src/test/run-fail-fulldeps",
733 mode: "run-fail",
734 suite: "run-fail-fulldeps"
735});
Mark Simulacrumf1d04a32017-07-20 15:42:18736
Mark Simulacrumf104b122018-02-11 16:51:58737host_test!(CompileFailFullDeps {
738 path: "src/test/compile-fail-fulldeps",
739 mode: "compile-fail",
740 suite: "compile-fail-fulldeps"
741});
Mark Simulacrumf1d04a32017-07-20 15:42:18742
Mark Simulacrumf104b122018-02-11 16:51:58743host_test!(IncrementalFullDeps {
744 path: "src/test/incremental-fulldeps",
745 mode: "incremental",
746 suite: "incremental-fulldeps"
747});
Mark Simulacrumf1d04a32017-07-20 15:42:18748
Mark Simulacrumf104b122018-02-11 16:51:58749host_test!(Rustdoc {
750 path: "src/test/rustdoc",
751 mode: "rustdoc",
752 suite: "rustdoc"
753});
Mark Simulacrumf1d04a32017-07-20 15:42:18754
Mark Simulacrumf104b122018-02-11 16:51:58755test!(Pretty {
756 path: "src/test/pretty",
757 mode: "pretty",
758 suite: "pretty",
759 default: false,
760 host: true
761});
762test!(RunPassPretty {
763 path: "src/test/run-pass/pretty",
764 mode: "pretty",
765 suite: "run-pass",
766 default: false,
767 host: true
768});
769test!(RunFailPretty {
770 path: "src/test/run-fail/pretty",
771 mode: "pretty",
772 suite: "run-fail",
773 default: false,
774 host: true
775});
776test!(RunPassValgrindPretty {
777 path: "src/test/run-pass-valgrind/pretty",
778 mode: "pretty",
779 suite: "run-pass-valgrind",
780 default: false,
781 host: true
782});
783test!(RunPassFullDepsPretty {
784 path: "src/test/run-pass-fulldeps/pretty",
785 mode: "pretty",
786 suite: "run-pass-fulldeps",
787 default: false,
788 host: true
789});
790test!(RunFailFullDepsPretty {
791 path: "src/test/run-fail-fulldeps/pretty",
792 mode: "pretty",
793 suite: "run-fail-fulldeps",
794 default: false,
795 host: true
796});
Mark Simulacrumf1d04a32017-07-20 15:42:18797
Alex Crichton7df6f412018-03-09 17:26:15798default_test!(RunMake {
Mark Simulacrumf104b122018-02-11 16:51:58799 path: "src/test/run-make",
800 mode: "run-make",
801 suite: "run-make"
802});
Mark Simulacrumf1d04a32017-07-20 15:42:18803
Alex Crichton7df6f412018-03-09 17:26:15804host_test!(RunMakeFullDeps {
805 path: "src/test/run-make-fulldeps",
806 mode: "run-make",
807 suite: "run-make-fulldeps"
808});
809
Mark Simulacrumf1d04a32017-07-20 15:42:18810#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
811struct Compiletest {
812 compiler: Compiler,
813 target: Interned<String>,
814 mode: &'static str,
815 suite: &'static str,
816}
817
818impl Step for Compiletest {
819 type Output = ();
820
821 fn should_run(run: ShouldRun) -> ShouldRun {
822 run.never()
823 }
824
Mark Simulacrum001e9f32017-07-05 01:41:43825 /// Executes the `compiletest` tool to run a suite of tests.
826 ///
827 /// Compiles all tests with `compiler` for `target` with the specified
828 /// compiletest `mode` and `suite` arguments. For example `mode` can be
829 /// "run-pass" or `suite` can be something like `debuginfo`.
830 fn run(self, builder: &Builder) {
831 let build = builder.build;
832 let compiler = self.compiler;
833 let target = self.target;
834 let mode = self.mode;
835 let suite = self.suite;
Mark Simulacrum6b3413d2017-07-05 12:41:27836
837 // Skip codegen tests if they aren't enabled in configuration.
838 if !build.config.codegen_tests && suite == "codegen" {
839 return;
840 }
841
842 if suite == "debuginfo" {
Mark Simulacrum951616c2017-07-20 17:23:29843 // Skip debuginfo tests on MSVC
844 if build.build.contains("msvc") {
845 return;
846 }
847
Mark Simulacrum6b3413d2017-07-05 12:41:27848 if mode == "debuginfo-XXX" {
849 return if build.build.contains("apple") {
850 builder.ensure(Compiletest {
851 mode: "debuginfo-lldb",
852 ..self
Mark Simulacrum528646e2017-07-14 00:48:44853 });
Mark Simulacrum6b3413d2017-07-05 12:41:27854 } else {
855 builder.ensure(Compiletest {
856 mode: "debuginfo-gdb",
857 ..self
Mark Simulacrum528646e2017-07-14 00:48:44858 });
Mark Simulacrum6b3413d2017-07-05 12:41:27859 };
860 }
861
Mark Simulacrum6b3413d2017-07-05 12:41:27862 builder.ensure(dist::DebuggerScripts {
Mark Simulacrum528646e2017-07-14 00:48:44863 sysroot: builder.sysroot(compiler),
Mark Simulacrumfef9b482017-07-23 16:03:40864 host: target
Mark Simulacrum6b3413d2017-07-05 12:41:27865 });
866 }
867
868 if suite.ends_with("fulldeps") ||
869 // FIXME: Does pretty need librustc compiled? Note that there are
870 // fulldeps test suites with mode = pretty as well.
871 mode == "pretty" ||
Alex Crichton7df6f412018-03-09 17:26:15872 mode == "rustdoc" {
Mark Simulacrum6b3413d2017-07-05 12:41:27873 builder.ensure(compile::Rustc { compiler, target });
874 }
875
876 builder.ensure(compile::Test { compiler, target });
877 builder.ensure(native::TestHelpers { target });
Mark Simulacrumaa8b93b2017-07-07 18:31:29878 builder.ensure(RemoteCopyLibs { compiler, target });
Mark Simulacrum6b3413d2017-07-05 12:41:27879
Mark Simulacrum6b3413d2017-07-05 12:41:27880 let mut cmd = builder.tool_cmd(Tool::Compiletest);
Alex Crichtonb325baf2016-04-05 18:34:23881
Mark Simulacrum001e9f32017-07-05 01:41:43882 // compiletest currently has... a lot of arguments, so let's just pass all
883 // of them!
Brian Anderson8401e372016-09-15 19:42:26884
Mark Simulacrumc114fe52017-07-05 17:21:33885 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
Mark Simulacrum60388302017-07-05 16:46:41886 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
Mark Simulacrumc114fe52017-07-05 17:21:33887 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
Mark Simulacrum4e5333c2017-07-25 22:54:33888
889 // Avoid depending on rustdoc when we don't need it.
Alex Crichton7df6f412018-03-09 17:26:15890 if mode == "rustdoc" || (mode == "run-make" && suite.ends_with("fulldeps")) {
Mark Simulacrumfacf5a92017-08-04 22:13:01891 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host));
Mark Simulacrum4e5333c2017-07-25 22:54:33892 }
893
Mark Simulacrum001e9f32017-07-05 01:41:43894 cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
895 cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
896 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
897 cmd.arg("--mode").arg(mode);
898 cmd.arg("--target").arg(target);
Mark Simulacrum528646e2017-07-14 00:48:44899 cmd.arg("--host").arg(&*compiler.host);
900 cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(build.build));
Alex Crichtonf4e4ec72016-05-13 22:26:41901
Mark Simulacrum001e9f32017-07-05 01:41:43902 if let Some(ref nodejs) = build.config.nodejs {
903 cmd.arg("--nodejs").arg(nodejs);
904 }
Alex Crichtonf4e4ec72016-05-13 22:26:41905
Mark Simulacrum001e9f32017-07-05 01:41:43906 let mut flags = vec!["-Crpath".to_string()];
907 if build.config.rust_optimize_tests {
908 flags.push("-O".to_string());
909 }
910 if build.config.rust_debuginfo_tests {
911 flags.push("-g".to_string());
912 }
Fabio B35087fc2018-04-13 07:43:10913 flags.push("-Zunstable-options".to_string());
Santiago Pastorinodb41f1e2018-01-18 22:44:41914 flags.push(build.config.cmd.rustc_args().join(" "));
Alex Crichtoncbe62922016-04-19 16:44:19915
Oliver Schneideracdf83f2017-12-06 08:25:29916 if let Some(linker) = build.linker(target) {
917 cmd.arg("--linker").arg(linker);
918 }
919
920 let hostflags = flags.clone();
Mark Simulacrum001e9f32017-07-05 01:41:43921 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
Alex Crichtoncbe62922016-04-19 16:44:19922
Oliver Schneideracdf83f2017-12-06 08:25:29923 let mut targetflags = flags.clone();
Mark Simulacrum001e9f32017-07-05 01:41:43924 targetflags.push(format!("-Lnative={}",
925 build.test_helpers_out(target).display()));
926 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
Alex Crichtonb325baf2016-04-05 18:34:23927
Mark Simulacrum001e9f32017-07-05 01:41:43928 cmd.arg("--docck-python").arg(build.python());
Alex Crichtonb325baf2016-04-05 18:34:23929
Mark Simulacrum001e9f32017-07-05 01:41:43930 if build.build.ends_with("apple-darwin") {
931 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
932 // LLDB plugin's compiled module which only works with the system python
933 // (namely not Homebrew-installed python)
934 cmd.arg("--lldb-python").arg("/usr/bin/python");
935 } else {
936 cmd.arg("--lldb-python").arg(build.python());
937 }
Alex Crichtonb325baf2016-04-05 18:34:23938
Mark Simulacrum001e9f32017-07-05 01:41:43939 if let Some(ref gdb) = build.config.gdb {
940 cmd.arg("--gdb").arg(gdb);
941 }
942 if let Some(ref vers) = build.lldb_version {
943 cmd.arg("--lldb-version").arg(vers);
944 }
945 if let Some(ref dir) = build.lldb_python_dir {
946 cmd.arg("--lldb-python-dir").arg(dir);
947 }
Alex Crichtonb325baf2016-04-05 18:34:23948
Mark Simulacrum44ffb612017-07-30 04:12:53949 cmd.args(&build.config.cmd.test_args());
Corey Farwellc8c6d2c2016-10-30 01:58:52950
Mark Simulacrum001e9f32017-07-05 01:41:43951 if build.is_verbose() {
952 cmd.arg("--verbose");
953 }
Alex Crichton126e09e2016-04-14 22:51:03954
Mark Simulacrum001e9f32017-07-05 01:41:43955 if build.config.quiet_tests {
956 cmd.arg("--quiet");
957 }
Alex Crichton1747ce22017-01-28 21:38:06958
bjorn30c97bbf2017-08-13 10:30:54959 if build.config.llvm_enabled {
Alex Crichtonbe902e72018-03-05 17:47:54960 let llvm_config = builder.ensure(native::Llvm {
961 target: build.config.build,
962 emscripten: false,
963 });
Mark Simulacrum0ce5cf02018-04-01 01:21:14964 if !build.config.dry_run {
965 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
966 cmd.arg("--llvm-version").arg(llvm_version);
967 }
bjorn30c97bbf2017-08-13 10:30:54968 if !build.is_rust_llvm(target) {
969 cmd.arg("--system-llvm");
970 }
971
972 // Only pass correct values for these flags for the `run-make` suite as it
973 // requires that a C++ compiler was configured which isn't always the case.
Mark Simulacrum0ce5cf02018-04-01 01:21:14974 if !build.config.dry_run && suite == "run-make-fulldeps" {
bjorn30c97bbf2017-08-13 10:30:54975 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
976 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
977 cmd.arg("--cc").arg(build.cc(target))
978 .arg("--cxx").arg(build.cxx(target).unwrap())
979 .arg("--cflags").arg(build.cflags(target).join(" "))
980 .arg("--llvm-components").arg(llvm_components.trim())
981 .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
Oliver Schneideracdf83f2017-12-06 08:25:29982 if let Some(ar) = build.ar(target) {
983 cmd.arg("--ar").arg(ar);
984 }
bjorn30c97bbf2017-08-13 10:30:54985 }
986 }
Alex Crichton7df6f412018-03-09 17:26:15987 if suite == "run-make-fulldeps" && !build.config.llvm_enabled {
Mark Simulacrum545b92f2018-03-28 15:25:09988 builder.info(
989 &format!("Ignoring run-make test suite as they generally don't work without LLVM"));
bjorn30c97bbf2017-08-13 10:30:54990 return;
991 }
992
Alex Crichton7df6f412018-03-09 17:26:15993 if suite != "run-make-fulldeps" {
Mark Simulacrum001e9f32017-07-05 01:41:43994 cmd.arg("--cc").arg("")
995 .arg("--cxx").arg("")
996 .arg("--cflags").arg("")
997 .arg("--llvm-components").arg("")
998 .arg("--llvm-cxxflags").arg("");
999 }
1000
1001 if build.remote_tested(target) {
Mark Simulacrum6b3413d2017-07-05 12:41:271002 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
Mark Simulacrum001e9f32017-07-05 01:41:431003 }
1004
1005 // Running a C compiler on MSVC requires a few env vars to be set, to be
1006 // sure to set them here.
1007 //
1008 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1009 // rather than stomp over it.
1010 if target.contains("msvc") {
Oliver Schneideracdf83f2017-12-06 08:25:291011 for &(ref k, ref v) in build.cc[&target].env() {
Mark Simulacrum001e9f32017-07-05 01:41:431012 if k != "PATH" {
1013 cmd.env(k, v);
1014 }
Alex Crichton126e09e2016-04-14 22:51:031015 }
1016 }
Mark Simulacrum001e9f32017-07-05 01:41:431017 cmd.env("RUSTC_BOOTSTRAP", "1");
1018 build.add_rust_test_threads(&mut cmd);
1019
1020 if build.config.sanitizers {
1021 cmd.env("SANITIZER_SUPPORT", "1");
1022 }
1023
1024 if build.config.profiler {
1025 cmd.env("PROFILER_SUPPORT", "1");
1026 }
1027
Alex Crichton884715c2018-01-22 15:29:241028 cmd.env("RUST_TEST_TMPDIR", build.out.join("tmp"));
1029
Mark Simulacrum001e9f32017-07-05 01:41:431030 cmd.arg("--adb-path").arg("adb");
1031 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1032 if target.contains("android") {
1033 // Assume that cc for this target comes from the android sysroot
1034 cmd.arg("--android-cross-path")
1035 .arg(build.cc(target).parent().unwrap().parent().unwrap());
1036 } else {
1037 cmd.arg("--android-cross-path").arg("");
1038 }
1039
1040 build.ci_env.force_coloring_in_ci(&mut cmd);
1041
Alex Crichton6fd4d672018-03-16 15:35:031042 let _folder = build.fold_output(|| format!("test_{}", suite));
Mark Simulacrum545b92f2018-03-28 15:25:091043 builder.info(&format!("Check compiletest suite={} mode={} ({} -> {})",
1044 suite, mode, &compiler.host, target));
1045 let _time = util::timeit(&build);
Mark Simulacrum001e9f32017-07-05 01:41:431046 try_run(build, &mut cmd);
Alex Crichton126e09e2016-04-14 22:51:031047 }
Alex Crichtonb325baf2016-04-05 18:34:231048}
Alex Crichtonede89442016-04-15 01:00:351049
Mark Simulacrum528646e2017-07-14 00:48:441050#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
kennytm0d300d42018-02-21 19:13:341051struct DocTest {
Mark Simulacrum528646e2017-07-14 00:48:441052 compiler: Compiler,
kennytm0d300d42018-02-21 19:13:341053 path: &'static str,
1054 name: &'static str,
1055 is_ext_doc: bool,
Mark Simulacruma5ab2ce2017-07-12 15:15:001056}
1057
kennytm0d300d42018-02-21 19:13:341058impl Step for DocTest {
Mark Simulacruma5ab2ce2017-07-12 15:15:001059 type Output = ();
Mark Simulacruma5ab2ce2017-07-12 15:15:001060 const ONLY_HOSTS: bool = true;
Alex Crichtonede89442016-04-15 01:00:351061
Mark Simulacrum56128fb2017-07-19 00:03:381062 fn should_run(run: ShouldRun) -> ShouldRun {
kennytm0d300d42018-02-21 19:13:341063 run.never()
Mark Simulacruma5ab2ce2017-07-12 15:15:001064 }
1065
1066 /// Run `rustdoc --test` for all documentation in `src/doc`.
1067 ///
1068 /// This will run all tests in our markdown documentation (e.g. the book)
1069 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
1070 /// `compiler`.
1071 fn run(self, builder: &Builder) {
1072 let build = builder.build;
1073 let compiler = self.compiler;
Mark Simulacrumceecd622017-07-12 16:12:471074
1075 builder.ensure(compile::Test { compiler, target: compiler.host });
1076
Mark Simulacruma5ab2ce2017-07-12 15:15:001077 // Do a breadth-first traversal of the `src/doc` directory and just run
1078 // tests for all files that end in `*.md`
kennytm0d300d42018-02-21 19:13:341079 let mut stack = vec![build.src.join(self.path)];
Mark Simulacrum545b92f2018-03-28 15:25:091080 let _time = util::timeit(&build);
kennytm0d300d42018-02-21 19:13:341081 let _folder = build.fold_output(|| format!("test_{}", self.name));
Mark Simulacruma5ab2ce2017-07-12 15:15:001082
Mark Simulacruma7274472018-03-27 14:06:471083 let mut files = Vec::new();
Mark Simulacruma5ab2ce2017-07-12 15:15:001084 while let Some(p) = stack.pop() {
1085 if p.is_dir() {
1086 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1087 continue
1088 }
1089
1090 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1091 continue;
1092 }
1093
1094 // The nostarch directory in the book is for no starch, and so isn't
1095 // guaranteed to build. We don't care if it doesn't build, so skip it.
1096 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
1097 continue;
1098 }
1099
Mark Simulacruma7274472018-03-27 14:06:471100 files.push(p);
1101 }
1102
1103 files.sort();
1104
1105 for file in files {
1106 let test_result = markdown_test(builder, compiler, &file);
kennytma9f940e2018-02-21 19:25:231107 if self.is_ext_doc {
1108 let toolstate = if test_result {
1109 ToolState::TestPass
1110 } else {
1111 ToolState::TestFail
1112 };
1113 build.save_toolstate(self.name, toolstate);
1114 }
Alex Crichtonede89442016-04-15 01:00:351115 }
Alex Crichtonede89442016-04-15 01:00:351116 }
1117}
1118
kennytm0d300d42018-02-21 19:13:341119macro_rules! test_book {
1120 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1121 $(
1122 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1123 pub struct $name {
1124 compiler: Compiler,
1125 }
1126
1127 impl Step for $name {
1128 type Output = ();
1129 const DEFAULT: bool = $default;
1130 const ONLY_HOSTS: bool = true;
1131
1132 fn should_run(run: ShouldRun) -> ShouldRun {
1133 run.path($path)
1134 }
1135
1136 fn make_run(run: RunConfig) {
1137 run.builder.ensure($name {
1138 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1139 });
1140 }
1141
1142 fn run(self, builder: &Builder) {
1143 builder.ensure(DocTest {
1144 compiler: self.compiler,
1145 path: $path,
1146 name: $book_name,
1147 is_ext_doc: !$default,
1148 });
1149 }
1150 }
1151 )+
1152 }
1153}
1154
1155test_book!(
1156 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1157 Reference, "src/doc/reference", "reference", default=false;
1158 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1159 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1160 TheBook, "src/doc/book", "book", default=false;
1161 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1162);
1163
Mark Simulacrum528646e2017-07-14 00:48:441164#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1165pub struct ErrorIndex {
1166 compiler: Compiler,
Mark Simulacrum001e9f32017-07-05 01:41:431167}
Alex Crichton0e272de2016-11-16 20:31:191168
Mark Simulacrum528646e2017-07-14 00:48:441169impl Step for ErrorIndex {
Mark Simulacrum001e9f32017-07-05 01:41:431170 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271171 const DEFAULT: bool = true;
1172 const ONLY_HOSTS: bool = true;
1173
Mark Simulacrum56128fb2017-07-19 00:03:381174 fn should_run(run: ShouldRun) -> ShouldRun {
1175 run.path("src/tools/error_index_generator")
Mark Simulacrum6b3413d2017-07-05 12:41:271176 }
1177
Mark Simulacrum6a67a052017-07-20 23:51:071178 fn make_run(run: RunConfig) {
1179 run.builder.ensure(ErrorIndex {
1180 compiler: run.builder.compiler(run.builder.top_stage, run.host),
Mark Simulacrum6b3413d2017-07-05 12:41:271181 });
1182 }
Alex Crichtonede89442016-04-15 01:00:351183
Mark Simulacrum001e9f32017-07-05 01:41:431184 /// Run the error index generator tool to execute the tests located in the error
1185 /// index.
1186 ///
1187 /// The `error_index_generator` tool lives in `src/tools` and is used to
1188 /// generate a markdown file from the error indexes of the code base which is
1189 /// then passed to `rustdoc --test`.
1190 fn run(self, builder: &Builder) {
1191 let build = builder.build;
1192 let compiler = self.compiler;
1193
Mark Simulacrum6b3413d2017-07-05 12:41:271194 builder.ensure(compile::Std { compiler, target: compiler.host });
1195
Mark Simulacrum001e9f32017-07-05 01:41:431196 let dir = testdir(build, compiler.host);
1197 t!(fs::create_dir_all(&dir));
1198 let output = dir.join("error-index.md");
1199
Alex Crichton6fd4d672018-03-16 15:35:031200 let mut tool = builder.tool_cmd(Tool::ErrorIndex);
1201 tool.arg("markdown")
1202 .arg(&output)
1203 .env("CFG_BUILD", &build.build)
1204 .env("RUSTC_ERROR_METADATA_DST", build.extended_error_dir());
Mark Simulacrum001e9f32017-07-05 01:41:431205
Alex Crichton6fd4d672018-03-16 15:35:031206
1207 let _folder = build.fold_output(|| "test_error_index");
Mark Simulacrum545b92f2018-03-28 15:25:091208 build.info(&format!("Testing error-index stage{}", compiler.stage));
1209 let _time = util::timeit(&build);
Alex Crichton6fd4d672018-03-16 15:35:031210 build.run(&mut tool);
Mark Simulacrumc114fe52017-07-05 17:21:331211 markdown_test(builder, compiler, &output);
Mark Simulacrum001e9f32017-07-05 01:41:431212 }
Alex Crichtonede89442016-04-15 01:00:351213}
1214
kennytma9f940e2018-02-21 19:25:231215fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) -> bool {
Mark Simulacrumc114fe52017-07-05 17:21:331216 let build = builder.build;
Mark Simulacrum0ce5cf02018-04-01 01:21:141217 match File::open(markdown) {
1218 Ok(mut file) => {
1219 let mut contents = String::new();
1220 t!(file.read_to_string(&mut contents));
1221 if !contents.contains("```") {
1222 return true;
1223 }
1224 }
1225 Err(_) => {},
Mark Simulacrumdd1d75e2017-06-04 23:55:501226 }
1227
Mark Simulacrum545b92f2018-03-28 15:25:091228 build.info(&format!("doc tests for: {}", markdown.display()));
Mark Simulacrumfacf5a92017-08-04 22:13:011229 let mut cmd = builder.rustdoc_cmd(compiler.host);
Alex Crichton0e272de2016-11-16 20:31:191230 build.add_rust_test_threads(&mut cmd);
Alex Crichtonede89442016-04-15 01:00:351231 cmd.arg("--test");
1232 cmd.arg(markdown);
Alex Crichton6f62fae2016-12-12 17:03:351233 cmd.env("RUSTC_BOOTSTRAP", "1");
Corey Farwellc8c6d2c2016-10-30 01:58:521234
Mark Simulacrum44ffb612017-07-30 04:12:531235 let test_args = build.config.cmd.test_args().join(" ");
Corey Farwellc8c6d2c2016-10-30 01:58:521236 cmd.arg("--test-args").arg(test_args);
1237
kennytm6ac07872017-05-21 20:27:471238 if build.config.quiet_tests {
kennytma9f940e2018-02-21 19:25:231239 try_run_quiet(build, &mut cmd)
kennytm6ac07872017-05-21 20:27:471240 } else {
kennytma9f940e2018-02-21 19:25:231241 try_run(build, &mut cmd)
kennytm6ac07872017-05-21 20:27:471242 }
Alex Crichtonede89442016-04-15 01:00:351243}
Alex Crichtonbb9062a2016-04-29 21:23:151244
Mark Simulacrum528646e2017-07-14 00:48:441245#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum981afa52017-07-18 21:28:531246pub struct CrateLibrustc {
Mark Simulacrum528646e2017-07-14 00:48:441247 compiler: Compiler,
1248 target: Interned<String>,
Mark Simulacrum6b3413d2017-07-05 12:41:271249 test_kind: TestKind,
Mark Simulacrumf104b122018-02-11 16:51:581250 krate: Interned<String>,
Mark Simulacrum6b3413d2017-07-05 12:41:271251}
1252
Mark Simulacrum981afa52017-07-18 21:28:531253impl Step for CrateLibrustc {
Mark Simulacrum6b3413d2017-07-05 12:41:271254 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271255 const DEFAULT: bool = true;
1256 const ONLY_HOSTS: bool = true;
1257
Mark Simulacrum56128fb2017-07-19 00:03:381258 fn should_run(run: ShouldRun) -> ShouldRun {
1259 run.krate("rustc-main")
Mark Simulacrum6b3413d2017-07-05 12:41:271260 }
1261
Mark Simulacrum6a67a052017-07-20 23:51:071262 fn make_run(run: RunConfig) {
1263 let builder = run.builder;
1264 let compiler = builder.compiler(builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:271265
Mark Simulacrumf104b122018-02-11 16:51:581266 for krate in builder.in_tree_crates("rustc-main") {
1267 if run.path.ends_with(&krate.path) {
1268 let test_kind = if builder.kind == Kind::Test {
1269 TestKind::Test
1270 } else if builder.kind == Kind::Bench {
1271 TestKind::Bench
1272 } else {
1273 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1274 };
Mark Simulacrum6b3413d2017-07-05 12:41:271275
Mark Simulacrumf104b122018-02-11 16:51:581276 builder.ensure(CrateLibrustc {
1277 compiler,
1278 target: run.target,
1279 test_kind,
1280 krate: krate.name,
1281 });
Mark Simulacrum6b3413d2017-07-05 12:41:271282 }
Mark Simulacrum6b3413d2017-07-05 12:41:271283 }
1284 }
1285
Mark Simulacrum6b3413d2017-07-05 12:41:271286 fn run(self, builder: &Builder) {
Mark Simulacrum981afa52017-07-18 21:28:531287 builder.ensure(Crate {
Mark Simulacrum6b3413d2017-07-05 12:41:271288 compiler: self.compiler,
1289 target: self.target,
1290 mode: Mode::Librustc,
1291 test_kind: self.test_kind,
1292 krate: self.krate,
1293 });
1294 }
1295}
1296
Mark Simulacrum528646e2017-07-14 00:48:441297#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrumf104b122018-02-11 16:51:581298pub struct CrateNotDefault {
Mark Simulacrum528646e2017-07-14 00:48:441299 compiler: Compiler,
1300 target: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:431301 test_kind: TestKind,
Mark Simulacrumf104b122018-02-11 16:51:581302 krate: &'static str,
Mark Simulacrum001e9f32017-07-05 01:41:431303}
Alex Crichtonbb9062a2016-04-29 21:23:151304
Mark Simulacrumf104b122018-02-11 16:51:581305impl Step for CrateNotDefault {
Mark Simulacrum001e9f32017-07-05 01:41:431306 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271307
Mark Simulacrum56128fb2017-07-19 00:03:381308 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumf104b122018-02-11 16:51:581309 run.path("src/liballoc_jemalloc")
1310 .path("src/librustc_asan")
1311 .path("src/librustc_lsan")
1312 .path("src/librustc_msan")
1313 .path("src/librustc_tsan")
Mark Simulacrum6b3413d2017-07-05 12:41:271314 }
1315
Mark Simulacrum6a67a052017-07-20 23:51:071316 fn make_run(run: RunConfig) {
1317 let builder = run.builder;
1318 let compiler = builder.compiler(builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:271319
Mark Simulacrumf104b122018-02-11 16:51:581320 let test_kind = if builder.kind == Kind::Test {
1321 TestKind::Test
1322 } else if builder.kind == Kind::Bench {
1323 TestKind::Bench
1324 } else {
1325 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1326 };
1327
1328 builder.ensure(CrateNotDefault {
1329 compiler,
1330 target: run.target,
1331 test_kind,
1332 krate: match run.path {
1333 _ if run.path.ends_with("src/liballoc_jemalloc") => "alloc_jemalloc",
1334 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1335 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1336 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1337 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1338 _ => panic!("unexpected path {:?}", run.path),
1339 },
1340 });
1341 }
1342
1343 fn run(self, builder: &Builder) {
1344 builder.ensure(Crate {
1345 compiler: self.compiler,
1346 target: self.target,
1347 mode: Mode::Libstd,
1348 test_kind: self.test_kind,
1349 krate: INTERNER.intern_str(self.krate),
1350 });
1351 }
1352}
1353
1354
1355#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1356pub struct Crate {
1357 compiler: Compiler,
1358 target: Interned<String>,
1359 mode: Mode,
1360 test_kind: TestKind,
1361 krate: Interned<String>,
1362}
1363
1364impl Step for Crate {
1365 type Output = ();
1366 const DEFAULT: bool = true;
1367
1368 fn should_run(mut run: ShouldRun) -> ShouldRun {
1369 let builder = run.builder;
1370 run = run.krate("test");
1371 for krate in run.builder.in_tree_crates("std") {
1372 if krate.is_local(&run.builder) &&
1373 !krate.name.contains("jemalloc") &&
1374 !(krate.name.starts_with("rustc_") && krate.name.ends_with("san")) &&
1375 krate.name != "dlmalloc" {
1376 run = run.path(krate.local_path(&builder).to_str().unwrap());
1377 }
1378 }
1379 run
1380 }
1381
1382 fn make_run(run: RunConfig) {
1383 let builder = run.builder;
1384 let compiler = builder.compiler(builder.top_stage, run.host);
1385
1386 let make = |mode: Mode, krate: &CargoCrate| {
Mark Simulacrum6b3413d2017-07-05 12:41:271387 let test_kind = if builder.kind == Kind::Test {
1388 TestKind::Test
1389 } else if builder.kind == Kind::Bench {
1390 TestKind::Bench
1391 } else {
Mark Simulacrum981afa52017-07-18 21:28:531392 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
Mark Simulacrum6b3413d2017-07-05 12:41:271393 };
1394
Mark Simulacrum981afa52017-07-18 21:28:531395 builder.ensure(Crate {
Mark Simulacrum6a67a052017-07-20 23:51:071396 compiler,
1397 target: run.target,
Zack M. Davis1b6c9602017-08-07 05:54:091398 mode,
1399 test_kind,
Mark Simulacrumf104b122018-02-11 16:51:581400 krate: krate.name,
Mark Simulacrum6b3413d2017-07-05 12:41:271401 });
1402 };
1403
Mark Simulacrumf104b122018-02-11 16:51:581404 for krate in builder.in_tree_crates("std") {
1405 if run.path.ends_with(&krate.local_path(&builder)) {
1406 make(Mode::Libstd, krate);
Mark Simulacrum6b3413d2017-07-05 12:41:271407 }
Mark Simulacrumf104b122018-02-11 16:51:581408 }
1409 for krate in builder.in_tree_crates("test") {
1410 if run.path.ends_with(&krate.local_path(&builder)) {
1411 make(Mode::Libtest, krate);
Mark Simulacrum6b3413d2017-07-05 12:41:271412 }
Mark Simulacrum6b3413d2017-07-05 12:41:271413 }
1414 }
Alex Crichton7046fea2016-12-25 23:20:331415
Mark Simulacrumf104b122018-02-11 16:51:581416 /// Run all unit tests plus documentation tests for a given crate defined
1417 /// by a `Cargo.toml` (single manifest)
Mark Simulacrum001e9f32017-07-05 01:41:431418 ///
1419 /// This is what runs tests for crates like the standard library, compiler, etc.
1420 /// It essentially is the driver for running `cargo test`.
1421 ///
1422 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1423 /// arguments, and those arguments are discovered from `cargo metadata`.
1424 fn run(self, builder: &Builder) {
1425 let build = builder.build;
1426 let compiler = self.compiler;
1427 let target = self.target;
1428 let mode = self.mode;
1429 let test_kind = self.test_kind;
1430 let krate = self.krate;
Alex Crichtonbb9062a2016-04-29 21:23:151431
Mark Simulacrum6b3413d2017-07-05 12:41:271432 builder.ensure(compile::Test { compiler, target });
1433 builder.ensure(RemoteCopyLibs { compiler, target });
Mark Simulacrum001e9f32017-07-05 01:41:431434
1435 // If we're not doing a full bootstrap but we're testing a stage2 version of
1436 // libstd, then what we're actually testing is the libstd produced in
1437 // stage1. Reflect that here by updating the compiler that we're working
1438 // with automatically.
1439 let compiler = if build.force_use_stage1(compiler, target) {
Mark Simulacrum6b3413d2017-07-05 12:41:271440 builder.compiler(1, compiler.host)
Mark Simulacrum001e9f32017-07-05 01:41:431441 } else {
1442 compiler.clone()
1443 };
1444
Alex Crichton90105672017-07-17 16:32:081445 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
Mark Simulacrumf104b122018-02-11 16:51:581446 match mode {
Alex Crichton90105672017-07-17 16:32:081447 Mode::Libstd => {
Alex Crichtonbe902e72018-03-05 17:47:541448 compile::std_cargo(builder, &compiler, target, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081449 }
1450 Mode::Libtest => {
1451 compile::test_cargo(build, &compiler, target, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081452 }
1453 Mode::Librustc => {
1454 builder.ensure(compile::Rustc { compiler, target });
Alex Crichton884715c2018-01-22 15:29:241455 compile::rustc_cargo(build, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081456 }
1457 _ => panic!("can only test libraries"),
1458 };
Alex Crichton90105672017-07-17 16:32:081459
Mark Simulacrum001e9f32017-07-05 01:41:431460 // Build up the base `cargo test` command.
1461 //
1462 // Pass in some standard flags then iterate over the graph we've discovered
1463 // in `cargo metadata` with the maps above and figure out what `-p`
1464 // arguments need to get passed.
Mark Simulacrum001e9f32017-07-05 01:41:431465 if test_kind.subcommand() == "test" && !build.fail_fast {
1466 cargo.arg("--no-fail-fast");
Alex Crichtonbb9062a2016-04-29 21:23:151467 }
Guillaume Gomez8e469272018-02-17 14:45:391468 if build.doc_tests {
1469 cargo.arg("--doc");
1470 }
Mark Simulacrum001e9f32017-07-05 01:41:431471
Mark Simulacrumf104b122018-02-11 16:51:581472 cargo.arg("-p").arg(krate);
Alex Crichtonbb9062a2016-04-29 21:23:151473
Mark Simulacrum001e9f32017-07-05 01:41:431474 // The tests are going to run with the *target* libraries, so we need to
1475 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1476 //
1477 // Note that to run the compiler we need to run with the *host* libraries,
1478 // but our wrapper scripts arrange for that to be the case anyway.
1479 let mut dylib_path = dylib_path();
Mark Simulacrum528646e2017-07-14 00:48:441480 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
Mark Simulacrum001e9f32017-07-05 01:41:431481 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
Alex Crichtonbb9062a2016-04-29 21:23:151482
Mark Simulacrum001e9f32017-07-05 01:41:431483 cargo.arg("--");
Mark Simulacrum44ffb612017-07-30 04:12:531484 cargo.args(&build.config.cmd.test_args());
Alex Crichton0e272de2016-11-16 20:31:191485
Mark Simulacrum001e9f32017-07-05 01:41:431486 if build.config.quiet_tests {
1487 cargo.arg("--quiet");
1488 }
Corey Farwellc8c6d2c2016-10-30 01:58:521489
Mark Simulacrum001e9f32017-07-05 01:41:431490 if target.contains("emscripten") {
Alex Crichton8e7849e2017-07-29 00:52:441491 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1492 build.config.nodejs.as_ref().expect("nodejs not configured"));
Oliver Schneideracdf83f2017-12-06 08:25:291493 } else if target.starts_with("wasm32") {
Diggory Blake0e6601f2018-01-11 17:51:491494 // Warn about running tests without the `wasm_syscall` feature enabled.
1495 // The javascript shim implements the syscall interface so that test
1496 // output can be correctly reported.
1497 if !build.config.wasm_syscall {
Mark Simulacrum545b92f2018-03-28 15:25:091498 build.info(&format!("Libstd was built without `wasm_syscall` feature enabled: \
1499 test output may not be visible."));
Diggory Blake0e6601f2018-01-11 17:51:491500 }
1501
Oliver Schneideracdf83f2017-12-06 08:25:291502 // On the wasm32-unknown-unknown target we're using LTO which is
1503 // incompatible with `-C prefer-dynamic`, so disable that here
1504 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
1505
1506 let node = build.config.nodejs.as_ref()
1507 .expect("nodejs not configured");
1508 let runner = format!("{} {}/src/etc/wasm32-shim.js",
1509 node.display(),
1510 build.src.display());
1511 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
Mark Simulacrum001e9f32017-07-05 01:41:431512 } else if build.remote_tested(target) {
Alex Crichton8e7849e2017-07-29 00:52:441513 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1514 format!("{} run",
1515 builder.tool_exe(Tool::RemoteTestClient).display()));
Mark Simulacrum001e9f32017-07-05 01:41:431516 }
Alex Crichton6fd4d672018-03-16 15:35:031517
1518 let _folder = build.fold_output(|| {
1519 format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, krate)
1520 });
Mark Simulacrum545b92f2018-03-28 15:25:091521 build.info(&format!("{} {} stage{} ({} -> {})", test_kind, krate, compiler.stage,
1522 &compiler.host, target));
1523 let _time = util::timeit(&build);
Alex Crichton8e7849e2017-07-29 00:52:441524 try_run(build, &mut cargo);
Alex Crichton39a5d3f2016-06-28 20:31:301525 }
1526}
1527
Mark Simulacrumf87696b2017-09-02 14:02:321528#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrumf104b122018-02-11 16:51:581529pub struct CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321530 host: Interned<String>,
1531 test_kind: TestKind,
1532}
1533
Mark Simulacrumf104b122018-02-11 16:51:581534impl Step for CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321535 type Output = ();
1536 const DEFAULT: bool = true;
1537 const ONLY_HOSTS: bool = true;
1538
1539 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumf104b122018-02-11 16:51:581540 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
Mark Simulacrumf87696b2017-09-02 14:02:321541 }
1542
1543 fn make_run(run: RunConfig) {
1544 let builder = run.builder;
1545
1546 let test_kind = if builder.kind == Kind::Test {
1547 TestKind::Test
1548 } else if builder.kind == Kind::Bench {
1549 TestKind::Bench
1550 } else {
1551 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1552 };
1553
Mark Simulacrumf104b122018-02-11 16:51:581554 builder.ensure(CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321555 host: run.host,
1556 test_kind,
1557 });
1558 }
1559
1560 fn run(self, builder: &Builder) {
1561 let build = builder.build;
1562 let test_kind = self.test_kind;
1563
1564 let compiler = builder.compiler(builder.top_stage, self.host);
1565 let target = compiler.host;
1566
Alex Crichton3da54fb2017-09-15 22:28:591567 let mut cargo = tool::prepare_tool_cargo(builder,
1568 compiler,
1569 target,
1570 test_kind.subcommand(),
1571 "src/tools/rustdoc");
Mark Simulacrumf87696b2017-09-02 14:02:321572 if test_kind.subcommand() == "test" && !build.fail_fast {
1573 cargo.arg("--no-fail-fast");
1574 }
1575
1576 cargo.arg("-p").arg("rustdoc:0.0.0");
1577
1578 cargo.arg("--");
1579 cargo.args(&build.config.cmd.test_args());
1580
1581 if build.config.quiet_tests {
1582 cargo.arg("--quiet");
1583 }
1584
Alex Crichton6fd4d672018-03-16 15:35:031585 let _folder = build.fold_output(|| {
1586 format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage)
1587 });
Mark Simulacrum545b92f2018-03-28 15:25:091588 build.info(&format!("{} rustdoc stage{} ({} -> {})", test_kind, compiler.stage,
1589 &compiler.host, target));
1590 let _time = util::timeit(&build);
Mark Simulacrumf87696b2017-09-02 14:02:321591
1592 try_run(build, &mut cargo);
1593 }
1594}
1595
Alex Crichton8e7849e2017-07-29 00:52:441596fn envify(s: &str) -> String {
1597 s.chars().map(|c| {
1598 match c {
1599 '-' => '_',
1600 c => c,
Alex Crichton1747ce22017-01-28 21:38:061601 }
Alex Crichton8e7849e2017-07-29 00:52:441602 }).flat_map(|c| c.to_uppercase()).collect()
Alex Crichton39a5d3f2016-06-28 20:31:301603}
1604
Mark Simulacrumceecd622017-07-12 16:12:471605/// Some test suites are run inside emulators or on remote devices, and most
1606/// of our test binaries are linked dynamically which means we need to ship
1607/// the standard library and such to the emulator ahead of time. This step
1608/// represents this and is a dependency of all test suites.
1609///
1610/// Most of the time this is a noop. For some steps such as shipping data to
1611/// QEMU we have to build our own tools so we've got conditional dependencies
1612/// on those programs as well. Note that the remote test client is built for
1613/// the build target (us) and the server is built for the target.
Mark Simulacrum528646e2017-07-14 00:48:441614#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1615pub struct RemoteCopyLibs {
1616 compiler: Compiler,
1617 target: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:431618}
Alex Crichton1747ce22017-01-28 21:38:061619
Mark Simulacrum528646e2017-07-14 00:48:441620impl Step for RemoteCopyLibs {
Mark Simulacrum001e9f32017-07-05 01:41:431621 type Output = ();
Alex Crichton1747ce22017-01-28 21:38:061622
Mark Simulacrum56128fb2017-07-19 00:03:381623 fn should_run(run: ShouldRun) -> ShouldRun {
1624 run.never()
Mark Simulacrum681b1232017-07-14 12:30:161625 }
1626
Mark Simulacrum001e9f32017-07-05 01:41:431627 fn run(self, builder: &Builder) {
1628 let build = builder.build;
1629 let compiler = self.compiler;
1630 let target = self.target;
1631 if !build.remote_tested(target) {
1632 return
1633 }
Alex Crichton1747ce22017-01-28 21:38:061634
Mark Simulacrum6b3413d2017-07-05 12:41:271635 builder.ensure(compile::Test { compiler, target });
1636
Mark Simulacrum545b92f2018-03-28 15:25:091637 build.info(&format!("REMOTE copy libs to emulator ({})", target));
Mark Simulacrum001e9f32017-07-05 01:41:431638 t!(fs::create_dir_all(build.out.join("tmp")));
1639
Mark Simulacrumfe0eca02017-07-23 01:29:081640 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
Mark Simulacrum001e9f32017-07-05 01:41:431641
1642 // Spawn the emulator and wait for it to come online
Mark Simulacrum6b3413d2017-07-05 12:41:271643 let tool = builder.tool_exe(Tool::RemoteTestClient);
Mark Simulacrum001e9f32017-07-05 01:41:431644 let mut cmd = Command::new(&tool);
1645 cmd.arg("spawn-emulator")
1646 .arg(target)
1647 .arg(&server)
1648 .arg(build.out.join("tmp"));
1649 if let Some(rootfs) = build.qemu_rootfs(target) {
1650 cmd.arg(rootfs);
1651 }
1652 build.run(&mut cmd);
1653
1654 // Push all our dylibs to the emulator
Mark Simulacrum60388302017-07-05 16:46:411655 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
Mark Simulacrum001e9f32017-07-05 01:41:431656 let f = t!(f);
1657 let name = f.file_name().into_string().unwrap();
1658 if util::is_dylib(&name) {
1659 build.run(Command::new(&tool)
1660 .arg("push")
1661 .arg(f.path()));
1662 }
Alex Crichton1747ce22017-01-28 21:38:061663 }
1664 }
1665}
1666
Mark Simulacrum528646e2017-07-14 00:48:441667#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum001e9f32017-07-05 01:41:431668pub struct Distcheck;
1669
Mark Simulacrum528646e2017-07-14 00:48:441670impl Step for Distcheck {
Mark Simulacrum001e9f32017-07-05 01:41:431671 type Output = ();
1672
Mark Simulacrum56128fb2017-07-19 00:03:381673 fn should_run(run: ShouldRun) -> ShouldRun {
1674 run.path("distcheck")
Mark Simulacrum681b1232017-07-14 12:30:161675 }
1676
Mark Simulacrum8f2e5762017-07-22 13:35:421677 fn make_run(run: RunConfig) {
1678 run.builder.ensure(Distcheck);
1679 }
1680
Mark Simulacrum001e9f32017-07-05 01:41:431681 /// Run "distcheck", a 'make check' from a tarball
1682 fn run(self, builder: &Builder) {
1683 let build = builder.build;
1684
Mark Simulacrum545b92f2018-03-28 15:25:091685 build.info(&format!("Distcheck"));
Mark Simulacrum001e9f32017-07-05 01:41:431686 let dir = build.out.join("tmp").join("distcheck");
1687 let _ = fs::remove_dir_all(&dir);
1688 t!(fs::create_dir_all(&dir));
1689
Mark Simulacrum1c118232017-07-22 16:48:291690 // Guarantee that these are built before we begin running.
1691 builder.ensure(dist::PlainSourceTarball);
1692 builder.ensure(dist::Src);
1693
Mark Simulacrum001e9f32017-07-05 01:41:431694 let mut cmd = Command::new("tar");
1695 cmd.arg("-xzf")
Mark Simulacrum5984e702017-07-13 00:52:311696 .arg(builder.ensure(dist::PlainSourceTarball))
Mark Simulacrum001e9f32017-07-05 01:41:431697 .arg("--strip-components=1")
1698 .current_dir(&dir);
1699 build.run(&mut cmd);
1700 build.run(Command::new("./configure")
1701 .args(&build.config.configure_args)
1702 .arg("--enable-vendor")
1703 .current_dir(&dir));
1704 build.run(Command::new(build_helper::make(&build.build))
1705 .arg("check")
1706 .current_dir(&dir));
1707
1708 // Now make sure that rust-src has all of libstd's dependencies
Mark Simulacrum545b92f2018-03-28 15:25:091709 build.info(&format!("Distcheck rust-src"));
Mark Simulacrum001e9f32017-07-05 01:41:431710 let dir = build.out.join("tmp").join("distcheck-src");
1711 let _ = fs::remove_dir_all(&dir);
1712 t!(fs::create_dir_all(&dir));
1713
1714 let mut cmd = Command::new("tar");
1715 cmd.arg("-xzf")
Mark Simulacrum5984e702017-07-13 00:52:311716 .arg(builder.ensure(dist::Src))
Mark Simulacrum001e9f32017-07-05 01:41:431717 .arg("--strip-components=1")
1718 .current_dir(&dir);
1719 build.run(&mut cmd);
1720
1721 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
1722 build.run(Command::new(&build.initial_cargo)
1723 .arg("generate-lockfile")
1724 .arg("--manifest-path")
1725 .arg(&toml)
1726 .current_dir(&dir));
Alex Crichtond38db822016-12-09 01:13:551727 }
Alex Crichtond38db822016-12-09 01:13:551728}
Alex Crichton1a040b32016-12-31 03:50:571729
Mark Simulacrum528646e2017-07-14 00:48:441730#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum001e9f32017-07-05 01:41:431731pub struct Bootstrap;
1732
Mark Simulacrum528646e2017-07-14 00:48:441733impl Step for Bootstrap {
Mark Simulacrum001e9f32017-07-05 01:41:431734 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271735 const DEFAULT: bool = true;
1736 const ONLY_HOSTS: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:431737
1738 /// Test the build system itself
1739 fn run(self, builder: &Builder) {
1740 let build = builder.build;
1741 let mut cmd = Command::new(&build.initial_cargo);
1742 cmd.arg("test")
1743 .current_dir(build.src.join("src/bootstrap"))
Mark Simulacrum42fde212018-03-10 14:03:061744 .env("RUSTFLAGS", "-Cdebuginfo=2")
Mark Simulacrum001e9f32017-07-05 01:41:431745 .env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
1746 .env("RUSTC_BOOTSTRAP", "1")
1747 .env("RUSTC", &build.initial_rustc);
Simon Sapine993e622018-03-23 18:55:411748 if let Some(flags) = option_env!("RUSTFLAGS") {
1749 // Use the same rustc flags for testing as for "normal" compilation,
1750 // so that Cargo doesn’t recompile the entire dependency graph every time:
1751 // https://github.com/rust-lang/rust/issues/49215
1752 cmd.env("RUSTFLAGS", flags);
1753 }
Mark Simulacrum001e9f32017-07-05 01:41:431754 if !build.fail_fast {
1755 cmd.arg("--no-fail-fast");
1756 }
Mark Simulacrum44ffb612017-07-30 04:12:531757 cmd.arg("--").args(&build.config.cmd.test_args());
Mark Simulacrum001e9f32017-07-05 01:41:431758 try_run(build, &mut cmd);
Josh Stone617aea42017-06-02 16:27:441759 }
Mark Simulacrum6b3413d2017-07-05 12:41:271760
Mark Simulacrum56128fb2017-07-19 00:03:381761 fn should_run(run: ShouldRun) -> ShouldRun {
1762 run.path("src/bootstrap")
Mark Simulacrum6b3413d2017-07-05 12:41:271763 }
1764
Mark Simulacrum6a67a052017-07-20 23:51:071765 fn make_run(run: RunConfig) {
1766 run.builder.ensure(Bootstrap);
Mark Simulacrum6b3413d2017-07-05 12:41:271767 }
Alex Crichton1a040b32016-12-31 03:50:571768}