blob: a8a1f871cf5c650681147630dbb015c67c9b6e0f [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 Crichtona270b802016-10-21 20:18:0916use std::collections::HashSet;
Alex Crichtonbb9062a2016-04-29 21:23:1517use std::env;
Nick Cameron04415dc2017-06-30 18:58:5418use std::ffi::OsString;
Mark Simulacrum5b44cbc2017-06-26 16:23:5019use std::iter;
Ulrik Sverdrupb1566ba2016-11-25 21:13:5920use std::fmt;
Mark Simulacrumdd1d75e2017-06-04 23:55:5021use std::fs::{self, File};
Alex Crichtonede89442016-04-15 01:00:3522use std::path::{PathBuf, Path};
23use std::process::Command;
Mark Simulacrumdd1d75e2017-06-04 23:55:5024use std::io::Read;
Alex Crichton73c2d2a2016-04-14 21:27:5125
kennytm2566fa22017-12-06 21:06:4826use build_helper::{self, output};
Alex Crichton126e09e2016-04-14 22:51:0327
Mark Simulacrum6a67a052017-07-20 23:51:0728use builder::{Kind, RunConfig, ShouldRun, Builder, Compiler, Step};
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
Josh Stone617aea42017-06-02 16:27:4481fn try_run_quiet(build: &Build, cmd: &mut Command) {
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));
Josh Stone617aea42017-06-02 16:27:4486 }
87 } else {
88 build.run_quiet(cmd);
89 }
90}
91
Mark Simulacrum528646e2017-07-14 00:48:4492#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
93pub struct Linkcheck {
94 host: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:4395}
96
Mark Simulacrum528646e2017-07-14 00:48:4497impl Step for Linkcheck {
Mark Simulacrum001e9f32017-07-05 01:41:4398 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:2799 const ONLY_HOSTS: bool = true;
100 const DEFAULT: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:43101
102 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
103 ///
104 /// This tool in `src/tools` will verify the validity of all our links in the
105 /// documentation to ensure we don't have a bunch of dead ones.
106 fn run(self, builder: &Builder) {
107 let build = builder.build;
108 let host = self.host;
109
110 println!("Linkcheck ({})", host);
Mark Simulacrum6b3413d2017-07-05 12:41:27111
112 builder.default_doc(None);
Mark Simulacrum001e9f32017-07-05 01:41:43113
114 let _time = util::timeit();
Mark Simulacrum6b3413d2017-07-05 12:41:27115 try_run(build, builder.tool_cmd(Tool::Linkchecker)
Mark Simulacrum001e9f32017-07-05 01:41:43116 .arg(build.out.join(host).join("doc")));
117 }
Mark Simulacrum6b3413d2017-07-05 12:41:27118
Mark Simulacrum56128fb2017-07-19 00:03:38119 fn should_run(run: ShouldRun) -> ShouldRun {
Mark Simulacrumb05af492017-07-20 23:24:11120 let builder = run.builder;
121 run.path("src/tools/linkchecker").default_condition(builder.build.config.docs)
Mark Simulacrum6b3413d2017-07-05 12:41:27122 }
123
Mark Simulacrum6a67a052017-07-20 23:51:07124 fn make_run(run: RunConfig) {
Mark Simulacrum9ee877b2017-07-27 12:50:43125 run.builder.ensure(Linkcheck { host: run.target });
Mark Simulacrum6b3413d2017-07-05 12:41:27126 }
Alex Crichtondefd1b32016-03-08 07:15:55127}
Brian Anderson3a790ac2016-03-18 20:54:31128
Mark Simulacrum528646e2017-07-14 00:48:44129#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
130pub struct Cargotest {
Mark Simulacrum001e9f32017-07-05 01:41:43131 stage: u32,
Mark Simulacrum528646e2017-07-14 00:48:44132 host: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:43133}
Alex Crichton73c2d2a2016-04-14 21:27:51134
Mark Simulacrum528646e2017-07-14 00:48:44135impl Step for Cargotest {
Mark Simulacrum001e9f32017-07-05 01:41:43136 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27137 const ONLY_HOSTS: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:43138
Mark Simulacrum56128fb2017-07-19 00:03:38139 fn should_run(run: ShouldRun) -> ShouldRun {
140 run.path("src/tools/cargotest")
Mark Simulacrumceecd622017-07-12 16:12:47141 }
142
Mark Simulacrum6a67a052017-07-20 23:51:07143 fn make_run(run: RunConfig) {
144 run.builder.ensure(Cargotest {
145 stage: run.builder.top_stage,
Mark Simulacrum9ee877b2017-07-27 12:50:43146 host: run.target,
Mark Simulacrumceecd622017-07-12 16:12:47147 });
148 }
149
Mark Simulacrum001e9f32017-07-05 01:41:43150 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
151 ///
152 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
153 /// test` to ensure that we don't regress the test suites there.
154 fn run(self, builder: &Builder) {
155 let build = builder.build;
Mark Simulacrum60388302017-07-05 16:46:41156 let compiler = builder.compiler(self.stage, self.host);
Mark Simulacrum6b3413d2017-07-05 12:41:27157 builder.ensure(compile::Rustc { compiler, target: compiler.host });
Mark Simulacrum001e9f32017-07-05 01:41:43158
159 // Note that this is a short, cryptic, and not scoped directory name. This
160 // is currently to minimize the length of path on Windows where we otherwise
161 // quickly run into path name limit constraints.
162 let out_dir = build.out.join("ct");
163 t!(fs::create_dir_all(&out_dir));
164
165 let _time = util::timeit();
Mark Simulacrum6b3413d2017-07-05 12:41:27166 let mut cmd = builder.tool_cmd(Tool::CargoTest);
Mark Simulacrum001e9f32017-07-05 01:41:43167 try_run(build, cmd.arg(&build.initial_cargo)
168 .arg(&out_dir)
Mark Simulacrumc114fe52017-07-05 17:21:33169 .env("RUSTC", builder.rustc(compiler))
Mark Simulacrumfacf5a92017-08-04 22:13:01170 .env("RUSTDOC", builder.rustdoc(compiler.host)));
Mark Simulacrum001e9f32017-07-05 01:41:43171 }
Alex Crichton009f45f2017-04-18 00:24:05172}
173
Mark Simulacrum528646e2017-07-14 00:48:44174#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
175pub struct Cargo {
Mark Simulacrum001e9f32017-07-05 01:41:43176 stage: u32,
Mark Simulacrum528646e2017-07-14 00:48:44177 host: Interned<String>,
Nick Cameron04415dc2017-06-30 18:58:54178}
179
Mark Simulacrum528646e2017-07-14 00:48:44180impl Step for Cargo {
Mark Simulacrum001e9f32017-07-05 01:41:43181 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27182 const ONLY_HOSTS: bool = true;
183
Mark Simulacrum56128fb2017-07-19 00:03:38184 fn should_run(run: ShouldRun) -> ShouldRun {
185 run.path("src/tools/cargo")
Mark Simulacrum6b3413d2017-07-05 12:41:27186 }
187
Mark Simulacrum6a67a052017-07-20 23:51:07188 fn make_run(run: RunConfig) {
189 run.builder.ensure(Cargo {
190 stage: run.builder.top_stage,
191 host: run.target,
Mark Simulacrum6b3413d2017-07-05 12:41:27192 });
193 }
Nick Cameron04415dc2017-06-30 18:58:54194
Mark Simulacrum001e9f32017-07-05 01:41:43195 /// Runs `cargo test` for `cargo` packaged with Rust.
196 fn run(self, builder: &Builder) {
197 let build = builder.build;
Mark Simulacrum6b3413d2017-07-05 12:41:27198 let compiler = builder.compiler(self.stage, self.host);
Nick Cameron04415dc2017-06-30 18:58:54199
Mark Simulacrumfe0eca02017-07-23 01:29:08200 builder.ensure(tool::Cargo { compiler, target: self.host });
Mark Simulacrumc114fe52017-07-05 17:21:33201 let mut cargo = builder.cargo(compiler, Mode::Tool, self.host, "test");
Mark Simulacrum001e9f32017-07-05 01:41:43202 cargo.arg("--manifest-path").arg(build.src.join("src/tools/cargo/Cargo.toml"));
203 if !build.fail_fast {
204 cargo.arg("--no-fail-fast");
205 }
Nick Cameron04415dc2017-06-30 18:58:54206
Mark Simulacrum001e9f32017-07-05 01:41:43207 // Don't build tests dynamically, just a pain to work with
208 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
209
210 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
211 // available.
212 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
213
Mark Simulacrumdec44b02017-07-17 15:52:05214 try_run(build, cargo.env("PATH", &path_for_cargo(builder, compiler)));
Mark Simulacrum001e9f32017-07-05 01:41:43215 }
216}
217
Mark Simulacrumdec44b02017-07-17 15:52:05218#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
219pub struct Rls {
Mark Simulacrum001e9f32017-07-05 01:41:43220 stage: u32,
Mark Simulacrumdec44b02017-07-17 15:52:05221 host: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:43222}
223
Mark Simulacrumdec44b02017-07-17 15:52:05224impl Step for Rls {
Mark Simulacrum001e9f32017-07-05 01:41:43225 type Output = ();
Mark Simulacrumdec44b02017-07-17 15:52:05226 const ONLY_HOSTS: bool = true;
227
Mark Simulacrum56128fb2017-07-19 00:03:38228 fn should_run(run: ShouldRun) -> ShouldRun {
229 run.path("src/tools/rls")
Mark Simulacrumdec44b02017-07-17 15:52:05230 }
231
Mark Simulacrum6a67a052017-07-20 23:51:07232 fn make_run(run: RunConfig) {
233 run.builder.ensure(Rls {
234 stage: run.builder.top_stage,
235 host: run.target,
Mark Simulacrumdec44b02017-07-17 15:52:05236 });
237 }
Mark Simulacrum001e9f32017-07-05 01:41:43238
239 /// Runs `cargo test` for the rls.
240 fn run(self, builder: &Builder) {
241 let build = builder.build;
242 let stage = self.stage;
243 let host = self.host;
Mark Simulacrumdec44b02017-07-17 15:52:05244 let compiler = builder.compiler(stage, host);
Mark Simulacrum001e9f32017-07-05 01:41:43245
Mark Simulacrumfe0eca02017-07-23 01:29:08246 builder.ensure(tool::Rls { compiler, target: self.host });
Oliver Schneideracdf83f2017-12-06 08:25:29247 let mut cargo = tool::prepare_tool_cargo(builder,
248 compiler,
249 host,
250 "test",
251 "src/tools/rls");
Mark Simulacrum001e9f32017-07-05 01:41:43252
253 // Don't build tests dynamically, just a pain to work with
254 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
255
Mark Simulacrumdec44b02017-07-17 15:52:05256 builder.add_rustc_lib_path(compiler, &mut cargo);
Mark Simulacrum001e9f32017-07-05 01:41:43257
kennytm2566fa22017-12-06 21:06:48258 if try_run(build, &mut cargo) {
kennytm44954ab2017-12-21 17:16:21259 build.save_toolstate("rls", ToolState::TestPass);
Oliver Schneideracdf83f2017-12-06 08:25:29260 }
Mark Simulacrum001e9f32017-07-05 01:41:43261 }
Nick Cameron04415dc2017-06-30 18:58:54262}
263
Nick Camerond0070e82017-09-01 06:43:00264#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
265pub struct Rustfmt {
266 stage: u32,
267 host: Interned<String>,
268}
269
270impl Step for Rustfmt {
271 type Output = ();
272 const ONLY_HOSTS: bool = true;
273
274 fn should_run(run: ShouldRun) -> ShouldRun {
275 run.path("src/tools/rustfmt")
276 }
277
278 fn make_run(run: RunConfig) {
279 run.builder.ensure(Rustfmt {
280 stage: run.builder.top_stage,
281 host: run.target,
282 });
283 }
284
285 /// Runs `cargo test` for rustfmt.
286 fn run(self, builder: &Builder) {
287 let build = builder.build;
288 let stage = self.stage;
289 let host = self.host;
290 let compiler = builder.compiler(stage, host);
291
292 builder.ensure(tool::Rustfmt { compiler, target: self.host });
Oliver Schneideracdf83f2017-12-06 08:25:29293 let mut cargo = tool::prepare_tool_cargo(builder,
294 compiler,
295 host,
296 "test",
297 "src/tools/rustfmt");
Nick Camerond0070e82017-09-01 06:43:00298
299 // Don't build tests dynamically, just a pain to work with
300 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
301
302 builder.add_rustc_lib_path(compiler, &mut cargo);
303
kennytm2566fa22017-12-06 21:06:48304 if try_run(build, &mut cargo) {
kennytm44954ab2017-12-21 17:16:21305 build.save_toolstate("rustfmt", ToolState::TestPass);
Oliver Schneideracdf83f2017-12-06 08:25:29306 }
Nick Camerond0070e82017-09-01 06:43:00307 }
308}
Oliver Schneider01555b12017-09-17 19:45:54309
310#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Oliver Schneiderf3817442017-08-28 14:54:50311pub struct Miri {
Oliver Schneideracdf83f2017-12-06 08:25:29312 stage: u32,
Oliver Schneiderf3817442017-08-28 14:54:50313 host: Interned<String>,
314}
315
316impl Step for Miri {
317 type Output = ();
318 const ONLY_HOSTS: bool = true;
319 const DEFAULT: bool = true;
320
321 fn should_run(run: ShouldRun) -> ShouldRun {
322 let test_miri = run.builder.build.config.test_miri;
323 run.path("src/tools/miri").default_condition(test_miri)
324 }
325
326 fn make_run(run: RunConfig) {
327 run.builder.ensure(Miri {
Oliver Schneideracdf83f2017-12-06 08:25:29328 stage: run.builder.top_stage,
Oliver Schneiderf3817442017-08-28 14:54:50329 host: run.target,
330 });
331 }
332
333 /// Runs `cargo test` for miri.
334 fn run(self, builder: &Builder) {
335 let build = builder.build;
Oliver Schneideracdf83f2017-12-06 08:25:29336 let stage = self.stage;
Oliver Schneiderf3817442017-08-28 14:54:50337 let host = self.host;
Oliver Schneideracdf83f2017-12-06 08:25:29338 let compiler = builder.compiler(stage, host);
Oliver Schneiderf3817442017-08-28 14:54:50339
Oliver Schneideracdf83f2017-12-06 08:25:29340 if let Some(miri) = builder.ensure(tool::Miri { compiler, target: self.host }) {
341 let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
342 cargo.arg("--manifest-path").arg(build.src.join("src/tools/miri/Cargo.toml"));
Oliver Schneiderf3817442017-08-28 14:54:50343
Oliver Schneideracdf83f2017-12-06 08:25:29344 // Don't build tests dynamically, just a pain to work with
345 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
346 // miri tests need to know about the stage sysroot
347 cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
348 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
349 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
350 cargo.env("MIRI_PATH", miri);
Oliver Schneiderf3817442017-08-28 14:54:50351
Oliver Schneideracdf83f2017-12-06 08:25:29352 builder.add_rustc_lib_path(compiler, &mut cargo);
Oliver Schneiderf3817442017-08-28 14:54:50353
kennytm2566fa22017-12-06 21:06:48354 if try_run(build, &mut cargo) {
kennytm44954ab2017-12-21 17:16:21355 build.save_toolstate("miri", ToolState::TestPass);
Oliver Schneideracdf83f2017-12-06 08:25:29356 }
357 } else {
358 eprintln!("failed to test miri: could not build");
359 }
Oliver Schneiderf3817442017-08-28 14:54:50360 }
361}
362
Oliver Schneiderd64a0672017-09-18 11:13:57363#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
364pub struct Clippy {
Oliver Schneideracdf83f2017-12-06 08:25:29365 stage: u32,
Oliver Schneiderd64a0672017-09-18 11:13:57366 host: Interned<String>,
367}
368
369impl Step for Clippy {
370 type Output = ();
371 const ONLY_HOSTS: bool = true;
372 const DEFAULT: bool = false;
373
374 fn should_run(run: ShouldRun) -> ShouldRun {
375 run.path("src/tools/clippy")
376 }
377
378 fn make_run(run: RunConfig) {
379 run.builder.ensure(Clippy {
Oliver Schneideracdf83f2017-12-06 08:25:29380 stage: run.builder.top_stage,
Oliver Schneiderd64a0672017-09-18 11:13:57381 host: run.target,
382 });
383 }
384
385 /// Runs `cargo test` for clippy.
386 fn run(self, builder: &Builder) {
387 let build = builder.build;
Oliver Schneideracdf83f2017-12-06 08:25:29388 let stage = self.stage;
Oliver Schneiderd64a0672017-09-18 11:13:57389 let host = self.host;
Oliver Schneideracdf83f2017-12-06 08:25:29390 let compiler = builder.compiler(stage, host);
Oliver Schneiderd64a0672017-09-18 11:13:57391
Oliver Schneideracdf83f2017-12-06 08:25:29392 if let Some(clippy) = builder.ensure(tool::Clippy { compiler, target: self.host }) {
393 let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
394 cargo.arg("--manifest-path").arg(build.src.join("src/tools/clippy/Cargo.toml"));
Oliver Schneiderd64a0672017-09-18 11:13:57395
Oliver Schneideracdf83f2017-12-06 08:25:29396 // Don't build tests dynamically, just a pain to work with
397 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
398 // clippy tests need to know about the stage sysroot
399 cargo.env("SYSROOT", builder.sysroot(compiler));
400 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
401 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
402 let host_libs = builder.stage_out(compiler, Mode::Tool).join(builder.cargo_dir());
403 cargo.env("HOST_LIBS", host_libs);
404 // clippy tests need to find the driver
405 cargo.env("CLIPPY_DRIVER_PATH", clippy);
Oliver Schneiderd64a0672017-09-18 11:13:57406
Oliver Schneideracdf83f2017-12-06 08:25:29407 builder.add_rustc_lib_path(compiler, &mut cargo);
Oliver Schneiderd64a0672017-09-18 11:13:57408
kennytm2566fa22017-12-06 21:06:48409 if try_run(build, &mut cargo) {
kennytm44954ab2017-12-21 17:16:21410 build.save_toolstate("clippy-driver", ToolState::TestPass);
Oliver Schneideracdf83f2017-12-06 08:25:29411 }
412 } else {
413 eprintln!("failed to test clippy: could not build");
414 }
Oliver Schneiderd64a0672017-09-18 11:13:57415 }
416}
Nick Camerond0070e82017-09-01 06:43:00417
Mark Simulacrumdec44b02017-07-17 15:52:05418fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
Nick Cameron04415dc2017-06-30 18:58:54419 // Configure PATH to find the right rustc. NB. we have to use PATH
420 // and not RUSTC because the Cargo test suite has tests that will
421 // fail if rustc is not spelled `rustc`.
Mark Simulacrumdec44b02017-07-17 15:52:05422 let path = builder.sysroot(compiler).join("bin");
Nick Cameron04415dc2017-06-30 18:58:54423 let old_path = env::var_os("PATH").unwrap_or_default();
424 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
Brian Anderson3a790ac2016-03-18 20:54:31425}
Alex Crichton9dd3c542016-03-29 20:14:52426
Mark Simulacrum528646e2017-07-14 00:48:44427#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
428pub struct Tidy {
429 host: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:43430}
431
Mark Simulacrum528646e2017-07-14 00:48:44432impl Step for Tidy {
Mark Simulacrum001e9f32017-07-05 01:41:43433 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27434 const DEFAULT: bool = true;
435 const ONLY_HOSTS: bool = true;
436 const ONLY_BUILD: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:43437
438 /// Runs the `tidy` tool as compiled in `stage` by the `host` compiler.
439 ///
440 /// This tool in `src/tools` checks up on various bits and pieces of style and
441 /// otherwise just implements a few lint-like checks that are specific to the
442 /// compiler itself.
443 fn run(self, builder: &Builder) {
444 let build = builder.build;
445 let host = self.host;
446
447 let _folder = build.fold_output(|| "tidy");
448 println!("tidy check ({})", host);
Mark Simulacrum60388302017-07-05 16:46:41449 let mut cmd = builder.tool_cmd(Tool::Tidy);
Mark Simulacrum001e9f32017-07-05 01:41:43450 cmd.arg(build.src.join("src"));
451 if !build.config.vendor {
452 cmd.arg("--no-vendor");
453 }
454 if build.config.quiet_tests {
455 cmd.arg("--quiet");
456 }
457 try_run(build, &mut cmd);
Eduard-Mihai Burtescud29f0bc2017-02-10 20:59:40458 }
Mark Simulacrum6b3413d2017-07-05 12:41:27459
Mark Simulacrum56128fb2017-07-19 00:03:38460 fn should_run(run: ShouldRun) -> ShouldRun {
461 run.path("src/tools/tidy")
Mark Simulacrum6b3413d2017-07-05 12:41:27462 }
463
Mark Simulacrum6a67a052017-07-20 23:51:07464 fn make_run(run: RunConfig) {
465 run.builder.ensure(Tidy {
466 host: run.builder.build.build,
Mark Simulacrum6b3413d2017-07-05 12:41:27467 });
468 }
Alex Crichton9dd3c542016-03-29 20:14:52469}
Alex Crichtonb325baf2016-04-05 18:34:23470
Mark Simulacrum528646e2017-07-14 00:48:44471fn testdir(build: &Build, host: Interned<String>) -> PathBuf {
Alex Crichtonb325baf2016-04-05 18:34:23472 build.out.join(host).join("test")
473}
474
Mark Simulacrum528646e2017-07-14 00:48:44475#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum1ab89302017-07-07 17:51:57476struct Test {
Mark Simulacrum1ab89302017-07-07 17:51:57477 path: &'static str,
478 mode: &'static str,
479 suite: &'static str,
480}
481
Mark Simulacrumaa8b93b2017-07-07 18:31:29482static DEFAULT_COMPILETESTS: &[Test] = &[
483 Test { path: "src/test/ui", mode: "ui", suite: "ui" },
484 Test { path: "src/test/run-pass", mode: "run-pass", suite: "run-pass" },
485 Test { path: "src/test/compile-fail", mode: "compile-fail", suite: "compile-fail" },
486 Test { path: "src/test/parse-fail", mode: "parse-fail", suite: "parse-fail" },
487 Test { path: "src/test/run-fail", mode: "run-fail", suite: "run-fail" },
Mark Simulacrum1ab89302017-07-07 17:51:57488 Test {
Mark Simulacrum1ab89302017-07-07 17:51:57489 path: "src/test/run-pass-valgrind",
490 mode: "run-pass-valgrind",
491 suite: "run-pass-valgrind"
492 },
Mark Simulacrumaa8b93b2017-07-07 18:31:29493 Test { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" },
494 Test { path: "src/test/codegen", mode: "codegen", suite: "codegen" },
495 Test { path: "src/test/codegen-units", mode: "codegen-units", suite: "codegen-units" },
496 Test { path: "src/test/incremental", mode: "incremental", suite: "incremental" },
Mark Simulacrum6b3413d2017-07-05 12:41:27497
Mark Simulacrumaa8b93b2017-07-07 18:31:29498 // What this runs varies depending on the native platform being apple
499 Test { path: "src/test/debuginfo", mode: "debuginfo-XXX", suite: "debuginfo" },
Mark Simulacrumaa8b93b2017-07-07 18:31:29500];
Mark Simulacrum6b3413d2017-07-05 12:41:27501
Mark Simulacrumf1d04a32017-07-20 15:42:18502#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
503pub struct DefaultCompiletest {
504 compiler: Compiler,
505 target: Interned<String>,
506 mode: &'static str,
507 suite: &'static str,
508}
509
510impl Step for DefaultCompiletest {
511 type Output = ();
512 const DEFAULT: bool = true;
513
514 fn should_run(mut run: ShouldRun) -> ShouldRun {
515 for test in DEFAULT_COMPILETESTS {
516 run = run.path(test.path);
517 }
518 run
519 }
520
Mark Simulacrum6a67a052017-07-20 23:51:07521 fn make_run(run: RunConfig) {
522 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
Mark Simulacrumf1d04a32017-07-20 15:42:18523
Mark Simulacrum6a67a052017-07-20 23:51:07524 let test = run.path.map(|path| {
Mark Simulacrumf1d04a32017-07-20 15:42:18525 DEFAULT_COMPILETESTS.iter().find(|&&test| {
526 path.ends_with(test.path)
527 }).unwrap_or_else(|| {
528 panic!("make_run in compile test to receive test path, received {:?}", path);
529 })
530 });
531
532 if let Some(test) = test {
Mark Simulacrum6a67a052017-07-20 23:51:07533 run.builder.ensure(DefaultCompiletest {
Mark Simulacrumf1d04a32017-07-20 15:42:18534 compiler,
Mark Simulacrum6a67a052017-07-20 23:51:07535 target: run.target,
Mark Simulacrumf1d04a32017-07-20 15:42:18536 mode: test.mode,
537 suite: test.suite,
538 });
539 } else {
540 for test in DEFAULT_COMPILETESTS {
Mark Simulacrum6a67a052017-07-20 23:51:07541 run.builder.ensure(DefaultCompiletest {
Mark Simulacrumf1d04a32017-07-20 15:42:18542 compiler,
Mark Simulacrum6a67a052017-07-20 23:51:07543 target: run.target,
Mark Simulacrumf1d04a32017-07-20 15:42:18544 mode: test.mode,
545 suite: test.suite
546 });
547 }
548 }
549 }
550
551 fn run(self, builder: &Builder) {
552 builder.ensure(Compiletest {
553 compiler: self.compiler,
554 target: self.target,
555 mode: self.mode,
556 suite: self.suite,
557 })
558 }
559}
560
Mark Simulacrumaa8b93b2017-07-07 18:31:29561// Also default, but host-only.
562static HOST_COMPILETESTS: &[Test] = &[
563 Test { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" },
564 Test { path: "src/test/run-pass-fulldeps", mode: "run-pass", suite: "run-pass-fulldeps" },
565 Test { path: "src/test/run-fail-fulldeps", mode: "run-fail", suite: "run-fail-fulldeps" },
Mark Simulacrum1ab89302017-07-07 17:51:57566 Test {
Mark Simulacrum1ab89302017-07-07 17:51:57567 path: "src/test/compile-fail-fulldeps",
568 mode: "compile-fail",
569 suite: "compile-fail-fulldeps",
570 },
Mark Simulacrumaa8b93b2017-07-07 18:31:29571 Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
572 Test { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" },
Mark Simulacrum6b3413d2017-07-05 12:41:27573
Mark Simulacrumaa8b93b2017-07-07 18:31:29574 Test { path: "src/test/pretty", mode: "pretty", suite: "pretty" },
575 Test { path: "src/test/run-pass/pretty", mode: "pretty", suite: "run-pass" },
576 Test { path: "src/test/run-fail/pretty", mode: "pretty", suite: "run-fail" },
577 Test { path: "src/test/run-pass-valgrind/pretty", mode: "pretty", suite: "run-pass-valgrind" },
578 Test { path: "src/test/run-pass-fulldeps/pretty", mode: "pretty", suite: "run-pass-fulldeps" },
579 Test { path: "src/test/run-fail-fulldeps/pretty", mode: "pretty", suite: "run-fail-fulldeps" },
Mark Simulacrum6b3413d2017-07-05 12:41:27580];
581
Mark Simulacrumf1d04a32017-07-20 15:42:18582#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
583pub struct HostCompiletest {
584 compiler: Compiler,
585 target: Interned<String>,
586 mode: &'static str,
587 suite: &'static str,
588}
Mark Simulacrum6b3413d2017-07-05 12:41:27589
Mark Simulacrumf1d04a32017-07-20 15:42:18590impl Step for HostCompiletest {
Mark Simulacrum001e9f32017-07-05 01:41:43591 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27592 const DEFAULT: bool = true;
Mark Simulacrumf1d04a32017-07-20 15:42:18593 const ONLY_HOSTS: bool = true;
Mark Simulacrum6b3413d2017-07-05 12:41:27594
Mark Simulacrum56128fb2017-07-19 00:03:38595 fn should_run(mut run: ShouldRun) -> ShouldRun {
Mark Simulacrumf1d04a32017-07-20 15:42:18596 for test in HOST_COMPILETESTS {
Mark Simulacrum56128fb2017-07-19 00:03:38597 run = run.path(test.path);
598 }
599 run
Mark Simulacrum6b3413d2017-07-05 12:41:27600 }
601
Mark Simulacrum6a67a052017-07-20 23:51:07602 fn make_run(run: RunConfig) {
603 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:27604
Mark Simulacrum6a67a052017-07-20 23:51:07605 let test = run.path.map(|path| {
Mark Simulacrumf1d04a32017-07-20 15:42:18606 HOST_COMPILETESTS.iter().find(|&&test| {
Mark Simulacrum1ab89302017-07-07 17:51:57607 path.ends_with(test.path)
Mark Simulacrum6b3413d2017-07-05 12:41:27608 }).unwrap_or_else(|| {
609 panic!("make_run in compile test to receive test path, received {:?}", path);
610 })
611 });
612
Mark Simulacrumf1d04a32017-07-20 15:42:18613 if let Some(test) = test {
Mark Simulacrum6a67a052017-07-20 23:51:07614 run.builder.ensure(HostCompiletest {
Mark Simulacrumf1d04a32017-07-20 15:42:18615 compiler,
Mark Simulacrum6a67a052017-07-20 23:51:07616 target: run.target,
Mark Simulacrumf1d04a32017-07-20 15:42:18617 mode: test.mode,
618 suite: test.suite,
Mark Simulacrum6b3413d2017-07-05 12:41:27619 });
Mark Simulacrumf1d04a32017-07-20 15:42:18620 } else {
621 for test in HOST_COMPILETESTS {
Mark Simulacruma88a09c2017-07-23 13:22:12622 if test.mode == "pretty" {
623 continue;
624 }
Mark Simulacrum6a67a052017-07-20 23:51:07625 run.builder.ensure(HostCompiletest {
Mark Simulacrumaa8b93b2017-07-07 18:31:29626 compiler,
Mark Simulacrum6a67a052017-07-20 23:51:07627 target: run.target,
Mark Simulacrumaa8b93b2017-07-07 18:31:29628 mode: test.mode,
629 suite: test.suite
630 });
631 }
Mark Simulacrum6b3413d2017-07-05 12:41:27632 }
633 }
Alex Crichtonf72bfe62016-05-02 22:16:15634
Mark Simulacrumf1d04a32017-07-20 15:42:18635 fn run(self, builder: &Builder) {
636 builder.ensure(Compiletest {
637 compiler: self.compiler,
638 target: self.target,
639 mode: self.mode,
640 suite: self.suite,
641 })
642 }
643}
644
645#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
646struct Compiletest {
647 compiler: Compiler,
648 target: Interned<String>,
649 mode: &'static str,
650 suite: &'static str,
651}
652
653impl Step for Compiletest {
654 type Output = ();
655
656 fn should_run(run: ShouldRun) -> ShouldRun {
657 run.never()
658 }
659
Mark Simulacrum001e9f32017-07-05 01:41:43660 /// Executes the `compiletest` tool to run a suite of tests.
661 ///
662 /// Compiles all tests with `compiler` for `target` with the specified
663 /// compiletest `mode` and `suite` arguments. For example `mode` can be
664 /// "run-pass" or `suite` can be something like `debuginfo`.
665 fn run(self, builder: &Builder) {
666 let build = builder.build;
667 let compiler = self.compiler;
668 let target = self.target;
669 let mode = self.mode;
670 let suite = self.suite;
Mark Simulacrum6b3413d2017-07-05 12:41:27671
672 // Skip codegen tests if they aren't enabled in configuration.
673 if !build.config.codegen_tests && suite == "codegen" {
674 return;
675 }
676
677 if suite == "debuginfo" {
Mark Simulacrum951616c2017-07-20 17:23:29678 // Skip debuginfo tests on MSVC
679 if build.build.contains("msvc") {
680 return;
681 }
682
Mark Simulacrum6b3413d2017-07-05 12:41:27683 if mode == "debuginfo-XXX" {
684 return if build.build.contains("apple") {
685 builder.ensure(Compiletest {
686 mode: "debuginfo-lldb",
687 ..self
Mark Simulacrum528646e2017-07-14 00:48:44688 });
Mark Simulacrum6b3413d2017-07-05 12:41:27689 } else {
690 builder.ensure(Compiletest {
691 mode: "debuginfo-gdb",
692 ..self
Mark Simulacrum528646e2017-07-14 00:48:44693 });
Mark Simulacrum6b3413d2017-07-05 12:41:27694 };
695 }
696
Mark Simulacrum6b3413d2017-07-05 12:41:27697 builder.ensure(dist::DebuggerScripts {
Mark Simulacrum528646e2017-07-14 00:48:44698 sysroot: builder.sysroot(compiler),
Mark Simulacrumfef9b482017-07-23 16:03:40699 host: target
Mark Simulacrum6b3413d2017-07-05 12:41:27700 });
701 }
702
703 if suite.ends_with("fulldeps") ||
704 // FIXME: Does pretty need librustc compiled? Note that there are
705 // fulldeps test suites with mode = pretty as well.
706 mode == "pretty" ||
707 mode == "rustdoc" ||
708 mode == "run-make" {
709 builder.ensure(compile::Rustc { compiler, target });
710 }
711
712 builder.ensure(compile::Test { compiler, target });
713 builder.ensure(native::TestHelpers { target });
Mark Simulacrumaa8b93b2017-07-07 18:31:29714 builder.ensure(RemoteCopyLibs { compiler, target });
Mark Simulacrum6b3413d2017-07-05 12:41:27715
Mark Simulacrum001e9f32017-07-05 01:41:43716 let _folder = build.fold_output(|| format!("test_{}", suite));
717 println!("Check compiletest suite={} mode={} ({} -> {})",
Mark Simulacrum528646e2017-07-14 00:48:44718 suite, mode, &compiler.host, target);
Mark Simulacrum6b3413d2017-07-05 12:41:27719 let mut cmd = builder.tool_cmd(Tool::Compiletest);
Alex Crichtonb325baf2016-04-05 18:34:23720
Mark Simulacrum001e9f32017-07-05 01:41:43721 // compiletest currently has... a lot of arguments, so let's just pass all
722 // of them!
Brian Anderson8401e372016-09-15 19:42:26723
Mark Simulacrumc114fe52017-07-05 17:21:33724 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
Mark Simulacrum60388302017-07-05 16:46:41725 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
Mark Simulacrumc114fe52017-07-05 17:21:33726 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
Mark Simulacrum4e5333c2017-07-25 22:54:33727
728 // Avoid depending on rustdoc when we don't need it.
729 if mode == "rustdoc" || mode == "run-make" {
Mark Simulacrumfacf5a92017-08-04 22:13:01730 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host));
Mark Simulacrum4e5333c2017-07-25 22:54:33731 }
732
Mark Simulacrum001e9f32017-07-05 01:41:43733 cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
734 cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
735 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
736 cmd.arg("--mode").arg(mode);
737 cmd.arg("--target").arg(target);
Mark Simulacrum528646e2017-07-14 00:48:44738 cmd.arg("--host").arg(&*compiler.host);
739 cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(build.build));
Alex Crichtonf4e4ec72016-05-13 22:26:41740
Mark Simulacrum001e9f32017-07-05 01:41:43741 if let Some(ref nodejs) = build.config.nodejs {
742 cmd.arg("--nodejs").arg(nodejs);
743 }
Alex Crichtonf4e4ec72016-05-13 22:26:41744
Mark Simulacrum001e9f32017-07-05 01:41:43745 let mut flags = vec!["-Crpath".to_string()];
746 if build.config.rust_optimize_tests {
747 flags.push("-O".to_string());
748 }
749 if build.config.rust_debuginfo_tests {
750 flags.push("-g".to_string());
751 }
Oliver Schneider8c2ec682017-12-11 21:27:32752 flags.push("-Zmiri -Zunstable-options".to_string());
Santiago Pastorinodb41f1e2018-01-18 22:44:41753 flags.push(build.config.cmd.rustc_args().join(" "));
Alex Crichtoncbe62922016-04-19 16:44:19754
Oliver Schneideracdf83f2017-12-06 08:25:29755 if let Some(linker) = build.linker(target) {
756 cmd.arg("--linker").arg(linker);
757 }
758
759 let hostflags = flags.clone();
Mark Simulacrum001e9f32017-07-05 01:41:43760 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
Alex Crichtoncbe62922016-04-19 16:44:19761
Oliver Schneideracdf83f2017-12-06 08:25:29762 let mut targetflags = flags.clone();
Mark Simulacrum001e9f32017-07-05 01:41:43763 targetflags.push(format!("-Lnative={}",
764 build.test_helpers_out(target).display()));
765 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
Alex Crichtonb325baf2016-04-05 18:34:23766
Mark Simulacrum001e9f32017-07-05 01:41:43767 cmd.arg("--docck-python").arg(build.python());
Alex Crichtonb325baf2016-04-05 18:34:23768
Mark Simulacrum001e9f32017-07-05 01:41:43769 if build.build.ends_with("apple-darwin") {
770 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
771 // LLDB plugin's compiled module which only works with the system python
772 // (namely not Homebrew-installed python)
773 cmd.arg("--lldb-python").arg("/usr/bin/python");
774 } else {
775 cmd.arg("--lldb-python").arg(build.python());
776 }
Alex Crichtonb325baf2016-04-05 18:34:23777
Mark Simulacrum001e9f32017-07-05 01:41:43778 if let Some(ref gdb) = build.config.gdb {
779 cmd.arg("--gdb").arg(gdb);
780 }
781 if let Some(ref vers) = build.lldb_version {
782 cmd.arg("--lldb-version").arg(vers);
783 }
784 if let Some(ref dir) = build.lldb_python_dir {
785 cmd.arg("--lldb-python-dir").arg(dir);
786 }
Alex Crichtonb325baf2016-04-05 18:34:23787
Mark Simulacrum44ffb612017-07-30 04:12:53788 cmd.args(&build.config.cmd.test_args());
Corey Farwellc8c6d2c2016-10-30 01:58:52789
Mark Simulacrum001e9f32017-07-05 01:41:43790 if build.is_verbose() {
791 cmd.arg("--verbose");
792 }
Alex Crichton126e09e2016-04-14 22:51:03793
Mark Simulacrum001e9f32017-07-05 01:41:43794 if build.config.quiet_tests {
795 cmd.arg("--quiet");
796 }
Alex Crichton1747ce22017-01-28 21:38:06797
bjorn30c97bbf2017-08-13 10:30:54798 if build.config.llvm_enabled {
799 let llvm_config = build.llvm_config(target);
800 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
801 cmd.arg("--llvm-version").arg(llvm_version);
802 if !build.is_rust_llvm(target) {
803 cmd.arg("--system-llvm");
804 }
805
806 // Only pass correct values for these flags for the `run-make` suite as it
807 // requires that a C++ compiler was configured which isn't always the case.
808 if suite == "run-make" {
809 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
810 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
811 cmd.arg("--cc").arg(build.cc(target))
812 .arg("--cxx").arg(build.cxx(target).unwrap())
813 .arg("--cflags").arg(build.cflags(target).join(" "))
814 .arg("--llvm-components").arg(llvm_components.trim())
815 .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
Oliver Schneideracdf83f2017-12-06 08:25:29816 if let Some(ar) = build.ar(target) {
817 cmd.arg("--ar").arg(ar);
818 }
bjorn30c97bbf2017-08-13 10:30:54819 }
820 }
821 if suite == "run-make" && !build.config.llvm_enabled {
bjorn31c28cf52017-08-13 14:49:09822 println!("Ignoring run-make test suite as they generally dont work without LLVM");
bjorn30c97bbf2017-08-13 10:30:54823 return;
824 }
825
826 if suite != "run-make" {
Mark Simulacrum001e9f32017-07-05 01:41:43827 cmd.arg("--cc").arg("")
828 .arg("--cxx").arg("")
829 .arg("--cflags").arg("")
830 .arg("--llvm-components").arg("")
831 .arg("--llvm-cxxflags").arg("");
832 }
833
834 if build.remote_tested(target) {
Mark Simulacrum6b3413d2017-07-05 12:41:27835 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
Mark Simulacrum001e9f32017-07-05 01:41:43836 }
837
838 // Running a C compiler on MSVC requires a few env vars to be set, to be
839 // sure to set them here.
840 //
841 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
842 // rather than stomp over it.
843 if target.contains("msvc") {
Oliver Schneideracdf83f2017-12-06 08:25:29844 for &(ref k, ref v) in build.cc[&target].env() {
Mark Simulacrum001e9f32017-07-05 01:41:43845 if k != "PATH" {
846 cmd.env(k, v);
847 }
Alex Crichton126e09e2016-04-14 22:51:03848 }
849 }
Mark Simulacrum001e9f32017-07-05 01:41:43850 cmd.env("RUSTC_BOOTSTRAP", "1");
851 build.add_rust_test_threads(&mut cmd);
852
853 if build.config.sanitizers {
854 cmd.env("SANITIZER_SUPPORT", "1");
855 }
856
857 if build.config.profiler {
858 cmd.env("PROFILER_SUPPORT", "1");
859 }
860
861 cmd.arg("--adb-path").arg("adb");
862 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
863 if target.contains("android") {
864 // Assume that cc for this target comes from the android sysroot
865 cmd.arg("--android-cross-path")
866 .arg(build.cc(target).parent().unwrap().parent().unwrap());
867 } else {
868 cmd.arg("--android-cross-path").arg("");
869 }
870
871 build.ci_env.force_coloring_in_ci(&mut cmd);
872
873 let _time = util::timeit();
874 try_run(build, &mut cmd);
Alex Crichton126e09e2016-04-14 22:51:03875 }
Alex Crichtonb325baf2016-04-05 18:34:23876}
Alex Crichtonede89442016-04-15 01:00:35877
Mark Simulacrum528646e2017-07-14 00:48:44878#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
879pub struct Docs {
880 compiler: Compiler,
Mark Simulacruma5ab2ce2017-07-12 15:15:00881}
882
Mark Simulacrum528646e2017-07-14 00:48:44883impl Step for Docs {
Mark Simulacruma5ab2ce2017-07-12 15:15:00884 type Output = ();
885 const DEFAULT: bool = true;
886 const ONLY_HOSTS: bool = true;
Alex Crichtonede89442016-04-15 01:00:35887
Mark Simulacrum56128fb2017-07-19 00:03:38888 fn should_run(run: ShouldRun) -> ShouldRun {
889 run.path("src/doc")
Mark Simulacruma5ab2ce2017-07-12 15:15:00890 }
891
Mark Simulacrum6a67a052017-07-20 23:51:07892 fn make_run(run: RunConfig) {
893 run.builder.ensure(Docs {
894 compiler: run.builder.compiler(run.builder.top_stage, run.host),
Mark Simulacruma5ab2ce2017-07-12 15:15:00895 });
896 }
897
898 /// Run `rustdoc --test` for all documentation in `src/doc`.
899 ///
900 /// This will run all tests in our markdown documentation (e.g. the book)
901 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
902 /// `compiler`.
903 fn run(self, builder: &Builder) {
904 let build = builder.build;
905 let compiler = self.compiler;
Mark Simulacrumceecd622017-07-12 16:12:47906
907 builder.ensure(compile::Test { compiler, target: compiler.host });
908
Mark Simulacruma5ab2ce2017-07-12 15:15:00909 // Do a breadth-first traversal of the `src/doc` directory and just run
910 // tests for all files that end in `*.md`
911 let mut stack = vec![build.src.join("src/doc")];
912 let _time = util::timeit();
913 let _folder = build.fold_output(|| "test_docs");
914
915 while let Some(p) = stack.pop() {
916 if p.is_dir() {
917 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
918 continue
919 }
920
921 if p.extension().and_then(|s| s.to_str()) != Some("md") {
922 continue;
923 }
924
925 // The nostarch directory in the book is for no starch, and so isn't
926 // guaranteed to build. We don't care if it doesn't build, so skip it.
927 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
928 continue;
929 }
930
931 markdown_test(builder, compiler, &p);
Alex Crichtonede89442016-04-15 01:00:35932 }
Alex Crichtonede89442016-04-15 01:00:35933 }
934}
935
Mark Simulacrum528646e2017-07-14 00:48:44936#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
937pub struct ErrorIndex {
938 compiler: Compiler,
Mark Simulacrum001e9f32017-07-05 01:41:43939}
Alex Crichton0e272de2016-11-16 20:31:19940
Mark Simulacrum528646e2017-07-14 00:48:44941impl Step for ErrorIndex {
Mark Simulacrum001e9f32017-07-05 01:41:43942 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:27943 const DEFAULT: bool = true;
944 const ONLY_HOSTS: bool = true;
945
Mark Simulacrum56128fb2017-07-19 00:03:38946 fn should_run(run: ShouldRun) -> ShouldRun {
947 run.path("src/tools/error_index_generator")
Mark Simulacrum6b3413d2017-07-05 12:41:27948 }
949
Mark Simulacrum6a67a052017-07-20 23:51:07950 fn make_run(run: RunConfig) {
951 run.builder.ensure(ErrorIndex {
952 compiler: run.builder.compiler(run.builder.top_stage, run.host),
Mark Simulacrum6b3413d2017-07-05 12:41:27953 });
954 }
Alex Crichtonede89442016-04-15 01:00:35955
Mark Simulacrum001e9f32017-07-05 01:41:43956 /// Run the error index generator tool to execute the tests located in the error
957 /// index.
958 ///
959 /// The `error_index_generator` tool lives in `src/tools` and is used to
960 /// generate a markdown file from the error indexes of the code base which is
961 /// then passed to `rustdoc --test`.
962 fn run(self, builder: &Builder) {
963 let build = builder.build;
964 let compiler = self.compiler;
965
Mark Simulacrum6b3413d2017-07-05 12:41:27966 builder.ensure(compile::Std { compiler, target: compiler.host });
967
Mark Simulacrum001e9f32017-07-05 01:41:43968 let _folder = build.fold_output(|| "test_error_index");
969 println!("Testing error-index stage{}", compiler.stage);
970
971 let dir = testdir(build, compiler.host);
972 t!(fs::create_dir_all(&dir));
973 let output = dir.join("error-index.md");
974
975 let _time = util::timeit();
Mark Simulacrum60388302017-07-05 16:46:41976 build.run(builder.tool_cmd(Tool::ErrorIndex)
Mark Simulacrum001e9f32017-07-05 01:41:43977 .arg("markdown")
978 .arg(&output)
Alex Crichton8c9bf662018-01-03 00:21:35979 .env("CFG_BUILD", &build.build)
980 .env("RUSTC_ERROR_METADATA_DST", build.extended_error_dir()));
Mark Simulacrum001e9f32017-07-05 01:41:43981
Mark Simulacrumc114fe52017-07-05 17:21:33982 markdown_test(builder, compiler, &output);
Mark Simulacrum001e9f32017-07-05 01:41:43983 }
Alex Crichtonede89442016-04-15 01:00:35984}
985
Mark Simulacrumc114fe52017-07-05 17:21:33986fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
987 let build = builder.build;
Mark Simulacrumdd1d75e2017-06-04 23:55:50988 let mut file = t!(File::open(markdown));
989 let mut contents = String::new();
990 t!(file.read_to_string(&mut contents));
991 if !contents.contains("```") {
992 return;
993 }
994
Mark Simulacrumbc8fabb2017-06-06 18:00:22995 println!("doc tests for: {}", markdown.display());
Mark Simulacrumfacf5a92017-08-04 22:13:01996 let mut cmd = builder.rustdoc_cmd(compiler.host);
Alex Crichton0e272de2016-11-16 20:31:19997 build.add_rust_test_threads(&mut cmd);
Alex Crichtonede89442016-04-15 01:00:35998 cmd.arg("--test");
999 cmd.arg(markdown);
Alex Crichton6f62fae2016-12-12 17:03:351000 cmd.env("RUSTC_BOOTSTRAP", "1");
Corey Farwellc8c6d2c2016-10-30 01:58:521001
Mark Simulacrum44ffb612017-07-30 04:12:531002 let test_args = build.config.cmd.test_args().join(" ");
Corey Farwellc8c6d2c2016-10-30 01:58:521003 cmd.arg("--test-args").arg(test_args);
1004
kennytm6ac07872017-05-21 20:27:471005 if build.config.quiet_tests {
Josh Stone617aea42017-06-02 16:27:441006 try_run_quiet(build, &mut cmd);
kennytm6ac07872017-05-21 20:27:471007 } else {
Josh Stone617aea42017-06-02 16:27:441008 try_run(build, &mut cmd);
kennytm6ac07872017-05-21 20:27:471009 }
Alex Crichtonede89442016-04-15 01:00:351010}
Alex Crichtonbb9062a2016-04-29 21:23:151011
Mark Simulacrum528646e2017-07-14 00:48:441012#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum981afa52017-07-18 21:28:531013pub struct CrateLibrustc {
Mark Simulacrum528646e2017-07-14 00:48:441014 compiler: Compiler,
1015 target: Interned<String>,
Mark Simulacrum6b3413d2017-07-05 12:41:271016 test_kind: TestKind,
Mark Simulacrum528646e2017-07-14 00:48:441017 krate: Option<Interned<String>>,
Mark Simulacrum6b3413d2017-07-05 12:41:271018}
1019
Mark Simulacrum981afa52017-07-18 21:28:531020impl Step for CrateLibrustc {
Mark Simulacrum6b3413d2017-07-05 12:41:271021 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271022 const DEFAULT: bool = true;
1023 const ONLY_HOSTS: bool = true;
1024
Mark Simulacrum56128fb2017-07-19 00:03:381025 fn should_run(run: ShouldRun) -> ShouldRun {
1026 run.krate("rustc-main")
Mark Simulacrum6b3413d2017-07-05 12:41:271027 }
1028
Mark Simulacrum6a67a052017-07-20 23:51:071029 fn make_run(run: RunConfig) {
1030 let builder = run.builder;
1031 let compiler = builder.compiler(builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:271032
Mark Simulacrum6a67a052017-07-20 23:51:071033 let make = |name: Option<Interned<String>>| {
Mark Simulacrum6b3413d2017-07-05 12:41:271034 let test_kind = if builder.kind == Kind::Test {
1035 TestKind::Test
1036 } else if builder.kind == Kind::Bench {
1037 TestKind::Bench
1038 } else {
Mark Simulacrum981afa52017-07-18 21:28:531039 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
Mark Simulacrum6b3413d2017-07-05 12:41:271040 };
1041
Mark Simulacrum981afa52017-07-18 21:28:531042 builder.ensure(CrateLibrustc {
Mark Simulacrum6b3413d2017-07-05 12:41:271043 compiler,
Mark Simulacrum6a67a052017-07-20 23:51:071044 target: run.target,
Zack M. Davis1b6c9602017-08-07 05:54:091045 test_kind,
Mark Simulacrum6b3413d2017-07-05 12:41:271046 krate: name,
1047 });
1048 };
1049
Mark Simulacrum6a67a052017-07-20 23:51:071050 if let Some(path) = run.path {
Mark Simulacrum6b3413d2017-07-05 12:41:271051 for (name, krate_path) in builder.crates("rustc-main") {
1052 if path.ends_with(krate_path) {
Mark Simulacrum6a67a052017-07-20 23:51:071053 make(Some(name));
Mark Simulacrum6b3413d2017-07-05 12:41:271054 }
1055 }
1056 } else {
Mark Simulacrum6a67a052017-07-20 23:51:071057 make(None);
Mark Simulacrum6b3413d2017-07-05 12:41:271058 }
1059 }
1060
1061
1062 fn run(self, builder: &Builder) {
Mark Simulacrum981afa52017-07-18 21:28:531063 builder.ensure(Crate {
Mark Simulacrum6b3413d2017-07-05 12:41:271064 compiler: self.compiler,
1065 target: self.target,
1066 mode: Mode::Librustc,
1067 test_kind: self.test_kind,
1068 krate: self.krate,
1069 });
1070 }
1071}
1072
Mark Simulacrum528646e2017-07-14 00:48:441073#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum981afa52017-07-18 21:28:531074pub struct Crate {
Mark Simulacrum528646e2017-07-14 00:48:441075 compiler: Compiler,
1076 target: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:431077 mode: Mode,
1078 test_kind: TestKind,
Mark Simulacrum528646e2017-07-14 00:48:441079 krate: Option<Interned<String>>,
Mark Simulacrum001e9f32017-07-05 01:41:431080}
Alex Crichtonbb9062a2016-04-29 21:23:151081
Mark Simulacrum981afa52017-07-18 21:28:531082impl Step for Crate {
Mark Simulacrum001e9f32017-07-05 01:41:431083 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271084 const DEFAULT: bool = true;
1085
Mark Simulacrum56128fb2017-07-19 00:03:381086 fn should_run(run: ShouldRun) -> ShouldRun {
1087 run.krate("std").krate("test")
Mark Simulacrum6b3413d2017-07-05 12:41:271088 }
1089
Mark Simulacrum6a67a052017-07-20 23:51:071090 fn make_run(run: RunConfig) {
1091 let builder = run.builder;
1092 let compiler = builder.compiler(builder.top_stage, run.host);
Mark Simulacrum6b3413d2017-07-05 12:41:271093
Mark Simulacrum6a67a052017-07-20 23:51:071094 let make = |mode: Mode, name: Option<Interned<String>>| {
Mark Simulacrum6b3413d2017-07-05 12:41:271095 let test_kind = if builder.kind == Kind::Test {
1096 TestKind::Test
1097 } else if builder.kind == Kind::Bench {
1098 TestKind::Bench
1099 } else {
Mark Simulacrum981afa52017-07-18 21:28:531100 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
Mark Simulacrum6b3413d2017-07-05 12:41:271101 };
1102
Mark Simulacrum981afa52017-07-18 21:28:531103 builder.ensure(Crate {
Mark Simulacrum6a67a052017-07-20 23:51:071104 compiler,
1105 target: run.target,
Zack M. Davis1b6c9602017-08-07 05:54:091106 mode,
1107 test_kind,
Mark Simulacrum6b3413d2017-07-05 12:41:271108 krate: name,
1109 });
1110 };
1111
Mark Simulacrum6a67a052017-07-20 23:51:071112 if let Some(path) = run.path {
Mark Simulacrum6b3413d2017-07-05 12:41:271113 for (name, krate_path) in builder.crates("std") {
1114 if path.ends_with(krate_path) {
Mark Simulacrum6a67a052017-07-20 23:51:071115 make(Mode::Libstd, Some(name));
Mark Simulacrum6b3413d2017-07-05 12:41:271116 }
1117 }
1118 for (name, krate_path) in builder.crates("test") {
1119 if path.ends_with(krate_path) {
Mark Simulacrum6a67a052017-07-20 23:51:071120 make(Mode::Libtest, Some(name));
Mark Simulacrum6b3413d2017-07-05 12:41:271121 }
1122 }
1123 } else {
Mark Simulacrum6a67a052017-07-20 23:51:071124 make(Mode::Libstd, None);
1125 make(Mode::Libtest, None);
Mark Simulacrum6b3413d2017-07-05 12:41:271126 }
1127 }
Alex Crichton7046fea2016-12-25 23:20:331128
Mark Simulacrum001e9f32017-07-05 01:41:431129 /// Run all unit tests plus documentation tests for an entire crate DAG defined
1130 /// by a `Cargo.toml`
1131 ///
1132 /// This is what runs tests for crates like the standard library, compiler, etc.
1133 /// It essentially is the driver for running `cargo test`.
1134 ///
1135 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1136 /// arguments, and those arguments are discovered from `cargo metadata`.
1137 fn run(self, builder: &Builder) {
1138 let build = builder.build;
1139 let compiler = self.compiler;
1140 let target = self.target;
1141 let mode = self.mode;
1142 let test_kind = self.test_kind;
1143 let krate = self.krate;
Alex Crichtonbb9062a2016-04-29 21:23:151144
Mark Simulacrum6b3413d2017-07-05 12:41:271145 builder.ensure(compile::Test { compiler, target });
1146 builder.ensure(RemoteCopyLibs { compiler, target });
Mark Simulacrum001e9f32017-07-05 01:41:431147
1148 // If we're not doing a full bootstrap but we're testing a stage2 version of
1149 // libstd, then what we're actually testing is the libstd produced in
1150 // stage1. Reflect that here by updating the compiler that we're working
1151 // with automatically.
1152 let compiler = if build.force_use_stage1(compiler, target) {
Mark Simulacrum6b3413d2017-07-05 12:41:271153 builder.compiler(1, compiler.host)
Mark Simulacrum001e9f32017-07-05 01:41:431154 } else {
1155 compiler.clone()
1156 };
1157
Alex Crichton90105672017-07-17 16:32:081158 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
1159 let (name, root) = match mode {
1160 Mode::Libstd => {
1161 compile::std_cargo(build, &compiler, target, &mut cargo);
1162 ("libstd", "std")
1163 }
1164 Mode::Libtest => {
1165 compile::test_cargo(build, &compiler, target, &mut cargo);
1166 ("libtest", "test")
1167 }
1168 Mode::Librustc => {
1169 builder.ensure(compile::Rustc { compiler, target });
O01eg83e76d62017-12-25 21:00:091170 compile::rustc_cargo(build, target, &mut cargo);
Alex Crichton90105672017-07-17 16:32:081171 ("librustc", "rustc-main")
1172 }
1173 _ => panic!("can only test libraries"),
1174 };
1175 let root = INTERNER.intern_string(String::from(root));
1176 let _folder = build.fold_output(|| {
1177 format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, name)
1178 });
1179 println!("{} {} stage{} ({} -> {})", test_kind, name, compiler.stage,
1180 &compiler.host, target);
1181
Mark Simulacrum001e9f32017-07-05 01:41:431182 // Build up the base `cargo test` command.
1183 //
1184 // Pass in some standard flags then iterate over the graph we've discovered
1185 // in `cargo metadata` with the maps above and figure out what `-p`
1186 // arguments need to get passed.
Mark Simulacrum001e9f32017-07-05 01:41:431187 if test_kind.subcommand() == "test" && !build.fail_fast {
1188 cargo.arg("--no-fail-fast");
Alex Crichtonbb9062a2016-04-29 21:23:151189 }
Mark Simulacrum001e9f32017-07-05 01:41:431190
1191 match krate {
1192 Some(krate) => {
1193 cargo.arg("-p").arg(krate);
1194 }
1195 None => {
1196 let mut visited = HashSet::new();
1197 let mut next = vec![root];
1198 while let Some(name) = next.pop() {
Alex Crichton90105672017-07-17 16:32:081199 // Right now jemalloc and the sanitizer crates are
1200 // target-specific crate in the sense that it's not present
1201 // on all platforms. Custom skip it here for now, but if we
1202 // add more this probably wants to get more generalized.
Mark Simulacrum001e9f32017-07-05 01:41:431203 //
Alex Crichton90105672017-07-17 16:32:081204 // Also skip `build_helper` as it's not compiled normally
1205 // for target during the bootstrap and it's just meant to be
1206 // a helper crate, not tested. If it leaks through then it
1207 // ends up messing with various mtime calculations and such.
1208 if !name.contains("jemalloc") &&
1209 *name != *"build_helper" &&
Oliver Schneideracdf83f2017-12-06 08:25:291210 !(name.starts_with("rustc_") && name.ends_with("san")) &&
1211 name != "dlmalloc" {
Mark Simulacrum001e9f32017-07-05 01:41:431212 cargo.arg("-p").arg(&format!("{}:0.0.0", name));
1213 }
Mark Simulacrum528646e2017-07-14 00:48:441214 for dep in build.crates[&name].deps.iter() {
Mark Simulacrum001e9f32017-07-05 01:41:431215 if visited.insert(dep) {
Mark Simulacrum528646e2017-07-14 00:48:441216 next.push(*dep);
Mark Simulacrum001e9f32017-07-05 01:41:431217 }
Alex Crichtona270b802016-10-21 20:18:091218 }
1219 }
Alex Crichtonbb9062a2016-04-29 21:23:151220 }
1221 }
Alex Crichtonbb9062a2016-04-29 21:23:151222
Mark Simulacrum001e9f32017-07-05 01:41:431223 // The tests are going to run with the *target* libraries, so we need to
1224 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1225 //
1226 // Note that to run the compiler we need to run with the *host* libraries,
1227 // but our wrapper scripts arrange for that to be the case anyway.
1228 let mut dylib_path = dylib_path();
Mark Simulacrum528646e2017-07-14 00:48:441229 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
Mark Simulacrum001e9f32017-07-05 01:41:431230 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
Alex Crichtonbb9062a2016-04-29 21:23:151231
Mark Simulacrum001e9f32017-07-05 01:41:431232 cargo.arg("--");
Mark Simulacrum44ffb612017-07-30 04:12:531233 cargo.args(&build.config.cmd.test_args());
Alex Crichton0e272de2016-11-16 20:31:191234
Mark Simulacrum001e9f32017-07-05 01:41:431235 if build.config.quiet_tests {
1236 cargo.arg("--quiet");
1237 }
Corey Farwellc8c6d2c2016-10-30 01:58:521238
Mark Simulacrum001e9f32017-07-05 01:41:431239 let _time = util::timeit();
Alex Crichton0e272de2016-11-16 20:31:191240
Mark Simulacrum001e9f32017-07-05 01:41:431241 if target.contains("emscripten") {
Alex Crichton8e7849e2017-07-29 00:52:441242 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1243 build.config.nodejs.as_ref().expect("nodejs not configured"));
Oliver Schneideracdf83f2017-12-06 08:25:291244 } else if target.starts_with("wasm32") {
1245 // On the wasm32-unknown-unknown target we're using LTO which is
1246 // incompatible with `-C prefer-dynamic`, so disable that here
1247 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
1248
1249 let node = build.config.nodejs.as_ref()
1250 .expect("nodejs not configured");
1251 let runner = format!("{} {}/src/etc/wasm32-shim.js",
1252 node.display(),
1253 build.src.display());
1254 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
Mark Simulacrum001e9f32017-07-05 01:41:431255 } else if build.remote_tested(target) {
Alex Crichton8e7849e2017-07-29 00:52:441256 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1257 format!("{} run",
1258 builder.tool_exe(Tool::RemoteTestClient).display()));
Mark Simulacrum001e9f32017-07-05 01:41:431259 }
Alex Crichton8e7849e2017-07-29 00:52:441260 try_run(build, &mut cargo);
Alex Crichton39a5d3f2016-06-28 20:31:301261 }
1262}
1263
Mark Simulacrumf87696b2017-09-02 14:02:321264#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1265pub struct Rustdoc {
1266 host: Interned<String>,
1267 test_kind: TestKind,
1268}
1269
1270impl Step for Rustdoc {
1271 type Output = ();
1272 const DEFAULT: bool = true;
1273 const ONLY_HOSTS: bool = true;
1274
1275 fn should_run(run: ShouldRun) -> ShouldRun {
1276 run.path("src/librustdoc").path("src/tools/rustdoc")
1277 }
1278
1279 fn make_run(run: RunConfig) {
1280 let builder = run.builder;
1281
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 };
1289
1290 builder.ensure(Rustdoc {
1291 host: run.host,
1292 test_kind,
1293 });
1294 }
1295
1296 fn run(self, builder: &Builder) {
1297 let build = builder.build;
1298 let test_kind = self.test_kind;
1299
1300 let compiler = builder.compiler(builder.top_stage, self.host);
1301 let target = compiler.host;
1302
Alex Crichton3da54fb2017-09-15 22:28:591303 let mut cargo = tool::prepare_tool_cargo(builder,
1304 compiler,
1305 target,
1306 test_kind.subcommand(),
1307 "src/tools/rustdoc");
Mark Simulacrumf87696b2017-09-02 14:02:321308 let _folder = build.fold_output(|| {
1309 format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage)
1310 });
1311 println!("{} rustdoc stage{} ({} -> {})", test_kind, compiler.stage,
1312 &compiler.host, target);
1313
1314 if test_kind.subcommand() == "test" && !build.fail_fast {
1315 cargo.arg("--no-fail-fast");
1316 }
1317
1318 cargo.arg("-p").arg("rustdoc:0.0.0");
1319
1320 cargo.arg("--");
1321 cargo.args(&build.config.cmd.test_args());
1322
1323 if build.config.quiet_tests {
1324 cargo.arg("--quiet");
1325 }
1326
1327 let _time = util::timeit();
1328
1329 try_run(build, &mut cargo);
1330 }
1331}
1332
Alex Crichton8e7849e2017-07-29 00:52:441333fn envify(s: &str) -> String {
1334 s.chars().map(|c| {
1335 match c {
1336 '-' => '_',
1337 c => c,
Alex Crichton1747ce22017-01-28 21:38:061338 }
Alex Crichton8e7849e2017-07-29 00:52:441339 }).flat_map(|c| c.to_uppercase()).collect()
Alex Crichton39a5d3f2016-06-28 20:31:301340}
1341
Mark Simulacrumceecd622017-07-12 16:12:471342/// Some test suites are run inside emulators or on remote devices, and most
1343/// of our test binaries are linked dynamically which means we need to ship
1344/// the standard library and such to the emulator ahead of time. This step
1345/// represents this and is a dependency of all test suites.
1346///
1347/// Most of the time this is a noop. For some steps such as shipping data to
1348/// QEMU we have to build our own tools so we've got conditional dependencies
1349/// on those programs as well. Note that the remote test client is built for
1350/// the build target (us) and the server is built for the target.
Mark Simulacrum528646e2017-07-14 00:48:441351#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1352pub struct RemoteCopyLibs {
1353 compiler: Compiler,
1354 target: Interned<String>,
Mark Simulacrum001e9f32017-07-05 01:41:431355}
Alex Crichton1747ce22017-01-28 21:38:061356
Mark Simulacrum528646e2017-07-14 00:48:441357impl Step for RemoteCopyLibs {
Mark Simulacrum001e9f32017-07-05 01:41:431358 type Output = ();
Alex Crichton1747ce22017-01-28 21:38:061359
Mark Simulacrum56128fb2017-07-19 00:03:381360 fn should_run(run: ShouldRun) -> ShouldRun {
1361 run.never()
Mark Simulacrum681b1232017-07-14 12:30:161362 }
1363
Mark Simulacrum001e9f32017-07-05 01:41:431364 fn run(self, builder: &Builder) {
1365 let build = builder.build;
1366 let compiler = self.compiler;
1367 let target = self.target;
1368 if !build.remote_tested(target) {
1369 return
1370 }
Alex Crichton1747ce22017-01-28 21:38:061371
Mark Simulacrum6b3413d2017-07-05 12:41:271372 builder.ensure(compile::Test { compiler, target });
1373
Mark Simulacrum001e9f32017-07-05 01:41:431374 println!("REMOTE copy libs to emulator ({})", target);
1375 t!(fs::create_dir_all(build.out.join("tmp")));
1376
Mark Simulacrumfe0eca02017-07-23 01:29:081377 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
Mark Simulacrum001e9f32017-07-05 01:41:431378
1379 // Spawn the emulator and wait for it to come online
Mark Simulacrum6b3413d2017-07-05 12:41:271380 let tool = builder.tool_exe(Tool::RemoteTestClient);
Mark Simulacrum001e9f32017-07-05 01:41:431381 let mut cmd = Command::new(&tool);
1382 cmd.arg("spawn-emulator")
1383 .arg(target)
1384 .arg(&server)
1385 .arg(build.out.join("tmp"));
1386 if let Some(rootfs) = build.qemu_rootfs(target) {
1387 cmd.arg(rootfs);
1388 }
1389 build.run(&mut cmd);
1390
1391 // Push all our dylibs to the emulator
Mark Simulacrum60388302017-07-05 16:46:411392 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
Mark Simulacrum001e9f32017-07-05 01:41:431393 let f = t!(f);
1394 let name = f.file_name().into_string().unwrap();
1395 if util::is_dylib(&name) {
1396 build.run(Command::new(&tool)
1397 .arg("push")
1398 .arg(f.path()));
1399 }
Alex Crichton1747ce22017-01-28 21:38:061400 }
1401 }
1402}
1403
Mark Simulacrum528646e2017-07-14 00:48:441404#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum001e9f32017-07-05 01:41:431405pub struct Distcheck;
1406
Mark Simulacrum528646e2017-07-14 00:48:441407impl Step for Distcheck {
Mark Simulacrum001e9f32017-07-05 01:41:431408 type Output = ();
Mark Simulacrum44ffb612017-07-30 04:12:531409 const ONLY_BUILD: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:431410
Mark Simulacrum56128fb2017-07-19 00:03:381411 fn should_run(run: ShouldRun) -> ShouldRun {
1412 run.path("distcheck")
Mark Simulacrum681b1232017-07-14 12:30:161413 }
1414
Mark Simulacrum8f2e5762017-07-22 13:35:421415 fn make_run(run: RunConfig) {
1416 run.builder.ensure(Distcheck);
1417 }
1418
Mark Simulacrum001e9f32017-07-05 01:41:431419 /// Run "distcheck", a 'make check' from a tarball
1420 fn run(self, builder: &Builder) {
1421 let build = builder.build;
1422
Mark Simulacrum001e9f32017-07-05 01:41:431423 println!("Distcheck");
1424 let dir = build.out.join("tmp").join("distcheck");
1425 let _ = fs::remove_dir_all(&dir);
1426 t!(fs::create_dir_all(&dir));
1427
Mark Simulacrum1c118232017-07-22 16:48:291428 // Guarantee that these are built before we begin running.
1429 builder.ensure(dist::PlainSourceTarball);
1430 builder.ensure(dist::Src);
1431
Mark Simulacrum001e9f32017-07-05 01:41:431432 let mut cmd = Command::new("tar");
1433 cmd.arg("-xzf")
Mark Simulacrum5984e702017-07-13 00:52:311434 .arg(builder.ensure(dist::PlainSourceTarball))
Mark Simulacrum001e9f32017-07-05 01:41:431435 .arg("--strip-components=1")
1436 .current_dir(&dir);
1437 build.run(&mut cmd);
1438 build.run(Command::new("./configure")
1439 .args(&build.config.configure_args)
1440 .arg("--enable-vendor")
1441 .current_dir(&dir));
1442 build.run(Command::new(build_helper::make(&build.build))
1443 .arg("check")
1444 .current_dir(&dir));
1445
1446 // Now make sure that rust-src has all of libstd's dependencies
1447 println!("Distcheck rust-src");
1448 let dir = build.out.join("tmp").join("distcheck-src");
1449 let _ = fs::remove_dir_all(&dir);
1450 t!(fs::create_dir_all(&dir));
1451
1452 let mut cmd = Command::new("tar");
1453 cmd.arg("-xzf")
Mark Simulacrum5984e702017-07-13 00:52:311454 .arg(builder.ensure(dist::Src))
Mark Simulacrum001e9f32017-07-05 01:41:431455 .arg("--strip-components=1")
1456 .current_dir(&dir);
1457 build.run(&mut cmd);
1458
1459 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
1460 build.run(Command::new(&build.initial_cargo)
1461 .arg("generate-lockfile")
1462 .arg("--manifest-path")
1463 .arg(&toml)
1464 .current_dir(&dir));
Alex Crichtond38db822016-12-09 01:13:551465 }
Alex Crichtond38db822016-12-09 01:13:551466}
Alex Crichton1a040b32016-12-31 03:50:571467
Mark Simulacrum528646e2017-07-14 00:48:441468#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Mark Simulacrum001e9f32017-07-05 01:41:431469pub struct Bootstrap;
1470
Mark Simulacrum528646e2017-07-14 00:48:441471impl Step for Bootstrap {
Mark Simulacrum001e9f32017-07-05 01:41:431472 type Output = ();
Mark Simulacrum6b3413d2017-07-05 12:41:271473 const DEFAULT: bool = true;
1474 const ONLY_HOSTS: bool = true;
1475 const ONLY_BUILD: bool = true;
Mark Simulacrum001e9f32017-07-05 01:41:431476
1477 /// Test the build system itself
1478 fn run(self, builder: &Builder) {
1479 let build = builder.build;
1480 let mut cmd = Command::new(&build.initial_cargo);
1481 cmd.arg("test")
1482 .current_dir(build.src.join("src/bootstrap"))
1483 .env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
1484 .env("RUSTC_BOOTSTRAP", "1")
1485 .env("RUSTC", &build.initial_rustc);
1486 if !build.fail_fast {
1487 cmd.arg("--no-fail-fast");
1488 }
Mark Simulacrum44ffb612017-07-30 04:12:531489 cmd.arg("--").args(&build.config.cmd.test_args());
Mark Simulacrum001e9f32017-07-05 01:41:431490 try_run(build, &mut cmd);
Josh Stone617aea42017-06-02 16:27:441491 }
Mark Simulacrum6b3413d2017-07-05 12:41:271492
Mark Simulacrum56128fb2017-07-19 00:03:381493 fn should_run(run: ShouldRun) -> ShouldRun {
1494 run.path("src/bootstrap")
Mark Simulacrum6b3413d2017-07-05 12:41:271495 }
1496
Mark Simulacrum6a67a052017-07-20 23:51:071497 fn make_run(run: RunConfig) {
1498 run.builder.ensure(Bootstrap);
Mark Simulacrum6b3413d2017-07-05 12:41:271499 }
Alex Crichton1a040b32016-12-31 03:50:571500}