Skip to content

Commit

Permalink
Auto merge of rust-lang#109811 - jyn514:symlink-fixes, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Replace any existing `build/host` symlink

This has two advantages:
1. If `build.build` changes between runs, the symlink is no longer silently wrong.
2. If the entire build directory is moved, the symlink is no longer broken because it points to the wrong absolute path.
  • Loading branch information
bors committed Apr 2, 2023
2 parents a5a690c + 28b7e6a commit 3a8a131
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use std::collections::{HashMap, HashSet};
use std::env;
use std::fs::{self, File};
use std::io;
use std::io::ErrorKind;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::str;
Expand Down Expand Up @@ -505,16 +504,18 @@ impl Build {
let build_triple = build.out.join(&build.build.triple);
t!(fs::create_dir_all(&build_triple));
let host = build.out.join("host");
if let Err(e) = symlink_dir(&build.config, &build_triple, &host) {
if e.kind() != ErrorKind::AlreadyExists {
panic!(
"symlink_dir({} => {}) failed with {}",
host.display(),
build_triple.display(),
e
);
}
}
if host.is_symlink() {
// Left over from a previous build; overwrite it.
// This matters if `build.build` has changed between invocations.
#[cfg(windows)]
t!(fs::remove_dir(&host));
#[cfg(not(windows))]
t!(fs::remove_file(&host));
}
t!(
symlink_dir(&build.config, &build_triple, &host),
format!("symlink_dir({} => {}) failed", host.display(), build_triple.display())
);

build
}
Expand Down

0 comments on commit 3a8a131

Please sign in to comment.