blob: 39740a83b0d0a804d267fa33eb7fbfc948a94e3c [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) {
462 let rustdoc = builder.rustdoc(self.compiler.host);
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
Mark Simulacrum528646e2017-07-14 00:48:44517#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum1c8f3b02018-02-11 22:41:06518pub struct Tidy;
Mark Simulacrum001e9f32017-07-05 01:41:43519
Mark Simulacrum528646e2017-07-14 00:48:44520impl Step for Tidy {
Mark Simulacrum001e9f32017-07-05 01:41:43521 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27522 const DEFAULT: bool = true;
523 const ONLY_HOSTS: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:43524
Mark Simulacrum1c8f3b02018-02-11 22:41:06525 /// Runs the `tidy` tool.
Mark Simulacrum001e9f32017-07-05 01:41:43526 ///
527 /// This tool in `src/tools` checks up on various bits and pieces of style and
528 /// otherwise just implements a few lint-like checks that are specific to the
529 /// compiler itself.
530 fn run(self, builder: &Builder) {
531 let build = builder.build;
Mark Simulacrum001e9f32017-07-05 01:41:43532
Mark Simulacrum60388302017-07-05 16:46:41533 let mut cmd = builder.tool_cmd(Tool::Tidy);
Mark Simulacrum001e9f32017-07-05 01:41:43534 cmd.arg(build.src.join("src"));
Mark Mansib9b1c372018-02-26 17:05:43535 cmd.arg(&build.initial_cargo);
Mark Simulacrum001e9f32017-07-05 01:41:43536 if !build.config.vendor {
537 cmd.arg("--no-vendor");
538 }
539 if build.config.quiet_tests {
540 cmd.arg("--quiet");
541 }
Alex Crichton6fd4d672018-03-16 15:35:03542
543 let _folder = build.fold_output(|| "tidy");
Mark Simulacrum545b92f2018-03-28 15:25:09544 builder.info(&format!("tidy check"));
Mark Simulacrum001e9f32017-07-05 01:41:43545 try_run(build, &mut cmd);
Eduard-Mihai Burtescud29f0bc2017-02-10 20:59:40546 }
Mark Simulacrum6b3413d2017-07-05 12:41:27547
Mark Simulacrum56128fb2017-07-19 00:03:38548 fn should_run(run: ShouldRun) -> ShouldRun {
549 run.path("src/tools/tidy")
Mark Simulacrum6b3413d2017-07-05 12:41:27550 }
551
Mark Simulacrum6a67a052017-07-20 23:51:07552 fn make_run(run: RunConfig) {
Mark Simulacrum1c8f3b02018-02-11 22:41:06553 run.builder.ensure(Tidy);
Mark Simulacrum6b3413d2017-07-05 12:41:27554 }
Alex Crichton9dd3c542016-03-29 20:14:52555}
Alex Crichtonb325baf2016-04-05 18:34:23556
Mark Simulacrum528646e2017-07-14 00:48:44557fn testdir(build: &Build, host: Interned<String>) -> PathBuf {
Alex Crichtonb325baf2016-04-05 18:34:23558 build.out.join(host).join("test")
559}
560
Mark Simulacrumf104b122018-02-11 16:51:58561macro_rules! default_test {
562 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
563 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
564 }
Mark Simulacrum1ab89302017-07-07 17:51:57565}
566
Mark Simulacrumf104b122018-02-11 16:51:58567macro_rules! host_test {
568 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
569 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
570 }
571}
Mark Simulacrum6b3413d2017-07-05 12:41:27572
Mark Simulacrumf104b122018-02-11 16:51:58573macro_rules! test {
574 ($name:ident {
575 path: $path:expr,
576 mode: $mode:expr,
577 suite: $suite:expr,
578 default: $default:expr,
579 host: $host:expr
580 }) => {
581 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
582 pub struct $name {
583 pub compiler: Compiler,
584 pub target: Interned<String>,
585 }
586
587 impl Step for $name {
588 type Output = ();
589 const DEFAULT: bool = $default;
590 const ONLY_HOSTS: bool = $host;
591
592 fn should_run(run: ShouldRun) -> ShouldRun {
593 run.path($path)
594 }
595
596 fn make_run(run: RunConfig) {
597 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
598
599 run.builder.ensure($name {
600 compiler,
601 target: run.target,
602 });
603 }
604
605 fn run(self, builder: &Builder) {
606 builder.ensure(Compiletest {
607 compiler: self.compiler,
608 target: self.target,
609 mode: $mode,
610 suite: $suite,
611 })
612 }
613 }
614 }
615}
616
617default_test!(Ui {
618 path: "src/test/ui",
619 mode: "ui",
620 suite: "ui"
621});
622
623default_test!(RunPass {
624 path: "src/test/run-pass",
625 mode: "run-pass",
626 suite: "run-pass"
627});
628
629default_test!(CompileFail {
630 path: "src/test/compile-fail",
631 mode: "compile-fail",
632 suite: "compile-fail"
633});
634
635default_test!(ParseFail {
636 path: "src/test/parse-fail",
637 mode: "parse-fail",
638 suite: "parse-fail"
639});
640
641default_test!(RunFail {
642 path: "src/test/run-fail",
643 mode: "run-fail",
644 suite: "run-fail"
645});
646
647default_test!(RunPassValgrind {
648 path: "src/test/run-pass-valgrind",
649 mode: "run-pass-valgrind",
650 suite: "run-pass-valgrind"
651});
652
653default_test!(MirOpt {
654 path: "src/test/mir-opt",
655 mode: "mir-opt",
656 suite: "mir-opt"
657});
658
659default_test!(Codegen {
660 path: "src/test/codegen",
661 mode: "codegen",
662 suite: "codegen"
663});
664
665default_test!(CodegenUnits {
666 path: "src/test/codegen-units",
667 mode: "codegen-units",
668 suite: "codegen-units"
669});
670
671default_test!(Incremental {
672 path: "src/test/incremental",
673 mode: "incremental",
674 suite: "incremental"
675});
676
677default_test!(Debuginfo {
678 path: "src/test/debuginfo",
Mark Simulacrumaa8b93b2017-07-07 18:31:29679 // What this runs varies depending on the native platform being apple
Mark Simulacrumf104b122018-02-11 16:51:58680 mode: "debuginfo-XXX",
681 suite: "debuginfo"
682});
Mark Simulacrum6b3413d2017-07-05 12:41:27683
Mark Simulacrumf104b122018-02-11 16:51:58684host_test!(UiFullDeps {
685 path: "src/test/ui-fulldeps",
686 mode: "ui",
687 suite: "ui-fulldeps"
688});
Mark Simulacrumf1d04a32017-07-20 15:42:18689
Mark Simulacrumf104b122018-02-11 16:51:58690host_test!(RunPassFullDeps {
691 path: "src/test/run-pass-fulldeps",
692 mode: "run-pass",
693 suite: "run-pass-fulldeps"
694});
Mark Simulacrumf1d04a32017-07-20 15:42:18695
Mark Simulacrumf104b122018-02-11 16:51:58696host_test!(RunFailFullDeps {
697 path: "src/test/run-fail-fulldeps",
698 mode: "run-fail",
699 suite: "run-fail-fulldeps"
700});
Mark Simulacrumf1d04a32017-07-20 15:42:18701
Mark Simulacrumf104b122018-02-11 16:51:58702host_test!(CompileFailFullDeps {
703 path: "src/test/compile-fail-fulldeps",
704 mode: "compile-fail",
705 suite: "compile-fail-fulldeps"
706});
Mark Simulacrumf1d04a32017-07-20 15:42:18707
Mark Simulacrumf104b122018-02-11 16:51:58708host_test!(IncrementalFullDeps {
709 path: "src/test/incremental-fulldeps",
710 mode: "incremental",
711 suite: "incremental-fulldeps"
712});
Mark Simulacrumf1d04a32017-07-20 15:42:18713
Mark Simulacrumf104b122018-02-11 16:51:58714host_test!(Rustdoc {
715 path: "src/test/rustdoc",
716 mode: "rustdoc",
717 suite: "rustdoc"
718});
Mark Simulacrumf1d04a32017-07-20 15:42:18719
Mark Simulacrumf104b122018-02-11 16:51:58720test!(Pretty {
721 path: "src/test/pretty",
722 mode: "pretty",
723 suite: "pretty",
724 default: false,
725 host: true
726});
727test!(RunPassPretty {
728 path: "src/test/run-pass/pretty",
729 mode: "pretty",
730 suite: "run-pass",
731 default: false,
732 host: true
733});
734test!(RunFailPretty {
735 path: "src/test/run-fail/pretty",
736 mode: "pretty",
737 suite: "run-fail",
738 default: false,
739 host: true
740});
741test!(RunPassValgrindPretty {
742 path: "src/test/run-pass-valgrind/pretty",
743 mode: "pretty",
744 suite: "run-pass-valgrind",
745 default: false,
746 host: true
747});
748test!(RunPassFullDepsPretty {
749 path: "src/test/run-pass-fulldeps/pretty",
750 mode: "pretty",
751 suite: "run-pass-fulldeps",
752 default: false,
753 host: true
754});
755test!(RunFailFullDepsPretty {
756 path: "src/test/run-fail-fulldeps/pretty",
757 mode: "pretty",
758 suite: "run-fail-fulldeps",
759 default: false,
760 host: true
761});
Mark Simulacrumf1d04a32017-07-20 15:42:18762
Alex Crichton7df6f412018-03-09 17:26:15763default_test!(RunMake {
Mark Simulacrumf104b122018-02-11 16:51:58764 path: "src/test/run-make",
765 mode: "run-make",
766 suite: "run-make"
767});
Mark Simulacrumf1d04a32017-07-20 15:42:18768
Alex Crichton7df6f412018-03-09 17:26:15769host_test!(RunMakeFullDeps {
770 path: "src/test/run-make-fulldeps",
771 mode: "run-make",
772 suite: "run-make-fulldeps"
773});
774
Mark Simulacrumf1d04a32017-07-20 15:42:18775#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
776struct Compiletest {
777 compiler: Compiler,
778 target: Interned<String>,
779 mode: &'static str,
780 suite: &'static str,
781}
782
783impl Step for Compiletest {
784 type Output = ();
785
786 fn should_run(run: ShouldRun) -> ShouldRun {
787 run.never()
788 }
789
Mark Simulacrum001e9f32017-07-05 01:41:43790 /// Executes the `compiletest` tool to run a suite of tests.
791 ///
792 /// Compiles all tests with `compiler` for `target` with the specified
793 /// compiletest `mode` and `suite` arguments. For example `mode` can be
794 /// "run-pass" or `suite` can be something like `debuginfo`.
795 fn run(self, builder: &Builder) {
796 let build = builder.build;
797 let compiler = self.compiler;
798 let target = self.target;
799 let mode = self.mode;
800 let suite = self.suite;
Mark Simulacrum6b3413d2017-07-05 12:41:27801
802 // Skip codegen tests if they aren't enabled in configuration.
803 if !build.config.codegen_tests && suite == "codegen" {
804 return;
805 }
806
807 if suite == "debuginfo" {
Mark Simulacrum951616c2017-07-20 17:23:29808 // Skip debuginfo tests on MSVC
809 if build.build.contains("msvc") {
810 return;
811 }
812
Mark Simulacrum6b3413d2017-07-05 12:41:27813 if mode == "debuginfo-XXX" {
814 return if build.build.contains("apple") {
815 builder.ensure(Compiletest {
816 mode: "debuginfo-lldb",
817 ..self
Mark Simulacrum528646e2017-07-14 00:48:44818 });
Mark Simulacrum6b3413d2017-07-05 12:41:27819 } else {
820 builder.ensure(Compiletest {
821 mode: "debuginfo-gdb",
822 ..self
Mark Simulacrum528646e2017-07-14 00:48:44823 });
Mark Simulacrum6b3413d2017-07-05 12:41:27824 };
825 }
826
Mark Simulacrum6b3413d2017-07-05 12:41:27827 builder.ensure(dist::DebuggerScripts {
Mark Simulacrum528646e2017-07-14 00:48:44828 sysroot: builder.sysroot(compiler),
Mark Simulacrumfef9b482017-07-23 16:03:40829 host: target
Mark Simulacrum6b3413d2017-07-05 12:41:27830 });
831 }
832
833 if suite.ends_with("fulldeps") ||
834 // FIXME: Does pretty need librustc compiled? Note that there are
835 // fulldeps test suites with mode = pretty as well.
836 mode == "pretty" ||
Alex Crichton7df6f412018-03-09 17:26:15837 mode == "rustdoc" {
Mark Simulacrum6b3413d2017-07-05 12:41:27838 builder.ensure(compile::Rustc { compiler, target });
839 }
840
841 builder.ensure(compile::Test { compiler, target });
842 builder.ensure(native::TestHelpers { target });
Mark Simulacrumaa8b93b2017-07-07 18:31:29843 builder.ensure(RemoteCopyLibs { compiler, target });
Mark Simulacrum6b3413d2017-07-05 12:41:27844
Mark Simulacrum6b3413d2017-07-05 12:41:27845 let mut cmd = builder.tool_cmd(Tool::Compiletest);
Alex Crichtonb325baf2016-04-05 18:34:23846
Mark Simulacrum001e9f32017-07-05 01:41:43847 // compiletest currently has... a lot of arguments, so let's just pass all
848 // of them!
Brian Anderson8401e372016-09-15 19:42:26849
Mark Simulacrumc114fe52017-07-05 17:21:33850 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
Mark Simulacrum60388302017-07-05 16:46:41851 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
Mark Simulacrumc114fe52017-07-05 17:21:33852 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
Mark Simulacrum4e5333c2017-07-25 22:54:33853
854 // Avoid depending on rustdoc when we don't need it.
Alex Crichton7df6f412018-03-09 17:26:15855 if mode == "rustdoc" || (mode == "run-make" && suite.ends_with("fulldeps")) {
Mark Simulacrumfacf5a92017-08-04 22:13:01856 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host));
Mark Simulacrum4e5333c2017-07-25 22:54:33857 }
858
Mark Simulacrum001e9f32017-07-05 01:41:43859 cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
860 cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
861 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
862 cmd.arg("--mode").arg(mode);
863 cmd.arg("--target").arg(target);
Mark Simulacrum528646e2017-07-14 00:48:44864 cmd.arg("--host").arg(&*compiler.host);
865 cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(build.build));
Alex Crichtonf4e4ec72016-05-13 22:26:41866
Mark Simulacrum001e9f32017-07-05 01:41:43867 if let Some(ref nodejs) = build.config.nodejs {
868 cmd.arg("--nodejs").arg(nodejs);
869 }
Alex Crichtonf4e4ec72016-05-13 22:26:41870
Mark Simulacrum001e9f32017-07-05 01:41:43871 let mut flags = vec!["-Crpath".to_string()];
872 if build.config.rust_optimize_tests {
873 flags.push("-O".to_string());
874 }
875 if build.config.rust_debuginfo_tests {
876 flags.push("-g".to_string());
877 }
Oliver Schneider8c2ec682017-12-11 21:27:32878 flags.push("-Zmiri -Zunstable-options".to_string());
Santiago Pastorinodb41f1e2018-01-18 22:44:41879 flags.push(build.config.cmd.rustc_args().join(" "));
Alex Crichtoncbe62922016-04-19 16:44:19880
Oliver Schneideracdf83f2017-12-06 08:25:29881 if let Some(linker) = build.linker(target) {
882 cmd.arg("--linker").arg(linker);
883 }
884
885 let hostflags = flags.clone();
Mark Simulacrum001e9f32017-07-05 01:41:43886 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
Alex Crichtoncbe62922016-04-19 16:44:19887
Oliver Schneideracdf83f2017-12-06 08:25:29888 let mut targetflags = flags.clone();
Mark Simulacrum001e9f32017-07-05 01:41:43889 targetflags.push(format!("-Lnative={}",
890 build.test_helpers_out(target).display()));
891 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
Alex Crichtonb325baf2016-04-05 18:34:23892
Mark Simulacrum001e9f32017-07-05 01:41:43893 cmd.arg("--docck-python").arg(build.python());
Alex Crichtonb325baf2016-04-05 18:34:23894
Mark Simulacrum001e9f32017-07-05 01:41:43895 if build.build.ends_with("apple-darwin") {
896 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
897 // LLDB plugin's compiled module which only works with the system python
898 // (namely not Homebrew-installed python)
899 cmd.arg("--lldb-python").arg("/usr/bin/python");
900 } else {
901 cmd.arg("--lldb-python").arg(build.python());
902 }
Alex Crichtonb325baf2016-04-05 18:34:23903
Mark Simulacrum001e9f32017-07-05 01:41:43904 if let Some(ref gdb) = build.config.gdb {
905 cmd.arg("--gdb").arg(gdb);
906 }
907 if let Some(ref vers) = build.lldb_version {
908 cmd.arg("--lldb-version").arg(vers);
909 }
910 if let Some(ref dir) = build.lldb_python_dir {
911 cmd.arg("--lldb-python-dir").arg(dir);
912 }
Alex Crichtonb325baf2016-04-05 18:34:23913
Mark Simulacrum44ffb612017-07-30 04:12:53914 cmd.args(&build.config.cmd.test_args());
Corey Farwellc8c6d2c2016-10-30 01:58:52915
Mark Simulacrum001e9f32017-07-05 01:41:43916 if build.is_verbose() {
917 cmd.arg("--verbose");
918 }
Alex Crichton126e09e2016-04-14 22:51:03919
Mark Simulacrum001e9f32017-07-05 01:41:43920 if build.config.quiet_tests {
921 cmd.arg("--quiet");
922 }
Alex Crichton1747ce22017-01-28 21:38:06923
bjorn30c97bbf2017-08-13 10:30:54924 if build.config.llvm_enabled {
Alex Crichtonbe902e72018-03-05 17:47:54925 let llvm_config = builder.ensure(native::Llvm {
926 target: build.config.build,
927 emscripten: false,
928 });
bjorn30c97bbf2017-08-13 10:30:54929 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
930 cmd.arg("--llvm-version").arg(llvm_version);
931 if !build.is_rust_llvm(target) {
932 cmd.arg("--system-llvm");
933 }
934
935 // Only pass correct values for these flags for the `run-make` suite as it
936 // requires that a C++ compiler was configured which isn't always the case.
Alex Crichton7df6f412018-03-09 17:26:15937 if suite == "run-make-fulldeps" {
bjorn30c97bbf2017-08-13 10:30:54938 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
939 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
940 cmd.arg("--cc").arg(build.cc(target))
941 .arg("--cxx").arg(build.cxx(target).unwrap())
942 .arg("--cflags").arg(build.cflags(target).join(" "))
943 .arg("--llvm-components").arg(llvm_components.trim())
944 .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
Oliver Schneideracdf83f2017-12-06 08:25:29945 if let Some(ar) = build.ar(target) {
946 cmd.arg("--ar").arg(ar);
947 }
bjorn30c97bbf2017-08-13 10:30:54948 }
949 }
Alex Crichton7df6f412018-03-09 17:26:15950 if suite == "run-make-fulldeps" && !build.config.llvm_enabled {
Mark Simulacrum545b92f2018-03-28 15:25:09951 builder.info(
952 &format!("Ignoring run-make test suite as they generally don't work without LLVM"));
bjorn30c97bbf2017-08-13 10:30:54953 return;
954 }
955
Alex Crichton7df6f412018-03-09 17:26:15956 if suite != "run-make-fulldeps" {
Mark Simulacrum001e9f32017-07-05 01:41:43957 cmd.arg("--cc").arg("")
958 .arg("--cxx").arg("")
959 .arg("--cflags").arg("")
960 .arg("--llvm-components").arg("")
961 .arg("--llvm-cxxflags").arg("");
962 }
963
964 if build.remote_tested(target) {
Mark Simulacrum6b3413d2017-07-05 12:41:27965 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
Mark Simulacrum001e9f32017-07-05 01:41:43966 }
967
968 // Running a C compiler on MSVC requires a few env vars to be set, to be
969 // sure to set them here.
970 //
971 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
972 // rather than stomp over it.
973 if target.contains("msvc") {
Oliver Schneideracdf83f2017-12-06 08:25:29974 for &(ref k, ref v) in build.cc[&target].env() {
Mark Simulacrum001e9f32017-07-05 01:41:43975 if k != "PATH" {
976 cmd.env(k, v);
977 }
Alex Crichton126e09e2016-04-14 22:51:03978 }
979 }
Mark Simulacrum001e9f32017-07-05 01:41:43980 cmd.env("RUSTC_BOOTSTRAP", "1");
981 build.add_rust_test_threads(&mut cmd);
982
983 if build.config.sanitizers {
984 cmd.env("SANITIZER_SUPPORT", "1");
985 }
986
987 if build.config.profiler {
988 cmd.env("PROFILER_SUPPORT", "1");
989 }
990
Alex Crichton884715c2018-01-22 15:29:24991 cmd.env("RUST_TEST_TMPDIR", build.out.join("tmp"));
992
Mark Simulacrum001e9f32017-07-05 01:41:43993 cmd.arg("--adb-path").arg("adb");
994 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
995 if target.contains("android") {
996 // Assume that cc for this target comes from the android sysroot
997 cmd.arg("--android-cross-path")
998 .arg(build.cc(target).parent().unwrap().parent().unwrap());
999 } else {
1000 cmd.arg("--android-cross-path").arg("");
1001 }
1002
1003 build.ci_env.force_coloring_in_ci(&mut cmd);
1004
Alex Crichton6fd4d672018-03-16 15:35:031005 let _folder = build.fold_output(|| format!("test_{}", suite));
Mark Simulacrum545b92f2018-03-28 15:25:091006 builder.info(&format!("Check compiletest suite={} mode={} ({} -> {})",
1007 suite, mode, &compiler.host, target));
1008 let _time = util::timeit(&build);
Mark Simulacrum001e9f32017-07-05 01:41:431009 try_run(build, &mut cmd);
Alex Crichton126e09e2016-04-14 22:51:031010 }
Alex Crichtonb325baf2016-04-05 18:34:231011}
Alex Crichtonede89442016-04-15 01:00:351012
Mark Simulacrum528646e2017-07-14 00:48:441013#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
kennytm0d300d42018-02-21 19:13:341014struct DocTest {
Mark Simulacrum528646e2017-07-14 00:48:441015 compiler: Compiler,
kennytm0d300d42018-02-21 19:13:341016 path: &'static str,
1017 name: &'static str,
1018 is_ext_doc: bool,
Mark Simulacruma5ab2ce2017-07-12 15:15:001019}
1020
kennytm0d300d42018-02-21 19:13:341021impl Step for DocTest {
Mark Simulacruma5ab2ce2017-07-12 15:15:001022 type Output = ();
Mark Simulacruma5ab2ce2017-07-12 15:15:001023 const ONLY_HOSTS: bool = true;
Alex Crichtonede89442016-04-15 01:00:351024
Mark Simulacrum56128fb2017-07-19 00:03:381025 fn should_run(run: ShouldRun) -> ShouldRun {
kennytm0d300d42018-02-21 19:13:341026 run.never()
Mark Simulacruma5ab2ce2017-07-12 15:15:001027 }
1028
1029 /// Run `rustdoc --test` for all documentation in `src/doc`.
1030 ///
1031 /// This will run all tests in our markdown documentation (e.g. the book)
1032 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
1033 /// `compiler`.
1034 fn run(self, builder: &Builder) {
1035 let build = builder.build;
1036 let compiler = self.compiler;
Mark Simulacrumceecd622017-07-12 16:12:471037
1038 builder.ensure(compile::Test { compiler, target: compiler.host });
1039
Mark Simulacruma5ab2ce2017-07-12 15:15:001040 // Do a breadth-first traversal of the `src/doc` directory and just run
1041 // tests for all files that end in `*.md`
kennytm0d300d42018-02-21 19:13:341042 let mut stack = vec![build.src.join(self.path)];
Mark Simulacrum545b92f2018-03-28 15:25:091043 let _time = util::timeit(&build);
kennytm0d300d42018-02-21 19:13:341044 let _folder = build.fold_output(|| format!("test_{}", self.name));
Mark Simulacruma5ab2ce2017-07-12 15:15:001045
Mark Simulacruma7274472018-03-27 14:06:471046 let mut files = Vec::new();
Mark Simulacruma5ab2ce2017-07-12 15:15:001047 while let Some(p) = stack.pop() {
1048 if p.is_dir() {
1049 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1050 continue
1051 }
1052
1053 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1054 continue;
1055 }
1056
1057 // The nostarch directory in the book is for no starch, and so isn't
1058 // guaranteed to build. We don't care if it doesn't build, so skip it.
1059 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
1060 continue;
1061 }
1062
Mark Simulacruma7274472018-03-27 14:06:471063 files.push(p);
1064 }
1065
1066 files.sort();
1067
1068 for file in files {
1069 let test_result = markdown_test(builder, compiler, &file);
kennytma9f940e2018-02-21 19:25:231070 if self.is_ext_doc {
1071 let toolstate = if test_result {
1072 ToolState::TestPass
1073 } else {
1074 ToolState::TestFail
1075 };
1076 build.save_toolstate(self.name, toolstate);
1077 }
Alex Crichtonede89442016-04-15 01:00:351078 }
Alex Crichtonede89442016-04-15 01:00:351079 }
1080}
1081
kennytm0d300d42018-02-21 19:13:341082macro_rules! test_book {
1083 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1084 $(
1085 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1086 pub struct $name {
1087 compiler: Compiler,
1088 }
1089
1090 impl Step for $name {
1091 type Output = ();
1092 const DEFAULT: bool = $default;
1093 const ONLY_HOSTS: bool = true;
1094
1095 fn should_run(run: ShouldRun) -> ShouldRun {
1096 run.path($path)
1097 }
1098
1099 fn make_run(run: RunConfig) {
1100 run.builder.ensure($name {
1101 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1102 });
1103 }
1104
1105 fn run(self, builder: &Builder) {
1106 builder.ensure(DocTest {
1107 compiler: self.compiler,
1108 path: $path,
1109 name: $book_name,
1110 is_ext_doc: !$default,
1111 });
1112 }
1113 }
1114 )+
1115 }
1116}
1117
1118test_book!(
1119 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1120 Reference, "src/doc/reference", "reference", default=false;
1121 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1122 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1123 TheBook, "src/doc/book", "book", default=false;
1124 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1125);
1126
Mark Simulacrum528646e2017-07-14 00:48:441127#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1128pub struct ErrorIndex {
1129 compiler: Compiler,
Mark Simulacrum001e9f32017-07-05 01:41:431130}
Alex Crichton0e272de2016-11-16 20:31:191131
Mark Simulacrum528646e2017-07-14 00:48:441132impl Step for ErrorIndex {
Mark Simulacrum001e9f32017-07-05 01:41:431133 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271134 const DEFAULT: bool = true;
1135 const ONLY_HOSTS: bool = true;
1136
Mark Simulacrum56128fb2017-07-19 00:03:381137 fn should_run(run: ShouldRun) -> ShouldRun {
1138 run.path("src/tools/error_index_generator")
Mark Simulacrum6b3413d2017-07-05 12:41:271139 }
1140
Mark Simulacrum6a67a052017-07-20 23:51:071141 fn make_run(run: RunConfig) {
1142 run.builder.ensure(ErrorIndex {
1143 compiler: run.builder.compiler(run.builder.top_stage, run.host),
Mark Simulacrum6b3413d2017-07-05 12:41:271144 });
1145 }
Alex Crichtonede89442016-04-15 01:00:351146
Mark Simulacrum001e9f32017-07-05 01:41:431147 /// Run the error index generator tool to execute the tests located in the error
1148 /// index.
1149 ///
1150 /// The `error_index_generator` tool lives in `src/tools` and is used to
1151 /// generate a markdown file from the error indexes of the code base which is
1152 /// then passed to `rustdoc --test`.
1153 fn run(self, builder: &Builder) {
1154 let build = builder.build;
1155 let compiler = self.compiler;
1156
Mark Simulacrum6b3413d2017-07-05 12:41:271157 builder.ensure(compile::Std { compiler, target: compiler.host });
1158
Mark Simulacrum001e9f32017-07-05 01:41:431159 let dir = testdir(build, compiler.host);
1160 t!(fs::create_dir_all(&dir));
1161 let output = dir.join("error-index.md");
1162
Alex Crichton6fd4d672018-03-16 15:35:031163 let mut tool = builder.tool_cmd(Tool::ErrorIndex);
1164 tool.arg("markdown")
1165 .arg(&output)
1166 .env("CFG_BUILD", &build.build)
1167 .env("RUSTC_ERROR_METADATA_DST", build.extended_error_dir());
Mark Simulacrum001e9f32017-07-05 01:41:431168
Alex Crichton6fd4d672018-03-16 15:35:031169
1170 let _folder = build.fold_output(|| "test_error_index");
Mark Simulacrum545b92f2018-03-28 15:25:091171 build.info(&format!("Testing error-index stage{}", compiler.stage));
1172 let _time = util::timeit(&build);
Alex Crichton6fd4d672018-03-16 15:35:031173 build.run(&mut tool);
Mark Simulacrumc114fe52017-07-05 17:21:331174 markdown_test(builder, compiler, &output);
Mark Simulacrum001e9f32017-07-05 01:41:431175 }
Alex Crichtonede89442016-04-15 01:00:351176}
1177
kennytma9f940e2018-02-21 19:25:231178fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) -> bool {
Mark Simulacrumc114fe52017-07-05 17:21:331179 let build = builder.build;
Mark Simulacrumdd1d75e2017-06-04 23:55:501180 let mut file = t!(File::open(markdown));
1181 let mut contents = String::new();
1182 t!(file.read_to_string(&mut contents));
1183 if !contents.contains("```") {
kennytma9f940e2018-02-21 19:25:231184 return true;
Mark Simulacrumdd1d75e2017-06-04 23:55:501185 }
1186
Mark Simulacrum545b92f2018-03-28 15:25:091187 build.info(&format!("doc tests for: {}", markdown.display()));
Mark Simulacrumfacf5a92017-08-04 22:13:011188 let mut cmd = builder.rustdoc_cmd(compiler.host);
Alex Crichton0e272de2016-11-16 20:31:191189 build.add_rust_test_threads(&mut cmd);
Alex Crichtonede89442016-04-15 01:00:351190 cmd.arg("--test");
1191 cmd.arg(markdown);
Alex Crichton6f62fae2016-12-12 17:03:351192 cmd.env("RUSTC_BOOTSTRAP", "1");
Corey Farwellc8c6d2c2016-10-30 01:58:521193
Mark Simulacrum44ffb612017-07-30 04:12:531194 let test_args = build.config.cmd.test_args().join(" ");
Corey Farwellc8c6d2c2016-10-30 01:58:521195 cmd.arg("--test-args").arg(test_args);
1196
kennytm6ac07872017-05-21 20:27:471197 if build.config.quiet_tests {
kennytma9f940e2018-02-21 19:25:231198 try_run_quiet(build, &mut cmd)
kennytm6ac07872017-05-21 20:27:471199 } else {
kennytma9f940e2018-02-21 19:25:231200 try_run(build, &mut cmd)
kennytm6ac07872017-05-21 20:27:471201 }
Alex Crichtonede89442016-04-15 01:00:351202}
Alex Crichtonbb9062a2016-04-29 21:23:151203
Mark Simulacrum528646e2017-07-14 00:48:441204#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum981afa52017-07-18 21:28:531205pub struct CrateLibrustc {
Mark Simulacrum528646e2017-07-14 00:48:441206 compiler: Compiler,
1207 target: Interned<String>,
Mark Simulacrum6b3413d2017-07-05 12:41:271208 test_kind: TestKind,
Mark Simulacrumf104b122018-02-11 16:51:581209 krate: Interned<String>,
Mark Simulacrum6b3413d2017-07-05 12:41:271210}
1211
Mark Simulacrum981afa52017-07-18 21:28:531212impl Step for CrateLibrustc {
Mark Simulacrum6b3413d2017-07-05 12:41:271213 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271214 const DEFAULT: bool = true;
1215 const ONLY_HOSTS: bool = true;
1216
Mark Simulacrum56128fb2017-07-19 00:03:381217 fn should_run(run: ShouldRun) -> ShouldRun {
1218 run.krate("rustc-main")
Mark Simulacrum6b3413d2017-07-05 12:41:271219 }
1220
Mark Simulacrum6a67a052017-07-20 23:51:071221 fn make_run(run: RunConfig) {
1222 let builder = run.builder;
1223 let compiler = builder.compiler(builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:271224
Mark Simulacrumf104b122018-02-11 16:51:581225 for krate in builder.in_tree_crates("rustc-main") {
1226 if run.path.ends_with(&krate.path) {
1227 let test_kind = if builder.kind == Kind::Test {
1228 TestKind::Test
1229 } else if builder.kind == Kind::Bench {
1230 TestKind::Bench
1231 } else {
1232 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1233 };
Mark Simulacrum6b3413d2017-07-05 12:41:271234
Mark Simulacrumf104b122018-02-11 16:51:581235 builder.ensure(CrateLibrustc {
1236 compiler,
1237 target: run.target,
1238 test_kind,
1239 krate: krate.name,
1240 });
Mark Simulacrum6b3413d2017-07-05 12:41:271241 }
Mark Simulacrum6b3413d2017-07-05 12:41:271242 }
1243 }
1244
Mark Simulacrum6b3413d2017-07-05 12:41:271245 fn run(self, builder: &Builder) {
Mark Simulacrum981afa52017-07-18 21:28:531246 builder.ensure(Crate {
Mark Simulacrum6b3413d2017-07-05 12:41:271247 compiler: self.compiler,
1248 target: self.target,
1249 mode: Mode::Librustc,
1250 test_kind: self.test_kind,
1251 krate: self.krate,
1252 });
1253 }
1254}
1255
Mark Simulacrum528646e2017-07-14 00:48:441256#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrumf104b122018-02-11 16:51:581257pub struct CrateNotDefault {
Mark Simulacrum528646e2017-07-14 00:48:441258 compiler: Compiler,
1259 target: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:431260 test_kind: TestKind,
Mark Simulacrumf104b122018-02-11 16:51:581261 krate: &'static str,
Mark Simulacrum001e9f32017-07-05 01:41:431262}
Alex Crichtonbb9062a2016-04-29 21:23:151263
Mark Simulacrumf104b122018-02-11 16:51:581264impl Step for CrateNotDefault {
Mark Simulacrum001e9f32017-07-05 01:41:431265 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271266
Mark Simulacrum56128fb2017-07-19 00:03:381267 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumf104b122018-02-11 16:51:581268 run.path("src/liballoc_jemalloc")
1269 .path("src/librustc_asan")
1270 .path("src/librustc_lsan")
1271 .path("src/librustc_msan")
1272 .path("src/librustc_tsan")
Mark Simulacrum6b3413d2017-07-05 12:41:271273 }
1274
Mark Simulacrum6a67a052017-07-20 23:51:071275 fn make_run(run: RunConfig) {
1276 let builder = run.builder;
1277 let compiler = builder.compiler(builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:271278
Mark Simulacrumf104b122018-02-11 16:51:581279 let test_kind = if builder.kind == Kind::Test {
1280 TestKind::Test
1281 } else if builder.kind == Kind::Bench {
1282 TestKind::Bench
1283 } else {
1284 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1285 };
1286
1287 builder.ensure(CrateNotDefault {
1288 compiler,
1289 target: run.target,
1290 test_kind,
1291 krate: match run.path {
1292 _ if run.path.ends_with("src/liballoc_jemalloc") => "alloc_jemalloc",
1293 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1294 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1295 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1296 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1297 _ => panic!("unexpected path {:?}", run.path),
1298 },
1299 });
1300 }
1301
1302 fn run(self, builder: &Builder) {
1303 builder.ensure(Crate {
1304 compiler: self.compiler,
1305 target: self.target,
1306 mode: Mode::Libstd,
1307 test_kind: self.test_kind,
1308 krate: INTERNER.intern_str(self.krate),
1309 });
1310 }
1311}
1312
1313
1314#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1315pub struct Crate {
1316 compiler: Compiler,
1317 target: Interned<String>,
1318 mode: Mode,
1319 test_kind: TestKind,
1320 krate: Interned<String>,
1321}
1322
1323impl Step for Crate {
1324 type Output = ();
1325 const DEFAULT: bool = true;
1326
1327 fn should_run(mut run: ShouldRun) -> ShouldRun {
1328 let builder = run.builder;
1329 run = run.krate("test");
1330 for krate in run.builder.in_tree_crates("std") {
1331 if krate.is_local(&run.builder) &&
1332 !krate.name.contains("jemalloc") &&
1333 !(krate.name.starts_with("rustc_") && krate.name.ends_with("san")) &&
1334 krate.name != "dlmalloc" {
1335 run = run.path(krate.local_path(&builder).to_str().unwrap());
1336 }
1337 }
1338 run
1339 }
1340
1341 fn make_run(run: RunConfig) {
1342 let builder = run.builder;
1343 let compiler = builder.compiler(builder.top_stage, run.host);
1344
1345 let make = |mode: Mode, krate: &CargoCrate| {
Mark Simulacrum6b3413d2017-07-05 12:41:271346 let test_kind = if builder.kind == Kind::Test {
1347 TestKind::Test
1348 } else if builder.kind == Kind::Bench {
1349 TestKind::Bench
1350 } else {
Mark Simulacrum981afa52017-07-18 21:28:531351 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
Mark Simulacrum6b3413d2017-07-05 12:41:271352 };
1353
Mark Simulacrum981afa52017-07-18 21:28:531354 builder.ensure(Crate {
Mark Simulacrum6a67a052017-07-20 23:51:071355 compiler,
1356 target: run.target,
Zack M. Davis1b6c9602017-08-07 05:54:091357 mode,
1358 test_kind,
Mark Simulacrumf104b122018-02-11 16:51:581359 krate: krate.name,
Mark Simulacrum6b3413d2017-07-05 12:41:271360 });
1361 };
1362
Mark Simulacrumf104b122018-02-11 16:51:581363 for krate in builder.in_tree_crates("std") {
1364 if run.path.ends_with(&krate.local_path(&builder)) {
1365 make(Mode::Libstd, krate);
Mark Simulacrum6b3413d2017-07-05 12:41:271366 }
Mark Simulacrumf104b122018-02-11 16:51:581367 }
1368 for krate in builder.in_tree_crates("test") {
1369 if run.path.ends_with(&krate.local_path(&builder)) {
1370 make(Mode::Libtest, krate);
Mark Simulacrum6b3413d2017-07-05 12:41:271371 }
Mark Simulacrum6b3413d2017-07-05 12:41:271372 }
1373 }
Alex Crichton7046fea2016-12-25 23:20:331374
Mark Simulacrumf104b122018-02-11 16:51:581375 /// Run all unit tests plus documentation tests for a given crate defined
1376 /// by a `Cargo.toml` (single manifest)
Mark Simulacrum001e9f32017-07-05 01:41:431377 ///
1378 /// This is what runs tests for crates like the standard library, compiler, etc.
1379 /// It essentially is the driver for running `cargo test`.
1380 ///
1381 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1382 /// arguments, and those arguments are discovered from `cargo metadata`.
1383 fn run(self, builder: &Builder) {
1384 let build = builder.build;
1385 let compiler = self.compiler;
1386 let target = self.target;
1387 let mode = self.mode;
1388 let test_kind = self.test_kind;
1389 let krate = self.krate;
Alex Crichtonbb9062a2016-04-29 21:23:151390
Mark Simulacrum6b3413d2017-07-05 12:41:271391 builder.ensure(compile::Test { compiler, target });
1392 builder.ensure(RemoteCopyLibs { compiler, target });
Mark Simulacrum001e9f32017-07-05 01:41:431393
1394 // If we're not doing a full bootstrap but we're testing a stage2 version of
1395 // libstd, then what we're actually testing is the libstd produced in
1396 // stage1. Reflect that here by updating the compiler that we're working
1397 // with automatically.
1398 let compiler = if build.force_use_stage1(compiler, target) {
Mark Simulacrum6b3413d2017-07-05 12:41:271399 builder.compiler(1, compiler.host)
Mark Simulacrum001e9f32017-07-05 01:41:431400 } else {
1401 compiler.clone()
1402 };
1403
Alex Crichton90105672017-07-17 16:32:081404 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
Mark Simulacrumf104b122018-02-11 16:51:581405 match mode {
Alex Crichton90105672017-07-17 16:32:081406 Mode::Libstd => {
Alex Crichtonbe902e72018-03-05 17:47:541407 compile::std_cargo(builder, &compiler, target, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081408 }
1409 Mode::Libtest => {
1410 compile::test_cargo(build, &compiler, target, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081411 }
1412 Mode::Librustc => {
1413 builder.ensure(compile::Rustc { compiler, target });
Alex Crichton884715c2018-01-22 15:29:241414 compile::rustc_cargo(build, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081415 }
1416 _ => panic!("can only test libraries"),
1417 };
Alex Crichton90105672017-07-17 16:32:081418
Mark Simulacrum001e9f32017-07-05 01:41:431419 // Build up the base `cargo test` command.
1420 //
1421 // Pass in some standard flags then iterate over the graph we've discovered
1422 // in `cargo metadata` with the maps above and figure out what `-p`
1423 // arguments need to get passed.
Mark Simulacrum001e9f32017-07-05 01:41:431424 if test_kind.subcommand() == "test" && !build.fail_fast {
1425 cargo.arg("--no-fail-fast");
Alex Crichtonbb9062a2016-04-29 21:23:151426 }
Guillaume Gomez8e469272018-02-17 14:45:391427 if build.doc_tests {
1428 cargo.arg("--doc");
1429 }
Mark Simulacrum001e9f32017-07-05 01:41:431430
Mark Simulacrumf104b122018-02-11 16:51:581431 cargo.arg("-p").arg(krate);
Alex Crichtonbb9062a2016-04-29 21:23:151432
Mark Simulacrum001e9f32017-07-05 01:41:431433 // The tests are going to run with the *target* libraries, so we need to
1434 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1435 //
1436 // Note that to run the compiler we need to run with the *host* libraries,
1437 // but our wrapper scripts arrange for that to be the case anyway.
1438 let mut dylib_path = dylib_path();
Mark Simulacrum528646e2017-07-14 00:48:441439 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
Mark Simulacrum001e9f32017-07-05 01:41:431440 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
Alex Crichtonbb9062a2016-04-29 21:23:151441
Mark Simulacrum001e9f32017-07-05 01:41:431442 cargo.arg("--");
Mark Simulacrum44ffb612017-07-30 04:12:531443 cargo.args(&build.config.cmd.test_args());
Alex Crichton0e272de2016-11-16 20:31:191444
Mark Simulacrum001e9f32017-07-05 01:41:431445 if build.config.quiet_tests {
1446 cargo.arg("--quiet");
1447 }
Corey Farwellc8c6d2c2016-10-30 01:58:521448
Mark Simulacrum001e9f32017-07-05 01:41:431449 if target.contains("emscripten") {
Alex Crichton8e7849e2017-07-29 00:52:441450 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1451 build.config.nodejs.as_ref().expect("nodejs not configured"));
Oliver Schneideracdf83f2017-12-06 08:25:291452 } else if target.starts_with("wasm32") {
Diggory Blake0e6601f2018-01-11 17:51:491453 // Warn about running tests without the `wasm_syscall` feature enabled.
1454 // The javascript shim implements the syscall interface so that test
1455 // output can be correctly reported.
1456 if !build.config.wasm_syscall {
Mark Simulacrum545b92f2018-03-28 15:25:091457 build.info(&format!("Libstd was built without `wasm_syscall` feature enabled: \
1458 test output may not be visible."));
Diggory Blake0e6601f2018-01-11 17:51:491459 }
1460
Oliver Schneideracdf83f2017-12-06 08:25:291461 // On the wasm32-unknown-unknown target we're using LTO which is
1462 // incompatible with `-C prefer-dynamic`, so disable that here
1463 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
1464
1465 let node = build.config.nodejs.as_ref()
1466 .expect("nodejs not configured");
1467 let runner = format!("{} {}/src/etc/wasm32-shim.js",
1468 node.display(),
1469 build.src.display());
1470 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
Mark Simulacrum001e9f32017-07-05 01:41:431471 } else if build.remote_tested(target) {
Alex Crichton8e7849e2017-07-29 00:52:441472 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1473 format!("{} run",
1474 builder.tool_exe(Tool::RemoteTestClient).display()));
Mark Simulacrum001e9f32017-07-05 01:41:431475 }
Alex Crichton6fd4d672018-03-16 15:35:031476
1477 let _folder = build.fold_output(|| {
1478 format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, krate)
1479 });
Mark Simulacrum545b92f2018-03-28 15:25:091480 build.info(&format!("{} {} stage{} ({} -> {})", test_kind, krate, compiler.stage,
1481 &compiler.host, target));
1482 let _time = util::timeit(&build);
Alex Crichton8e7849e2017-07-29 00:52:441483 try_run(build, &mut cargo);
Alex Crichton39a5d3f2016-06-28 20:31:301484 }
1485}
1486
Mark Simulacrumf87696b2017-09-02 14:02:321487#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrumf104b122018-02-11 16:51:581488pub struct CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321489 host: Interned<String>,
1490 test_kind: TestKind,
1491}
1492
Mark Simulacrumf104b122018-02-11 16:51:581493impl Step for CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321494 type Output = ();
1495 const DEFAULT: bool = true;
1496 const ONLY_HOSTS: bool = true;
1497
1498 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumf104b122018-02-11 16:51:581499 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
Mark Simulacrumf87696b2017-09-02 14:02:321500 }
1501
1502 fn make_run(run: RunConfig) {
1503 let builder = run.builder;
1504
1505 let test_kind = if builder.kind == Kind::Test {
1506 TestKind::Test
1507 } else if builder.kind == Kind::Bench {
1508 TestKind::Bench
1509 } else {
1510 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1511 };
1512
Mark Simulacrumf104b122018-02-11 16:51:581513 builder.ensure(CrateRustdoc {
Mark Simulacrumf87696b2017-09-02 14:02:321514 host: run.host,
1515 test_kind,
1516 });
1517 }
1518
1519 fn run(self, builder: &Builder) {
1520 let build = builder.build;
1521 let test_kind = self.test_kind;
1522
1523 let compiler = builder.compiler(builder.top_stage, self.host);
1524 let target = compiler.host;
1525
Alex Crichton3da54fb2017-09-15 22:28:591526 let mut cargo = tool::prepare_tool_cargo(builder,
1527 compiler,
1528 target,
1529 test_kind.subcommand(),
1530 "src/tools/rustdoc");
Mark Simulacrumf87696b2017-09-02 14:02:321531 if test_kind.subcommand() == "test" && !build.fail_fast {
1532 cargo.arg("--no-fail-fast");
1533 }
1534
1535 cargo.arg("-p").arg("rustdoc:0.0.0");
1536
1537 cargo.arg("--");
1538 cargo.args(&build.config.cmd.test_args());
1539
1540 if build.config.quiet_tests {
1541 cargo.arg("--quiet");
1542 }
1543
Alex Crichton6fd4d672018-03-16 15:35:031544 let _folder = build.fold_output(|| {
1545 format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage)
1546 });
Mark Simulacrum545b92f2018-03-28 15:25:091547 build.info(&format!("{} rustdoc stage{} ({} -> {})", test_kind, compiler.stage,
1548 &compiler.host, target));
1549 let _time = util::timeit(&build);
Mark Simulacrumf87696b2017-09-02 14:02:321550
1551 try_run(build, &mut cargo);
1552 }
1553}
1554
Alex Crichton8e7849e2017-07-29 00:52:441555fn envify(s: &str) -> String {
1556 s.chars().map(|c| {
1557 match c {
1558 '-' => '_',
1559 c => c,
Alex Crichton1747ce22017-01-28 21:38:061560 }
Alex Crichton8e7849e2017-07-29 00:52:441561 }).flat_map(|c| c.to_uppercase()).collect()
Alex Crichton39a5d3f2016-06-28 20:31:301562}
1563
Mark Simulacrumceecd622017-07-12 16:12:471564/// Some test suites are run inside emulators or on remote devices, and most
1565/// of our test binaries are linked dynamically which means we need to ship
1566/// the standard library and such to the emulator ahead of time. This step
1567/// represents this and is a dependency of all test suites.
1568///
1569/// Most of the time this is a noop. For some steps such as shipping data to
1570/// QEMU we have to build our own tools so we've got conditional dependencies
1571/// on those programs as well. Note that the remote test client is built for
1572/// the build target (us) and the server is built for the target.
Mark Simulacrum528646e2017-07-14 00:48:441573#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1574pub struct RemoteCopyLibs {
1575 compiler: Compiler,
1576 target: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:431577}
Alex Crichton1747ce22017-01-28 21:38:061578
Mark Simulacrum528646e2017-07-14 00:48:441579impl Step for RemoteCopyLibs {
Mark Simulacrum001e9f32017-07-05 01:41:431580 type Output = ();
Alex Crichton1747ce22017-01-28 21:38:061581
Mark Simulacrum56128fb2017-07-19 00:03:381582 fn should_run(run: ShouldRun) -> ShouldRun {
1583 run.never()
Mark Simulacrum681b1232017-07-14 12:30:161584 }
1585
Mark Simulacrum001e9f32017-07-05 01:41:431586 fn run(self, builder: &Builder) {
1587 let build = builder.build;
1588 let compiler = self.compiler;
1589 let target = self.target;
1590 if !build.remote_tested(target) {
1591 return
1592 }
Alex Crichton1747ce22017-01-28 21:38:061593
Mark Simulacrum6b3413d2017-07-05 12:41:271594 builder.ensure(compile::Test { compiler, target });
1595
Mark Simulacrum545b92f2018-03-28 15:25:091596 build.info(&format!("REMOTE copy libs to emulator ({})", target));
Mark Simulacrum001e9f32017-07-05 01:41:431597 t!(fs::create_dir_all(build.out.join("tmp")));
1598
Mark Simulacrumfe0eca02017-07-23 01:29:081599 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
Mark Simulacrum001e9f32017-07-05 01:41:431600
1601 // Spawn the emulator and wait for it to come online
Mark Simulacrum6b3413d2017-07-05 12:41:271602 let tool = builder.tool_exe(Tool::RemoteTestClient);
Mark Simulacrum001e9f32017-07-05 01:41:431603 let mut cmd = Command::new(&tool);
1604 cmd.arg("spawn-emulator")
1605 .arg(target)
1606 .arg(&server)
1607 .arg(build.out.join("tmp"));
1608 if let Some(rootfs) = build.qemu_rootfs(target) {
1609 cmd.arg(rootfs);
1610 }
1611 build.run(&mut cmd);
1612
1613 // Push all our dylibs to the emulator
Mark Simulacrum60388302017-07-05 16:46:411614 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
Mark Simulacrum001e9f32017-07-05 01:41:431615 let f = t!(f);
1616 let name = f.file_name().into_string().unwrap();
1617 if util::is_dylib(&name) {
1618 build.run(Command::new(&tool)
1619 .arg("push")
1620 .arg(f.path()));
1621 }
Alex Crichton1747ce22017-01-28 21:38:061622 }
1623 }
1624}
1625
Mark Simulacrum528646e2017-07-14 00:48:441626#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum001e9f32017-07-05 01:41:431627pub struct Distcheck;
1628
Mark Simulacrum528646e2017-07-14 00:48:441629impl Step for Distcheck {
Mark Simulacrum001e9f32017-07-05 01:41:431630 type Output = ();
1631
Mark Simulacrum56128fb2017-07-19 00:03:381632 fn should_run(run: ShouldRun) -> ShouldRun {
1633 run.path("distcheck")
Mark Simulacrum681b1232017-07-14 12:30:161634 }
1635
Mark Simulacrum8f2e5762017-07-22 13:35:421636 fn make_run(run: RunConfig) {
1637 run.builder.ensure(Distcheck);
1638 }
1639
Mark Simulacrum001e9f32017-07-05 01:41:431640 /// Run "distcheck", a 'make check' from a tarball
1641 fn run(self, builder: &Builder) {
1642 let build = builder.build;
1643
Mark Simulacrum545b92f2018-03-28 15:25:091644 build.info(&format!("Distcheck"));
Mark Simulacrum001e9f32017-07-05 01:41:431645 let dir = build.out.join("tmp").join("distcheck");
1646 let _ = fs::remove_dir_all(&dir);
1647 t!(fs::create_dir_all(&dir));
1648
Mark Simulacrum1c118232017-07-22 16:48:291649 // Guarantee that these are built before we begin running.
1650 builder.ensure(dist::PlainSourceTarball);
1651 builder.ensure(dist::Src);
1652
Mark Simulacrum001e9f32017-07-05 01:41:431653 let mut cmd = Command::new("tar");
1654 cmd.arg("-xzf")
Mark Simulacrum5984e702017-07-13 00:52:311655 .arg(builder.ensure(dist::PlainSourceTarball))
Mark Simulacrum001e9f32017-07-05 01:41:431656 .arg("--strip-components=1")
1657 .current_dir(&dir);
1658 build.run(&mut cmd);
1659 build.run(Command::new("./configure")
1660 .args(&build.config.configure_args)
1661 .arg("--enable-vendor")
1662 .current_dir(&dir));
1663 build.run(Command::new(build_helper::make(&build.build))
1664 .arg("check")
1665 .current_dir(&dir));
1666
1667 // Now make sure that rust-src has all of libstd's dependencies
Mark Simulacrum545b92f2018-03-28 15:25:091668 build.info(&format!("Distcheck rust-src"));
Mark Simulacrum001e9f32017-07-05 01:41:431669 let dir = build.out.join("tmp").join("distcheck-src");
1670 let _ = fs::remove_dir_all(&dir);
1671 t!(fs::create_dir_all(&dir));
1672
1673 let mut cmd = Command::new("tar");
1674 cmd.arg("-xzf")
Mark Simulacrum5984e702017-07-13 00:52:311675 .arg(builder.ensure(dist::Src))
Mark Simulacrum001e9f32017-07-05 01:41:431676 .arg("--strip-components=1")
1677 .current_dir(&dir);
1678 build.run(&mut cmd);
1679
1680 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
1681 build.run(Command::new(&build.initial_cargo)
1682 .arg("generate-lockfile")
1683 .arg("--manifest-path")
1684 .arg(&toml)
1685 .current_dir(&dir));
Alex Crichtond38db822016-12-09 01:13:551686 }
Alex Crichtond38db822016-12-09 01:13:551687}
Alex Crichton1a040b32016-12-31 03:50:571688
Mark Simulacrum528646e2017-07-14 00:48:441689#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum001e9f32017-07-05 01:41:431690pub struct Bootstrap;
1691
Mark Simulacrum528646e2017-07-14 00:48:441692impl Step for Bootstrap {
Mark Simulacrum001e9f32017-07-05 01:41:431693 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271694 const DEFAULT: bool = true;
1695 const ONLY_HOSTS: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:431696
1697 /// Test the build system itself
1698 fn run(self, builder: &Builder) {
1699 let build = builder.build;
1700 let mut cmd = Command::new(&build.initial_cargo);
1701 cmd.arg("test")
1702 .current_dir(build.src.join("src/bootstrap"))
Mark Simulacrum42fde212018-03-10 14:03:061703 .env("RUSTFLAGS", "-Cdebuginfo=2")
Mark Simulacrum001e9f32017-07-05 01:41:431704 .env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
1705 .env("RUSTC_BOOTSTRAP", "1")
1706 .env("RUSTC", &build.initial_rustc);
Simon Sapine993e622018-03-23 18:55:411707 if let Some(flags) = option_env!("RUSTFLAGS") {
1708 // Use the same rustc flags for testing as for "normal" compilation,
1709 // so that Cargo doesn’t recompile the entire dependency graph every time:
1710 // https://github.com/rust-lang/rust/issues/49215
1711 cmd.env("RUSTFLAGS", flags);
1712 }
Mark Simulacrum001e9f32017-07-05 01:41:431713 if !build.fail_fast {
1714 cmd.arg("--no-fail-fast");
1715 }
Mark Simulacrum44ffb612017-07-30 04:12:531716 cmd.arg("--").args(&build.config.cmd.test_args());
Mark Simulacrum001e9f32017-07-05 01:41:431717 try_run(build, &mut cmd);
Josh Stone617aea42017-06-02 16:27:441718 }
Mark Simulacrum6b3413d2017-07-05 12:41:271719
Mark Simulacrum56128fb2017-07-19 00:03:381720 fn should_run(run: ShouldRun) -> ShouldRun {
1721 run.path("src/bootstrap")
Mark Simulacrum6b3413d2017-07-05 12:41:271722 }
1723
Mark Simulacrum6a67a052017-07-20 23:51:071724 fn make_run(run: RunConfig) {
1725 run.builder.ensure(Bootstrap);
Mark Simulacrum6b3413d2017-07-05 12:41:271726 }
Alex Crichton1a040b32016-12-31 03:50:571727}