]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/test.rs
concerning well-formed suggestions for unused shorthand field patterns
[rust.git] / src / bootstrap / test.rs
1 // 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
11 //! Implementation of the test-related targets of the build system.
12 //!
13 //! This file implements the various regression test suites that we execute on
14 //! our CI.
15
16 use std::collections::HashSet;
17 use std::env;
18 use std::ffi::OsString;
19 use std::iter;
20 use std::fmt;
21 use std::fs::{self, File};
22 use std::path::{PathBuf, Path};
23 use std::process::Command;
24 use std::io::Read;
25
26 use build_helper::{self, output};
27
28 use builder::{Kind, RunConfig, ShouldRun, Builder, Compiler, Step};
29 use cache::{INTERNER, Interned};
30 use compile;
31 use dist;
32 use native;
33 use tool::{self, Tool};
34 use util::{self, dylib_path, dylib_path_var};
35 use {Build, Mode};
36 use toolstate::ToolState;
37
38 const ADB_TEST_DIR: &str = "/data/tmp/work";
39
40 /// The two modes of the test runner; tests or benchmarks.
41 #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone)]
42 pub enum TestKind {
43     /// Run `cargo test`
44     Test,
45     /// Run `cargo bench`
46     Bench,
47 }
48
49 impl 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
59 impl 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
68 fn try_run(build: &Build, cmd: &mut Command) -> bool {
69     if !build.fail_fast {
70         if !build.try_run(cmd) {
71             let mut failures = build.delayed_failures.borrow_mut();
72             failures.push(format!("{:?}", cmd));
73             return false;
74         }
75     } else {
76         build.run(cmd);
77     }
78     true
79 }
80
81 fn try_run_quiet(build: &Build, cmd: &mut Command) {
82     if !build.fail_fast {
83         if !build.try_run_quiet(cmd) {
84             let mut failures = build.delayed_failures.borrow_mut();
85             failures.push(format!("{:?}", cmd));
86         }
87     } else {
88         build.run_quiet(cmd);
89     }
90 }
91
92 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
93 pub struct Linkcheck {
94     host: Interned<String>,
95 }
96
97 impl Step for Linkcheck {
98     type Output = ();
99     const ONLY_HOSTS: bool = true;
100     const DEFAULT: bool = true;
101
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);
111
112         builder.default_doc(None);
113
114         let _time = util::timeit();
115         try_run(build, builder.tool_cmd(Tool::Linkchecker)
116                             .arg(build.out.join(host).join("doc")));
117     }
118
119     fn should_run(run: ShouldRun) -> ShouldRun {
120         let builder = run.builder;
121         run.path("src/tools/linkchecker").default_condition(builder.build.config.docs)
122     }
123
124     fn make_run(run: RunConfig) {
125         run.builder.ensure(Linkcheck { host: run.target });
126     }
127 }
128
129 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
130 pub struct Cargotest {
131     stage: u32,
132     host: Interned<String>,
133 }
134
135 impl Step for Cargotest {
136     type Output = ();
137     const ONLY_HOSTS: bool = true;
138
139     fn should_run(run: ShouldRun) -> ShouldRun {
140         run.path("src/tools/cargotest")
141     }
142
143     fn make_run(run: RunConfig) {
144         run.builder.ensure(Cargotest {
145             stage: run.builder.top_stage,
146             host: run.target,
147         });
148     }
149
150     /// 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;
156         let compiler = builder.compiler(self.stage, self.host);
157         builder.ensure(compile::Rustc { compiler, target: compiler.host });
158
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();
166         let mut cmd = builder.tool_cmd(Tool::CargoTest);
167         try_run(build, cmd.arg(&build.initial_cargo)
168                           .arg(&out_dir)
169                           .env("RUSTC", builder.rustc(compiler))
170                           .env("RUSTDOC", builder.rustdoc(compiler.host)));
171     }
172 }
173
174 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
175 pub struct Cargo {
176     stage: u32,
177     host: Interned<String>,
178 }
179
180 impl Step for Cargo {
181     type Output = ();
182     const ONLY_HOSTS: bool = true;
183
184     fn should_run(run: ShouldRun) -> ShouldRun {
185         run.path("src/tools/cargo")
186     }
187
188     fn make_run(run: RunConfig) {
189         run.builder.ensure(Cargo {
190             stage: run.builder.top_stage,
191             host: run.target,
192         });
193     }
194
195     /// Runs `cargo test` for `cargo` packaged with Rust.
196     fn run(self, builder: &Builder) {
197         let build = builder.build;
198         let compiler = builder.compiler(self.stage, self.host);
199
200         builder.ensure(tool::Cargo { compiler, target: self.host });
201         let mut cargo = builder.cargo(compiler, Mode::Tool, self.host, "test");
202         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         }
206
207         // 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
214         try_run(build, cargo.env("PATH", &path_for_cargo(builder, compiler)));
215     }
216 }
217
218 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
219 pub struct Rls {
220     stage: u32,
221     host: Interned<String>,
222 }
223
224 impl Step for Rls {
225     type Output = ();
226     const ONLY_HOSTS: bool = true;
227
228     fn should_run(run: ShouldRun) -> ShouldRun {
229         run.path("src/tools/rls")
230     }
231
232     fn make_run(run: RunConfig) {
233         run.builder.ensure(Rls {
234             stage: run.builder.top_stage,
235             host: run.target,
236         });
237     }
238
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;
244         let compiler = builder.compiler(stage, host);
245
246         builder.ensure(tool::Rls { compiler, target: self.host });
247         let mut cargo = tool::prepare_tool_cargo(builder,
248                                                  compiler,
249                                                  host,
250                                                  "test",
251                                                  "src/tools/rls");
252
253         // Don't build tests dynamically, just a pain to work with
254         cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
255
256         builder.add_rustc_lib_path(compiler, &mut cargo);
257
258         if try_run(build, &mut cargo) {
259             build.save_toolstate("rls", ToolState::TestPass);
260         }
261     }
262 }
263
264 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
265 pub struct Rustfmt {
266     stage: u32,
267     host: Interned<String>,
268 }
269
270 impl 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 });
293         let mut cargo = tool::prepare_tool_cargo(builder,
294                                                  compiler,
295                                                  host,
296                                                  "test",
297                                                  "src/tools/rustfmt");
298
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
304         if try_run(build, &mut cargo) {
305             build.save_toolstate("rustfmt", ToolState::TestPass);
306         }
307     }
308 }
309
310 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
311 pub struct Miri {
312     stage: u32,
313     host: Interned<String>,
314 }
315
316 impl 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 {
328             stage: run.builder.top_stage,
329             host: run.target,
330         });
331     }
332
333     /// Runs `cargo test` for miri.
334     fn run(self, builder: &Builder) {
335         let build = builder.build;
336         let stage = self.stage;
337         let host = self.host;
338         let compiler = builder.compiler(stage, host);
339
340         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"));
343
344             // 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);
351
352             builder.add_rustc_lib_path(compiler, &mut cargo);
353
354             if try_run(build, &mut cargo) {
355                 build.save_toolstate("miri", ToolState::TestPass);
356             }
357         } else {
358             eprintln!("failed to test miri: could not build");
359         }
360     }
361 }
362
363 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
364 pub struct Clippy {
365     stage: u32,
366     host: Interned<String>,
367 }
368
369 impl 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 {
380             stage: run.builder.top_stage,
381             host: run.target,
382         });
383     }
384
385     /// Runs `cargo test` for clippy.
386     fn run(self, builder: &Builder) {
387         let build = builder.build;
388         let stage = self.stage;
389         let host = self.host;
390         let compiler = builder.compiler(stage, host);
391
392         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"));
395
396             // 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);
406
407             builder.add_rustc_lib_path(compiler, &mut cargo);
408
409             if try_run(build, &mut cargo) {
410                 build.save_toolstate("clippy-driver", ToolState::TestPass);
411             }
412         } else {
413             eprintln!("failed to test clippy: could not build");
414         }
415     }
416 }
417
418 fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
419     // 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`.
422     let path = builder.sysroot(compiler).join("bin");
423     let old_path = env::var_os("PATH").unwrap_or_default();
424     env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
425 }
426
427 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
428 pub struct RustdocJS {
429     pub host: Interned<String>,
430     pub target: Interned<String>,
431 }
432
433 impl Step for RustdocJS {
434     type Output = ();
435     const DEFAULT: bool = true;
436     const ONLY_HOSTS: bool = true;
437
438     fn should_run(run: ShouldRun) -> ShouldRun {
439         run.path("src/test/rustdoc-js")
440     }
441
442     fn make_run(run: RunConfig) {
443         run.builder.ensure(RustdocJS {
444             host: run.host,
445             target: run.target,
446         });
447     }
448
449     fn run(self, builder: &Builder) {
450         if let Some(ref nodejs) = builder.config.nodejs {
451             let mut command = Command::new(nodejs);
452             command.args(&["src/tools/rustdoc-js/tester.js", &*self.host]);
453             builder.ensure(::doc::Std {
454                 target: self.target,
455                 stage: builder.top_stage,
456             });
457             builder.run(&mut command);
458         } else {
459             println!("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
460         }
461     }
462 }
463
464 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
465 pub struct Tidy {
466     host: Interned<String>,
467 }
468
469 impl Step for Tidy {
470     type Output = ();
471     const DEFAULT: bool = true;
472     const ONLY_HOSTS: bool = true;
473     const ONLY_BUILD: bool = true;
474
475     /// Runs the `tidy` tool as compiled in `stage` by the `host` compiler.
476     ///
477     /// This tool in `src/tools` checks up on various bits and pieces of style and
478     /// otherwise just implements a few lint-like checks that are specific to the
479     /// compiler itself.
480     fn run(self, builder: &Builder) {
481         let build = builder.build;
482         let host = self.host;
483
484         let _folder = build.fold_output(|| "tidy");
485         println!("tidy check ({})", host);
486         let mut cmd = builder.tool_cmd(Tool::Tidy);
487         cmd.arg(build.src.join("src"));
488         if !build.config.vendor {
489             cmd.arg("--no-vendor");
490         }
491         if build.config.quiet_tests {
492             cmd.arg("--quiet");
493         }
494         try_run(build, &mut cmd);
495     }
496
497     fn should_run(run: ShouldRun) -> ShouldRun {
498         run.path("src/tools/tidy")
499     }
500
501     fn make_run(run: RunConfig) {
502         run.builder.ensure(Tidy {
503             host: run.builder.build.build,
504         });
505     }
506 }
507
508 fn testdir(build: &Build, host: Interned<String>) -> PathBuf {
509     build.out.join(host).join("test")
510 }
511
512 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
513 struct Test {
514     path: &'static str,
515     mode: &'static str,
516     suite: &'static str,
517 }
518
519 static DEFAULT_COMPILETESTS: &[Test] = &[
520     Test { path: "src/test/ui", mode: "ui", suite: "ui" },
521     Test { path: "src/test/run-pass", mode: "run-pass", suite: "run-pass" },
522     Test { path: "src/test/compile-fail", mode: "compile-fail", suite: "compile-fail" },
523     Test { path: "src/test/parse-fail", mode: "parse-fail", suite: "parse-fail" },
524     Test { path: "src/test/run-fail", mode: "run-fail", suite: "run-fail" },
525     Test {
526         path: "src/test/run-pass-valgrind",
527         mode: "run-pass-valgrind",
528         suite: "run-pass-valgrind"
529     },
530     Test { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" },
531     Test { path: "src/test/codegen", mode: "codegen", suite: "codegen" },
532     Test { path: "src/test/codegen-units", mode: "codegen-units", suite: "codegen-units" },
533     Test { path: "src/test/incremental", mode: "incremental", suite: "incremental" },
534
535     // What this runs varies depending on the native platform being apple
536     Test { path: "src/test/debuginfo", mode: "debuginfo-XXX", suite: "debuginfo" },
537 ];
538
539 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
540 pub struct DefaultCompiletest {
541     compiler: Compiler,
542     target: Interned<String>,
543     mode: &'static str,
544     suite: &'static str,
545 }
546
547 impl Step for DefaultCompiletest {
548     type Output = ();
549     const DEFAULT: bool = true;
550
551     fn should_run(mut run: ShouldRun) -> ShouldRun {
552         for test in DEFAULT_COMPILETESTS {
553             run = run.path(test.path);
554         }
555         run
556     }
557
558     fn make_run(run: RunConfig) {
559         let compiler = run.builder.compiler(run.builder.top_stage, run.host);
560
561         let test = run.path.map(|path| {
562             DEFAULT_COMPILETESTS.iter().find(|&&test| {
563                 path.ends_with(test.path)
564             }).unwrap_or_else(|| {
565                 panic!("make_run in compile test to receive test path, received {:?}", path);
566             })
567         });
568
569         if let Some(test) = test {
570             run.builder.ensure(DefaultCompiletest {
571                 compiler,
572                 target: run.target,
573                 mode: test.mode,
574                 suite: test.suite,
575             });
576         } else {
577             for test in DEFAULT_COMPILETESTS {
578                 run.builder.ensure(DefaultCompiletest {
579                     compiler,
580                     target: run.target,
581                     mode: test.mode,
582                     suite: test.suite
583                 });
584             }
585         }
586     }
587
588     fn run(self, builder: &Builder) {
589         builder.ensure(Compiletest {
590             compiler: self.compiler,
591             target: self.target,
592             mode: self.mode,
593             suite: self.suite,
594         })
595     }
596 }
597
598 // Also default, but host-only.
599 static HOST_COMPILETESTS: &[Test] = &[
600     Test { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" },
601     Test { path: "src/test/run-pass-fulldeps", mode: "run-pass", suite: "run-pass-fulldeps" },
602     Test { path: "src/test/run-fail-fulldeps", mode: "run-fail", suite: "run-fail-fulldeps" },
603     Test {
604         path: "src/test/compile-fail-fulldeps",
605         mode: "compile-fail",
606         suite: "compile-fail-fulldeps",
607     },
608     Test {
609         path: "src/test/incremental-fulldeps",
610         mode: "incremental",
611         suite: "incremental-fulldeps",
612     },
613     Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
614     Test { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" },
615
616     Test { path: "src/test/pretty", mode: "pretty", suite: "pretty" },
617     Test { path: "src/test/run-pass/pretty", mode: "pretty", suite: "run-pass" },
618     Test { path: "src/test/run-fail/pretty", mode: "pretty", suite: "run-fail" },
619     Test { path: "src/test/run-pass-valgrind/pretty", mode: "pretty", suite: "run-pass-valgrind" },
620     Test { path: "src/test/run-pass-fulldeps/pretty", mode: "pretty", suite: "run-pass-fulldeps" },
621     Test { path: "src/test/run-fail-fulldeps/pretty", mode: "pretty", suite: "run-fail-fulldeps" },
622 ];
623
624 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
625 pub struct HostCompiletest {
626     compiler: Compiler,
627     target: Interned<String>,
628     mode: &'static str,
629     suite: &'static str,
630 }
631
632 impl Step for HostCompiletest {
633     type Output = ();
634     const DEFAULT: bool = true;
635     const ONLY_HOSTS: bool = true;
636
637     fn should_run(mut run: ShouldRun) -> ShouldRun {
638         for test in HOST_COMPILETESTS {
639             run = run.path(test.path);
640         }
641         run
642     }
643
644     fn make_run(run: RunConfig) {
645         let compiler = run.builder.compiler(run.builder.top_stage, run.host);
646
647         let test = run.path.map(|path| {
648             HOST_COMPILETESTS.iter().find(|&&test| {
649                 path.ends_with(test.path)
650             }).unwrap_or_else(|| {
651                 panic!("make_run in compile test to receive test path, received {:?}", path);
652             })
653         });
654
655         if let Some(test) = test {
656             run.builder.ensure(HostCompiletest {
657                 compiler,
658                 target: run.target,
659                 mode: test.mode,
660                 suite: test.suite,
661             });
662         } else {
663             for test in HOST_COMPILETESTS {
664                 if test.mode == "pretty" {
665                     continue;
666                 }
667                 run.builder.ensure(HostCompiletest {
668                     compiler,
669                     target: run.target,
670                     mode: test.mode,
671                     suite: test.suite
672                 });
673             }
674         }
675     }
676
677     fn run(self, builder: &Builder) {
678         builder.ensure(Compiletest {
679             compiler: self.compiler,
680             target: self.target,
681             mode: self.mode,
682             suite: self.suite,
683         })
684     }
685 }
686
687 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
688 struct Compiletest {
689     compiler: Compiler,
690     target: Interned<String>,
691     mode: &'static str,
692     suite: &'static str,
693 }
694
695 impl Step for Compiletest {
696     type Output = ();
697
698     fn should_run(run: ShouldRun) -> ShouldRun {
699         run.never()
700     }
701
702     /// Executes the `compiletest` tool to run a suite of tests.
703     ///
704     /// Compiles all tests with `compiler` for `target` with the specified
705     /// compiletest `mode` and `suite` arguments. For example `mode` can be
706     /// "run-pass" or `suite` can be something like `debuginfo`.
707     fn run(self, builder: &Builder) {
708         let build = builder.build;
709         let compiler = self.compiler;
710         let target = self.target;
711         let mode = self.mode;
712         let suite = self.suite;
713
714         // Skip codegen tests if they aren't enabled in configuration.
715         if !build.config.codegen_tests && suite == "codegen" {
716             return;
717         }
718
719         if suite == "debuginfo" {
720             // Skip debuginfo tests on MSVC
721             if build.build.contains("msvc") {
722                 return;
723             }
724
725             if mode == "debuginfo-XXX" {
726                 return if build.build.contains("apple") {
727                     builder.ensure(Compiletest {
728                         mode: "debuginfo-lldb",
729                         ..self
730                     });
731                 } else {
732                     builder.ensure(Compiletest {
733                         mode: "debuginfo-gdb",
734                         ..self
735                     });
736                 };
737             }
738
739             builder.ensure(dist::DebuggerScripts {
740                 sysroot: builder.sysroot(compiler),
741                 host: target
742             });
743         }
744
745         if suite.ends_with("fulldeps") ||
746             // FIXME: Does pretty need librustc compiled? Note that there are
747             // fulldeps test suites with mode = pretty as well.
748             mode == "pretty" ||
749             mode == "rustdoc" ||
750             mode == "run-make" {
751             builder.ensure(compile::Rustc { compiler, target });
752         }
753
754         builder.ensure(compile::Test { compiler, target });
755         builder.ensure(native::TestHelpers { target });
756         builder.ensure(RemoteCopyLibs { compiler, target });
757
758         let _folder = build.fold_output(|| format!("test_{}", suite));
759         println!("Check compiletest suite={} mode={} ({} -> {})",
760                  suite, mode, &compiler.host, target);
761         let mut cmd = builder.tool_cmd(Tool::Compiletest);
762
763         // compiletest currently has... a lot of arguments, so let's just pass all
764         // of them!
765
766         cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
767         cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
768         cmd.arg("--rustc-path").arg(builder.rustc(compiler));
769
770         // Avoid depending on rustdoc when we don't need it.
771         if mode == "rustdoc" || mode == "run-make" {
772             cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host));
773         }
774
775         cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
776         cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
777         cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
778         cmd.arg("--mode").arg(mode);
779         cmd.arg("--target").arg(target);
780         cmd.arg("--host").arg(&*compiler.host);
781         cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(build.build));
782
783         if let Some(ref nodejs) = build.config.nodejs {
784             cmd.arg("--nodejs").arg(nodejs);
785         }
786
787         let mut flags = vec!["-Crpath".to_string()];
788         if build.config.rust_optimize_tests {
789             flags.push("-O".to_string());
790         }
791         if build.config.rust_debuginfo_tests {
792             flags.push("-g".to_string());
793         }
794         flags.push("-Zmiri -Zunstable-options".to_string());
795         flags.push(build.config.cmd.rustc_args().join(" "));
796
797         if let Some(linker) = build.linker(target) {
798             cmd.arg("--linker").arg(linker);
799         }
800
801         let hostflags = flags.clone();
802         cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
803
804         let mut targetflags = flags.clone();
805         targetflags.push(format!("-Lnative={}",
806                                  build.test_helpers_out(target).display()));
807         cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
808
809         cmd.arg("--docck-python").arg(build.python());
810
811         if build.build.ends_with("apple-darwin") {
812             // Force /usr/bin/python on macOS for LLDB tests because we're loading the
813             // LLDB plugin's compiled module which only works with the system python
814             // (namely not Homebrew-installed python)
815             cmd.arg("--lldb-python").arg("/usr/bin/python");
816         } else {
817             cmd.arg("--lldb-python").arg(build.python());
818         }
819
820         if let Some(ref gdb) = build.config.gdb {
821             cmd.arg("--gdb").arg(gdb);
822         }
823         if let Some(ref vers) = build.lldb_version {
824             cmd.arg("--lldb-version").arg(vers);
825         }
826         if let Some(ref dir) = build.lldb_python_dir {
827             cmd.arg("--lldb-python-dir").arg(dir);
828         }
829
830         cmd.args(&build.config.cmd.test_args());
831
832         if build.is_verbose() {
833             cmd.arg("--verbose");
834         }
835
836         if build.config.quiet_tests {
837             cmd.arg("--quiet");
838         }
839
840         if build.config.llvm_enabled {
841             let llvm_config = build.llvm_config(target);
842             let llvm_version = output(Command::new(&llvm_config).arg("--version"));
843             cmd.arg("--llvm-version").arg(llvm_version);
844             if !build.is_rust_llvm(target) {
845                 cmd.arg("--system-llvm");
846             }
847
848             // Only pass correct values for these flags for the `run-make` suite as it
849             // requires that a C++ compiler was configured which isn't always the case.
850             if suite == "run-make" {
851                 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
852                 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
853                 cmd.arg("--cc").arg(build.cc(target))
854                 .arg("--cxx").arg(build.cxx(target).unwrap())
855                 .arg("--cflags").arg(build.cflags(target).join(" "))
856                 .arg("--llvm-components").arg(llvm_components.trim())
857                 .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
858                 if let Some(ar) = build.ar(target) {
859                     cmd.arg("--ar").arg(ar);
860                 }
861             }
862         }
863         if suite == "run-make" && !build.config.llvm_enabled {
864             println!("Ignoring run-make test suite as they generally dont work without LLVM");
865             return;
866         }
867
868         if suite != "run-make" {
869             cmd.arg("--cc").arg("")
870                .arg("--cxx").arg("")
871                .arg("--cflags").arg("")
872                .arg("--llvm-components").arg("")
873                .arg("--llvm-cxxflags").arg("");
874         }
875
876         if build.remote_tested(target) {
877             cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
878         }
879
880         // Running a C compiler on MSVC requires a few env vars to be set, to be
881         // sure to set them here.
882         //
883         // Note that if we encounter `PATH` we make sure to append to our own `PATH`
884         // rather than stomp over it.
885         if target.contains("msvc") {
886             for &(ref k, ref v) in build.cc[&target].env() {
887                 if k != "PATH" {
888                     cmd.env(k, v);
889                 }
890             }
891         }
892         cmd.env("RUSTC_BOOTSTRAP", "1");
893         build.add_rust_test_threads(&mut cmd);
894
895         if build.config.sanitizers {
896             cmd.env("SANITIZER_SUPPORT", "1");
897         }
898
899         if build.config.profiler {
900             cmd.env("PROFILER_SUPPORT", "1");
901         }
902
903         cmd.env("RUST_TEST_TMPDIR", build.out.join("tmp"));
904
905         cmd.arg("--adb-path").arg("adb");
906         cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
907         if target.contains("android") {
908             // Assume that cc for this target comes from the android sysroot
909             cmd.arg("--android-cross-path")
910                .arg(build.cc(target).parent().unwrap().parent().unwrap());
911         } else {
912             cmd.arg("--android-cross-path").arg("");
913         }
914
915         build.ci_env.force_coloring_in_ci(&mut cmd);
916
917         let _time = util::timeit();
918         try_run(build, &mut cmd);
919     }
920 }
921
922 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
923 pub struct Docs {
924     compiler: Compiler,
925 }
926
927 impl Step for Docs {
928     type Output = ();
929     const DEFAULT: bool = true;
930     const ONLY_HOSTS: bool = true;
931
932     fn should_run(run: ShouldRun) -> ShouldRun {
933         run.path("src/doc")
934     }
935
936     fn make_run(run: RunConfig) {
937         run.builder.ensure(Docs {
938             compiler: run.builder.compiler(run.builder.top_stage, run.host),
939         });
940     }
941
942     /// Run `rustdoc --test` for all documentation in `src/doc`.
943     ///
944     /// This will run all tests in our markdown documentation (e.g. the book)
945     /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
946     /// `compiler`.
947     fn run(self, builder: &Builder) {
948         let build = builder.build;
949         let compiler = self.compiler;
950
951         builder.ensure(compile::Test { compiler, target: compiler.host });
952
953         // Do a breadth-first traversal of the `src/doc` directory and just run
954         // tests for all files that end in `*.md`
955         let mut stack = vec![build.src.join("src/doc")];
956         let _time = util::timeit();
957         let _folder = build.fold_output(|| "test_docs");
958
959         while let Some(p) = stack.pop() {
960             if p.is_dir() {
961                 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
962                 continue
963             }
964
965             if p.extension().and_then(|s| s.to_str()) != Some("md") {
966                 continue;
967             }
968
969             // The nostarch directory in the book is for no starch, and so isn't
970             // guaranteed to build. We don't care if it doesn't build, so skip it.
971             if p.to_str().map_or(false, |p| p.contains("nostarch")) {
972                 continue;
973             }
974
975             markdown_test(builder, compiler, &p);
976         }
977     }
978 }
979
980 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
981 pub struct ErrorIndex {
982     compiler: Compiler,
983 }
984
985 impl Step for ErrorIndex {
986     type Output = ();
987     const DEFAULT: bool = true;
988     const ONLY_HOSTS: bool = true;
989
990     fn should_run(run: ShouldRun) -> ShouldRun {
991         run.path("src/tools/error_index_generator")
992     }
993
994     fn make_run(run: RunConfig) {
995         run.builder.ensure(ErrorIndex {
996             compiler: run.builder.compiler(run.builder.top_stage, run.host),
997         });
998     }
999
1000     /// Run the error index generator tool to execute the tests located in the error
1001     /// index.
1002     ///
1003     /// The `error_index_generator` tool lives in `src/tools` and is used to
1004     /// generate a markdown file from the error indexes of the code base which is
1005     /// then passed to `rustdoc --test`.
1006     fn run(self, builder: &Builder) {
1007         let build = builder.build;
1008         let compiler = self.compiler;
1009
1010         builder.ensure(compile::Std { compiler, target: compiler.host });
1011
1012         let _folder = build.fold_output(|| "test_error_index");
1013         println!("Testing error-index stage{}", compiler.stage);
1014
1015         let dir = testdir(build, compiler.host);
1016         t!(fs::create_dir_all(&dir));
1017         let output = dir.join("error-index.md");
1018
1019         let _time = util::timeit();
1020         build.run(builder.tool_cmd(Tool::ErrorIndex)
1021                     .arg("markdown")
1022                     .arg(&output)
1023                     .env("CFG_BUILD", &build.build)
1024                     .env("RUSTC_ERROR_METADATA_DST", build.extended_error_dir()));
1025
1026         markdown_test(builder, compiler, &output);
1027     }
1028 }
1029
1030 fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
1031     let build = builder.build;
1032     let mut file = t!(File::open(markdown));
1033     let mut contents = String::new();
1034     t!(file.read_to_string(&mut contents));
1035     if !contents.contains("```") {
1036         return;
1037     }
1038
1039     println!("doc tests for: {}", markdown.display());
1040     let mut cmd = builder.rustdoc_cmd(compiler.host);
1041     build.add_rust_test_threads(&mut cmd);
1042     cmd.arg("--test");
1043     cmd.arg(markdown);
1044     cmd.env("RUSTC_BOOTSTRAP", "1");
1045
1046     let test_args = build.config.cmd.test_args().join(" ");
1047     cmd.arg("--test-args").arg(test_args);
1048
1049     if build.config.quiet_tests {
1050         try_run_quiet(build, &mut cmd);
1051     } else {
1052         try_run(build, &mut cmd);
1053     }
1054 }
1055
1056 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1057 pub struct CrateLibrustc {
1058     compiler: Compiler,
1059     target: Interned<String>,
1060     test_kind: TestKind,
1061     krate: Option<Interned<String>>,
1062 }
1063
1064 impl Step for CrateLibrustc {
1065     type Output = ();
1066     const DEFAULT: bool = true;
1067     const ONLY_HOSTS: bool = true;
1068
1069     fn should_run(run: ShouldRun) -> ShouldRun {
1070         run.krate("rustc-main")
1071     }
1072
1073     fn make_run(run: RunConfig) {
1074         let builder = run.builder;
1075         let compiler = builder.compiler(builder.top_stage, run.host);
1076
1077         let make = |name: Option<Interned<String>>| {
1078             let test_kind = if builder.kind == Kind::Test {
1079                 TestKind::Test
1080             } else if builder.kind == Kind::Bench {
1081                 TestKind::Bench
1082             } else {
1083                 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1084             };
1085
1086             builder.ensure(CrateLibrustc {
1087                 compiler,
1088                 target: run.target,
1089                 test_kind,
1090                 krate: name,
1091             });
1092         };
1093
1094         if let Some(path) = run.path {
1095             for (name, krate_path) in builder.crates("rustc-main") {
1096                 if path.ends_with(krate_path) {
1097                     make(Some(name));
1098                 }
1099             }
1100         } else {
1101             make(None);
1102         }
1103     }
1104
1105
1106     fn run(self, builder: &Builder) {
1107         builder.ensure(Crate {
1108             compiler: self.compiler,
1109             target: self.target,
1110             mode: Mode::Librustc,
1111             test_kind: self.test_kind,
1112             krate: self.krate,
1113         });
1114     }
1115 }
1116
1117 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1118 pub struct Crate {
1119     compiler: Compiler,
1120     target: Interned<String>,
1121     mode: Mode,
1122     test_kind: TestKind,
1123     krate: Option<Interned<String>>,
1124 }
1125
1126 impl Step for Crate {
1127     type Output = ();
1128     const DEFAULT: bool = true;
1129
1130     fn should_run(run: ShouldRun) -> ShouldRun {
1131         run.krate("std").krate("test")
1132     }
1133
1134     fn make_run(run: RunConfig) {
1135         let builder = run.builder;
1136         let compiler = builder.compiler(builder.top_stage, run.host);
1137
1138         let make = |mode: Mode, name: Option<Interned<String>>| {
1139             let test_kind = if builder.kind == Kind::Test {
1140                 TestKind::Test
1141             } else if builder.kind == Kind::Bench {
1142                 TestKind::Bench
1143             } else {
1144                 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1145             };
1146
1147             builder.ensure(Crate {
1148                 compiler,
1149                 target: run.target,
1150                 mode,
1151                 test_kind,
1152                 krate: name,
1153             });
1154         };
1155
1156         if let Some(path) = run.path {
1157             for (name, krate_path) in builder.crates("std") {
1158                 if path.ends_with(krate_path) {
1159                     make(Mode::Libstd, Some(name));
1160                 }
1161             }
1162             for (name, krate_path) in builder.crates("test") {
1163                 if path.ends_with(krate_path) {
1164                     make(Mode::Libtest, Some(name));
1165                 }
1166             }
1167         } else {
1168             make(Mode::Libstd, None);
1169             make(Mode::Libtest, None);
1170         }
1171     }
1172
1173     /// Run all unit tests plus documentation tests for an entire crate DAG defined
1174     /// by a `Cargo.toml`
1175     ///
1176     /// This is what runs tests for crates like the standard library, compiler, etc.
1177     /// It essentially is the driver for running `cargo test`.
1178     ///
1179     /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1180     /// arguments, and those arguments are discovered from `cargo metadata`.
1181     fn run(self, builder: &Builder) {
1182         let build = builder.build;
1183         let compiler = self.compiler;
1184         let target = self.target;
1185         let mode = self.mode;
1186         let test_kind = self.test_kind;
1187         let krate = self.krate;
1188
1189         builder.ensure(compile::Test { compiler, target });
1190         builder.ensure(RemoteCopyLibs { compiler, target });
1191
1192         // If we're not doing a full bootstrap but we're testing a stage2 version of
1193         // libstd, then what we're actually testing is the libstd produced in
1194         // stage1. Reflect that here by updating the compiler that we're working
1195         // with automatically.
1196         let compiler = if build.force_use_stage1(compiler, target) {
1197             builder.compiler(1, compiler.host)
1198         } else {
1199             compiler.clone()
1200         };
1201
1202         let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
1203         let (name, root) = match mode {
1204             Mode::Libstd => {
1205                 compile::std_cargo(build, &compiler, target, &mut cargo);
1206                 ("libstd", "std")
1207             }
1208             Mode::Libtest => {
1209                 compile::test_cargo(build, &compiler, target, &mut cargo);
1210                 ("libtest", "test")
1211             }
1212             Mode::Librustc => {
1213                 builder.ensure(compile::Rustc { compiler, target });
1214                 compile::rustc_cargo(build, &mut cargo);
1215                 ("librustc", "rustc-main")
1216             }
1217             _ => panic!("can only test libraries"),
1218         };
1219         let root = INTERNER.intern_string(String::from(root));
1220         let _folder = build.fold_output(|| {
1221             format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, name)
1222         });
1223         println!("{} {} stage{} ({} -> {})", test_kind, name, compiler.stage,
1224                 &compiler.host, target);
1225
1226         // Build up the base `cargo test` command.
1227         //
1228         // Pass in some standard flags then iterate over the graph we've discovered
1229         // in `cargo metadata` with the maps above and figure out what `-p`
1230         // arguments need to get passed.
1231         if test_kind.subcommand() == "test" && !build.fail_fast {
1232             cargo.arg("--no-fail-fast");
1233         }
1234
1235         match krate {
1236             Some(krate) => {
1237                 cargo.arg("-p").arg(krate);
1238             }
1239             None => {
1240                 let mut visited = HashSet::new();
1241                 let mut next = vec![root];
1242                 while let Some(name) = next.pop() {
1243                     // Right now jemalloc and the sanitizer crates are
1244                     // target-specific crate in the sense that it's not present
1245                     // on all platforms. Custom skip it here for now, but if we
1246                     // add more this probably wants to get more generalized.
1247                     //
1248                     // Also skip `build_helper` as it's not compiled normally
1249                     // for target during the bootstrap and it's just meant to be
1250                     // a helper crate, not tested. If it leaks through then it
1251                     // ends up messing with various mtime calculations and such.
1252                     if !name.contains("jemalloc") &&
1253                        *name != *"build_helper" &&
1254                        !(name.starts_with("rustc_") && name.ends_with("san")) &&
1255                        name != "dlmalloc" {
1256                         cargo.arg("-p").arg(&format!("{}:0.0.0", name));
1257                     }
1258                     for dep in build.crates[&name].deps.iter() {
1259                         if visited.insert(dep) {
1260                             next.push(*dep);
1261                         }
1262                     }
1263                 }
1264             }
1265         }
1266
1267         // The tests are going to run with the *target* libraries, so we need to
1268         // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1269         //
1270         // Note that to run the compiler we need to run with the *host* libraries,
1271         // but our wrapper scripts arrange for that to be the case anyway.
1272         let mut dylib_path = dylib_path();
1273         dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1274         cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1275
1276         cargo.arg("--");
1277         cargo.args(&build.config.cmd.test_args());
1278
1279         if build.config.quiet_tests {
1280             cargo.arg("--quiet");
1281         }
1282
1283         let _time = util::timeit();
1284
1285         if target.contains("emscripten") {
1286             cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1287                       build.config.nodejs.as_ref().expect("nodejs not configured"));
1288         } else if target.starts_with("wasm32") {
1289             // On the wasm32-unknown-unknown target we're using LTO which is
1290             // incompatible with `-C prefer-dynamic`, so disable that here
1291             cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
1292
1293             let node = build.config.nodejs.as_ref()
1294                 .expect("nodejs not configured");
1295             let runner = format!("{} {}/src/etc/wasm32-shim.js",
1296                                  node.display(),
1297                                  build.src.display());
1298             cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
1299         } else if build.remote_tested(target) {
1300             cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1301                       format!("{} run",
1302                               builder.tool_exe(Tool::RemoteTestClient).display()));
1303         }
1304         try_run(build, &mut cargo);
1305     }
1306 }
1307
1308 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1309 pub struct Rustdoc {
1310     host: Interned<String>,
1311     test_kind: TestKind,
1312 }
1313
1314 impl Step for Rustdoc {
1315     type Output = ();
1316     const DEFAULT: bool = true;
1317     const ONLY_HOSTS: bool = true;
1318
1319     fn should_run(run: ShouldRun) -> ShouldRun {
1320         run.path("src/librustdoc").path("src/tools/rustdoc")
1321     }
1322
1323     fn make_run(run: RunConfig) {
1324         let builder = run.builder;
1325
1326         let test_kind = if builder.kind == Kind::Test {
1327             TestKind::Test
1328         } else if builder.kind == Kind::Bench {
1329             TestKind::Bench
1330         } else {
1331             panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1332         };
1333
1334         builder.ensure(Rustdoc {
1335             host: run.host,
1336             test_kind,
1337         });
1338     }
1339
1340     fn run(self, builder: &Builder) {
1341         let build = builder.build;
1342         let test_kind = self.test_kind;
1343
1344         let compiler = builder.compiler(builder.top_stage, self.host);
1345         let target = compiler.host;
1346
1347         let mut cargo = tool::prepare_tool_cargo(builder,
1348                                                  compiler,
1349                                                  target,
1350                                                  test_kind.subcommand(),
1351                                                  "src/tools/rustdoc");
1352         let _folder = build.fold_output(|| {
1353             format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage)
1354         });
1355         println!("{} rustdoc stage{} ({} -> {})", test_kind, compiler.stage,
1356                 &compiler.host, target);
1357
1358         if test_kind.subcommand() == "test" && !build.fail_fast {
1359             cargo.arg("--no-fail-fast");
1360         }
1361
1362         cargo.arg("-p").arg("rustdoc:0.0.0");
1363
1364         cargo.arg("--");
1365         cargo.args(&build.config.cmd.test_args());
1366
1367         if build.config.quiet_tests {
1368             cargo.arg("--quiet");
1369         }
1370
1371         let _time = util::timeit();
1372
1373         try_run(build, &mut cargo);
1374     }
1375 }
1376
1377 fn envify(s: &str) -> String {
1378     s.chars().map(|c| {
1379         match c {
1380             '-' => '_',
1381             c => c,
1382         }
1383     }).flat_map(|c| c.to_uppercase()).collect()
1384 }
1385
1386 /// Some test suites are run inside emulators or on remote devices, and most
1387 /// of our test binaries are linked dynamically which means we need to ship
1388 /// the standard library and such to the emulator ahead of time. This step
1389 /// represents this and is a dependency of all test suites.
1390 ///
1391 /// Most of the time this is a noop. For some steps such as shipping data to
1392 /// QEMU we have to build our own tools so we've got conditional dependencies
1393 /// on those programs as well. Note that the remote test client is built for
1394 /// the build target (us) and the server is built for the target.
1395 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1396 pub struct RemoteCopyLibs {
1397     compiler: Compiler,
1398     target: Interned<String>,
1399 }
1400
1401 impl Step for RemoteCopyLibs {
1402     type Output = ();
1403
1404     fn should_run(run: ShouldRun) -> ShouldRun {
1405         run.never()
1406     }
1407
1408     fn run(self, builder: &Builder) {
1409         let build = builder.build;
1410         let compiler = self.compiler;
1411         let target = self.target;
1412         if !build.remote_tested(target) {
1413             return
1414         }
1415
1416         builder.ensure(compile::Test { compiler, target });
1417
1418         println!("REMOTE copy libs to emulator ({})", target);
1419         t!(fs::create_dir_all(build.out.join("tmp")));
1420
1421         let server = builder.ensure(tool::RemoteTestServer { compiler, target });
1422
1423         // Spawn the emulator and wait for it to come online
1424         let tool = builder.tool_exe(Tool::RemoteTestClient);
1425         let mut cmd = Command::new(&tool);
1426         cmd.arg("spawn-emulator")
1427            .arg(target)
1428            .arg(&server)
1429            .arg(build.out.join("tmp"));
1430         if let Some(rootfs) = build.qemu_rootfs(target) {
1431             cmd.arg(rootfs);
1432         }
1433         build.run(&mut cmd);
1434
1435         // Push all our dylibs to the emulator
1436         for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1437             let f = t!(f);
1438             let name = f.file_name().into_string().unwrap();
1439             if util::is_dylib(&name) {
1440                 build.run(Command::new(&tool)
1441                                   .arg("push")
1442                                   .arg(f.path()));
1443             }
1444         }
1445     }
1446 }
1447
1448 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1449 pub struct Distcheck;
1450
1451 impl Step for Distcheck {
1452     type Output = ();
1453     const ONLY_BUILD: bool = true;
1454
1455     fn should_run(run: ShouldRun) -> ShouldRun {
1456         run.path("distcheck")
1457     }
1458
1459     fn make_run(run: RunConfig) {
1460         run.builder.ensure(Distcheck);
1461     }
1462
1463     /// Run "distcheck", a 'make check' from a tarball
1464     fn run(self, builder: &Builder) {
1465         let build = builder.build;
1466
1467         println!("Distcheck");
1468         let dir = build.out.join("tmp").join("distcheck");
1469         let _ = fs::remove_dir_all(&dir);
1470         t!(fs::create_dir_all(&dir));
1471
1472         // Guarantee that these are built before we begin running.
1473         builder.ensure(dist::PlainSourceTarball);
1474         builder.ensure(dist::Src);
1475
1476         let mut cmd = Command::new("tar");
1477         cmd.arg("-xzf")
1478            .arg(builder.ensure(dist::PlainSourceTarball))
1479            .arg("--strip-components=1")
1480            .current_dir(&dir);
1481         build.run(&mut cmd);
1482         build.run(Command::new("./configure")
1483                          .args(&build.config.configure_args)
1484                          .arg("--enable-vendor")
1485                          .current_dir(&dir));
1486         build.run(Command::new(build_helper::make(&build.build))
1487                          .arg("check")
1488                          .current_dir(&dir));
1489
1490         // Now make sure that rust-src has all of libstd's dependencies
1491         println!("Distcheck rust-src");
1492         let dir = build.out.join("tmp").join("distcheck-src");
1493         let _ = fs::remove_dir_all(&dir);
1494         t!(fs::create_dir_all(&dir));
1495
1496         let mut cmd = Command::new("tar");
1497         cmd.arg("-xzf")
1498            .arg(builder.ensure(dist::Src))
1499            .arg("--strip-components=1")
1500            .current_dir(&dir);
1501         build.run(&mut cmd);
1502
1503         let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
1504         build.run(Command::new(&build.initial_cargo)
1505                          .arg("generate-lockfile")
1506                          .arg("--manifest-path")
1507                          .arg(&toml)
1508                          .current_dir(&dir));
1509     }
1510 }
1511
1512 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1513 pub struct Bootstrap;
1514
1515 impl Step for Bootstrap {
1516     type Output = ();
1517     const DEFAULT: bool = true;
1518     const ONLY_HOSTS: bool = true;
1519     const ONLY_BUILD: bool = true;
1520
1521     /// Test the build system itself
1522     fn run(self, builder: &Builder) {
1523         let build = builder.build;
1524         let mut cmd = Command::new(&build.initial_cargo);
1525         cmd.arg("test")
1526            .current_dir(build.src.join("src/bootstrap"))
1527            .env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
1528            .env("RUSTC_BOOTSTRAP", "1")
1529            .env("RUSTC", &build.initial_rustc);
1530         if !build.fail_fast {
1531             cmd.arg("--no-fail-fast");
1532         }
1533         cmd.arg("--").args(&build.config.cmd.test_args());
1534         try_run(build, &mut cmd);
1535     }
1536
1537     fn should_run(run: ShouldRun) -> ShouldRun {
1538         run.path("src/bootstrap")
1539     }
1540
1541     fn make_run(run: RunConfig) {
1542         run.builder.ensure(Bootstrap);
1543     }
1544 }