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