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