blob: 992dec5217d4fbd898e64cf863bf5f740b17691b [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
Guillaume Gomezb2192ae2018-04-01 19:06:35889 let is_rustdoc_ui = suite.ends_with("rustdoc-ui");
890
Mark Simulacrum4e5333c2017-07-25 22:54:33891 // Avoid depending on rustdoc when we don't need it.
Guillaume Gomezb2192ae2018-04-01 19:06:35892 if mode == "rustdoc" ||
893 (mode == "run-make" && suite.ends_with("fulldeps")) ||
894 (mode == "ui" && is_rustdoc_ui) {
Mark Simulacrumfacf5a92017-08-04 22:13:01895 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host));
Mark Simulacrum4e5333c2017-07-25 22:54:33896 }
897
Mark Simulacrum001e9f32017-07-05 01:41:43898 cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
899 cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
900 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
901 cmd.arg("--mode").arg(mode);
902 cmd.arg("--target").arg(target);
Mark Simulacrum528646e2017-07-14 00:48:44903 cmd.arg("--host").arg(&*compiler.host);
904 cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(build.build));
Alex Crichtonf4e4ec72016-05-13 22:26:41905
Mark Simulacrum001e9f32017-07-05 01:41:43906 if let Some(ref nodejs) = build.config.nodejs {
907 cmd.arg("--nodejs").arg(nodejs);
908 }
Alex Crichtonf4e4ec72016-05-13 22:26:41909
Guillaume Gomezb2192ae2018-04-01 19:06:35910 let mut flags = if is_rustdoc_ui {
911 Vec::new()
912 } else {
913 vec!["-Crpath".to_string()]
914 };
915 if !is_rustdoc_ui {
916 if build.config.rust_optimize_tests {
917 flags.push("-O".to_string());
918 }
919 if build.config.rust_debuginfo_tests {
920 flags.push("-g".to_string());
921 }
Mark Simulacrum001e9f32017-07-05 01:41:43922 }
Guillaume Gomezb2192ae2018-04-01 19:06:35923 if !is_rustdoc_ui {
924 flags.push("-Zmiri -Zunstable-options".to_string());
925 } else {
926 flags.push("-Zunstable-options".to_string());
Mark Simulacrum001e9f32017-07-05 01:41:43927 }
Santiago Pastorinodb41f1e2018-01-18 22:44:41928 flags.push(build.config.cmd.rustc_args().join(" "));
Alex Crichtoncbe62922016-04-19 16:44:19929
Oliver Schneideracdf83f2017-12-06 08:25:29930 if let Some(linker) = build.linker(target) {
931 cmd.arg("--linker").arg(linker);
932 }
933
934 let hostflags = flags.clone();
Mark Simulacrum001e9f32017-07-05 01:41:43935 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
Alex Crichtoncbe62922016-04-19 16:44:19936
Oliver Schneideracdf83f2017-12-06 08:25:29937 let mut targetflags = flags.clone();
Mark Simulacrum001e9f32017-07-05 01:41:43938 targetflags.push(format!("-Lnative={}",
939 build.test_helpers_out(target).display()));
940 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
Alex Crichtonb325baf2016-04-05 18:34:23941
Mark Simulacrum001e9f32017-07-05 01:41:43942 cmd.arg("--docck-python").arg(build.python());
Alex Crichtonb325baf2016-04-05 18:34:23943
Mark Simulacrum001e9f32017-07-05 01:41:43944 if build.build.ends_with("apple-darwin") {
945 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
946 // LLDB plugin's compiled module which only works with the system python
947 // (namely not Homebrew-installed python)
948 cmd.arg("--lldb-python").arg("/usr/bin/python");
949 } else {
950 cmd.arg("--lldb-python").arg(build.python());
951 }
Alex Crichtonb325baf2016-04-05 18:34:23952
Mark Simulacrum001e9f32017-07-05 01:41:43953 if let Some(ref gdb) = build.config.gdb {
954 cmd.arg("--gdb").arg(gdb);
955 }
956 if let Some(ref vers) = build.lldb_version {
957 cmd.arg("--lldb-version").arg(vers);
958 }
959 if let Some(ref dir) = build.lldb_python_dir {
960 cmd.arg("--lldb-python-dir").arg(dir);
961 }
Alex Crichtonb325baf2016-04-05 18:34:23962
Mark Simulacrum44ffb612017-07-30 04:12:53963 cmd.args(&build.config.cmd.test_args());
Corey Farwellc8c6d2c2016-10-30 01:58:52964
Mark Simulacrum001e9f32017-07-05 01:41:43965 if build.is_verbose() {
966 cmd.arg("--verbose");
967 }
Alex Crichton126e09e2016-04-14 22:51:03968
Mark Simulacrum001e9f32017-07-05 01:41:43969 if build.config.quiet_tests {
970 cmd.arg("--quiet");
971 }
Alex Crichton1747ce22017-01-28 21:38:06972
bjorn30c97bbf2017-08-13 10:30:54973 if build.config.llvm_enabled {
Alex Crichtonbe902e72018-03-05 17:47:54974 let llvm_config = builder.ensure(native::Llvm {
975 target: build.config.build,
976 emscripten: false,
977 });
Mark Simulacrum0ce5cf02018-04-01 01:21:14978 if !build.config.dry_run {
979 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
980 cmd.arg("--llvm-version").arg(llvm_version);
981 }
bjorn30c97bbf2017-08-13 10:30:54982 if !build.is_rust_llvm(target) {
983 cmd.arg("--system-llvm");
984 }
985
986 // Only pass correct values for these flags for the `run-make` suite as it
987 // requires that a C++ compiler was configured which isn't always the case.
Mark Simulacrum0ce5cf02018-04-01 01:21:14988 if !build.config.dry_run && suite == "run-make-fulldeps" {
bjorn30c97bbf2017-08-13 10:30:54989 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
990 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
991 cmd.arg("--cc").arg(build.cc(target))
992 .arg("--cxx").arg(build.cxx(target).unwrap())
993 .arg("--cflags").arg(build.cflags(target).join(" "))
994 .arg("--llvm-components").arg(llvm_components.trim())
995 .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
Oliver Schneideracdf83f2017-12-06 08:25:29996 if let Some(ar) = build.ar(target) {
997 cmd.arg("--ar").arg(ar);
998 }
bjorn30c97bbf2017-08-13 10:30:54999 }
1000 }
Alex Crichton7df6f412018-03-09 17:26:151001 if suite == "run-make-fulldeps" && !build.config.llvm_enabled {
Mark Simulacrum545b92f2018-03-28 15:25:091002 builder.info(
1003 &format!("Ignoring run-make test suite as they generally don't work without LLVM"));
bjorn30c97bbf2017-08-13 10:30:541004 return;
1005 }
1006
Alex Crichton7df6f412018-03-09 17:26:151007 if suite != "run-make-fulldeps" {
Mark Simulacrum001e9f32017-07-05 01:41:431008 cmd.arg("--cc").arg("")
1009 .arg("--cxx").arg("")
1010 .arg("--cflags").arg("")
1011 .arg("--llvm-components").arg("")
1012 .arg("--llvm-cxxflags").arg("");
1013 }
1014
1015 if build.remote_tested(target) {
Mark Simulacrum6b3413d2017-07-05 12:41:271016 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
Mark Simulacrum001e9f32017-07-05 01:41:431017 }
1018
1019 // Running a C compiler on MSVC requires a few env vars to be set, to be
1020 // sure to set them here.
1021 //
1022 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1023 // rather than stomp over it.
1024 if target.contains("msvc") {
Oliver Schneideracdf83f2017-12-06 08:25:291025 for &(ref k, ref v) in build.cc[&target].env() {
Mark Simulacrum001e9f32017-07-05 01:41:431026 if k != "PATH" {
1027 cmd.env(k, v);
1028 }
Alex Crichton126e09e2016-04-14 22:51:031029 }
1030 }
Mark Simulacrum001e9f32017-07-05 01:41:431031 cmd.env("RUSTC_BOOTSTRAP", "1");
1032 build.add_rust_test_threads(&mut cmd);
1033
1034 if build.config.sanitizers {
1035 cmd.env("SANITIZER_SUPPORT", "1");
1036 }
1037
1038 if build.config.profiler {
1039 cmd.env("PROFILER_SUPPORT", "1");
1040 }
1041
Alex Crichton884715c2018-01-22 15:29:241042 cmd.env("RUST_TEST_TMPDIR", build.out.join("tmp"));
1043
Mark Simulacrum001e9f32017-07-05 01:41:431044 cmd.arg("--adb-path").arg("adb");
1045 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1046 if target.contains("android") {
1047 // Assume that cc for this target comes from the android sysroot
1048 cmd.arg("--android-cross-path")
1049 .arg(build.cc(target).parent().unwrap().parent().unwrap());
1050 } else {
1051 cmd.arg("--android-cross-path").arg("");
1052 }
1053
1054 build.ci_env.force_coloring_in_ci(&mut cmd);
1055
Alex Crichton6fd4d672018-03-16 15:35:031056 let _folder = build.fold_output(|| format!("test_{}", suite));
Mark Simulacrum545b92f2018-03-28 15:25:091057 builder.info(&format!("Check compiletest suite={} mode={} ({} -> {})",
1058 suite, mode, &compiler.host, target));
1059 let _time = util::timeit(&build);
Mark Simulacrum001e9f32017-07-05 01:41:431060 try_run(build, &mut cmd);
Alex Crichton126e09e2016-04-14 22:51:031061 }
Alex Crichtonb325baf2016-04-05 18:34:231062}
Alex Crichtonede89442016-04-15 01:00:351063
Mark Simulacrum528646e2017-07-14 00:48:441064#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
kennytm0d300d42018-02-21 19:13:341065struct DocTest {
Mark Simulacrum528646e2017-07-14 00:48:441066 compiler: Compiler,
kennytm0d300d42018-02-21 19:13:341067 path: &'static str,
1068 name: &'static str,
1069 is_ext_doc: bool,
Mark Simulacruma5ab2ce2017-07-12 15:15:001070}
1071
kennytm0d300d42018-02-21 19:13:341072impl Step for DocTest {
Mark Simulacruma5ab2ce2017-07-12 15:15:001073 type Output = ();
Mark Simulacruma5ab2ce2017-07-12 15:15:001074 const ONLY_HOSTS: bool = true;
Alex Crichtonede89442016-04-15 01:00:351075
Mark Simulacrum56128fb2017-07-19 00:03:381076 fn should_run(run: ShouldRun) -> ShouldRun {
kennytm0d300d42018-02-21 19:13:341077 run.never()
Mark Simulacruma5ab2ce2017-07-12 15:15:001078 }
1079
1080 /// Run `rustdoc --test` for all documentation in `src/doc`.
1081 ///
1082 /// This will run all tests in our markdown documentation (e.g. the book)
1083 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
1084 /// `compiler`.
1085 fn run(self, builder: &Builder) {
1086 let build = builder.build;
1087 let compiler = self.compiler;
Mark Simulacrumceecd622017-07-12 16:12:471088
1089 builder.ensure(compile::Test { compiler, target: compiler.host });
1090
Mark Simulacruma5ab2ce2017-07-12 15:15:001091 // Do a breadth-first traversal of the `src/doc` directory and just run
1092 // tests for all files that end in `*.md`
kennytm0d300d42018-02-21 19:13:341093 let mut stack = vec![build.src.join(self.path)];
Mark Simulacrum545b92f2018-03-28 15:25:091094 let _time = util::timeit(&build);
kennytm0d300d42018-02-21 19:13:341095 let _folder = build.fold_output(|| format!("test_{}", self.name));
Mark Simulacruma5ab2ce2017-07-12 15:15:001096
Mark Simulacruma7274472018-03-27 14:06:471097 let mut files = Vec::new();
Mark Simulacruma5ab2ce2017-07-12 15:15:001098 while let Some(p) = stack.pop() {
1099 if p.is_dir() {
1100 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1101 continue
1102 }
1103
1104 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1105 continue;
1106 }
1107
1108 // The nostarch directory in the book is for no starch, and so isn't
1109 // guaranteed to build. We don't care if it doesn't build, so skip it.
1110 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
1111 continue;
1112 }
1113
Mark Simulacruma7274472018-03-27 14:06:471114 files.push(p);
1115 }
1116
1117 files.sort();
1118
1119 for file in files {
1120 let test_result = markdown_test(builder, compiler, &file);
kennytma9f940e2018-02-21 19:25:231121 if self.is_ext_doc {
1122 let toolstate = if test_result {
1123 ToolState::TestPass
1124 } else {
1125 ToolState::TestFail
1126 };
1127 build.save_toolstate(self.name, toolstate);
1128 }
Alex Crichtonede89442016-04-15 01:00:351129 }
Alex Crichtonede89442016-04-15 01:00:351130 }
1131}
1132
kennytm0d300d42018-02-21 19:13:341133macro_rules! test_book {
1134 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1135 $(
1136 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1137 pub struct $name {
1138 compiler: Compiler,
1139 }
1140
1141 impl Step for $name {
1142 type Output = ();
1143 const DEFAULT: bool = $default;
1144 const ONLY_HOSTS: bool = true;
1145
1146 fn should_run(run: ShouldRun) -> ShouldRun {
1147 run.path($path)
1148 }
1149
1150 fn make_run(run: RunConfig) {
1151 run.builder.ensure($name {
1152 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1153 });
1154 }
1155
1156 fn run(self, builder: &Builder) {
1157 builder.ensure(DocTest {
1158 compiler: self.compiler,
1159 path: $path,
1160 name: $book_name,
1161 is_ext_doc: !$default,
1162 });
1163 }
1164 }
1165 )+
1166 }
1167}
1168
1169test_book!(
1170 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1171 Reference, "src/doc/reference", "reference", default=false;
1172 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1173 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1174 TheBook, "src/doc/book", "book", default=false;
1175 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1176);
1177
Mark Simulacrum528646e2017-07-14 00:48:441178#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1179pub struct ErrorIndex {
1180 compiler: Compiler,
Mark Simulacrum001e9f32017-07-05 01:41:431181}
Alex Crichton0e272de2016-11-16 20:31:191182
Mark Simulacrum528646e2017-07-14 00:48:441183impl Step for ErrorIndex {
Mark Simulacrum001e9f32017-07-05 01:41:431184 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271185 const DEFAULT: bool = true;
1186 const ONLY_HOSTS: bool = true;
1187
Mark Simulacrum56128fb2017-07-19 00:03:381188 fn should_run(run: ShouldRun) -> ShouldRun {
1189 run.path("src/tools/error_index_generator")
Mark Simulacrum6b3413d2017-07-05 12:41:271190 }
1191
Mark Simulacrum6a67a052017-07-20 23:51:071192 fn make_run(run: RunConfig) {
1193 run.builder.ensure(ErrorIndex {
1194 compiler: run.builder.compiler(run.builder.top_stage, run.host),
Mark Simulacrum6b3413d2017-07-05 12:41:271195 });
1196 }
Alex Crichtonede89442016-04-15 01:00:351197
Mark Simulacrum001e9f32017-07-05 01:41:431198 /// Run the error index generator tool to execute the tests located in the error
1199 /// index.
1200 ///
1201 /// The `error_index_generator` tool lives in `src/tools` and is used to
1202 /// generate a markdown file from the error indexes of the code base which is
1203 /// then passed to `rustdoc --test`.
1204 fn run(self, builder: &Builder) {
1205 let build = builder.build;
1206 let compiler = self.compiler;
1207
Mark Simulacrum6b3413d2017-07-05 12:41:271208 builder.ensure(compile::Std { compiler, target: compiler.host });
1209
Mark Simulacrum001e9f32017-07-05 01:41:431210 let dir = testdir(build, compiler.host);
1211 t!(fs::create_dir_all(&dir));
1212 let output = dir.join("error-index.md");
1213
Alex Crichton6fd4d672018-03-16 15:35:031214 let mut tool = builder.tool_cmd(Tool::ErrorIndex);
1215 tool.arg("markdown")
1216 .arg(&output)
1217 .env("CFG_BUILD", &build.build)
1218 .env("RUSTC_ERROR_METADATA_DST", build.extended_error_dir());
Mark Simulacrum001e9f32017-07-05 01:41:431219
Alex Crichton6fd4d672018-03-16 15:35:031220
1221 let _folder = build.fold_output(|| "test_error_index");
Mark Simulacrum545b92f2018-03-28 15:25:091222 build.info(&format!("Testing error-index stage{}", compiler.stage));
1223 let _time = util::timeit(&build);
Alex Crichton6fd4d672018-03-16 15:35:031224 build.run(&mut tool);
Mark Simulacrumc114fe52017-07-05 17:21:331225 markdown_test(builder, compiler, &output);
Mark Simulacrum001e9f32017-07-05 01:41:431226 }
Alex Crichtonede89442016-04-15 01:00:351227}
1228
kennytma9f940e2018-02-21 19:25:231229fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) -> bool {
Mark Simulacrumc114fe52017-07-05 17:21:331230 let build = builder.build;
Mark Simulacrum0ce5cf02018-04-01 01:21:141231 match File::open(markdown) {
1232 Ok(mut file) => {
1233 let mut contents = String::new();
1234 t!(file.read_to_string(&mut contents));
1235 if !contents.contains("```") {
1236 return true;
1237 }
1238 }
1239 Err(_) => {},
Mark Simulacrumdd1d75e2017-06-04 23:55:501240 }
1241
Mark Simulacrum545b92f2018-03-28 15:25:091242 build.info(&format!("doc tests for: {}", markdown.display()));
Mark Simulacrumfacf5a92017-08-04 22:13:011243 let mut cmd = builder.rustdoc_cmd(compiler.host);
Alex Crichton0e272de2016-11-16 20:31:191244 build.add_rust_test_threads(&mut cmd);
Alex Crichtonede89442016-04-15 01:00:351245 cmd.arg("--test");
1246 cmd.arg(markdown);
Alex Crichton6f62fae2016-12-12 17:03:351247 cmd.env("RUSTC_BOOTSTRAP", "1");
Corey Farwellc8c6d2c2016-10-30 01:58:521248
Mark Simulacrum44ffb612017-07-30 04:12:531249 let test_args = build.config.cmd.test_args().join(" ");
Corey Farwellc8c6d2c2016-10-30 01:58:521250 cmd.arg("--test-args").arg(test_args);
1251
kennytm6ac07872017-05-21 20:27:471252 if build.config.quiet_tests {
kennytma9f940e2018-02-21 19:25:231253 try_run_quiet(build, &mut cmd)
kennytm6ac07872017-05-21 20:27:471254 } else {
kennytma9f940e2018-02-21 19:25:231255 try_run(build, &mut cmd)
kennytm6ac07872017-05-21 20:27:471256 }
Alex Crichtonede89442016-04-15 01:00:351257}
Alex Crichtonbb9062a2016-04-29 21:23:151258
Mark Simulacrum528646e2017-07-14 00:48:441259#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum981afa52017-07-18 21:28:531260pub struct CrateLibrustc {
Mark Simulacrum528646e2017-07-14 00:48:441261 compiler: Compiler,
1262 target: Interned<String>,
Mark Simulacrum6b3413d2017-07-05 12:41:271263 test_kind: TestKind,
Mark Simulacrumf104b122018-02-11 16:51:581264 krate: Interned<String>,
Mark Simulacrum6b3413d2017-07-05 12:41:271265}
1266
Mark Simulacrum981afa52017-07-18 21:28:531267impl Step for CrateLibrustc {
Mark Simulacrum6b3413d2017-07-05 12:41:271268 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271269 const DEFAULT: bool = true;
1270 const ONLY_HOSTS: bool = true;
1271
Mark Simulacrum56128fb2017-07-19 00:03:381272 fn should_run(run: ShouldRun) -> ShouldRun {
1273 run.krate("rustc-main")
Mark Simulacrum6b3413d2017-07-05 12:41:271274 }
1275
Mark Simulacrum6a67a052017-07-20 23:51:071276 fn make_run(run: RunConfig) {
1277 let builder = run.builder;
1278 let compiler = builder.compiler(builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:271279
Mark Simulacrumf104b122018-02-11 16:51:581280 for krate in builder.in_tree_crates("rustc-main") {
1281 if run.path.ends_with(&krate.path) {
1282 let test_kind = if builder.kind == Kind::Test {
1283 TestKind::Test
1284 } else if builder.kind == Kind::Bench {
1285 TestKind::Bench
1286 } else {
1287 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1288 };
Mark Simulacrum6b3413d2017-07-05 12:41:271289
Mark Simulacrumf104b122018-02-11 16:51:581290 builder.ensure(CrateLibrustc {
1291 compiler,
1292 target: run.target,
1293 test_kind,
1294 krate: krate.name,
1295 });
Mark Simulacrum6b3413d2017-07-05 12:41:271296 }
Mark Simulacrum6b3413d2017-07-05 12:41:271297 }
1298 }
1299
Mark Simulacrum6b3413d2017-07-05 12:41:271300 fn run(self, builder: &Builder) {
Mark Simulacrum981afa52017-07-18 21:28:531301 builder.ensure(Crate {
Mark Simulacrum6b3413d2017-07-05 12:41:271302 compiler: self.compiler,
1303 target: self.target,
1304 mode: Mode::Librustc,
1305 test_kind: self.test_kind,
1306 krate: self.krate,
1307 });
1308 }
1309}
1310
Mark Simulacrum528646e2017-07-14 00:48:441311#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrumf104b122018-02-11 16:51:581312pub struct CrateNotDefault {
Mark Simulacrum528646e2017-07-14 00:48:441313 compiler: Compiler,
1314 target: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:431315 test_kind: TestKind,
Mark Simulacrumf104b122018-02-11 16:51:581316 krate: &'static str,
Mark Simulacrum001e9f32017-07-05 01:41:431317}
Alex Crichtonbb9062a2016-04-29 21:23:151318
Mark Simulacrumf104b122018-02-11 16:51:581319impl Step for CrateNotDefault {
Mark Simulacrum001e9f32017-07-05 01:41:431320 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271321
Mark Simulacrum56128fb2017-07-19 00:03:381322 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumf104b122018-02-11 16:51:581323 run.path("src/liballoc_jemalloc")
1324 .path("src/librustc_asan")
1325 .path("src/librustc_lsan")
1326 .path("src/librustc_msan")
1327 .path("src/librustc_tsan")
Mark Simulacrum6b3413d2017-07-05 12:41:271328 }
1329
Mark Simulacrum6a67a052017-07-20 23:51:071330 fn make_run(run: RunConfig) {
1331 let builder = run.builder;
1332 let compiler = builder.compiler(builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:271333
Mark Simulacrumf104b122018-02-11 16:51:581334 let test_kind = if builder.kind == Kind::Test {
1335 TestKind::Test
1336 } else if builder.kind == Kind::Bench {
1337 TestKind::Bench
1338 } else {
1339 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1340 };
1341
1342 builder.ensure(CrateNotDefault {
1343 compiler,
1344 target: run.target,
1345 test_kind,
1346 krate: match run.path {
1347 _ if run.path.ends_with("src/liballoc_jemalloc") => "alloc_jemalloc",
1348 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1349 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1350 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1351 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1352 _ => panic!("unexpected path {:?}", run.path),
1353 },
1354 });
1355 }
1356
1357 fn run(self, builder: &Builder) {
1358 builder.ensure(Crate {
1359 compiler: self.compiler,
1360 target: self.target,
1361 mode: Mode::Libstd,
1362 test_kind: self.test_kind,
1363 krate: INTERNER.intern_str(self.krate),
1364 });
1365 }
1366}
1367
1368
1369#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1370pub struct Crate {
1371 compiler: Compiler,
1372 target: Interned<String>,
1373 mode: Mode,
1374 test_kind: TestKind,
1375 krate: Interned<String>,
1376}
1377
1378impl Step for Crate {
1379 type Output = ();
1380 const DEFAULT: bool = true;
1381
1382 fn should_run(mut run: ShouldRun) -> ShouldRun {
1383 let builder = run.builder;
1384 run = run.krate("test");
1385 for krate in run.builder.in_tree_crates("std") {
1386 if krate.is_local(&run.builder) &&
1387 !krate.name.contains("jemalloc") &&
1388 !(krate.name.starts_with("rustc_") && krate.name.ends_with("san")) &&
1389 krate.name != "dlmalloc" {
1390 run = run.path(krate.local_path(&builder).to_str().unwrap());
1391 }
1392 }
1393 run
1394 }
1395
1396 fn make_run(run: RunConfig) {
1397 let builder = run.builder;
1398 let compiler = builder.compiler(builder.top_stage, run.host);
1399
1400 let make = |mode: Mode, krate: &CargoCrate| {
Mark Simulacrum6b3413d2017-07-05 12:41:271401 let test_kind = if builder.kind == Kind::Test {
1402 TestKind::Test
1403 } else if builder.kind == Kind::Bench {
1404 TestKind::Bench
1405 } else {
Mark Simulacrum981afa52017-07-18 21:28:531406 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
Mark Simulacrum6b3413d2017-07-05 12:41:271407 };
1408
Mark Simulacrum981afa52017-07-18 21:28:531409 builder.ensure(Crate {
Mark Simulacrum6a67a052017-07-20 23:51:071410 compiler,
1411 target: run.target,
Zack M. Davis1b6c9602017-08-07 05:54:091412 mode,
1413 test_kind,
Mark Simulacrumf104b122018-02-11 16:51:581414 krate: krate.name,
Mark Simulacrum6b3413d2017-07-05 12:41:271415 });
1416 };
1417
Mark Simulacrumf104b122018-02-11 16:51:581418 for krate in builder.in_tree_crates("std") {
1419 if run.path.ends_with(&krate.local_path(&builder)) {
1420 make(Mode::Libstd, krate);
Mark Simulacrum6b3413d2017-07-05 12:41:271421 }
Mark Simulacrumf104b122018-02-11 16:51:581422 }
1423 for krate in builder.in_tree_crates("test") {
1424 if run.path.ends_with(&krate.local_path(&builder)) {
1425 make(Mode::Libtest, krate);
Mark Simulacrum6b3413d2017-07-05 12:41:271426 }
Mark Simulacrum6b3413d2017-07-05 12:41:271427 }
1428 }
Alex Crichton7046fea2016-12-25 23:20:331429
Mark Simulacrumf104b122018-02-11 16:51:581430 /// Run all unit tests plus documentation tests for a given crate defined
1431 /// by a `Cargo.toml` (single manifest)
Mark Simulacrum001e9f32017-07-05 01:41:431432 ///
1433 /// This is what runs tests for crates like the standard library, compiler, etc.
1434 /// It essentially is the driver for running `cargo test`.
1435 ///
1436 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1437 /// arguments, and those arguments are discovered from `cargo metadata`.
1438 fn run(self, builder: &Builder) {
1439 let build = builder.build;
1440 let compiler = self.compiler;
1441 let target = self.target;
1442 let mode = self.mode;
1443 let test_kind = self.test_kind;
1444 let krate = self.krate;
Alex Crichtonbb9062a2016-04-29 21:23:151445
Mark Simulacrum6b3413d2017-07-05 12:41:271446 builder.ensure(compile::Test { compiler, target });
1447 builder.ensure(RemoteCopyLibs { compiler, target });
Mark Simulacrum001e9f32017-07-05 01:41:431448
1449 // If we're not doing a full bootstrap but we're testing a stage2 version of
1450 // libstd, then what we're actually testing is the libstd produced in
1451 // stage1. Reflect that here by updating the compiler that we're working
1452 // with automatically.
1453 let compiler = if build.force_use_stage1(compiler, target) {
Mark Simulacrum6b3413d2017-07-05 12:41:271454 builder.compiler(1, compiler.host)
Mark Simulacrum001e9f32017-07-05 01:41:431455 } else {
1456 compiler.clone()
1457 };
1458
Alex Crichton90105672017-07-17 16:32:081459 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
Mark Simulacrumf104b122018-02-11 16:51:581460 match mode {
Alex Crichton90105672017-07-17 16:32:081461 Mode::Libstd => {
Alex Crichtonbe902e72018-03-05 17:47:541462 compile::std_cargo(builder, &compiler, target, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081463 }
1464 Mode::Libtest => {
1465 compile::test_cargo(build, &compiler, target, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081466 }
1467 Mode::Librustc => {
1468 builder.ensure(compile::Rustc { compiler, target });
Alex Crichton884715c2018-01-22 15:29:241469 compile::rustc_cargo(build, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081470 }
1471 _ => panic!("can only test libraries"),
1472 };
Alex Crichton90105672017-07-17 16:32:081473
Mark Simulacrum001e9f32017-07-05 01:41:431474 // Build up the base `cargo test` command.
1475 //
1476 // Pass in some standard flags then iterate over the graph we've discovered
1477 // in `cargo metadata` with the maps above and figure out what `-p`
1478 // arguments need to get passed.
Mark Simulacrum001e9f32017-07-05 01:41:431479 if test_kind.subcommand() == "test" && !build.fail_fast {
1480 cargo.arg("--no-fail-fast");
Alex Crichtonbb9062a2016-04-29 21:23:151481 }
Guillaume Gomez8e469272018-02-17 14:45:391482 if build.doc_tests {
1483 cargo.arg("--doc");
1484 }
Mark Simulacrum001e9f32017-07-05 01:41:431485
Mark Simulacrumf104b122018-02-11 16:51:581486 cargo.arg("-p").arg(krate);
Alex Crichtonbb9062a2016-04-29 21:23:151487
Mark Simulacrum001e9f32017-07-05 01:41:431488 // The tests are going to run with the *target* libraries, so we need to
1489 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1490 //
1491 // Note that to run the compiler we need to run with the *host* libraries,
1492 // but our wrapper scripts arrange for that to be the case anyway.
1493 let mut dylib_path = dylib_path();
Mark Simulacrum528646e2017-07-14 00:48:441494 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
Mark Simulacrum001e9f32017-07-05 01:41:431495 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
Alex Crichtonbb9062a2016-04-29 21:23:151496
Mark Simulacrum001e9f32017-07-05 01:41:431497 cargo.arg("--");
Mark Simulacrum44ffb612017-07-30 04:12:531498 cargo.args(&build.config.cmd.test_args());
Alex Crichton0e272de2016-11-16 20:31:191499
Mark Simulacrum001e9f32017-07-05 01:41:431500 if build.config.quiet_tests {
1501 cargo.arg("--quiet");
1502 }
Corey Farwellc8c6d2c2016-10-30 01:58:521503
Mark Simulacrum001e9f32017-07-05 01:41:431504 if target.contains("emscripten") {
Alex Crichton8e7849e2017-07-29 00:52:441505 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1506 build.config.nodejs.as_ref().expect("nodejs not configured"));
Oliver Schneideracdf83f2017-12-06 08:25:291507 } else if target.starts_with("wasm32") {
Diggory Blake0e6601f2018-01-11 17:51:491508 // Warn about running tests without the `wasm_syscall` feature enabled.
1509 // The javascript shim implements the syscall interface so that test
1510 // output can be correctly reported.
1511 if !build.config.wasm_syscall {
Mark Simulacrum545b92f2018-03-28 15:25:091512 build.info(&format!("Libstd was built without `wasm_syscall` feature enabled: \
1513 test output may not be visible."));
Diggory Blake0e6601f2018-01-11 17:51:491514 }
1515
Oliver Schneideracdf83f2017-12-06 08:25:291516 // On the wasm32-unknown-unknown target we're using LTO which is
1517 // incompatible with `-C prefer-dynamic`, so disable that here
1518 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
1519
1520 let node = build.config.nodejs.as_ref()
1521 .expect("nodejs not configured");
1522 let runner = format!("{} {}/src/etc/wasm32-shim.js",
1523 node.display(),
1524 build.src.display());
1525 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
Mark Simulacrum001e9f32017-07-05 01:41:431526 } else if build.remote_tested(target) {
Alex Crichton8e7849e2017-07-29 00:52:441527 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1528 format!("{} run",
1529 builder.tool_exe(Tool::RemoteTestClient).display()));
Mark Simulacrum001e9f32017-07-05 01:41:431530 }
Alex Crichton6fd4d672018-03-16 15:35:031531
1532 let _folder = build.fold_output(|| {
1533 format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, krate)
1534 });
Mark Simulacrum545b92f2018-03-28 15:25:091535 build.info(&format!("{} {} stage{} ({} -> {})", test_kind, krate, compiler.stage,
1536 &compiler.host, target));
1537 let _time = util::timeit(&build);
Alex Crichton8e7849e2017-07-29 00:52:441538 try_run(build, &mut cargo);
Alex Crichton39a5d3f2016-06-28 20:31:301539 }
1540}
1541
Mark Simulacrumf87696b2017-09-02 14:02:321542#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrumf104b122018-02-11 16:51:581543pub struct CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321544 host: Interned<String>,
1545 test_kind: TestKind,
1546}
1547
Mark Simulacrumf104b122018-02-11 16:51:581548impl Step for CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321549 type Output = ();
1550 const DEFAULT: bool = true;
1551 const ONLY_HOSTS: bool = true;
1552
1553 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumf104b122018-02-11 16:51:581554 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
Mark Simulacrumf87696b2017-09-02 14:02:321555 }
1556
1557 fn make_run(run: RunConfig) {
1558 let builder = run.builder;
1559
1560 let test_kind = if builder.kind == Kind::Test {
1561 TestKind::Test
1562 } else if builder.kind == Kind::Bench {
1563 TestKind::Bench
1564 } else {
1565 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1566 };
1567
Mark Simulacrumf104b122018-02-11 16:51:581568 builder.ensure(CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321569 host: run.host,
1570 test_kind,
1571 });
1572 }
1573
1574 fn run(self, builder: &Builder) {
1575 let build = builder.build;
1576 let test_kind = self.test_kind;
1577
1578 let compiler = builder.compiler(builder.top_stage, self.host);
1579 let target = compiler.host;
1580
Alex Crichton3da54fb2017-09-15 22:28:591581 let mut cargo = tool::prepare_tool_cargo(builder,
1582 compiler,
1583 target,
1584 test_kind.subcommand(),
1585 "src/tools/rustdoc");
Mark Simulacrumf87696b2017-09-02 14:02:321586 if test_kind.subcommand() == "test" && !build.fail_fast {
1587 cargo.arg("--no-fail-fast");
1588 }
1589
1590 cargo.arg("-p").arg("rustdoc:0.0.0");
1591
1592 cargo.arg("--");
1593 cargo.args(&build.config.cmd.test_args());
1594
1595 if build.config.quiet_tests {
1596 cargo.arg("--quiet");
1597 }
1598
Alex Crichton6fd4d672018-03-16 15:35:031599 let _folder = build.fold_output(|| {
1600 format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage)
1601 });
Mark Simulacrum545b92f2018-03-28 15:25:091602 build.info(&format!("{} rustdoc stage{} ({} -> {})", test_kind, compiler.stage,
1603 &compiler.host, target));
1604 let _time = util::timeit(&build);
Mark Simulacrumf87696b2017-09-02 14:02:321605
1606 try_run(build, &mut cargo);
1607 }
1608}
1609
Alex Crichton8e7849e2017-07-29 00:52:441610fn envify(s: &str) -> String {
1611 s.chars().map(|c| {
1612 match c {
1613 '-' => '_',
1614 c => c,
Alex Crichton1747ce22017-01-28 21:38:061615 }
Alex Crichton8e7849e2017-07-29 00:52:441616 }).flat_map(|c| c.to_uppercase()).collect()
Alex Crichton39a5d3f2016-06-28 20:31:301617}
1618
Mark Simulacrumceecd622017-07-12 16:12:471619/// Some test suites are run inside emulators or on remote devices, and most
1620/// of our test binaries are linked dynamically which means we need to ship
1621/// the standard library and such to the emulator ahead of time. This step
1622/// represents this and is a dependency of all test suites.
1623///
1624/// Most of the time this is a noop. For some steps such as shipping data to
1625/// QEMU we have to build our own tools so we've got conditional dependencies
1626/// on those programs as well. Note that the remote test client is built for
1627/// the build target (us) and the server is built for the target.
Mark Simulacrum528646e2017-07-14 00:48:441628#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1629pub struct RemoteCopyLibs {
1630 compiler: Compiler,
1631 target: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:431632}
Alex Crichton1747ce22017-01-28 21:38:061633
Mark Simulacrum528646e2017-07-14 00:48:441634impl Step for RemoteCopyLibs {
Mark Simulacrum001e9f32017-07-05 01:41:431635 type Output = ();
Alex Crichton1747ce22017-01-28 21:38:061636
Mark Simulacrum56128fb2017-07-19 00:03:381637 fn should_run(run: ShouldRun) -> ShouldRun {
1638 run.never()
Mark Simulacrum681b1232017-07-14 12:30:161639 }
1640
Mark Simulacrum001e9f32017-07-05 01:41:431641 fn run(self, builder: &Builder) {
1642 let build = builder.build;
1643 let compiler = self.compiler;
1644 let target = self.target;
1645 if !build.remote_tested(target) {
1646 return
1647 }
Alex Crichton1747ce22017-01-28 21:38:061648
Mark Simulacrum6b3413d2017-07-05 12:41:271649 builder.ensure(compile::Test { compiler, target });
1650
Mark Simulacrum545b92f2018-03-28 15:25:091651 build.info(&format!("REMOTE copy libs to emulator ({})", target));
Mark Simulacrum001e9f32017-07-05 01:41:431652 t!(fs::create_dir_all(build.out.join("tmp")));
1653
Mark Simulacrumfe0eca02017-07-23 01:29:081654 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
Mark Simulacrum001e9f32017-07-05 01:41:431655
1656 // Spawn the emulator and wait for it to come online
Mark Simulacrum6b3413d2017-07-05 12:41:271657 let tool = builder.tool_exe(Tool::RemoteTestClient);
Mark Simulacrum001e9f32017-07-05 01:41:431658 let mut cmd = Command::new(&tool);
1659 cmd.arg("spawn-emulator")
1660 .arg(target)
1661 .arg(&server)
1662 .arg(build.out.join("tmp"));
1663 if let Some(rootfs) = build.qemu_rootfs(target) {
1664 cmd.arg(rootfs);
1665 }
1666 build.run(&mut cmd);
1667
1668 // Push all our dylibs to the emulator
Mark Simulacrum60388302017-07-05 16:46:411669 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
Mark Simulacrum001e9f32017-07-05 01:41:431670 let f = t!(f);
1671 let name = f.file_name().into_string().unwrap();
1672 if util::is_dylib(&name) {
1673 build.run(Command::new(&tool)
1674 .arg("push")
1675 .arg(f.path()));
1676 }
Alex Crichton1747ce22017-01-28 21:38:061677 }
1678 }
1679}
1680
Mark Simulacrum528646e2017-07-14 00:48:441681#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum001e9f32017-07-05 01:41:431682pub struct Distcheck;
1683
Mark Simulacrum528646e2017-07-14 00:48:441684impl Step for Distcheck {
Mark Simulacrum001e9f32017-07-05 01:41:431685 type Output = ();
1686
Mark Simulacrum56128fb2017-07-19 00:03:381687 fn should_run(run: ShouldRun) -> ShouldRun {
1688 run.path("distcheck")
Mark Simulacrum681b1232017-07-14 12:30:161689 }
1690
Mark Simulacrum8f2e5762017-07-22 13:35:421691 fn make_run(run: RunConfig) {
1692 run.builder.ensure(Distcheck);
1693 }
1694
Mark Simulacrum001e9f32017-07-05 01:41:431695 /// Run "distcheck", a 'make check' from a tarball
1696 fn run(self, builder: &Builder) {
1697 let build = builder.build;
1698
Mark Simulacrum545b92f2018-03-28 15:25:091699 build.info(&format!("Distcheck"));
Mark Simulacrum001e9f32017-07-05 01:41:431700 let dir = build.out.join("tmp").join("distcheck");
1701 let _ = fs::remove_dir_all(&dir);
1702 t!(fs::create_dir_all(&dir));
1703
Mark Simulacrum1c118232017-07-22 16:48:291704 // Guarantee that these are built before we begin running.
1705 builder.ensure(dist::PlainSourceTarball);
1706 builder.ensure(dist::Src);
1707
Mark Simulacrum001e9f32017-07-05 01:41:431708 let mut cmd = Command::new("tar");
1709 cmd.arg("-xzf")
Mark Simulacrum5984e702017-07-13 00:52:311710 .arg(builder.ensure(dist::PlainSourceTarball))
Mark Simulacrum001e9f32017-07-05 01:41:431711 .arg("--strip-components=1")
1712 .current_dir(&dir);
1713 build.run(&mut cmd);
1714 build.run(Command::new("./configure")
1715 .args(&build.config.configure_args)
1716 .arg("--enable-vendor")
1717 .current_dir(&dir));
1718 build.run(Command::new(build_helper::make(&build.build))
1719 .arg("check")
1720 .current_dir(&dir));
1721
1722 // Now make sure that rust-src has all of libstd's dependencies
Mark Simulacrum545b92f2018-03-28 15:25:091723 build.info(&format!("Distcheck rust-src"));
Mark Simulacrum001e9f32017-07-05 01:41:431724 let dir = build.out.join("tmp").join("distcheck-src");
1725 let _ = fs::remove_dir_all(&dir);
1726 t!(fs::create_dir_all(&dir));
1727
1728 let mut cmd = Command::new("tar");
1729 cmd.arg("-xzf")
Mark Simulacrum5984e702017-07-13 00:52:311730 .arg(builder.ensure(dist::Src))
Mark Simulacrum001e9f32017-07-05 01:41:431731 .arg("--strip-components=1")
1732 .current_dir(&dir);
1733 build.run(&mut cmd);
1734
1735 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
1736 build.run(Command::new(&build.initial_cargo)
1737 .arg("generate-lockfile")
1738 .arg("--manifest-path")
1739 .arg(&toml)
1740 .current_dir(&dir));
Alex Crichtond38db822016-12-09 01:13:551741 }
Alex Crichtond38db822016-12-09 01:13:551742}
Alex Crichton1a040b32016-12-31 03:50:571743
Mark Simulacrum528646e2017-07-14 00:48:441744#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum001e9f32017-07-05 01:41:431745pub struct Bootstrap;
1746
Mark Simulacrum528646e2017-07-14 00:48:441747impl Step for Bootstrap {
Mark Simulacrum001e9f32017-07-05 01:41:431748 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271749 const DEFAULT: bool = true;
1750 const ONLY_HOSTS: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:431751
1752 /// Test the build system itself
1753 fn run(self, builder: &Builder) {
1754 let build = builder.build;
1755 let mut cmd = Command::new(&build.initial_cargo);
1756 cmd.arg("test")
1757 .current_dir(build.src.join("src/bootstrap"))
Mark Simulacrum42fde212018-03-10 14:03:061758 .env("RUSTFLAGS", "-Cdebuginfo=2")
Mark Simulacrum001e9f32017-07-05 01:41:431759 .env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
1760 .env("RUSTC_BOOTSTRAP", "1")
1761 .env("RUSTC", &build.initial_rustc);
Simon Sapine993e622018-03-23 18:55:411762 if let Some(flags) = option_env!("RUSTFLAGS") {
1763 // Use the same rustc flags for testing as for "normal" compilation,
1764 // so that Cargo doesn’t recompile the entire dependency graph every time:
1765 // https://github.com/rust-lang/rust/issues/49215
1766 cmd.env("RUSTFLAGS", flags);
1767 }
Mark Simulacrum001e9f32017-07-05 01:41:431768 if !build.fail_fast {
1769 cmd.arg("--no-fail-fast");
1770 }
Mark Simulacrum44ffb612017-07-30 04:12:531771 cmd.arg("--").args(&build.config.cmd.test_args());
Mark Simulacrum001e9f32017-07-05 01:41:431772 try_run(build, &mut cmd);
Josh Stone617aea42017-06-02 16:27:441773 }
Mark Simulacrum6b3413d2017-07-05 12:41:271774
Mark Simulacrum56128fb2017-07-19 00:03:381775 fn should_run(run: ShouldRun) -> ShouldRun {
1776 run.path("src/bootstrap")
Mark Simulacrum6b3413d2017-07-05 12:41:271777 }
1778
Mark Simulacrum6a67a052017-07-20 23:51:071779 fn make_run(run: RunConfig) {
1780 run.builder.ensure(Bootstrap);
Mark Simulacrum6b3413d2017-07-05 12:41:271781 }
Alex Crichton1a040b32016-12-31 03:50:571782}