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