test.rs 58.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

11
//! Implementation of the test-related targets of the build system.
12 13 14 15
//!
//! This file implements the various regression test suites that we execute on
//! our CI.

16
use std::env;
N
Nick Cameron 已提交
17
use std::ffi::OsString;
U
Ulrik Sverdrup 已提交
18
use std::fmt;
19 20
use std::fs::{self, File};
use std::io::Read;
S
Santiago Pastorino 已提交
21 22 23
use std::iter;
use std::path::{Path, PathBuf};
use std::process::Command;
24

25
use build_helper::{self, output};
26

S
Santiago Pastorino 已提交
27 28
use builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
use cache::{Interned, INTERNER};
29
use compile;
A
Alex Crichton 已提交
30
use dist;
S
Santiago Pastorino 已提交
31
use flags::Subcommand;
32
use native;
33
use tool::{self, Tool};
34
use toolstate::ToolState;
S
Santiago Pastorino 已提交
35 36 37
use util::{self, dylib_path, dylib_path_var};
use Crate as CargoCrate;
use {DocTests, Mode};
38

M
Mark Simulacrum 已提交
39
const ADB_TEST_DIR: &str = "/data/tmp/work";
40

U
Ulrik Sverdrup 已提交
41
/// The two modes of the test runner; tests or benchmarks.
K
kennytm 已提交
42
#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord)]
U
Ulrik Sverdrup 已提交
43 44 45 46 47 48 49
pub enum TestKind {
    /// Run `cargo test`
    Test,
    /// Run `cargo bench`
    Bench,
}

50 51 52 53 54
impl From<Kind> for TestKind {
    fn from(kind: Kind) -> Self {
        match kind {
            Kind::Test => TestKind::Test,
            Kind::Bench => TestKind::Bench,
S
Santiago Pastorino 已提交
55
            _ => panic!("unexpected kind in crate: {:?}", kind),
56 57 58 59
        }
    }
}

U
Ulrik Sverdrup 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
impl TestKind {
    // Return the cargo subcommand for this test kind
    fn subcommand(self) -> &'static str {
        match self {
            TestKind::Test => "test",
            TestKind::Bench => "bench",
        }
    }
}

impl fmt::Display for TestKind {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str(match *self {
            TestKind::Test => "Testing",
            TestKind::Bench => "Benchmarking",
        })
    }
}

79 80 81 82
fn try_run(builder: &Builder, cmd: &mut Command) -> bool {
    if !builder.fail_fast {
        if !builder.try_run(cmd) {
            let mut failures = builder.delayed_failures.borrow_mut();
83
            failures.push(format!("{:?}", cmd));
O
Oliver Schneider 已提交
84
            return false;
85 86
        }
    } else {
87
        builder.run(cmd);
88
    }
O
Oliver Schneider 已提交
89
    true
90 91
}

92 93 94 95
fn try_run_quiet(builder: &Builder, cmd: &mut Command) -> bool {
    if !builder.fail_fast {
        if !builder.try_run_quiet(cmd) {
            let mut failures = builder.delayed_failures.borrow_mut();
96
            failures.push(format!("{:?}", cmd));
97
            return false;
98 99
        }
    } else {
100
        builder.run_quiet(cmd);
101
    }
102
    true
103 104
}

105 106 107
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Linkcheck {
    host: Interned<String>,
108 109
}

110
impl Step for Linkcheck {
111
    type Output = ();
112 113
    const ONLY_HOSTS: bool = true;
    const DEFAULT: bool = true;
114 115 116 117 118 119 120 121

    /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
    ///
    /// This tool in `src/tools` will verify the validity of all our links in the
    /// documentation to ensure we don't have a bunch of dead ones.
    fn run(self, builder: &Builder) {
        let host = self.host;

122
        builder.info(&format!("Linkcheck ({})", host));
123 124

        builder.default_doc(None);
125

126
        let _time = util::timeit(&builder);
S
Santiago Pastorino 已提交
127 128 129 130 131 132
        try_run(
            builder,
            builder
                .tool_cmd(Tool::Linkchecker)
                .arg(builder.out.join(host).join("doc")),
        );
133
    }
134

135
    fn should_run(run: ShouldRun) -> ShouldRun {
136
        let builder = run.builder;
S
Santiago Pastorino 已提交
137 138
        run.path("src/tools/linkchecker")
            .default_condition(builder.config.docs)
139 140
    }

141
    fn make_run(run: RunConfig) {
142
        run.builder.ensure(Linkcheck { host: run.target });
143
    }
144
}
145

146 147
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Cargotest {
148
    stage: u32,
149
    host: Interned<String>,
150
}
151

152
impl Step for Cargotest {
153
    type Output = ();
154
    const ONLY_HOSTS: bool = true;
155

156 157
    fn should_run(run: ShouldRun) -> ShouldRun {
        run.path("src/tools/cargotest")
158 159
    }

160 161 162
    fn make_run(run: RunConfig) {
        run.builder.ensure(Cargotest {
            stage: run.builder.top_stage,
163
            host: run.target,
164 165 166
        });
    }

167 168 169 170 171
    /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
    ///
    /// This tool in `src/tools` will check out a few Rust projects and run `cargo
    /// test` to ensure that we don't regress the test suites there.
    fn run(self, builder: &Builder) {
172
        let compiler = builder.compiler(self.stage, self.host);
S
Santiago Pastorino 已提交
173 174 175 176
        builder.ensure(compile::Rustc {
            compiler,
            target: compiler.host,
        });
177 178 179 180

        // Note that this is a short, cryptic, and not scoped directory name. This
        // is currently to minimize the length of path on Windows where we otherwise
        // quickly run into path name limit constraints.
181
        let out_dir = builder.out.join("ct");
182 183
        t!(fs::create_dir_all(&out_dir));

184
        let _time = util::timeit(&builder);
185
        let mut cmd = builder.tool_cmd(Tool::CargoTest);
S
Santiago Pastorino 已提交
186 187 188 189 190 191 192
        try_run(
            builder,
            cmd.arg(&builder.initial_cargo)
                .arg(&out_dir)
                .env("RUSTC", builder.rustc(compiler))
                .env("RUSTDOC", builder.rustdoc(compiler.host)),
        );
193
    }
194 195
}

196 197
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Cargo {
198
    stage: u32,
199
    host: Interned<String>,
200 201
}

202
impl Step for Cargo {
203
    type Output = ();
204 205
    const ONLY_HOSTS: bool = true;

206 207
    fn should_run(run: ShouldRun) -> ShouldRun {
        run.path("src/tools/cargo")
208 209
    }

210 211 212 213
    fn make_run(run: RunConfig) {
        run.builder.ensure(Cargo {
            stage: run.builder.top_stage,
            host: run.target,
214 215
        });
    }
216 217 218

    /// Runs `cargo test` for `cargo` packaged with Rust.
    fn run(self, builder: &Builder) {
219
        let compiler = builder.compiler(self.stage, self.host);
220

S
Santiago Pastorino 已提交
221 222 223 224
        builder.ensure(tool::Cargo {
            compiler,
            target: self.host,
        });
225
        let mut cargo = builder.cargo(compiler, Mode::Tool, self.host, "test");
S
Santiago Pastorino 已提交
226 227 228
        cargo
            .arg("--manifest-path")
            .arg(builder.src.join("src/tools/cargo/Cargo.toml"));
229
        if !builder.fail_fast {
230 231
            cargo.arg("--no-fail-fast");
        }
232

233 234 235 236 237 238
        // Don't build tests dynamically, just a pain to work with
        cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");

        // Don't run cross-compile tests, we may not have cross-compiled libstd libs
        // available.
        cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
239

S
Santiago Pastorino 已提交
240 241 242 243
        try_run(
            builder,
            cargo.env("PATH", &path_for_cargo(builder, compiler)),
        );
244
    }
N
Nick Cameron 已提交
245 246
}

M
Mark Simulacrum 已提交
247 248
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Rls {
249
    stage: u32,
M
Mark Simulacrum 已提交
250
    host: Interned<String>,
251
}
N
Nick Cameron 已提交
252

M
Mark Simulacrum 已提交
253
impl Step for Rls {
254
    type Output = ();
M
Mark Simulacrum 已提交
255 256
    const ONLY_HOSTS: bool = true;

257 258
    fn should_run(run: ShouldRun) -> ShouldRun {
        run.path("src/tools/rls")
M
Mark Simulacrum 已提交
259 260
    }

261 262 263 264
    fn make_run(run: RunConfig) {
        run.builder.ensure(Rls {
            stage: run.builder.top_stage,
            host: run.target,
M
Mark Simulacrum 已提交
265 266
        });
    }
N
Nick Cameron 已提交
267

268 269 270 271
    /// Runs `cargo test` for the rls.
    fn run(self, builder: &Builder) {
        let stage = self.stage;
        let host = self.host;
M
Mark Simulacrum 已提交
272
        let compiler = builder.compiler(stage, host);
N
Nick Cameron 已提交
273

274 275 276 277 278 279 280 281 282 283
        let build_result = builder.ensure(tool::Rls {
            compiler,
            target: self.host,
            extra_features: Vec::new(),
        });
        if build_result.is_none() {
            eprintln!("failed to test rls: could not build");
            return;
        }

S
Santiago Pastorino 已提交
284
        let mut cargo = tool::prepare_tool_cargo(builder, compiler, host, "test", "src/tools/rls");
N
Nick Cameron 已提交
285

286 287 288
        // Don't build tests dynamically, just a pain to work with
        cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");

M
Mark Simulacrum 已提交
289
        builder.add_rustc_lib_path(compiler, &mut cargo);
290

291 292
        if try_run(builder, &mut cargo) {
            builder.save_toolstate("rls", ToolState::TestPass);
O
Oliver Schneider 已提交
293
        }
294
    }
N
Nick Cameron 已提交
295 296
}

N
Nick Cameron 已提交
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Rustfmt {
    stage: u32,
    host: Interned<String>,
}

impl Step for Rustfmt {
    type Output = ();
    const ONLY_HOSTS: bool = true;

    fn should_run(run: ShouldRun) -> ShouldRun {
        run.path("src/tools/rustfmt")
    }

    fn make_run(run: RunConfig) {
        run.builder.ensure(Rustfmt {
            stage: run.builder.top_stage,
            host: run.target,
        });
    }

    /// Runs `cargo test` for rustfmt.
    fn run(self, builder: &Builder) {
        let stage = self.stage;
        let host = self.host;
        let compiler = builder.compiler(stage, host);

324 325 326 327 328 329 330 331 332 333
        let build_result = builder.ensure(tool::Rustfmt {
            compiler,
            target: self.host,
            extra_features: Vec::new(),
        });
        if build_result.is_none() {
            eprintln!("failed to test rustfmt: could not build");
            return;
        }

S
Santiago Pastorino 已提交
334 335
        let mut cargo =
            tool::prepare_tool_cargo(builder, compiler, host, "test", "src/tools/rustfmt");
N
Nick Cameron 已提交
336 337 338

        // Don't build tests dynamically, just a pain to work with
        cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
N
Nick Cameron 已提交
339 340 341
        let dir = testdir(builder, compiler.host);
        t!(fs::create_dir_all(&dir));
        cargo.env("RUSTFMT_TEST_DIR", dir);
N
Nick Cameron 已提交
342 343 344

        builder.add_rustc_lib_path(compiler, &mut cargo);

345 346
        if try_run(builder, &mut cargo) {
            builder.save_toolstate("rustfmt", ToolState::TestPass);
O
Oliver Schneider 已提交
347
        }
N
Nick Cameron 已提交
348 349
    }
}
O
Oliver Schneider 已提交
350 351

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
352
pub struct Miri {
O
Oliver Schneider 已提交
353
    stage: u32,
354 355 356 357 358 359 360 361 362
    host: Interned<String>,
}

impl Step for Miri {
    type Output = ();
    const ONLY_HOSTS: bool = true;
    const DEFAULT: bool = true;

    fn should_run(run: ShouldRun) -> ShouldRun {
363
        let test_miri = run.builder.config.test_miri;
364 365 366 367 368
        run.path("src/tools/miri").default_condition(test_miri)
    }

    fn make_run(run: RunConfig) {
        run.builder.ensure(Miri {
O
Oliver Schneider 已提交
369
            stage: run.builder.top_stage,
370 371 372 373 374 375
            host: run.target,
        });
    }

    /// Runs `cargo test` for miri.
    fn run(self, builder: &Builder) {
O
Oliver Schneider 已提交
376
        let stage = self.stage;
377
        let host = self.host;
O
Oliver Schneider 已提交
378
        let compiler = builder.compiler(stage, host);
379

380 381 382 383 384 385
        let miri = builder.ensure(tool::Miri {
            compiler,
            target: self.host,
            extra_features: Vec::new(),
        });
        if let Some(miri) = miri {
O
Oliver Schneider 已提交
386
            let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
S
Santiago Pastorino 已提交
387 388 389
            cargo
                .arg("--manifest-path")
                .arg(builder.src.join("src/tools/miri/Cargo.toml"));
O
Oliver Schneider 已提交
390 391 392 393 394 395 396 397 398 399 400

            // Don't build tests dynamically, just a pain to work with
            cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
            // miri tests need to know about the stage sysroot
            cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
            cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
            cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
            cargo.env("MIRI_PATH", miri);

            builder.add_rustc_lib_path(compiler, &mut cargo);

401 402
            if try_run(builder, &mut cargo) {
                builder.save_toolstate("miri", ToolState::TestPass);
O
Oliver Schneider 已提交
403 404 405 406
            }
        } else {
            eprintln!("failed to test miri: could not build");
        }
407 408 409
    }
}

410 411
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Clippy {
O
Oliver Schneider 已提交
412
    stage: u32,
413 414 415 416 417 418 419 420 421 422 423 424 425 426
    host: Interned<String>,
}

impl Step for Clippy {
    type Output = ();
    const ONLY_HOSTS: bool = true;
    const DEFAULT: bool = false;

    fn should_run(run: ShouldRun) -> ShouldRun {
        run.path("src/tools/clippy")
    }

    fn make_run(run: RunConfig) {
        run.builder.ensure(Clippy {
O
Oliver Schneider 已提交
427
            stage: run.builder.top_stage,
428 429 430 431 432 433
            host: run.target,
        });
    }

    /// Runs `cargo test` for clippy.
    fn run(self, builder: &Builder) {
O
Oliver Schneider 已提交
434
        let stage = self.stage;
435
        let host = self.host;
O
Oliver Schneider 已提交
436
        let compiler = builder.compiler(stage, host);
437

438 439 440 441 442 443
        let clippy = builder.ensure(tool::Clippy {
            compiler,
            target: self.host,
            extra_features: Vec::new(),
        });
        if let Some(clippy) = clippy {
O
Oliver Schneider 已提交
444
            let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
S
Santiago Pastorino 已提交
445 446 447
            cargo
                .arg("--manifest-path")
                .arg(builder.src.join("src/tools/clippy/Cargo.toml"));
O
Oliver Schneider 已提交
448 449 450 451 452 453 454

            // Don't build tests dynamically, just a pain to work with
            cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
            // clippy tests need to know about the stage sysroot
            cargo.env("SYSROOT", builder.sysroot(compiler));
            cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
            cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
S
Santiago Pastorino 已提交
455 456 457
            let host_libs = builder
                .stage_out(compiler, Mode::Tool)
                .join(builder.cargo_dir());
O
Oliver Schneider 已提交
458 459 460 461 462 463
            cargo.env("HOST_LIBS", host_libs);
            // clippy tests need to find the driver
            cargo.env("CLIPPY_DRIVER_PATH", clippy);

            builder.add_rustc_lib_path(compiler, &mut cargo);

464 465
            if try_run(builder, &mut cargo) {
                builder.save_toolstate("clippy-driver", ToolState::TestPass);
O
Oliver Schneider 已提交
466 467 468 469
            }
        } else {
            eprintln!("failed to test clippy: could not build");
        }
470 471
    }
}
N
Nick Cameron 已提交
472

M
Mark Simulacrum 已提交
473
fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
N
Nick Cameron 已提交
474 475 476
    // Configure PATH to find the right rustc. NB. we have to use PATH
    // and not RUSTC because the Cargo test suite has tests that will
    // fail if rustc is not spelled `rustc`.
M
Mark Simulacrum 已提交
477
    let path = builder.sysroot(compiler).join("bin");
N
Nick Cameron 已提交
478 479
    let old_path = env::var_os("PATH").unwrap_or_default();
    env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
480
}
481

G
Guillaume Gomez 已提交
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct RustdocTheme {
    pub compiler: Compiler,
}

impl Step for RustdocTheme {
    type Output = ();
    const DEFAULT: bool = true;
    const ONLY_HOSTS: bool = true;

    fn should_run(run: ShouldRun) -> ShouldRun {
        run.path("src/tools/rustdoc-themes")
    }

    fn make_run(run: RunConfig) {
        let compiler = run.builder.compiler(run.builder.top_stage, run.host);

S
Santiago Pastorino 已提交
499
        run.builder.ensure(RustdocTheme { compiler: compiler });
G
Guillaume Gomez 已提交
500 501 502
    }

    fn run(self, builder: &Builder) {
503
        let rustdoc = builder.out.join("bootstrap/debug/rustdoc");
G
Guillaume Gomez 已提交
504 505
        let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
        cmd.arg(rustdoc.to_str().unwrap())
S
Santiago Pastorino 已提交
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
            .arg(
                builder
                    .src
                    .join("src/librustdoc/html/static/themes")
                    .to_str()
                    .unwrap(),
            )
            .env("RUSTC_STAGE", self.compiler.stage.to_string())
            .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
            .env(
                "RUSTDOC_LIBDIR",
                builder.sysroot_libdir(self.compiler, self.compiler.host),
            )
            .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
            .env("RUSTDOC_REAL", builder.rustdoc(self.compiler.host))
            .env("RUSTDOC_CRATE_VERSION", builder.rust_version())
            .env("RUSTC_BOOTSTRAP", "1");
523
        if let Some(linker) = builder.linker(self.compiler.host) {
G
Guillaume Gomez 已提交
524 525
            cmd.env("RUSTC_TARGET_LINKER", linker);
        }
526
        try_run(builder, &mut cmd);
G
Guillaume Gomez 已提交
527 528 529
    }
}

G
Guillaume Gomez 已提交
530 531 532
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct RustdocJS {
    pub host: Interned<String>,
533
    pub target: Interned<String>,
G
Guillaume Gomez 已提交
534 535 536
}

impl Step for RustdocJS {
537
    type Output = ();
G
Guillaume Gomez 已提交
538 539 540 541
    const DEFAULT: bool = true;
    const ONLY_HOSTS: bool = true;

    fn should_run(run: ShouldRun) -> ShouldRun {
542
        run.path("src/test/rustdoc-js")
G
Guillaume Gomez 已提交
543 544 545 546 547
    }

    fn make_run(run: RunConfig) {
        run.builder.ensure(RustdocJS {
            host: run.host,
548
            target: run.target,
G
Guillaume Gomez 已提交
549 550 551
        });
    }

552
    fn run(self, builder: &Builder) {
553 554 555 556 557 558 559 560 561
        if let Some(ref nodejs) = builder.config.nodejs {
            let mut command = Command::new(nodejs);
            command.args(&["src/tools/rustdoc-js/tester.js", &*self.host]);
            builder.ensure(::doc::Std {
                target: self.target,
                stage: builder.top_stage,
            });
            builder.run(&mut command);
        } else {
S
Santiago Pastorino 已提交
562 563 564
            builder.info(&format!(
                "No nodejs found, skipping \"src/test/rustdoc-js\" tests"
            ));
565
        }
G
Guillaume Gomez 已提交
566 567 568
    }
}

569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct RustdocUi {
    pub host: Interned<String>,
    pub target: Interned<String>,
    pub compiler: Compiler,
}

impl Step for RustdocUi {
    type Output = ();
    const DEFAULT: bool = true;
    const ONLY_HOSTS: bool = true;

    fn should_run(run: ShouldRun) -> ShouldRun {
        run.path("src/test/rustdoc-ui")
    }

    fn make_run(run: RunConfig) {
        let compiler = run.builder.compiler(run.builder.top_stage, run.host);
        run.builder.ensure(RustdocUi {
            host: run.host,
            target: run.target,
            compiler,
        });
    }

    fn run(self, builder: &Builder) {
        builder.ensure(Compiletest {
            compiler: self.compiler,
            target: self.target,
            mode: "ui",
            suite: "rustdoc-ui",
600
            path: None,
601
            compare_mode: None,
602 603 604 605
        })
    }
}

606
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
M
Mark Simulacrum 已提交
607
pub struct Tidy;
608

609
impl Step for Tidy {
610
    type Output = ();
611 612
    const DEFAULT: bool = true;
    const ONLY_HOSTS: bool = true;
613

M
Mark Simulacrum 已提交
614
    /// Runs the `tidy` tool.
615 616 617 618 619
    ///
    /// This tool in `src/tools` checks up on various bits and pieces of style and
    /// otherwise just implements a few lint-like checks that are specific to the
    /// compiler itself.
    fn run(self, builder: &Builder) {
620
        let mut cmd = builder.tool_cmd(Tool::Tidy);
621 622 623
        cmd.arg(builder.src.join("src"));
        cmd.arg(&builder.initial_cargo);
        if !builder.config.vendor {
624 625
            cmd.arg("--no-vendor");
        }
626
        if builder.config.quiet_tests {
627 628
            cmd.arg("--quiet");
        }
629

630
        let _folder = builder.fold_output(|| "tidy");
631
        builder.info(&format!("tidy check"));
632
        try_run(builder, &mut cmd);
633
    }
634

635 636
    fn should_run(run: ShouldRun) -> ShouldRun {
        run.path("src/tools/tidy")
637 638
    }

639
    fn make_run(run: RunConfig) {
M
Mark Simulacrum 已提交
640
        run.builder.ensure(Tidy);
641
    }
642
}
643

644 645
fn testdir(builder: &Builder, host: Interned<String>) -> PathBuf {
    builder.out.join(host).join("test")
646 647
}

648 649 650 651
macro_rules! default_test {
    ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
        test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
    }
652 653
}

654 655 656 657 658 659 660 661
macro_rules! default_test_with_compare_mode {
    ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
                   compare_mode: $compare_mode:expr }) => {
        test_with_compare_mode!($name { path: $path, mode: $mode, suite: $suite, default: true,
                                        host: false, compare_mode: $compare_mode });
    }
}

662 663 664 665
macro_rules! host_test {
    ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
        test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
    }
666 667
}

668
macro_rules! test {
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684
    ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
                   host: $host:expr }) => {
        test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default,
                                  host: $host, compare_mode: None });
    }
}

macro_rules! test_with_compare_mode {
    ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
                   host: $host:expr, compare_mode: $compare_mode:expr }) => {
        test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default,
                                  host: $host, compare_mode: Some($compare_mode) });
    }
}

macro_rules! test_definitions {
685 686 687 688 689
    ($name:ident {
        path: $path:expr,
        mode: $mode:expr,
        suite: $suite:expr,
        default: $default:expr,
690 691
        host: $host:expr,
        compare_mode: $compare_mode:expr
692 693 694 695 696
    }) => {
        #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
        pub struct $name {
            pub compiler: Compiler,
            pub target: Interned<String>,
697 698
        }

699 700 701 702
        impl Step for $name {
            type Output = ();
            const DEFAULT: bool = $default;
            const ONLY_HOSTS: bool = $host;
703

704
            fn should_run(run: ShouldRun) -> ShouldRun {
705
                run.suite_path($path)
706
            }
707

708 709
            fn make_run(run: RunConfig) {
                let compiler = run.builder.compiler(run.builder.top_stage, run.host);
710

711
                run.builder.ensure($name {
712
                    compiler,
713
                    target: run.target,
714 715
                });
            }
716

717 718 719 720 721 722
            fn run(self, builder: &Builder) {
                builder.ensure(Compiletest {
                    compiler: self.compiler,
                    target: self.target,
                    mode: $mode,
                    suite: $suite,
723
                    path: Some($path),
724
                    compare_mode: $compare_mode,
725 726 727
                })
            }
        }
728 729 730
    }
}

731
default_test_with_compare_mode!(Ui {
732 733
    path: "src/test/ui",
    mode: "ui",
734 735
    suite: "ui",
    compare_mode: "nll"
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877
});

default_test!(RunPass {
    path: "src/test/run-pass",
    mode: "run-pass",
    suite: "run-pass"
});

default_test!(CompileFail {
    path: "src/test/compile-fail",
    mode: "compile-fail",
    suite: "compile-fail"
});

default_test!(ParseFail {
    path: "src/test/parse-fail",
    mode: "parse-fail",
    suite: "parse-fail"
});

default_test!(RunFail {
    path: "src/test/run-fail",
    mode: "run-fail",
    suite: "run-fail"
});

default_test!(RunPassValgrind {
    path: "src/test/run-pass-valgrind",
    mode: "run-pass-valgrind",
    suite: "run-pass-valgrind"
});

default_test!(MirOpt {
    path: "src/test/mir-opt",
    mode: "mir-opt",
    suite: "mir-opt"
});

default_test!(Codegen {
    path: "src/test/codegen",
    mode: "codegen",
    suite: "codegen"
});

default_test!(CodegenUnits {
    path: "src/test/codegen-units",
    mode: "codegen-units",
    suite: "codegen-units"
});

default_test!(Incremental {
    path: "src/test/incremental",
    mode: "incremental",
    suite: "incremental"
});

default_test!(Debuginfo {
    path: "src/test/debuginfo",
    // What this runs varies depending on the native platform being apple
    mode: "debuginfo-XXX",
    suite: "debuginfo"
});

host_test!(UiFullDeps {
    path: "src/test/ui-fulldeps",
    mode: "ui",
    suite: "ui-fulldeps"
});

host_test!(RunPassFullDeps {
    path: "src/test/run-pass-fulldeps",
    mode: "run-pass",
    suite: "run-pass-fulldeps"
});

host_test!(RunFailFullDeps {
    path: "src/test/run-fail-fulldeps",
    mode: "run-fail",
    suite: "run-fail-fulldeps"
});

host_test!(CompileFailFullDeps {
    path: "src/test/compile-fail-fulldeps",
    mode: "compile-fail",
    suite: "compile-fail-fulldeps"
});

host_test!(IncrementalFullDeps {
    path: "src/test/incremental-fulldeps",
    mode: "incremental",
    suite: "incremental-fulldeps"
});

host_test!(Rustdoc {
    path: "src/test/rustdoc",
    mode: "rustdoc",
    suite: "rustdoc"
});

test!(Pretty {
    path: "src/test/pretty",
    mode: "pretty",
    suite: "pretty",
    default: false,
    host: true
});
test!(RunPassPretty {
    path: "src/test/run-pass/pretty",
    mode: "pretty",
    suite: "run-pass",
    default: false,
    host: true
});
test!(RunFailPretty {
    path: "src/test/run-fail/pretty",
    mode: "pretty",
    suite: "run-fail",
    default: false,
    host: true
});
test!(RunPassValgrindPretty {
    path: "src/test/run-pass-valgrind/pretty",
    mode: "pretty",
    suite: "run-pass-valgrind",
    default: false,
    host: true
});
test!(RunPassFullDepsPretty {
    path: "src/test/run-pass-fulldeps/pretty",
    mode: "pretty",
    suite: "run-pass-fulldeps",
    default: false,
    host: true
});
test!(RunFailFullDepsPretty {
    path: "src/test/run-fail-fulldeps/pretty",
    mode: "pretty",
    suite: "run-fail-fulldeps",
    default: false,
    host: true
});

E
Eric Huss 已提交
878
default_test!(RunMake {
879 880 881 882 883
    path: "src/test/run-make",
    mode: "run-make",
    suite: "run-make"
});

884 885 886 887 888 889
host_test!(RunMakeFullDeps {
    path: "src/test/run-make-fulldeps",
    mode: "run-make",
    suite: "run-make-fulldeps"
});

890 891 892 893 894 895
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
struct Compiletest {
    compiler: Compiler,
    target: Interned<String>,
    mode: &'static str,
    suite: &'static str,
896
    path: Option<&'static str>,
897
    compare_mode: Option<&'static str>,
898 899 900 901 902 903 904 905 906
}

impl Step for Compiletest {
    type Output = ();

    fn should_run(run: ShouldRun) -> ShouldRun {
        run.never()
    }

907 908 909 910 911 912 913 914 915 916
    /// Executes the `compiletest` tool to run a suite of tests.
    ///
    /// Compiles all tests with `compiler` for `target` with the specified
    /// compiletest `mode` and `suite` arguments. For example `mode` can be
    /// "run-pass" or `suite` can be something like `debuginfo`.
    fn run(self, builder: &Builder) {
        let compiler = self.compiler;
        let target = self.target;
        let mode = self.mode;
        let suite = self.suite;
917

918 919 920
        // Path for test suite
        let suite_path = self.path.unwrap_or("");

921
        // Skip codegen tests if they aren't enabled in configuration.
922
        if !builder.config.codegen_tests && suite == "codegen" {
923 924 925 926
            return;
        }

        if suite == "debuginfo" {
927
            // Skip debuginfo tests on MSVC
928
            if builder.config.build.contains("msvc") {
929 930 931
                return;
            }

932
            if mode == "debuginfo-XXX" {
933
                return if builder.config.build.contains("apple") {
934 935 936
                    builder.ensure(Compiletest {
                        mode: "debuginfo-lldb",
                        ..self
937
                    });
938 939 940 941
                } else {
                    builder.ensure(Compiletest {
                        mode: "debuginfo-gdb",
                        ..self
942
                    });
943 944 945 946
                };
            }

            builder.ensure(dist::DebuggerScripts {
947
                sysroot: builder.sysroot(compiler),
S
Santiago Pastorino 已提交
948
                host: target,
949 950 951 952 953 954 955
            });
        }

        if suite.ends_with("fulldeps") ||
            // FIXME: Does pretty need librustc compiled? Note that there are
            // fulldeps test suites with mode = pretty as well.
            mode == "pretty" ||
S
Santiago Pastorino 已提交
956 957
            mode == "rustdoc"
        {
958 959 960 961 962
            builder.ensure(compile::Rustc { compiler, target });
        }

        builder.ensure(compile::Test { compiler, target });
        builder.ensure(native::TestHelpers { target });
963
        builder.ensure(RemoteCopyLibs { compiler, target });
964 965

        let mut cmd = builder.tool_cmd(Tool::Compiletest);
966 967 968 969

        // compiletest currently has... a lot of arguments, so let's just pass all
        // of them!

S
Santiago Pastorino 已提交
970 971 972 973
        cmd.arg("--compile-lib-path")
            .arg(builder.rustc_libdir(compiler));
        cmd.arg("--run-lib-path")
            .arg(builder.sysroot_libdir(compiler, target));
974
        cmd.arg("--rustc-path").arg(builder.rustc(compiler));
975

G
Guillaume Gomez 已提交
976 977
        let is_rustdoc_ui = suite.ends_with("rustdoc-ui");

978
        // Avoid depending on rustdoc when we don't need it.
S
Santiago Pastorino 已提交
979 980 981 982 983 984
        if mode == "rustdoc"
            || (mode == "run-make" && suite.ends_with("fulldeps"))
            || (mode == "ui" && is_rustdoc_ui)
        {
            cmd.arg("--rustdoc-path")
                .arg(builder.rustdoc(compiler.host));
985 986
        }

S
Santiago Pastorino 已提交
987 988 989 990 991 992
        cmd.arg("--src-base")
            .arg(builder.src.join("src/test").join(suite));
        cmd.arg("--build-base")
            .arg(testdir(builder, compiler.host).join(suite));
        cmd.arg("--stage-id")
            .arg(format!("stage{}-{}", compiler.stage, target));
993 994
        cmd.arg("--mode").arg(mode);
        cmd.arg("--target").arg(target);
995
        cmd.arg("--host").arg(&*compiler.host);
S
Santiago Pastorino 已提交
996 997
        cmd.arg("--llvm-filecheck")
            .arg(builder.llvm_filecheck(builder.config.build));
998

999
        if builder.config.cmd.bless() {
1000 1001 1002
            cmd.arg("--bless");
        }

S
Santiago Pastorino 已提交
1003 1004
        let compare_mode = builder.config.cmd.compare_mode().or(self.compare_mode);

1005
        if let Some(ref nodejs) = builder.config.nodejs {
1006 1007
            cmd.arg("--nodejs").arg(nodejs);
        }
1008

G
Guillaume Gomez 已提交
1009 1010 1011 1012 1013 1014
        let mut flags = if is_rustdoc_ui {
            Vec::new()
        } else {
            vec!["-Crpath".to_string()]
        };
        if !is_rustdoc_ui {
1015
            if builder.config.rust_optimize_tests {
G
Guillaume Gomez 已提交
1016 1017
                flags.push("-O".to_string());
            }
1018
            if builder.config.rust_debuginfo_tests {
G
Guillaume Gomez 已提交
1019 1020
                flags.push("-g".to_string());
            }
1021
        }
G
Guillaume Gomez 已提交
1022
        flags.push("-Zunstable-options".to_string());
1023
        flags.push(builder.config.cmd.rustc_args().join(" "));
1024

1025
        if let Some(linker) = builder.linker(target) {
O
Oliver Schneider 已提交
1026 1027 1028 1029
            cmd.arg("--linker").arg(linker);
        }

        let hostflags = flags.clone();
1030 1031
        cmd.arg("--host-rustcflags").arg(hostflags.join(" "));

O
Oliver Schneider 已提交
1032
        let mut targetflags = flags.clone();
S
Santiago Pastorino 已提交
1033 1034 1035 1036
        targetflags.push(format!(
            "-Lnative={}",
            builder.test_helpers_out(target).display()
        ));
1037 1038
        cmd.arg("--target-rustcflags").arg(targetflags.join(" "));

1039
        cmd.arg("--docck-python").arg(builder.python());
1040

1041
        if builder.config.build.ends_with("apple-darwin") {
1042 1043 1044 1045 1046
            // Force /usr/bin/python on macOS for LLDB tests because we're loading the
            // LLDB plugin's compiled module which only works with the system python
            // (namely not Homebrew-installed python)
            cmd.arg("--lldb-python").arg("/usr/bin/python");
        } else {
1047
            cmd.arg("--lldb-python").arg(builder.python());
1048
        }
1049

1050
        if let Some(ref gdb) = builder.config.gdb {
1051 1052
            cmd.arg("--gdb").arg(gdb);
        }
1053
        if let Some(ref vers) = builder.lldb_version {
1054 1055
            cmd.arg("--lldb-version").arg(vers);
        }
1056
        if let Some(ref dir) = builder.lldb_python_dir {
1057 1058
            cmd.arg("--lldb-python-dir").arg(dir);
        }
1059

1060 1061
        // Get paths from cmd args
        let paths = match &builder.config.cmd {
S
Santiago Pastorino 已提交
1062 1063
            Subcommand::Test { ref paths, .. } => &paths[..],
            _ => &[],
1064 1065 1066
        };

        // Get test-args by striping suite path
S
Santiago Pastorino 已提交
1067 1068 1069 1070 1071
        let mut test_args: Vec<&str> = paths
            .iter()
            .filter(|p| p.starts_with(suite_path) && p.is_file())
            .map(|p| p.strip_prefix(suite_path).unwrap().to_str().unwrap())
            .collect();
1072 1073 1074 1075

        test_args.append(&mut builder.config.cmd.test_args());

        cmd.args(&test_args);
1076

1077
        if builder.is_verbose() {
1078 1079
            cmd.arg("--verbose");
        }
1080

1081
        if builder.config.quiet_tests {
1082 1083
            cmd.arg("--quiet");
        }
1084

1085
        if builder.config.llvm_enabled {
1086
            let llvm_config = builder.ensure(native::Llvm {
1087
                target: builder.config.build,
1088 1089
                emscripten: false,
            });
1090
            if !builder.config.dry_run {
1091 1092 1093
                let llvm_version = output(Command::new(&llvm_config).arg("--version"));
                cmd.arg("--llvm-version").arg(llvm_version);
            }
1094
            if !builder.is_rust_llvm(target) {
B
bjorn3 已提交
1095 1096 1097 1098 1099
                cmd.arg("--system-llvm");
            }

            // Only pass correct values for these flags for the `run-make` suite as it
            // requires that a C++ compiler was configured which isn't always the case.
E
Eric Huss 已提交
1100
            if !builder.config.dry_run && suite == "run-make-fulldeps" {
B
bjorn3 已提交
1101 1102
                let llvm_components = output(Command::new(&llvm_config).arg("--components"));
                let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
S
Santiago Pastorino 已提交
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
                cmd.arg("--cc")
                    .arg(builder.cc(target))
                    .arg("--cxx")
                    .arg(builder.cxx(target).unwrap())
                    .arg("--cflags")
                    .arg(builder.cflags(target).join(" "))
                    .arg("--llvm-components")
                    .arg(llvm_components.trim())
                    .arg("--llvm-cxxflags")
                    .arg(llvm_cxxflags.trim());
1113
                if let Some(ar) = builder.ar(target) {
O
Oliver Schneider 已提交
1114 1115
                    cmd.arg("--ar").arg(ar);
                }
B
bjorn3 已提交
1116 1117
            }
        }
E
Eric Huss 已提交
1118
        if suite == "run-make-fulldeps" && !builder.config.llvm_enabled {
S
Santiago Pastorino 已提交
1119 1120 1121
            builder.info(&format!(
                "Ignoring run-make test suite as they generally don't work without LLVM"
            ));
B
bjorn3 已提交
1122 1123 1124
            return;
        }

E
Eric Huss 已提交
1125
        if suite != "run-make-fulldeps" {
S
Santiago Pastorino 已提交
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
            cmd.arg("--cc")
                .arg("")
                .arg("--cxx")
                .arg("")
                .arg("--cflags")
                .arg("")
                .arg("--llvm-components")
                .arg("")
                .arg("--llvm-cxxflags")
                .arg("");
1136
        }
1137

1138
        if builder.remote_tested(target) {
S
Santiago Pastorino 已提交
1139 1140
            cmd.arg("--remote-test-client")
                .arg(builder.tool_exe(Tool::RemoteTestClient));
1141
        }
1142

1143 1144 1145 1146 1147 1148
        // Running a C compiler on MSVC requires a few env vars to be set, to be
        // sure to set them here.
        //
        // Note that if we encounter `PATH` we make sure to append to our own `PATH`
        // rather than stomp over it.
        if target.contains("msvc") {
1149
            for &(ref k, ref v) in builder.cc[&target].env() {
1150 1151 1152
                if k != "PATH" {
                    cmd.env(k, v);
                }
1153 1154
            }
        }
1155
        cmd.env("RUSTC_BOOTSTRAP", "1");
1156
        builder.add_rust_test_threads(&mut cmd);
1157

1158
        if builder.config.sanitizers {
1159 1160
            cmd.env("SANITIZER_SUPPORT", "1");
        }
1161

1162
        if builder.config.profiler {
1163 1164
            cmd.env("PROFILER_SUPPORT", "1");
        }
1165

1166
        cmd.env("RUST_TEST_TMPDIR", builder.out.join("tmp"));
1167

1168 1169 1170 1171 1172
        cmd.arg("--adb-path").arg("adb");
        cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
        if target.contains("android") {
            // Assume that cc for this target comes from the android sysroot
            cmd.arg("--android-cross-path")
S
Santiago Pastorino 已提交
1173
                .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1174 1175 1176
        } else {
            cmd.arg("--android-cross-path").arg("");
        }
1177

1178
        builder.ci_env.force_coloring_in_ci(&mut cmd);
1179

1180
        let _folder = builder.fold_output(|| format!("test_{}", suite));
S
Santiago Pastorino 已提交
1181 1182 1183 1184
        builder.info(&format!(
            "Check compiletest suite={} mode={} ({} -> {})",
            suite, mode, &compiler.host, target
        ));
1185 1186
        let _time = util::timeit(&builder);
        try_run(builder, &mut cmd);
1187 1188 1189 1190

        if let Some(compare_mode) = compare_mode {
            cmd.arg("--compare-mode").arg(compare_mode);
            let _folder = builder.fold_output(|| format!("test_{}_{}", suite, compare_mode));
S
Santiago Pastorino 已提交
1191 1192 1193 1194
            builder.info(&format!(
                "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
                suite, mode, compare_mode, &compiler.host, target
            ));
1195 1196 1197
            let _time = util::timeit(&builder);
            try_run(builder, &mut cmd);
        }
1198
    }
1199
}
1200

1201
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1202
struct DocTest {
1203
    compiler: Compiler,
1204 1205 1206
    path: &'static str,
    name: &'static str,
    is_ext_doc: bool,
1207 1208
}

1209
impl Step for DocTest {
1210 1211
    type Output = ();
    const ONLY_HOSTS: bool = true;
1212

1213
    fn should_run(run: ShouldRun) -> ShouldRun {
1214
        run.never()
1215
    }
M
Mark Simulacrum 已提交
1216

1217 1218 1219 1220 1221 1222 1223
    /// Run `rustdoc --test` for all documentation in `src/doc`.
    ///
    /// This will run all tests in our markdown documentation (e.g. the book)
    /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
    /// `compiler`.
    fn run(self, builder: &Builder) {
        let compiler = self.compiler;
1224

S
Santiago Pastorino 已提交
1225 1226 1227 1228
        builder.ensure(compile::Test {
            compiler,
            target: compiler.host,
        });
1229

1230 1231
        // Do a breadth-first traversal of the `src/doc` directory and just run
        // tests for all files that end in `*.md`
1232 1233 1234
        let mut stack = vec![builder.src.join(self.path)];
        let _time = util::timeit(&builder);
        let _folder = builder.fold_output(|| format!("test_{}", self.name));
1235

1236
        let mut files = Vec::new();
1237 1238 1239
        while let Some(p) = stack.pop() {
            if p.is_dir() {
                stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
S
Santiago Pastorino 已提交
1240
                continue;
1241 1242 1243 1244 1245 1246 1247
            }

            if p.extension().and_then(|s| s.to_str()) != Some("md") {
                continue;
            }

            // The nostarch directory in the book is for no starch, and so isn't
1248
            // guaranteed to builder. We don't care if it doesn't build, so skip it.
1249 1250 1251 1252
            if p.to_str().map_or(false, |p| p.contains("nostarch")) {
                continue;
            }

1253 1254 1255 1256 1257 1258 1259
            files.push(p);
        }

        files.sort();

        for file in files {
            let test_result = markdown_test(builder, compiler, &file);
1260 1261 1262 1263 1264 1265
            if self.is_ext_doc {
                let toolstate = if test_result {
                    ToolState::TestPass
                } else {
                    ToolState::TestFail
                };
1266
                builder.save_toolstate(self.name, toolstate);
1267
            }
1268
        }
1269 1270 1271
    }
}

1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311
macro_rules! test_book {
    ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
        $(
            #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
            pub struct $name {
                compiler: Compiler,
            }

            impl Step for $name {
                type Output = ();
                const DEFAULT: bool = $default;
                const ONLY_HOSTS: bool = true;

                fn should_run(run: ShouldRun) -> ShouldRun {
                    run.path($path)
                }

                fn make_run(run: RunConfig) {
                    run.builder.ensure($name {
                        compiler: run.builder.compiler(run.builder.top_stage, run.host),
                    });
                }

                fn run(self, builder: &Builder) {
                    builder.ensure(DocTest {
                        compiler: self.compiler,
                        path: $path,
                        name: $book_name,
                        is_ext_doc: !$default,
                    });
                }
            }
        )+
    }
}

test_book!(
    Nomicon, "src/doc/nomicon", "nomicon", default=false;
    Reference, "src/doc/reference", "reference", default=false;
    RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1312
    RustcBook, "src/doc/rustc", "rustc", default=true;
1313 1314 1315 1316 1317
    RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
    TheBook, "src/doc/book", "book", default=false;
    UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
);

1318 1319 1320
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct ErrorIndex {
    compiler: Compiler,
1321
}
1322

1323
impl Step for ErrorIndex {
1324
    type Output = ();
1325 1326 1327
    const DEFAULT: bool = true;
    const ONLY_HOSTS: bool = true;

1328 1329
    fn should_run(run: ShouldRun) -> ShouldRun {
        run.path("src/tools/error_index_generator")
1330 1331
    }

1332 1333 1334
    fn make_run(run: RunConfig) {
        run.builder.ensure(ErrorIndex {
            compiler: run.builder.compiler(run.builder.top_stage, run.host),
1335 1336
        });
    }
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346

    /// Run the error index generator tool to execute the tests located in the error
    /// index.
    ///
    /// The `error_index_generator` tool lives in `src/tools` and is used to
    /// generate a markdown file from the error indexes of the code base which is
    /// then passed to `rustdoc --test`.
    fn run(self, builder: &Builder) {
        let compiler = self.compiler;

S
Santiago Pastorino 已提交
1347 1348 1349 1350
        builder.ensure(compile::Std {
            compiler,
            target: compiler.host,
        });
1351

1352
        let dir = testdir(builder, compiler.host);
1353 1354 1355
        t!(fs::create_dir_all(&dir));
        let output = dir.join("error-index.md");

1356 1357 1358
        let mut tool = builder.tool_cmd(Tool::ErrorIndex);
        tool.arg("markdown")
            .arg(&output)
1359 1360
            .env("CFG_BUILD", &builder.config.build)
            .env("RUSTC_ERROR_METADATA_DST", builder.extended_error_dir());
1361

1362 1363 1364 1365
        let _folder = builder.fold_output(|| "test_error_index");
        builder.info(&format!("Testing error-index stage{}", compiler.stage));
        let _time = util::timeit(&builder);
        builder.run(&mut tool);
1366
        markdown_test(builder, compiler, &output);
1367
    }
1368 1369
}

1370
fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) -> bool {
1371 1372 1373 1374 1375 1376 1377 1378
    match File::open(markdown) {
        Ok(mut file) => {
            let mut contents = String::new();
            t!(file.read_to_string(&mut contents));
            if !contents.contains("```") {
                return true;
            }
        }
S
Santiago Pastorino 已提交
1379
        Err(_) => {}
1380 1381
    }

1382
    builder.info(&format!("doc tests for: {}", markdown.display()));
1383
    let mut cmd = builder.rustdoc_cmd(compiler.host);
1384
    builder.add_rust_test_threads(&mut cmd);
1385 1386
    cmd.arg("--test");
    cmd.arg(markdown);
1387
    cmd.env("RUSTC_BOOTSTRAP", "1");
1388

1389
    let test_args = builder.config.cmd.test_args().join(" ");
1390 1391
    cmd.arg("--test-args").arg(test_args);

1392 1393
    if builder.config.quiet_tests {
        try_run_quiet(builder, &mut cmd)
1394
    } else {
1395
        try_run(builder, &mut cmd)
1396
    }
1397
}
1398

1399
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
M
Mark Simulacrum 已提交
1400
pub struct CrateLibrustc {
1401 1402
    compiler: Compiler,
    target: Interned<String>,
1403
    test_kind: TestKind,
1404
    krate: Interned<String>,
1405 1406
}

M
Mark Simulacrum 已提交
1407
impl Step for CrateLibrustc {
1408 1409 1410 1411
    type Output = ();
    const DEFAULT: bool = true;
    const ONLY_HOSTS: bool = true;

1412 1413
    fn should_run(run: ShouldRun) -> ShouldRun {
        run.krate("rustc-main")
1414 1415
    }

1416 1417 1418
    fn make_run(run: RunConfig) {
        let builder = run.builder;
        let compiler = builder.compiler(builder.top_stage, run.host);
1419

1420 1421
        for krate in builder.in_tree_crates("rustc-main") {
            if run.path.ends_with(&krate.path) {
1422
                let test_kind = builder.kind.into();
1423

1424 1425 1426 1427 1428 1429
                builder.ensure(CrateLibrustc {
                    compiler,
                    target: run.target,
                    test_kind,
                    krate: krate.name,
                });
1430 1431 1432 1433 1434
            }
        }
    }

    fn run(self, builder: &Builder) {
M
Mark Simulacrum 已提交
1435
        builder.ensure(Crate {
1436 1437 1438 1439 1440 1441 1442 1443 1444
            compiler: self.compiler,
            target: self.target,
            mode: Mode::Librustc,
            test_kind: self.test_kind,
            krate: self.krate,
        });
    }
}

1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct CrateNotDefault {
    compiler: Compiler,
    target: Interned<String>,
    test_kind: TestKind,
    krate: &'static str,
}

impl Step for CrateNotDefault {
    type Output = ();

    fn should_run(run: ShouldRun) -> ShouldRun {
        run.path("src/liballoc_jemalloc")
            .path("src/librustc_asan")
            .path("src/librustc_lsan")
            .path("src/librustc_msan")
            .path("src/librustc_tsan")
    }

    fn make_run(run: RunConfig) {
        let builder = run.builder;
        let compiler = builder.compiler(builder.top_stage, run.host);

1468
        let test_kind = builder.kind.into();
1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495

        builder.ensure(CrateNotDefault {
            compiler,
            target: run.target,
            test_kind,
            krate: match run.path {
                _ if run.path.ends_with("src/liballoc_jemalloc") => "alloc_jemalloc",
                _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
                _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
                _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
                _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
                _ => panic!("unexpected path {:?}", run.path),
            },
        });
    }

    fn run(self, builder: &Builder) {
        builder.ensure(Crate {
            compiler: self.compiler,
            target: self.target,
            mode: Mode::Libstd,
            test_kind: self.test_kind,
            krate: INTERNER.intern_str(self.krate),
        });
    }
}

K
kennytm 已提交
1496
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
M
Mark Simulacrum 已提交
1497
pub struct Crate {
K
kennytm 已提交
1498 1499 1500 1501 1502
    pub compiler: Compiler,
    pub target: Interned<String>,
    pub mode: Mode,
    pub test_kind: TestKind,
    pub krate: Interned<String>,
1503
}
1504

M
Mark Simulacrum 已提交
1505
impl Step for Crate {
1506
    type Output = ();
1507 1508
    const DEFAULT: bool = true;

1509 1510 1511 1512
    fn should_run(mut run: ShouldRun) -> ShouldRun {
        let builder = run.builder;
        run = run.krate("test");
        for krate in run.builder.in_tree_crates("std") {
S
Santiago Pastorino 已提交
1513 1514 1515 1516 1517
            if krate.is_local(&run.builder)
                && !krate.name.contains("jemalloc")
                && !(krate.name.starts_with("rustc_") && krate.name.ends_with("san"))
                && krate.name != "dlmalloc"
            {
1518 1519 1520 1521
                run = run.path(krate.local_path(&builder).to_str().unwrap());
            }
        }
        run
1522 1523
    }

1524 1525 1526
    fn make_run(run: RunConfig) {
        let builder = run.builder;
        let compiler = builder.compiler(builder.top_stage, run.host);
1527

1528
        let make = |mode: Mode, krate: &CargoCrate| {
1529
            let test_kind = builder.kind.into();
1530

M
Mark Simulacrum 已提交
1531
            builder.ensure(Crate {
1532 1533
                compiler,
                target: run.target,
1534 1535
                mode,
                test_kind,
1536
                krate: krate.name,
1537 1538 1539
            });
        };

1540 1541 1542
        for krate in builder.in_tree_crates("std") {
            if run.path.ends_with(&krate.local_path(&builder)) {
                make(Mode::Libstd, krate);
1543
            }
1544 1545 1546 1547
        }
        for krate in builder.in_tree_crates("test") {
            if run.path.ends_with(&krate.local_path(&builder)) {
                make(Mode::Libtest, krate);
1548 1549 1550
            }
        }
    }
1551

1552 1553
    /// Run all unit tests plus documentation tests for a given crate defined
    /// by a `Cargo.toml` (single manifest)
1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566
    ///
    /// This is what runs tests for crates like the standard library, compiler, etc.
    /// It essentially is the driver for running `cargo test`.
    ///
    /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
    /// arguments, and those arguments are discovered from `cargo metadata`.
    fn run(self, builder: &Builder) {
        let compiler = self.compiler;
        let target = self.target;
        let mode = self.mode;
        let test_kind = self.test_kind;
        let krate = self.krate;

1567 1568
        builder.ensure(compile::Test { compiler, target });
        builder.ensure(RemoteCopyLibs { compiler, target });
A
Alex Crichton 已提交
1569 1570 1571 1572 1573

        // If we're not doing a full bootstrap but we're testing a stage2 version of
        // libstd, then what we're actually testing is the libstd produced in
        // stage1. Reflect that here by updating the compiler that we're working
        // with automatically.
1574
        let compiler = if builder.force_use_stage1(compiler, target) {
A
Alex Crichton 已提交
1575 1576 1577 1578 1579 1580
            builder.compiler(1, compiler.host)
        } else {
            compiler.clone()
        };

        let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
1581
        match mode {
1582
            Mode::Libstd => {
1583
                compile::std_cargo(builder, &compiler, target, &mut cargo);
1584 1585
            }
            Mode::Libtest => {
1586
                compile::test_cargo(builder, &compiler, target, &mut cargo);
1587 1588
            }
            Mode::Librustc => {
1589
                builder.ensure(compile::Rustc { compiler, target });
1590
                compile::rustc_cargo(builder, &mut cargo);
1591 1592 1593 1594 1595 1596 1597 1598 1599
            }
            _ => panic!("can only test libraries"),
        };

        // Build up the base `cargo test` command.
        //
        // Pass in some standard flags then iterate over the graph we've discovered
        // in `cargo metadata` with the maps above and figure out what `-p`
        // arguments need to get passed.
1600
        if test_kind.subcommand() == "test" && !builder.fail_fast {
1601 1602
            cargo.arg("--no-fail-fast");
        }
K
kennytm 已提交
1603
        match builder.doc_tests {
K
kennytm 已提交
1604
            DocTests::Only => {
K
kennytm 已提交
1605 1606
                cargo.arg("--doc");
            }
K
kennytm 已提交
1607
            DocTests::No => {
K
kennytm 已提交
1608 1609
                cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
            }
K
kennytm 已提交
1610
            DocTests::Yes => {}
1611
        }
1612

1613
        cargo.arg("-p").arg(krate);
1614

1615 1616 1617 1618 1619 1620
        // The tests are going to run with the *target* libraries, so we need to
        // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
        //
        // Note that to run the compiler we need to run with the *host* libraries,
        // but our wrapper scripts arrange for that to be the case anyway.
        let mut dylib_path = dylib_path();
1621
        dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1622 1623 1624
        cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());

        cargo.arg("--");
1625
        cargo.args(&builder.config.cmd.test_args());
1626

1627
        if builder.config.quiet_tests {
1628 1629
            cargo.arg("--quiet");
        }
1630

1631
        if target.contains("emscripten") {
S
Santiago Pastorino 已提交
1632 1633 1634 1635 1636 1637 1638 1639
            cargo.env(
                format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
                builder
                    .config
                    .nodejs
                    .as_ref()
                    .expect("nodejs not configured"),
            );
O
Oliver Schneider 已提交
1640
        } else if target.starts_with("wasm32") {
1641 1642 1643
            // Warn about running tests without the `wasm_syscall` feature enabled.
            // The javascript shim implements the syscall interface so that test
            // output can be correctly reported.
1644
            if !builder.config.wasm_syscall {
S
Santiago Pastorino 已提交
1645 1646 1647 1648
                builder.info(&format!(
                    "Libstd was built without `wasm_syscall` feature enabled: \
                     test output may not be visible."
                ));
1649 1650
            }

O
Oliver Schneider 已提交
1651 1652 1653 1654
            // On the wasm32-unknown-unknown target we're using LTO which is
            // incompatible with `-C prefer-dynamic`, so disable that here
            cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");

S
Santiago Pastorino 已提交
1655 1656 1657 1658
            let node = builder
                .config
                .nodejs
                .as_ref()
O
Oliver Schneider 已提交
1659
                .expect("nodejs not configured");
S
Santiago Pastorino 已提交
1660 1661 1662 1663 1664
            let runner = format!(
                "{} {}/src/etc/wasm32-shim.js",
                node.display(),
                builder.src.display()
            );
O
Oliver Schneider 已提交
1665
            cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
1666
        } else if builder.remote_tested(target) {
S
Santiago Pastorino 已提交
1667 1668 1669 1670
            cargo.env(
                format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
                format!("{} run", builder.tool_exe(Tool::RemoteTestClient).display()),
            );
1671
        }
1672

1673
        let _folder = builder.fold_output(|| {
S
Santiago Pastorino 已提交
1674 1675 1676 1677 1678 1679
            format!(
                "{}_stage{}-{}",
                test_kind.subcommand(),
                compiler.stage,
                krate
            )
1680
        });
S
Santiago Pastorino 已提交
1681 1682 1683 1684
        builder.info(&format!(
            "{} {} stage{} ({} -> {})",
            test_kind, krate, compiler.stage, &compiler.host, target
        ));
1685 1686
        let _time = util::timeit(&builder);
        try_run(builder, &mut cargo);
1687 1688
    }
}
1689

M
Mark Simulacrum 已提交
1690
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1691
pub struct CrateRustdoc {
M
Mark Simulacrum 已提交
1692 1693 1694 1695
    host: Interned<String>,
    test_kind: TestKind,
}

1696
impl Step for CrateRustdoc {
M
Mark Simulacrum 已提交
1697 1698 1699 1700 1701
    type Output = ();
    const DEFAULT: bool = true;
    const ONLY_HOSTS: bool = true;

    fn should_run(run: ShouldRun) -> ShouldRun {
1702
        run.paths(&["src/librustdoc", "src/tools/rustdoc"])
M
Mark Simulacrum 已提交
1703 1704 1705 1706 1707
    }

    fn make_run(run: RunConfig) {
        let builder = run.builder;

1708
        let test_kind = builder.kind.into();
M
Mark Simulacrum 已提交
1709

1710
        builder.ensure(CrateRustdoc {
M
Mark Simulacrum 已提交
1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721
            host: run.host,
            test_kind,
        });
    }

    fn run(self, builder: &Builder) {
        let test_kind = self.test_kind;

        let compiler = builder.compiler(builder.top_stage, self.host);
        let target = compiler.host;

S
Santiago Pastorino 已提交
1722 1723 1724 1725 1726 1727 1728
        let mut cargo = tool::prepare_tool_cargo(
            builder,
            compiler,
            target,
            test_kind.subcommand(),
            "src/tools/rustdoc",
        );
1729
        if test_kind.subcommand() == "test" && !builder.fail_fast {
M
Mark Simulacrum 已提交
1730 1731 1732 1733 1734 1735
            cargo.arg("--no-fail-fast");
        }

        cargo.arg("-p").arg("rustdoc:0.0.0");

        cargo.arg("--");
1736
        cargo.args(&builder.config.cmd.test_args());
M
Mark Simulacrum 已提交
1737

1738
        if builder.config.quiet_tests {
M
Mark Simulacrum 已提交
1739 1740 1741
            cargo.arg("--quiet");
        }

S
Santiago Pastorino 已提交
1742 1743 1744 1745 1746 1747
        let _folder = builder
            .fold_output(|| format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage));
        builder.info(&format!(
            "{} rustdoc stage{} ({} -> {})",
            test_kind, compiler.stage, &compiler.host, target
        ));
1748
        let _time = util::timeit(&builder);
M
Mark Simulacrum 已提交
1749

1750
        try_run(builder, &mut cargo);
M
Mark Simulacrum 已提交
1751 1752 1753
    }
}

1754
fn envify(s: &str) -> String {
S
Santiago Pastorino 已提交
1755 1756
    s.chars()
        .map(|c| match c {
1757 1758
            '-' => '_',
            c => c,
S
Santiago Pastorino 已提交
1759 1760 1761
        })
        .flat_map(|c| c.to_uppercase())
        .collect()
1762 1763
}

1764 1765 1766 1767 1768 1769 1770 1771 1772
/// Some test suites are run inside emulators or on remote devices, and most
/// of our test binaries are linked dynamically which means we need to ship
/// the standard library and such to the emulator ahead of time. This step
/// represents this and is a dependency of all test suites.
///
/// Most of the time this is a noop. For some steps such as shipping data to
/// QEMU we have to build our own tools so we've got conditional dependencies
/// on those programs as well. Note that the remote test client is built for
/// the build target (us) and the server is built for the target.
1773 1774 1775 1776
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct RemoteCopyLibs {
    compiler: Compiler,
    target: Interned<String>,
1777
}
1778

1779
impl Step for RemoteCopyLibs {
1780
    type Output = ();
1781

1782 1783
    fn should_run(run: ShouldRun) -> ShouldRun {
        run.never()
1784 1785
    }

1786 1787 1788
    fn run(self, builder: &Builder) {
        let compiler = self.compiler;
        let target = self.target;
1789
        if !builder.remote_tested(target) {
S
Santiago Pastorino 已提交
1790
            return;
1791 1792
        }

1793 1794
        builder.ensure(compile::Test { compiler, target });

1795 1796
        builder.info(&format!("REMOTE copy libs to emulator ({})", target));
        t!(fs::create_dir_all(builder.out.join("tmp")));
1797

1798
        let server = builder.ensure(tool::RemoteTestServer { compiler, target });
1799 1800

        // Spawn the emulator and wait for it to come online
1801
        let tool = builder.tool_exe(Tool::RemoteTestClient);
1802 1803
        let mut cmd = Command::new(&tool);
        cmd.arg("spawn-emulator")
S
Santiago Pastorino 已提交
1804 1805 1806
            .arg(target)
            .arg(&server)
            .arg(builder.out.join("tmp"));
1807
        if let Some(rootfs) = builder.qemu_rootfs(target) {
1808 1809
            cmd.arg(rootfs);
        }
1810
        builder.run(&mut cmd);
1811 1812

        // Push all our dylibs to the emulator
1813
        for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1814 1815 1816
            let f = t!(f);
            let name = f.file_name().into_string().unwrap();
            if util::is_dylib(&name) {
S
Santiago Pastorino 已提交
1817
                builder.run(Command::new(&tool).arg("push").arg(f.path()));
1818
            }
1819 1820 1821 1822
        }
    }
}

1823
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1824
pub struct Distcheck;
A
Alex Crichton 已提交
1825

1826
impl Step for Distcheck {
1827 1828
    type Output = ();

1829 1830
    fn should_run(run: ShouldRun) -> ShouldRun {
        run.path("distcheck")
1831 1832
    }

M
Mark Simulacrum 已提交
1833 1834 1835 1836
    fn make_run(run: RunConfig) {
        run.builder.ensure(Distcheck);
    }

1837 1838
    /// Run "distcheck", a 'make check' from a tarball
    fn run(self, builder: &Builder) {
1839 1840
        builder.info(&format!("Distcheck"));
        let dir = builder.out.join("tmp").join("distcheck");
1841 1842 1843
        let _ = fs::remove_dir_all(&dir);
        t!(fs::create_dir_all(&dir));

M
Mark Simulacrum 已提交
1844 1845 1846 1847
        // Guarantee that these are built before we begin running.
        builder.ensure(dist::PlainSourceTarball);
        builder.ensure(dist::Src);

1848 1849
        let mut cmd = Command::new("tar");
        cmd.arg("-xzf")
S
Santiago Pastorino 已提交
1850 1851 1852
            .arg(builder.ensure(dist::PlainSourceTarball))
            .arg("--strip-components=1")
            .current_dir(&dir);
1853
        builder.run(&mut cmd);
S
Santiago Pastorino 已提交
1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864
        builder.run(
            Command::new("./configure")
                .args(&builder.config.configure_args)
                .arg("--enable-vendor")
                .current_dir(&dir),
        );
        builder.run(
            Command::new(build_helper::make(&builder.config.build))
                .arg("check")
                .current_dir(&dir),
        );
1865 1866

        // Now make sure that rust-src has all of libstd's dependencies
1867 1868
        builder.info(&format!("Distcheck rust-src"));
        let dir = builder.out.join("tmp").join("distcheck-src");
1869 1870 1871 1872 1873
        let _ = fs::remove_dir_all(&dir);
        t!(fs::create_dir_all(&dir));

        let mut cmd = Command::new("tar");
        cmd.arg("-xzf")
S
Santiago Pastorino 已提交
1874 1875 1876
            .arg(builder.ensure(dist::Src))
            .arg("--strip-components=1")
            .current_dir(&dir);
1877
        builder.run(&mut cmd);
1878 1879

        let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
S
Santiago Pastorino 已提交
1880 1881 1882 1883 1884 1885 1886
        builder.run(
            Command::new(&builder.initial_cargo)
                .arg("generate-lockfile")
                .arg("--manifest-path")
                .arg(&toml)
                .current_dir(&dir),
        );
1887
    }
A
Alex Crichton 已提交
1888
}
1889

1890
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1891 1892
pub struct Bootstrap;

1893
impl Step for Bootstrap {
1894
    type Output = ();
1895 1896
    const DEFAULT: bool = true;
    const ONLY_HOSTS: bool = true;
1897 1898 1899

    /// Test the build system itself
    fn run(self, builder: &Builder) {
1900
        let mut cmd = Command::new(&builder.initial_cargo);
1901
        cmd.arg("test")
S
Santiago Pastorino 已提交
1902 1903 1904 1905 1906
            .current_dir(builder.src.join("src/bootstrap"))
            .env("RUSTFLAGS", "-Cdebuginfo=2")
            .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
            .env("RUSTC_BOOTSTRAP", "1")
            .env("RUSTC", &builder.initial_rustc);
1907 1908 1909 1910 1911 1912
        if let Some(flags) = option_env!("RUSTFLAGS") {
            // Use the same rustc flags for testing as for "normal" compilation,
            // so that Cargo doesn’t recompile the entire dependency graph every time:
            // https://github.com/rust-lang/rust/issues/49215
            cmd.env("RUSTFLAGS", flags);
        }
1913
        if !builder.fail_fast {
1914 1915
            cmd.arg("--no-fail-fast");
        }
1916 1917
        cmd.arg("--").args(&builder.config.cmd.test_args());
        try_run(builder, &mut cmd);
1918
    }
1919

1920 1921
    fn should_run(run: ShouldRun) -> ShouldRun {
        run.path("src/bootstrap")
1922 1923
    }

1924 1925
    fn make_run(run: RunConfig) {
        run.builder.ensure(Bootstrap);
1926
    }
1927
}