Revert "port over symlink_file function from Build to Config and create symlink for legacy rustfmt path"

This reverts commit 41c6c5d499.
This commit is contained in:
Jakub Beránek 2023-02-21 10:04:19 +01:00
parent f715e430aa
commit a5d27316fe
No known key found for this signature in database
GPG Key ID: 909CD0D26483516B
3 changed files with 12 additions and 20 deletions

View File

@ -2,7 +2,7 @@
env, env,
ffi::{OsStr, OsString}, ffi::{OsStr, OsString},
fs::{self, File}, fs::{self, File},
io::{self, BufRead, BufReader, ErrorKind}, io::{BufRead, BufReader, ErrorKind},
path::{Path, PathBuf}, path::{Path, PathBuf},
process::{Command, Stdio}, process::{Command, Stdio},
}; };
@ -26,14 +26,6 @@ pub fn is_verbose(&self) -> bool {
self.verbose > 0 self.verbose > 0
} }
pub fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(&self, src: P, link: Q) -> io::Result<()> {
#[cfg(unix)]
use std::os::unix::fs::symlink as symlink_file;
#[cfg(windows)]
use std::os::windows::fs::symlink_file;
if !self.dry_run() { symlink_file(src.as_ref(), link.as_ref()) } else { Ok(()) }
}
pub(crate) fn create(&self, path: &Path, s: &str) { pub(crate) fn create(&self, path: &Path, s: &str) {
if self.dry_run() { if self.dry_run() {
return; return;
@ -338,15 +330,6 @@ pub(crate) fn maybe_download_rustfmt(&self) -> Option<PathBuf> {
let bin_root = self.out.join(host.triple).join("rustfmt"); let bin_root = self.out.join(host.triple).join("rustfmt");
let rustfmt_path = bin_root.join("bin").join(exe("rustfmt", host)); let rustfmt_path = bin_root.join("bin").join(exe("rustfmt", host));
let rustfmt_stamp = bin_root.join(".rustfmt-stamp"); let rustfmt_stamp = bin_root.join(".rustfmt-stamp");
#[cfg(not(windows))]
{
let legacy_rustfmt = self.initial_rustc.with_file_name(exe("rustfmt", host));
if !legacy_rustfmt.exists() {
t!(self.symlink_file(&rustfmt_path, &legacy_rustfmt));
}
}
if rustfmt_path.exists() && !program_out_of_date(&rustfmt_stamp, &channel) { if rustfmt_path.exists() && !program_out_of_date(&rustfmt_stamp, &channel) {
return Some(rustfmt_path); return Some(rustfmt_path);
} }

View File

@ -20,6 +20,7 @@
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::env; use std::env;
use std::fs::{self, File}; use std::fs::{self, File};
use std::io;
use std::io::ErrorKind; use std::io::ErrorKind;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
@ -1406,7 +1407,7 @@ fn copy_internal(&self, src: &Path, dst: &Path, dereference_symlinks: bool) {
src = t!(fs::canonicalize(src)); src = t!(fs::canonicalize(src));
} else { } else {
let link = t!(fs::read_link(src)); let link = t!(fs::read_link(src));
t!(self.config.symlink_file(link, dst)); t!(self.symlink_file(link, dst));
return; return;
} }
} }
@ -1524,6 +1525,14 @@ fn read_dir(&self, dir: &Path) -> impl Iterator<Item = fs::DirEntry> {
iter.map(|e| t!(e)).collect::<Vec<_>>().into_iter() iter.map(|e| t!(e)).collect::<Vec<_>>().into_iter()
} }
fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(&self, src: P, link: Q) -> io::Result<()> {
#[cfg(unix)]
use std::os::unix::fs::symlink as symlink_file;
#[cfg(windows)]
use std::os::windows::fs::symlink_file;
if !self.config.dry_run() { symlink_file(src.as_ref(), link.as_ref()) } else { Ok(()) }
}
/// Returns if config.ninja is enabled, and checks for ninja existence, /// Returns if config.ninja is enabled, and checks for ninja existence,
/// exiting with a nicer error message if not. /// exiting with a nicer error message if not.
fn ninja(&self) -> bool { fn ninja(&self) -> bool {

View File

@ -516,7 +516,7 @@ fn run(self, builder: &Builder<'_>) -> LlvmResult {
let lib_llvm = out_dir.join("build").join("lib").join(lib_name); let lib_llvm = out_dir.join("build").join("lib").join(lib_name);
if !lib_llvm.exists() { if !lib_llvm.exists() {
t!(builder.build.config.symlink_file("libLLVM.dylib", &lib_llvm)); t!(builder.symlink_file("libLLVM.dylib", &lib_llvm));
} }
} }