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