Skip to content

Commit

Permalink
Auto merge of #112256 - jyn514:faster-mingw-check, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Don't compile rustc to self-test compiletest

This was changed from stage 0 to 1 in #108905, but I'm not sure why. Change it to `top_stage` instead to allow people to choose the stage.

This should save quite a bit of time in the `mingw-check` builder, which explicitly runs `x test --stage 0 compiletest`.

Note that this also fixes a latent bug that depended on running `x build compiler` before `x doc compiler`, as well as a couple cleanups related to symlinks (which made the latent bug easier to find).

cc `@pietroalbini`
  • Loading branch information
bors committed Jun 10, 2023
2 parents 7820972 + d613134 commit b8a5001
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
23 changes: 13 additions & 10 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//! `rustdoc`.

use std::fs;
use std::io;
use std::path::{Path, PathBuf};

use crate::builder::crate_description;
Expand Down Expand Up @@ -694,11 +693,12 @@ impl Step for Rustc {
// rustc. rustdoc needs to be able to see everything, for example when
// merging the search index, or generating local (relative) links.
let out_dir = builder.stage_out(compiler, Mode::Rustc).join(target.triple).join("doc");
t!(symlink_dir_force(&builder.config, &out, &out_dir));
t!(fs::create_dir_all(out_dir.parent().unwrap()));
symlink_dir_force(&builder.config, &out, &out_dir);
// Cargo puts proc macros in `target/doc` even if you pass `--target`
// explicitly (https://github.com/rust-lang/cargo/issues/7677).
let proc_macro_out_dir = builder.stage_out(compiler, Mode::Rustc).join("doc");
t!(symlink_dir_force(&builder.config, &out, &proc_macro_out_dir));
symlink_dir_force(&builder.config, &out, &proc_macro_out_dir);

// Build cargo command.
let mut cargo = builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "doc");
Expand Down Expand Up @@ -821,7 +821,7 @@ macro_rules! tool_doc {
];
for out_dir in out_dirs {
t!(fs::create_dir_all(&out_dir));
t!(symlink_dir_force(&builder.config, &out, &out_dir));
symlink_dir_force(&builder.config, &out, &out_dir);
}

// Build cargo command.
Expand Down Expand Up @@ -964,21 +964,24 @@ impl Step for UnstableBookGen {
}
}

fn symlink_dir_force(config: &Config, src: &Path, dst: &Path) -> io::Result<()> {
fn symlink_dir_force(config: &Config, original: &Path, link: &Path) {
if config.dry_run() {
return Ok(());
return;
}
if let Ok(m) = fs::symlink_metadata(dst) {
if let Ok(m) = fs::symlink_metadata(link) {
if m.file_type().is_dir() {
fs::remove_dir_all(dst)?;
t!(fs::remove_dir_all(link));
} else {
// handle directory junctions on windows by falling back to
// `remove_dir`.
fs::remove_file(dst).or_else(|_| fs::remove_dir(dst))?;
t!(fs::remove_file(link).or_else(|_| fs::remove_dir(link)));
}
}

symlink_dir(config, src, dst)
t!(
symlink_dir(config, original, link),
format!("failed to create link from {} -> {}", link.display(), original.display())
);
}

#[derive(Ord, PartialOrd, Debug, Copy, Clone, Hash, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ impl Step for CompiletestTest {
/// Runs `cargo test` for compiletest.
fn run(self, builder: &Builder<'_>) {
let host = self.host;
let compiler = builder.compiler(1, host);
let compiler = builder.compiler(builder.top_stage, host);

// We need `ToolStd` for the locally-built sysroot because
// compiletest uses unstable features of the `test` crate.
Expand Down
10 changes: 5 additions & 5 deletions src/bootstrap/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ pub(crate) fn program_out_of_date(stamp: &Path, key: &str) -> bool {

/// Symlinks two directories, using junctions on Windows and normal symlinks on
/// Unix.
pub fn symlink_dir(config: &Config, src: &Path, dest: &Path) -> io::Result<()> {
pub fn symlink_dir(config: &Config, original: &Path, link: &Path) -> io::Result<()> {
if config.dry_run() {
return Ok(());
}
let _ = fs::remove_dir(dest);
return symlink_dir_inner(src, dest);
let _ = fs::remove_dir(link);
return symlink_dir_inner(original, link);

#[cfg(not(windows))]
fn symlink_dir_inner(src: &Path, dest: &Path) -> io::Result<()> {
fn symlink_dir_inner(original: &Path, link: &Path) -> io::Result<()> {
use std::os::unix::fs;
fs::symlink(src, dest)
fs::symlink(original, link)
}

#[cfg(windows)]
Expand Down

0 comments on commit b8a5001

Please sign in to comment.