]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/check.rs
Auto merge of #42972 - GuillaumeGomez:fix-toggles-rustdoc, r=QuietMisdreavus
[rust.git] / src / bootstrap / check.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Implementation of the test-related targets of the build system.
12 //!
13 //! This file implements the various regression test suites that we execute on
14 //! our CI.
15
16 use std::collections::HashSet;
17 use std::env;
18 use std::iter;
19 use std::fmt;
20 use std::fs::{self, File};
21 use std::path::{PathBuf, Path};
22 use std::process::Command;
23 use std::io::Read;
24
25 use build_helper::{self, output};
26
27 use {Build, Compiler, Mode};
28 use dist;
29 use util::{self, dylib_path, dylib_path_var, exe};
30
31 const ADB_TEST_DIR: &str = "/data/tmp/work";
32
33 /// The two modes of the test runner; tests or benchmarks.
34 #[derive(Copy, Clone)]
35 pub enum TestKind {
36     /// Run `cargo test`
37     Test,
38     /// Run `cargo bench`
39     Bench,
40 }
41
42 impl TestKind {
43     // Return the cargo subcommand for this test kind
44     fn subcommand(self) -> &'static str {
45         match self {
46             TestKind::Test => "test",
47             TestKind::Bench => "bench",
48         }
49     }
50 }
51
52 impl fmt::Display for TestKind {
53     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
54         f.write_str(match *self {
55             TestKind::Test => "Testing",
56             TestKind::Bench => "Benchmarking",
57         })
58     }
59 }
60
61 fn try_run(build: &Build, cmd: &mut Command) {
62     if !build.fail_fast {
63         if !build.try_run(cmd) {
64             let failures = build.delayed_failures.get();
65             build.delayed_failures.set(failures + 1);
66         }
67     } else {
68         build.run(cmd);
69     }
70 }
71
72 fn try_run_quiet(build: &Build, cmd: &mut Command) {
73     if !build.fail_fast {
74         if !build.try_run_quiet(cmd) {
75             let failures = build.delayed_failures.get();
76             build.delayed_failures.set(failures + 1);
77         }
78     } else {
79         build.run_quiet(cmd);
80     }
81 }
82
83 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
84 ///
85 /// This tool in `src/tools` will verify the validity of all our links in the
86 /// documentation to ensure we don't have a bunch of dead ones.
87 pub fn linkcheck(build: &Build, host: &str) {
88     println!("Linkcheck ({})", host);
89     let compiler = Compiler::new(0, host);
90
91     let _time = util::timeit();
92     try_run(build, build.tool_cmd(&compiler, "linkchecker")
93                         .arg(build.out.join(host).join("doc")));
94 }
95
96 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
97 ///
98 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
99 /// test` to ensure that we don't regress the test suites there.
100 pub fn cargotest(build: &Build, stage: u32, host: &str) {
101     let compiler = Compiler::new(stage, host);
102
103     // Note that this is a short, cryptic, and not scoped directory name. This
104     // is currently to minimize the length of path on Windows where we otherwise
105     // quickly run into path name limit constraints.
106     let out_dir = build.out.join("ct");
107     t!(fs::create_dir_all(&out_dir));
108
109     let _time = util::timeit();
110     let mut cmd = Command::new(build.tool(&Compiler::new(0, host), "cargotest"));
111     build.prepare_tool_cmd(&compiler, &mut cmd);
112     try_run(build, cmd.arg(&build.initial_cargo)
113                       .arg(&out_dir)
114                       .env("RUSTC", build.compiler_path(&compiler))
115                       .env("RUSTDOC", build.rustdoc(&compiler)));
116 }
117
118 /// Runs `cargo test` for `cargo` packaged with Rust.
119 pub fn cargo(build: &Build, stage: u32, host: &str) {
120     let ref compiler = Compiler::new(stage, host);
121
122     // Configure PATH to find the right rustc. NB. we have to use PATH
123     // and not RUSTC because the Cargo test suite has tests that will
124     // fail if rustc is not spelled `rustc`.
125     let path = build.sysroot(compiler).join("bin");
126     let old_path = env::var_os("PATH").unwrap_or_default();
127     let newpath = env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("");
128
129     let mut cargo = build.cargo(compiler, Mode::Tool, host, "test");
130     cargo.arg("--manifest-path").arg(build.src.join("src/tools/cargo/Cargo.toml"));
131     if !build.fail_fast {
132         cargo.arg("--no-fail-fast");
133     }
134
135     // Don't build tests dynamically, just a pain to work with
136     cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
137
138     // Don't run cross-compile tests, we may not have cross-compiled libstd libs
139     // available.
140     cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
141
142     try_run(build, cargo.env("PATH", newpath));
143 }
144
145 /// Runs the `tidy` tool as compiled in `stage` by the `host` compiler.
146 ///
147 /// This tool in `src/tools` checks up on various bits and pieces of style and
148 /// otherwise just implements a few lint-like checks that are specific to the
149 /// compiler itself.
150 pub fn tidy(build: &Build, host: &str) {
151     let _folder = build.fold_output(|| "tidy");
152     println!("tidy check ({})", host);
153     let compiler = Compiler::new(0, host);
154     let mut cmd = build.tool_cmd(&compiler, "tidy");
155     cmd.arg(build.src.join("src"));
156     if !build.config.vendor {
157         cmd.arg("--no-vendor");
158     }
159     if build.config.quiet_tests {
160         cmd.arg("--quiet");
161     }
162     try_run(build, &mut cmd);
163 }
164
165 fn testdir(build: &Build, host: &str) -> PathBuf {
166     build.out.join(host).join("test")
167 }
168
169 /// Executes the `compiletest` tool to run a suite of tests.
170 ///
171 /// Compiles all tests with `compiler` for `target` with the specified
172 /// compiletest `mode` and `suite` arguments. For example `mode` can be
173 /// "run-pass" or `suite` can be something like `debuginfo`.
174 pub fn compiletest(build: &Build,
175                    compiler: &Compiler,
176                    target: &str,
177                    mode: &str,
178                    suite: &str) {
179     let _folder = build.fold_output(|| format!("test_{}", suite));
180     println!("Check compiletest suite={} mode={} ({} -> {})",
181              suite, mode, compiler.host, target);
182     let mut cmd = Command::new(build.tool(&Compiler::new(0, compiler.host),
183                                           "compiletest"));
184     build.prepare_tool_cmd(compiler, &mut cmd);
185
186     // compiletest currently has... a lot of arguments, so let's just pass all
187     // of them!
188
189     cmd.arg("--compile-lib-path").arg(build.rustc_libdir(compiler));
190     cmd.arg("--run-lib-path").arg(build.sysroot_libdir(compiler, target));
191     cmd.arg("--rustc-path").arg(build.compiler_path(compiler));
192     cmd.arg("--rustdoc-path").arg(build.rustdoc(compiler));
193     cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
194     cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
195     cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
196     cmd.arg("--mode").arg(mode);
197     cmd.arg("--target").arg(target);
198     cmd.arg("--host").arg(compiler.host);
199     cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(&build.build));
200
201     if let Some(ref nodejs) = build.config.nodejs {
202         cmd.arg("--nodejs").arg(nodejs);
203     }
204
205     let mut flags = vec!["-Crpath".to_string()];
206     if build.config.rust_optimize_tests {
207         flags.push("-O".to_string());
208     }
209     if build.config.rust_debuginfo_tests {
210         flags.push("-g".to_string());
211     }
212
213     let mut hostflags = build.rustc_flags(&compiler.host);
214     hostflags.extend(flags.clone());
215     cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
216
217     let mut targetflags = build.rustc_flags(&target);
218     targetflags.extend(flags);
219     targetflags.push(format!("-Lnative={}",
220                              build.test_helpers_out(target).display()));
221     cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
222
223     cmd.arg("--docck-python").arg(build.python());
224
225     if build.build.ends_with("apple-darwin") {
226         // Force /usr/bin/python on macOS for LLDB tests because we're loading the
227         // LLDB plugin's compiled module which only works with the system python
228         // (namely not Homebrew-installed python)
229         cmd.arg("--lldb-python").arg("/usr/bin/python");
230     } else {
231         cmd.arg("--lldb-python").arg(build.python());
232     }
233
234     if let Some(ref gdb) = build.config.gdb {
235         cmd.arg("--gdb").arg(gdb);
236     }
237     if let Some(ref vers) = build.lldb_version {
238         cmd.arg("--lldb-version").arg(vers);
239     }
240     if let Some(ref dir) = build.lldb_python_dir {
241         cmd.arg("--lldb-python-dir").arg(dir);
242     }
243     let llvm_config = build.llvm_config(target);
244     let llvm_version = output(Command::new(&llvm_config).arg("--version"));
245     cmd.arg("--llvm-version").arg(llvm_version);
246     if !build.is_rust_llvm(target) {
247         cmd.arg("--system-llvm");
248     }
249
250     cmd.args(&build.flags.cmd.test_args());
251
252     if build.is_verbose() {
253         cmd.arg("--verbose");
254     }
255
256     if build.config.quiet_tests {
257         cmd.arg("--quiet");
258     }
259
260     // Only pass correct values for these flags for the `run-make` suite as it
261     // requires that a C++ compiler was configured which isn't always the case.
262     if suite == "run-make" {
263         let llvm_components = output(Command::new(&llvm_config).arg("--components"));
264         let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
265         cmd.arg("--cc").arg(build.cc(target))
266            .arg("--cxx").arg(build.cxx(target).unwrap())
267            .arg("--cflags").arg(build.cflags(target).join(" "))
268            .arg("--llvm-components").arg(llvm_components.trim())
269            .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
270     } else {
271         cmd.arg("--cc").arg("")
272            .arg("--cxx").arg("")
273            .arg("--cflags").arg("")
274            .arg("--llvm-components").arg("")
275            .arg("--llvm-cxxflags").arg("");
276     }
277
278     if build.remote_tested(target) {
279         cmd.arg("--remote-test-client")
280            .arg(build.tool(&Compiler::new(0, &build.build),
281                            "remote-test-client"));
282     }
283
284     // Running a C compiler on MSVC requires a few env vars to be set, to be
285     // sure to set them here.
286     //
287     // Note that if we encounter `PATH` we make sure to append to our own `PATH`
288     // rather than stomp over it.
289     if target.contains("msvc") {
290         for &(ref k, ref v) in build.cc[target].0.env() {
291             if k != "PATH" {
292                 cmd.env(k, v);
293             }
294         }
295     }
296     cmd.env("RUSTC_BOOTSTRAP", "1");
297     build.add_rust_test_threads(&mut cmd);
298
299     if build.config.sanitizers {
300         cmd.env("SANITIZER_SUPPORT", "1");
301     }
302
303     if build.config.profiler {
304         cmd.env("PROFILER_SUPPORT", "1");
305     }
306
307     cmd.arg("--adb-path").arg("adb");
308     cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
309     if target.contains("android") {
310         // Assume that cc for this target comes from the android sysroot
311         cmd.arg("--android-cross-path")
312            .arg(build.cc(target).parent().unwrap().parent().unwrap());
313     } else {
314         cmd.arg("--android-cross-path").arg("");
315     }
316
317     build.ci_env.force_coloring_in_ci(&mut cmd);
318
319     let _time = util::timeit();
320     try_run(build, &mut cmd);
321 }
322
323 /// Run `rustdoc --test` for all documentation in `src/doc`.
324 ///
325 /// This will run all tests in our markdown documentation (e.g. the book)
326 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
327 /// `compiler`.
328 pub fn docs(build: &Build, compiler: &Compiler) {
329     // Do a breadth-first traversal of the `src/doc` directory and just run
330     // tests for all files that end in `*.md`
331     let mut stack = vec![build.src.join("src/doc")];
332     let _time = util::timeit();
333     let _folder = build.fold_output(|| "test_docs");
334
335     while let Some(p) = stack.pop() {
336         if p.is_dir() {
337             stack.extend(t!(p.read_dir()).map(|p| t!(p).path()).filter(|p| {
338                 p.extension().and_then(|s| s.to_str()) == Some("md") &&
339                 // The nostarch directory in the book is for no starch, and so isn't guaranteed to
340                 // build. We don't care if it doesn't build, so skip it.
341                 p.to_str().map_or(true, |p| !p.contains("nostarch"))
342             }));
343             continue
344         }
345
346         markdown_test(build, compiler, &p);
347     }
348 }
349
350 /// Run the error index generator tool to execute the tests located in the error
351 /// index.
352 ///
353 /// The `error_index_generator` tool lives in `src/tools` and is used to
354 /// generate a markdown file from the error indexes of the code base which is
355 /// then passed to `rustdoc --test`.
356 pub fn error_index(build: &Build, compiler: &Compiler) {
357     let _folder = build.fold_output(|| "test_error_index");
358     println!("Testing error-index stage{}", compiler.stage);
359
360     let dir = testdir(build, compiler.host);
361     t!(fs::create_dir_all(&dir));
362     let output = dir.join("error-index.md");
363
364     let _time = util::timeit();
365     build.run(build.tool_cmd(&Compiler::new(0, compiler.host),
366                              "error_index_generator")
367                    .arg("markdown")
368                    .arg(&output)
369                    .env("CFG_BUILD", &build.build));
370
371     markdown_test(build, compiler, &output);
372 }
373
374 fn markdown_test(build: &Build, compiler: &Compiler, markdown: &Path) {
375     let mut file = t!(File::open(markdown));
376     let mut contents = String::new();
377     t!(file.read_to_string(&mut contents));
378     if !contents.contains("```") {
379         return;
380     }
381
382     println!("doc tests for: {}", markdown.display());
383     let mut cmd = Command::new(build.rustdoc(compiler));
384     build.add_rustc_lib_path(compiler, &mut cmd);
385     build.add_rust_test_threads(&mut cmd);
386     cmd.arg("--test");
387     cmd.arg(markdown);
388     cmd.env("RUSTC_BOOTSTRAP", "1");
389
390     let test_args = build.flags.cmd.test_args().join(" ");
391     cmd.arg("--test-args").arg(test_args);
392
393     if build.config.quiet_tests {
394         try_run_quiet(build, &mut cmd);
395     } else {
396         try_run(build, &mut cmd);
397     }
398 }
399
400 /// Run all unit tests plus documentation tests for an entire crate DAG defined
401 /// by a `Cargo.toml`
402 ///
403 /// This is what runs tests for crates like the standard library, compiler, etc.
404 /// It essentially is the driver for running `cargo test`.
405 ///
406 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
407 /// arguments, and those arguments are discovered from `cargo metadata`.
408 pub fn krate(build: &Build,
409              compiler: &Compiler,
410              target: &str,
411              mode: Mode,
412              test_kind: TestKind,
413              krate: Option<&str>) {
414     let (name, path, features, root) = match mode {
415         Mode::Libstd => {
416             ("libstd", "src/libstd", build.std_features(), "std")
417         }
418         Mode::Libtest => {
419             ("libtest", "src/libtest", String::new(), "test")
420         }
421         Mode::Librustc => {
422             ("librustc", "src/rustc", build.rustc_features(), "rustc-main")
423         }
424         _ => panic!("can only test libraries"),
425     };
426     let _folder = build.fold_output(|| {
427         format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, name)
428     });
429     println!("{} {} stage{} ({} -> {})", test_kind, name, compiler.stage,
430              compiler.host, target);
431
432     // If we're not doing a full bootstrap but we're testing a stage2 version of
433     // libstd, then what we're actually testing is the libstd produced in
434     // stage1. Reflect that here by updating the compiler that we're working
435     // with automatically.
436     let compiler = if build.force_use_stage1(compiler, target) {
437         Compiler::new(1, compiler.host)
438     } else {
439         compiler.clone()
440     };
441
442     // Build up the base `cargo test` command.
443     //
444     // Pass in some standard flags then iterate over the graph we've discovered
445     // in `cargo metadata` with the maps above and figure out what `-p`
446     // arguments need to get passed.
447     let mut cargo = build.cargo(&compiler, mode, target, test_kind.subcommand());
448     cargo.arg("--manifest-path")
449          .arg(build.src.join(path).join("Cargo.toml"))
450          .arg("--features").arg(features);
451     if test_kind.subcommand() == "test" && !build.fail_fast {
452         cargo.arg("--no-fail-fast");
453     }
454
455     match krate {
456         Some(krate) => {
457             cargo.arg("-p").arg(krate);
458         }
459         None => {
460             let mut visited = HashSet::new();
461             let mut next = vec![root];
462             while let Some(name) = next.pop() {
463                 // Right now jemalloc is our only target-specific crate in the
464                 // sense that it's not present on all platforms. Custom skip it
465                 // here for now, but if we add more this probably wants to get
466                 // more generalized.
467                 //
468                 // Also skip `build_helper` as it's not compiled normally for
469                 // target during the bootstrap and it's just meant to be a
470                 // helper crate, not tested. If it leaks through then it ends up
471                 // messing with various mtime calculations and such.
472                 if !name.contains("jemalloc") && name != "build_helper" {
473                     cargo.arg("-p").arg(&format!("{}:0.0.0", name));
474                 }
475                 for dep in build.crates[name].deps.iter() {
476                     if visited.insert(dep) {
477                         next.push(dep);
478                     }
479                 }
480             }
481         }
482     }
483
484     // The tests are going to run with the *target* libraries, so we need to
485     // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
486     //
487     // Note that to run the compiler we need to run with the *host* libraries,
488     // but our wrapper scripts arrange for that to be the case anyway.
489     let mut dylib_path = dylib_path();
490     dylib_path.insert(0, build.sysroot_libdir(&compiler, target));
491     cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
492
493     if target.contains("emscripten") || build.remote_tested(target) {
494         cargo.arg("--no-run");
495     }
496
497     cargo.arg("--");
498
499     if build.config.quiet_tests {
500         cargo.arg("--quiet");
501     }
502
503     let _time = util::timeit();
504
505     if target.contains("emscripten") {
506         build.run(&mut cargo);
507         krate_emscripten(build, &compiler, target, mode);
508     } else if build.remote_tested(target) {
509         build.run(&mut cargo);
510         krate_remote(build, &compiler, target, mode);
511     } else {
512         cargo.args(&build.flags.cmd.test_args());
513         try_run(build, &mut cargo);
514     }
515 }
516
517 fn krate_emscripten(build: &Build,
518                     compiler: &Compiler,
519                     target: &str,
520                     mode: Mode) {
521     let out_dir = build.cargo_out(compiler, mode, target);
522     let tests = find_tests(&out_dir.join("deps"), target);
523
524     let nodejs = build.config.nodejs.as_ref().expect("nodejs not configured");
525     for test in tests {
526         println!("running {}", test.display());
527         let mut cmd = Command::new(nodejs);
528         cmd.arg(&test);
529         if build.config.quiet_tests {
530             cmd.arg("--quiet");
531         }
532         try_run(build, &mut cmd);
533     }
534 }
535
536 fn krate_remote(build: &Build,
537                 compiler: &Compiler,
538                 target: &str,
539                 mode: Mode) {
540     let out_dir = build.cargo_out(compiler, mode, target);
541     let tests = find_tests(&out_dir.join("deps"), target);
542
543     let tool = build.tool(&Compiler::new(0, &build.build),
544                           "remote-test-client");
545     for test in tests {
546         let mut cmd = Command::new(&tool);
547         cmd.arg("run")
548            .arg(&test);
549         if build.config.quiet_tests {
550             cmd.arg("--quiet");
551         }
552         cmd.args(&build.flags.cmd.test_args());
553         try_run(build, &mut cmd);
554     }
555 }
556
557 fn find_tests(dir: &Path, target: &str) -> Vec<PathBuf> {
558     let mut dst = Vec::new();
559     for e in t!(dir.read_dir()).map(|e| t!(e)) {
560         let file_type = t!(e.file_type());
561         if !file_type.is_file() {
562             continue
563         }
564         let filename = e.file_name().into_string().unwrap();
565         if (target.contains("windows") && filename.ends_with(".exe")) ||
566            (!target.contains("windows") && !filename.contains(".")) ||
567            (target.contains("emscripten") &&
568             filename.ends_with(".js") &&
569             !filename.ends_with(".asm.js")) {
570             dst.push(e.path());
571         }
572     }
573     dst
574 }
575
576 pub fn remote_copy_libs(build: &Build, compiler: &Compiler, target: &str) {
577     if !build.remote_tested(target) {
578         return
579     }
580
581     println!("REMOTE copy libs to emulator ({})", target);
582     t!(fs::create_dir_all(build.out.join("tmp")));
583
584     let server = build.cargo_out(compiler, Mode::Tool, target)
585                       .join(exe("remote-test-server", target));
586
587     // Spawn the emulator and wait for it to come online
588     let tool = build.tool(&Compiler::new(0, &build.build),
589                           "remote-test-client");
590     let mut cmd = Command::new(&tool);
591     cmd.arg("spawn-emulator")
592        .arg(target)
593        .arg(&server)
594        .arg(build.out.join("tmp"));
595     if let Some(rootfs) = build.qemu_rootfs(target) {
596         cmd.arg(rootfs);
597     }
598     build.run(&mut cmd);
599
600     // Push all our dylibs to the emulator
601     for f in t!(build.sysroot_libdir(compiler, target).read_dir()) {
602         let f = t!(f);
603         let name = f.file_name().into_string().unwrap();
604         if util::is_dylib(&name) {
605             build.run(Command::new(&tool)
606                               .arg("push")
607                               .arg(f.path()));
608         }
609     }
610 }
611
612 /// Run "distcheck", a 'make check' from a tarball
613 pub fn distcheck(build: &Build) {
614     if build.build != "x86_64-unknown-linux-gnu" {
615         return
616     }
617     if !build.config.host.iter().any(|s| s == "x86_64-unknown-linux-gnu") {
618         return
619     }
620     if !build.config.target.iter().any(|s| s == "x86_64-unknown-linux-gnu") {
621         return
622     }
623
624     println!("Distcheck");
625     let dir = build.out.join("tmp").join("distcheck");
626     let _ = fs::remove_dir_all(&dir);
627     t!(fs::create_dir_all(&dir));
628
629     let mut cmd = Command::new("tar");
630     cmd.arg("-xzf")
631        .arg(dist::rust_src_location(build))
632        .arg("--strip-components=1")
633        .current_dir(&dir);
634     build.run(&mut cmd);
635     build.run(Command::new("./configure")
636                      .args(&build.config.configure_args)
637                      .arg("--enable-vendor")
638                      .current_dir(&dir));
639     build.run(Command::new(build_helper::make(&build.build))
640                      .arg("check")
641                      .current_dir(&dir));
642
643     // Now make sure that rust-src has all of libstd's dependencies
644     println!("Distcheck rust-src");
645     let dir = build.out.join("tmp").join("distcheck-src");
646     let _ = fs::remove_dir_all(&dir);
647     t!(fs::create_dir_all(&dir));
648
649     let mut cmd = Command::new("tar");
650     cmd.arg("-xzf")
651        .arg(dist::rust_src_installer(build))
652        .arg("--strip-components=1")
653        .current_dir(&dir);
654     build.run(&mut cmd);
655
656     let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
657     build.run(Command::new(&build.initial_cargo)
658                      .arg("generate-lockfile")
659                      .arg("--manifest-path")
660                      .arg(&toml)
661                      .current_dir(&dir));
662 }
663
664 /// Test the build system itself
665 pub fn bootstrap(build: &Build) {
666     let mut cmd = Command::new(&build.initial_cargo);
667     cmd.arg("test")
668        .current_dir(build.src.join("src/bootstrap"))
669        .env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
670        .env("RUSTC_BOOTSTRAP", "1")
671        .env("RUSTC", &build.initial_rustc);
672     if !build.fail_fast {
673         cmd.arg("--no-fail-fast");
674     }
675     cmd.arg("--").args(&build.flags.cmd.test_args());
676     try_run(build, &mut cmd);
677 }