]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/check.rs
Rollup merge of #47313 - ollie27:rustdoc_record_extern_trait, r=QuietMisdreavus
[rust.git] / src / bootstrap / check.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 { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
609     Test { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" },
610
611     Test { path: "src/test/pretty", mode: "pretty", suite: "pretty" },
612     Test { path: "src/test/run-pass/pretty", mode: "pretty", suite: "run-pass" },
613     Test { path: "src/test/run-fail/pretty", mode: "pretty", suite: "run-fail" },
614     Test { path: "src/test/run-pass-valgrind/pretty", mode: "pretty", suite: "run-pass-valgrind" },
615     Test { path: "src/test/run-pass-fulldeps/pretty", mode: "pretty", suite: "run-pass-fulldeps" },
616     Test { path: "src/test/run-fail-fulldeps/pretty", mode: "pretty", suite: "run-fail-fulldeps" },
617 ];
618
619 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
620 pub struct HostCompiletest {
621     compiler: Compiler,
622     target: Interned<String>,
623     mode: &'static str,
624     suite: &'static str,
625 }
626
627 impl Step for HostCompiletest {
628     type Output = ();
629     const DEFAULT: bool = true;
630     const ONLY_HOSTS: bool = true;
631
632     fn should_run(mut run: ShouldRun) -> ShouldRun {
633         for test in HOST_COMPILETESTS {
634             run = run.path(test.path);
635         }
636         run
637     }
638
639     fn make_run(run: RunConfig) {
640         let compiler = run.builder.compiler(run.builder.top_stage, run.host);
641
642         let test = run.path.map(|path| {
643             HOST_COMPILETESTS.iter().find(|&&test| {
644                 path.ends_with(test.path)
645             }).unwrap_or_else(|| {
646                 panic!("make_run in compile test to receive test path, received {:?}", path);
647             })
648         });
649
650         if let Some(test) = test {
651             run.builder.ensure(HostCompiletest {
652                 compiler,
653                 target: run.target,
654                 mode: test.mode,
655                 suite: test.suite,
656             });
657         } else {
658             for test in HOST_COMPILETESTS {
659                 if test.mode == "pretty" {
660                     continue;
661                 }
662                 run.builder.ensure(HostCompiletest {
663                     compiler,
664                     target: run.target,
665                     mode: test.mode,
666                     suite: test.suite
667                 });
668             }
669         }
670     }
671
672     fn run(self, builder: &Builder) {
673         builder.ensure(Compiletest {
674             compiler: self.compiler,
675             target: self.target,
676             mode: self.mode,
677             suite: self.suite,
678         })
679     }
680 }
681
682 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
683 struct Compiletest {
684     compiler: Compiler,
685     target: Interned<String>,
686     mode: &'static str,
687     suite: &'static str,
688 }
689
690 impl Step for Compiletest {
691     type Output = ();
692
693     fn should_run(run: ShouldRun) -> ShouldRun {
694         run.never()
695     }
696
697     /// Executes the `compiletest` tool to run a suite of tests.
698     ///
699     /// Compiles all tests with `compiler` for `target` with the specified
700     /// compiletest `mode` and `suite` arguments. For example `mode` can be
701     /// "run-pass" or `suite` can be something like `debuginfo`.
702     fn run(self, builder: &Builder) {
703         let build = builder.build;
704         let compiler = self.compiler;
705         let target = self.target;
706         let mode = self.mode;
707         let suite = self.suite;
708
709         // Skip codegen tests if they aren't enabled in configuration.
710         if !build.config.codegen_tests && suite == "codegen" {
711             return;
712         }
713
714         if suite == "debuginfo" {
715             // Skip debuginfo tests on MSVC
716             if build.build.contains("msvc") {
717                 return;
718             }
719
720             if mode == "debuginfo-XXX" {
721                 return if build.build.contains("apple") {
722                     builder.ensure(Compiletest {
723                         mode: "debuginfo-lldb",
724                         ..self
725                     });
726                 } else {
727                     builder.ensure(Compiletest {
728                         mode: "debuginfo-gdb",
729                         ..self
730                     });
731                 };
732             }
733
734             builder.ensure(dist::DebuggerScripts {
735                 sysroot: builder.sysroot(compiler),
736                 host: target
737             });
738         }
739
740         if suite.ends_with("fulldeps") ||
741             // FIXME: Does pretty need librustc compiled? Note that there are
742             // fulldeps test suites with mode = pretty as well.
743             mode == "pretty" ||
744             mode == "rustdoc" ||
745             mode == "run-make" {
746             builder.ensure(compile::Rustc { compiler, target });
747         }
748
749         builder.ensure(compile::Test { compiler, target });
750         builder.ensure(native::TestHelpers { target });
751         builder.ensure(RemoteCopyLibs { compiler, target });
752
753         let _folder = build.fold_output(|| format!("test_{}", suite));
754         println!("Check compiletest suite={} mode={} ({} -> {})",
755                  suite, mode, &compiler.host, target);
756         let mut cmd = builder.tool_cmd(Tool::Compiletest);
757
758         // compiletest currently has... a lot of arguments, so let's just pass all
759         // of them!
760
761         cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
762         cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
763         cmd.arg("--rustc-path").arg(builder.rustc(compiler));
764
765         // Avoid depending on rustdoc when we don't need it.
766         if mode == "rustdoc" || mode == "run-make" {
767             cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host));
768         }
769
770         cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
771         cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
772         cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
773         cmd.arg("--mode").arg(mode);
774         cmd.arg("--target").arg(target);
775         cmd.arg("--host").arg(&*compiler.host);
776         cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(build.build));
777
778         if let Some(ref nodejs) = build.config.nodejs {
779             cmd.arg("--nodejs").arg(nodejs);
780         }
781
782         let mut flags = vec!["-Crpath".to_string()];
783         if build.config.rust_optimize_tests {
784             flags.push("-O".to_string());
785         }
786         if build.config.rust_debuginfo_tests {
787             flags.push("-g".to_string());
788         }
789         flags.push("-Zmiri -Zunstable-options".to_string());
790
791         if let Some(linker) = build.linker(target) {
792             cmd.arg("--linker").arg(linker);
793         }
794
795         let hostflags = flags.clone();
796         cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
797
798         let mut targetflags = flags.clone();
799         targetflags.push(format!("-Lnative={}",
800                                  build.test_helpers_out(target).display()));
801         cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
802
803         cmd.arg("--docck-python").arg(build.python());
804
805         if build.build.ends_with("apple-darwin") {
806             // Force /usr/bin/python on macOS for LLDB tests because we're loading the
807             // LLDB plugin's compiled module which only works with the system python
808             // (namely not Homebrew-installed python)
809             cmd.arg("--lldb-python").arg("/usr/bin/python");
810         } else {
811             cmd.arg("--lldb-python").arg(build.python());
812         }
813
814         if let Some(ref gdb) = build.config.gdb {
815             cmd.arg("--gdb").arg(gdb);
816         }
817         if let Some(ref vers) = build.lldb_version {
818             cmd.arg("--lldb-version").arg(vers);
819         }
820         if let Some(ref dir) = build.lldb_python_dir {
821             cmd.arg("--lldb-python-dir").arg(dir);
822         }
823
824         cmd.args(&build.config.cmd.test_args());
825
826         if build.is_verbose() {
827             cmd.arg("--verbose");
828         }
829
830         if build.config.quiet_tests {
831             cmd.arg("--quiet");
832         }
833
834         if build.config.llvm_enabled {
835             let llvm_config = build.llvm_config(target);
836             let llvm_version = output(Command::new(&llvm_config).arg("--version"));
837             cmd.arg("--llvm-version").arg(llvm_version);
838             if !build.is_rust_llvm(target) {
839                 cmd.arg("--system-llvm");
840             }
841
842             // Only pass correct values for these flags for the `run-make` suite as it
843             // requires that a C++ compiler was configured which isn't always the case.
844             if suite == "run-make" {
845                 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
846                 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
847                 cmd.arg("--cc").arg(build.cc(target))
848                 .arg("--cxx").arg(build.cxx(target).unwrap())
849                 .arg("--cflags").arg(build.cflags(target).join(" "))
850                 .arg("--llvm-components").arg(llvm_components.trim())
851                 .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
852                 if let Some(ar) = build.ar(target) {
853                     cmd.arg("--ar").arg(ar);
854                 }
855             }
856         }
857         if suite == "run-make" && !build.config.llvm_enabled {
858             println!("Ignoring run-make test suite as they generally dont work without LLVM");
859             return;
860         }
861
862         if suite != "run-make" {
863             cmd.arg("--cc").arg("")
864                .arg("--cxx").arg("")
865                .arg("--cflags").arg("")
866                .arg("--llvm-components").arg("")
867                .arg("--llvm-cxxflags").arg("");
868         }
869
870         if build.remote_tested(target) {
871             cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
872         }
873
874         // Running a C compiler on MSVC requires a few env vars to be set, to be
875         // sure to set them here.
876         //
877         // Note that if we encounter `PATH` we make sure to append to our own `PATH`
878         // rather than stomp over it.
879         if target.contains("msvc") {
880             for &(ref k, ref v) in build.cc[&target].env() {
881                 if k != "PATH" {
882                     cmd.env(k, v);
883                 }
884             }
885         }
886         cmd.env("RUSTC_BOOTSTRAP", "1");
887         build.add_rust_test_threads(&mut cmd);
888
889         if build.config.sanitizers {
890             cmd.env("SANITIZER_SUPPORT", "1");
891         }
892
893         if build.config.profiler {
894             cmd.env("PROFILER_SUPPORT", "1");
895         }
896
897         cmd.arg("--adb-path").arg("adb");
898         cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
899         if target.contains("android") {
900             // Assume that cc for this target comes from the android sysroot
901             cmd.arg("--android-cross-path")
902                .arg(build.cc(target).parent().unwrap().parent().unwrap());
903         } else {
904             cmd.arg("--android-cross-path").arg("");
905         }
906
907         build.ci_env.force_coloring_in_ci(&mut cmd);
908
909         let _time = util::timeit();
910         try_run(build, &mut cmd);
911     }
912 }
913
914 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
915 pub struct Docs {
916     compiler: Compiler,
917 }
918
919 impl Step for Docs {
920     type Output = ();
921     const DEFAULT: bool = true;
922     const ONLY_HOSTS: bool = true;
923
924     fn should_run(run: ShouldRun) -> ShouldRun {
925         run.path("src/doc")
926     }
927
928     fn make_run(run: RunConfig) {
929         run.builder.ensure(Docs {
930             compiler: run.builder.compiler(run.builder.top_stage, run.host),
931         });
932     }
933
934     /// Run `rustdoc --test` for all documentation in `src/doc`.
935     ///
936     /// This will run all tests in our markdown documentation (e.g. the book)
937     /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
938     /// `compiler`.
939     fn run(self, builder: &Builder) {
940         let build = builder.build;
941         let compiler = self.compiler;
942
943         builder.ensure(compile::Test { compiler, target: compiler.host });
944
945         // Do a breadth-first traversal of the `src/doc` directory and just run
946         // tests for all files that end in `*.md`
947         let mut stack = vec![build.src.join("src/doc")];
948         let _time = util::timeit();
949         let _folder = build.fold_output(|| "test_docs");
950
951         while let Some(p) = stack.pop() {
952             if p.is_dir() {
953                 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
954                 continue
955             }
956
957             if p.extension().and_then(|s| s.to_str()) != Some("md") {
958                 continue;
959             }
960
961             // The nostarch directory in the book is for no starch, and so isn't
962             // guaranteed to build. We don't care if it doesn't build, so skip it.
963             if p.to_str().map_or(false, |p| p.contains("nostarch")) {
964                 continue;
965             }
966
967             markdown_test(builder, compiler, &p);
968         }
969     }
970 }
971
972 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
973 pub struct ErrorIndex {
974     compiler: Compiler,
975 }
976
977 impl Step for ErrorIndex {
978     type Output = ();
979     const DEFAULT: bool = true;
980     const ONLY_HOSTS: bool = true;
981
982     fn should_run(run: ShouldRun) -> ShouldRun {
983         run.path("src/tools/error_index_generator")
984     }
985
986     fn make_run(run: RunConfig) {
987         run.builder.ensure(ErrorIndex {
988             compiler: run.builder.compiler(run.builder.top_stage, run.host),
989         });
990     }
991
992     /// Run the error index generator tool to execute the tests located in the error
993     /// index.
994     ///
995     /// The `error_index_generator` tool lives in `src/tools` and is used to
996     /// generate a markdown file from the error indexes of the code base which is
997     /// then passed to `rustdoc --test`.
998     fn run(self, builder: &Builder) {
999         let build = builder.build;
1000         let compiler = self.compiler;
1001
1002         builder.ensure(compile::Std { compiler, target: compiler.host });
1003
1004         let _folder = build.fold_output(|| "test_error_index");
1005         println!("Testing error-index stage{}", compiler.stage);
1006
1007         let dir = testdir(build, compiler.host);
1008         t!(fs::create_dir_all(&dir));
1009         let output = dir.join("error-index.md");
1010
1011         let _time = util::timeit();
1012         build.run(builder.tool_cmd(Tool::ErrorIndex)
1013                     .arg("markdown")
1014                     .arg(&output)
1015                     .env("CFG_BUILD", &build.build)
1016                     .env("RUSTC_ERROR_METADATA_DST", build.extended_error_dir()));
1017
1018         markdown_test(builder, compiler, &output);
1019     }
1020 }
1021
1022 fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
1023     let build = builder.build;
1024     let mut file = t!(File::open(markdown));
1025     let mut contents = String::new();
1026     t!(file.read_to_string(&mut contents));
1027     if !contents.contains("```") {
1028         return;
1029     }
1030
1031     println!("doc tests for: {}", markdown.display());
1032     let mut cmd = builder.rustdoc_cmd(compiler.host);
1033     build.add_rust_test_threads(&mut cmd);
1034     cmd.arg("--test");
1035     cmd.arg(markdown);
1036     cmd.env("RUSTC_BOOTSTRAP", "1");
1037
1038     let test_args = build.config.cmd.test_args().join(" ");
1039     cmd.arg("--test-args").arg(test_args);
1040
1041     if build.config.quiet_tests {
1042         try_run_quiet(build, &mut cmd);
1043     } else {
1044         try_run(build, &mut cmd);
1045     }
1046 }
1047
1048 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1049 pub struct CrateLibrustc {
1050     compiler: Compiler,
1051     target: Interned<String>,
1052     test_kind: TestKind,
1053     krate: Option<Interned<String>>,
1054 }
1055
1056 impl Step for CrateLibrustc {
1057     type Output = ();
1058     const DEFAULT: bool = true;
1059     const ONLY_HOSTS: bool = true;
1060
1061     fn should_run(run: ShouldRun) -> ShouldRun {
1062         run.krate("rustc-main")
1063     }
1064
1065     fn make_run(run: RunConfig) {
1066         let builder = run.builder;
1067         let compiler = builder.compiler(builder.top_stage, run.host);
1068
1069         let make = |name: Option<Interned<String>>| {
1070             let test_kind = if builder.kind == Kind::Test {
1071                 TestKind::Test
1072             } else if builder.kind == Kind::Bench {
1073                 TestKind::Bench
1074             } else {
1075                 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1076             };
1077
1078             builder.ensure(CrateLibrustc {
1079                 compiler,
1080                 target: run.target,
1081                 test_kind,
1082                 krate: name,
1083             });
1084         };
1085
1086         if let Some(path) = run.path {
1087             for (name, krate_path) in builder.crates("rustc-main") {
1088                 if path.ends_with(krate_path) {
1089                     make(Some(name));
1090                 }
1091             }
1092         } else {
1093             make(None);
1094         }
1095     }
1096
1097
1098     fn run(self, builder: &Builder) {
1099         builder.ensure(Crate {
1100             compiler: self.compiler,
1101             target: self.target,
1102             mode: Mode::Librustc,
1103             test_kind: self.test_kind,
1104             krate: self.krate,
1105         });
1106     }
1107 }
1108
1109 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1110 pub struct Crate {
1111     compiler: Compiler,
1112     target: Interned<String>,
1113     mode: Mode,
1114     test_kind: TestKind,
1115     krate: Option<Interned<String>>,
1116 }
1117
1118 impl Step for Crate {
1119     type Output = ();
1120     const DEFAULT: bool = true;
1121
1122     fn should_run(run: ShouldRun) -> ShouldRun {
1123         run.krate("std").krate("test")
1124     }
1125
1126     fn make_run(run: RunConfig) {
1127         let builder = run.builder;
1128         let compiler = builder.compiler(builder.top_stage, run.host);
1129
1130         let make = |mode: Mode, name: Option<Interned<String>>| {
1131             let test_kind = if builder.kind == Kind::Test {
1132                 TestKind::Test
1133             } else if builder.kind == Kind::Bench {
1134                 TestKind::Bench
1135             } else {
1136                 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1137             };
1138
1139             builder.ensure(Crate {
1140                 compiler,
1141                 target: run.target,
1142                 mode,
1143                 test_kind,
1144                 krate: name,
1145             });
1146         };
1147
1148         if let Some(path) = run.path {
1149             for (name, krate_path) in builder.crates("std") {
1150                 if path.ends_with(krate_path) {
1151                     make(Mode::Libstd, Some(name));
1152                 }
1153             }
1154             for (name, krate_path) in builder.crates("test") {
1155                 if path.ends_with(krate_path) {
1156                     make(Mode::Libtest, Some(name));
1157                 }
1158             }
1159         } else {
1160             make(Mode::Libstd, None);
1161             make(Mode::Libtest, None);
1162         }
1163     }
1164
1165     /// Run all unit tests plus documentation tests for an entire crate DAG defined
1166     /// by a `Cargo.toml`
1167     ///
1168     /// This is what runs tests for crates like the standard library, compiler, etc.
1169     /// It essentially is the driver for running `cargo test`.
1170     ///
1171     /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1172     /// arguments, and those arguments are discovered from `cargo metadata`.
1173     fn run(self, builder: &Builder) {
1174         let build = builder.build;
1175         let compiler = self.compiler;
1176         let target = self.target;
1177         let mode = self.mode;
1178         let test_kind = self.test_kind;
1179         let krate = self.krate;
1180
1181         builder.ensure(compile::Test { compiler, target });
1182         builder.ensure(RemoteCopyLibs { compiler, target });
1183
1184         // If we're not doing a full bootstrap but we're testing a stage2 version of
1185         // libstd, then what we're actually testing is the libstd produced in
1186         // stage1. Reflect that here by updating the compiler that we're working
1187         // with automatically.
1188         let compiler = if build.force_use_stage1(compiler, target) {
1189             builder.compiler(1, compiler.host)
1190         } else {
1191             compiler.clone()
1192         };
1193
1194         let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
1195         let (name, root) = match mode {
1196             Mode::Libstd => {
1197                 compile::std_cargo(build, &compiler, target, &mut cargo);
1198                 ("libstd", "std")
1199             }
1200             Mode::Libtest => {
1201                 compile::test_cargo(build, &compiler, target, &mut cargo);
1202                 ("libtest", "test")
1203             }
1204             Mode::Librustc => {
1205                 builder.ensure(compile::Rustc { compiler, target });
1206                 compile::rustc_cargo(build, target, &mut cargo);
1207                 ("librustc", "rustc-main")
1208             }
1209             _ => panic!("can only test libraries"),
1210         };
1211         let root = INTERNER.intern_string(String::from(root));
1212         let _folder = build.fold_output(|| {
1213             format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, name)
1214         });
1215         println!("{} {} stage{} ({} -> {})", test_kind, name, compiler.stage,
1216                 &compiler.host, target);
1217
1218         // Build up the base `cargo test` command.
1219         //
1220         // Pass in some standard flags then iterate over the graph we've discovered
1221         // in `cargo metadata` with the maps above and figure out what `-p`
1222         // arguments need to get passed.
1223         if test_kind.subcommand() == "test" && !build.fail_fast {
1224             cargo.arg("--no-fail-fast");
1225         }
1226
1227         match krate {
1228             Some(krate) => {
1229                 cargo.arg("-p").arg(krate);
1230             }
1231             None => {
1232                 let mut visited = HashSet::new();
1233                 let mut next = vec![root];
1234                 while let Some(name) = next.pop() {
1235                     // Right now jemalloc and the sanitizer crates are
1236                     // target-specific crate in the sense that it's not present
1237                     // on all platforms. Custom skip it here for now, but if we
1238                     // add more this probably wants to get more generalized.
1239                     //
1240                     // Also skip `build_helper` as it's not compiled normally
1241                     // for target during the bootstrap and it's just meant to be
1242                     // a helper crate, not tested. If it leaks through then it
1243                     // ends up messing with various mtime calculations and such.
1244                     if !name.contains("jemalloc") &&
1245                        *name != *"build_helper" &&
1246                        !(name.starts_with("rustc_") && name.ends_with("san")) &&
1247                        name != "dlmalloc" {
1248                         cargo.arg("-p").arg(&format!("{}:0.0.0", name));
1249                     }
1250                     for dep in build.crates[&name].deps.iter() {
1251                         if visited.insert(dep) {
1252                             next.push(*dep);
1253                         }
1254                     }
1255                 }
1256             }
1257         }
1258
1259         // The tests are going to run with the *target* libraries, so we need to
1260         // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1261         //
1262         // Note that to run the compiler we need to run with the *host* libraries,
1263         // but our wrapper scripts arrange for that to be the case anyway.
1264         let mut dylib_path = dylib_path();
1265         dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1266         cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1267
1268         cargo.arg("--");
1269         cargo.args(&build.config.cmd.test_args());
1270
1271         if build.config.quiet_tests {
1272             cargo.arg("--quiet");
1273         }
1274
1275         let _time = util::timeit();
1276
1277         if target.contains("emscripten") {
1278             cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1279                       build.config.nodejs.as_ref().expect("nodejs not configured"));
1280         } else if target.starts_with("wasm32") {
1281             // On the wasm32-unknown-unknown target we're using LTO which is
1282             // incompatible with `-C prefer-dynamic`, so disable that here
1283             cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
1284
1285             let node = build.config.nodejs.as_ref()
1286                 .expect("nodejs not configured");
1287             let runner = format!("{} {}/src/etc/wasm32-shim.js",
1288                                  node.display(),
1289                                  build.src.display());
1290             cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
1291         } else if build.remote_tested(target) {
1292             cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1293                       format!("{} run",
1294                               builder.tool_exe(Tool::RemoteTestClient).display()));
1295         }
1296         try_run(build, &mut cargo);
1297     }
1298 }
1299
1300 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1301 pub struct Rustdoc {
1302     host: Interned<String>,
1303     test_kind: TestKind,
1304 }
1305
1306 impl Step for Rustdoc {
1307     type Output = ();
1308     const DEFAULT: bool = true;
1309     const ONLY_HOSTS: bool = true;
1310
1311     fn should_run(run: ShouldRun) -> ShouldRun {
1312         run.path("src/librustdoc").path("src/tools/rustdoc")
1313     }
1314
1315     fn make_run(run: RunConfig) {
1316         let builder = run.builder;
1317
1318         let test_kind = if builder.kind == Kind::Test {
1319             TestKind::Test
1320         } else if builder.kind == Kind::Bench {
1321             TestKind::Bench
1322         } else {
1323             panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1324         };
1325
1326         builder.ensure(Rustdoc {
1327             host: run.host,
1328             test_kind,
1329         });
1330     }
1331
1332     fn run(self, builder: &Builder) {
1333         let build = builder.build;
1334         let test_kind = self.test_kind;
1335
1336         let compiler = builder.compiler(builder.top_stage, self.host);
1337         let target = compiler.host;
1338
1339         let mut cargo = tool::prepare_tool_cargo(builder,
1340                                                  compiler,
1341                                                  target,
1342                                                  test_kind.subcommand(),
1343                                                  "src/tools/rustdoc");
1344         let _folder = build.fold_output(|| {
1345             format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage)
1346         });
1347         println!("{} rustdoc stage{} ({} -> {})", test_kind, compiler.stage,
1348                 &compiler.host, target);
1349
1350         if test_kind.subcommand() == "test" && !build.fail_fast {
1351             cargo.arg("--no-fail-fast");
1352         }
1353
1354         cargo.arg("-p").arg("rustdoc:0.0.0");
1355
1356         cargo.arg("--");
1357         cargo.args(&build.config.cmd.test_args());
1358
1359         if build.config.quiet_tests {
1360             cargo.arg("--quiet");
1361         }
1362
1363         let _time = util::timeit();
1364
1365         try_run(build, &mut cargo);
1366     }
1367 }
1368
1369 fn envify(s: &str) -> String {
1370     s.chars().map(|c| {
1371         match c {
1372             '-' => '_',
1373             c => c,
1374         }
1375     }).flat_map(|c| c.to_uppercase()).collect()
1376 }
1377
1378 /// Some test suites are run inside emulators or on remote devices, and most
1379 /// of our test binaries are linked dynamically which means we need to ship
1380 /// the standard library and such to the emulator ahead of time. This step
1381 /// represents this and is a dependency of all test suites.
1382 ///
1383 /// Most of the time this is a noop. For some steps such as shipping data to
1384 /// QEMU we have to build our own tools so we've got conditional dependencies
1385 /// on those programs as well. Note that the remote test client is built for
1386 /// the build target (us) and the server is built for the target.
1387 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1388 pub struct RemoteCopyLibs {
1389     compiler: Compiler,
1390     target: Interned<String>,
1391 }
1392
1393 impl Step for RemoteCopyLibs {
1394     type Output = ();
1395
1396     fn should_run(run: ShouldRun) -> ShouldRun {
1397         run.never()
1398     }
1399
1400     fn run(self, builder: &Builder) {
1401         let build = builder.build;
1402         let compiler = self.compiler;
1403         let target = self.target;
1404         if !build.remote_tested(target) {
1405             return
1406         }
1407
1408         builder.ensure(compile::Test { compiler, target });
1409
1410         println!("REMOTE copy libs to emulator ({})", target);
1411         t!(fs::create_dir_all(build.out.join("tmp")));
1412
1413         let server = builder.ensure(tool::RemoteTestServer { compiler, target });
1414
1415         // Spawn the emulator and wait for it to come online
1416         let tool = builder.tool_exe(Tool::RemoteTestClient);
1417         let mut cmd = Command::new(&tool);
1418         cmd.arg("spawn-emulator")
1419            .arg(target)
1420            .arg(&server)
1421            .arg(build.out.join("tmp"));
1422         if let Some(rootfs) = build.qemu_rootfs(target) {
1423             cmd.arg(rootfs);
1424         }
1425         build.run(&mut cmd);
1426
1427         // Push all our dylibs to the emulator
1428         for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1429             let f = t!(f);
1430             let name = f.file_name().into_string().unwrap();
1431             if util::is_dylib(&name) {
1432                 build.run(Command::new(&tool)
1433                                   .arg("push")
1434                                   .arg(f.path()));
1435             }
1436         }
1437     }
1438 }
1439
1440 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1441 pub struct Distcheck;
1442
1443 impl Step for Distcheck {
1444     type Output = ();
1445     const ONLY_BUILD: bool = true;
1446
1447     fn should_run(run: ShouldRun) -> ShouldRun {
1448         run.path("distcheck")
1449     }
1450
1451     fn make_run(run: RunConfig) {
1452         run.builder.ensure(Distcheck);
1453     }
1454
1455     /// Run "distcheck", a 'make check' from a tarball
1456     fn run(self, builder: &Builder) {
1457         let build = builder.build;
1458
1459         println!("Distcheck");
1460         let dir = build.out.join("tmp").join("distcheck");
1461         let _ = fs::remove_dir_all(&dir);
1462         t!(fs::create_dir_all(&dir));
1463
1464         // Guarantee that these are built before we begin running.
1465         builder.ensure(dist::PlainSourceTarball);
1466         builder.ensure(dist::Src);
1467
1468         let mut cmd = Command::new("tar");
1469         cmd.arg("-xzf")
1470            .arg(builder.ensure(dist::PlainSourceTarball))
1471            .arg("--strip-components=1")
1472            .current_dir(&dir);
1473         build.run(&mut cmd);
1474         build.run(Command::new("./configure")
1475                          .args(&build.config.configure_args)
1476                          .arg("--enable-vendor")
1477                          .current_dir(&dir));
1478         build.run(Command::new(build_helper::make(&build.build))
1479                          .arg("check")
1480                          .current_dir(&dir));
1481
1482         // Now make sure that rust-src has all of libstd's dependencies
1483         println!("Distcheck rust-src");
1484         let dir = build.out.join("tmp").join("distcheck-src");
1485         let _ = fs::remove_dir_all(&dir);
1486         t!(fs::create_dir_all(&dir));
1487
1488         let mut cmd = Command::new("tar");
1489         cmd.arg("-xzf")
1490            .arg(builder.ensure(dist::Src))
1491            .arg("--strip-components=1")
1492            .current_dir(&dir);
1493         build.run(&mut cmd);
1494
1495         let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
1496         build.run(Command::new(&build.initial_cargo)
1497                          .arg("generate-lockfile")
1498                          .arg("--manifest-path")
1499                          .arg(&toml)
1500                          .current_dir(&dir));
1501     }
1502 }
1503
1504 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1505 pub struct Bootstrap;
1506
1507 impl Step for Bootstrap {
1508     type Output = ();
1509     const DEFAULT: bool = true;
1510     const ONLY_HOSTS: bool = true;
1511     const ONLY_BUILD: bool = true;
1512
1513     /// Test the build system itself
1514     fn run(self, builder: &Builder) {
1515         let build = builder.build;
1516         let mut cmd = Command::new(&build.initial_cargo);
1517         cmd.arg("test")
1518            .current_dir(build.src.join("src/bootstrap"))
1519            .env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
1520            .env("RUSTC_BOOTSTRAP", "1")
1521            .env("RUSTC", &build.initial_rustc);
1522         if !build.fail_fast {
1523             cmd.arg("--no-fail-fast");
1524         }
1525         cmd.arg("--").args(&build.config.cmd.test_args());
1526         try_run(build, &mut cmd);
1527     }
1528
1529     fn should_run(run: ShouldRun) -> ShouldRun {
1530         run.path("src/bootstrap")
1531     }
1532
1533     fn make_run(run: RunConfig) {
1534         run.builder.ensure(Bootstrap);
1535     }
1536 }