Skip to content

Commit 28b7e6a

Browse files
committed
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.
1 parent eb3e9c1 commit 28b7e6a

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/bootstrap/lib.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use std::collections::{HashMap, HashSet};
2121
use std::env;
2222
use std::fs::{self, File};
2323
use std::io;
24-
use std::io::ErrorKind;
2524
use std::path::{Path, PathBuf};
2625
use std::process::{Command, Stdio};
2726
use std::str;
@@ -505,16 +504,18 @@ impl Build {
505504
let build_triple = build.out.join(&build.build.triple);
506505
t!(fs::create_dir_all(&build_triple));
507506
let host = build.out.join("host");
508-
if let Err(e) = symlink_dir(&build.config, &build_triple, &host) {
509-
if e.kind() != ErrorKind::AlreadyExists {
510-
panic!(
511-
"symlink_dir({} => {}) failed with {}",
512-
host.display(),
513-
build_triple.display(),
514-
e
515-
);
516-
}
517-
}
507+
if host.is_symlink() {
508+
// Left over from a previous build; overwrite it.
509+
// This matters if `build.build` has changed between invocations.
510+
#[cfg(windows)]
511+
t!(fs::remove_dir(&host));
512+
#[cfg(not(windows))]
513+
t!(fs::remove_file(&host));
514+
}
515+
t!(
516+
symlink_dir(&build.config, &build_triple, &host),
517+
format!("symlink_dir({} => {}) failed", host.display(), build_triple.display())
518+
);
518519

519520
build
520521
}

0 commit comments

Comments
 (0)