]> git.lizzy.rs Git - rust.git/commitdiff
port over symlink_file function from Build to Config and create symlink for legacy...
authorZephaniah Ong <zealorez@gmail.com>
Thu, 9 Feb 2023 08:01:29 +0000 (16:01 +0800)
committerZephaniah Ong <zealorez@gmail.com>
Thu, 9 Feb 2023 08:01:29 +0000 (16:01 +0800)
src/bootstrap/download.rs
src/bootstrap/lib.rs
src/bootstrap/native.rs

index bd67978a7662ee1d61c9d572d6194c8b243276c0..5c863015adb278893d7ed2dbf7d6f3f1d4d9697f 100644 (file)
@@ -2,7 +2,7 @@
     env,
     ffi::{OsStr, OsString},
     fs::{self, File},
-    io::{BufRead, BufReader, ErrorKind},
+    io::{self, BufRead, BufReader, ErrorKind},
     path::{Path, PathBuf},
     process::{Command, Stdio},
 };
@@ -26,6 +26,14 @@ pub fn is_verbose(&self) -> bool {
         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) {
         if self.dry_run() {
             return;
@@ -331,6 +339,12 @@ pub(crate) fn maybe_download_rustfmt(&self) -> Option<PathBuf> {
         let bin_root = self.out.join(host.triple).join("rustfmt");
         let rustfmt_path = bin_root.join("bin").join(exe("rustfmt", host));
         let rustfmt_stamp = bin_root.join(".rustfmt-stamp");
+
+        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) {
             return Some(rustfmt_path);
         }
index f4abdf1cc57589e51c8c8aec36e07e48dfdecac9..f753720b353066bcb05a8e9889a0d97497e70587 100644 (file)
@@ -20,7 +20,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};
@@ -1407,7 +1406,7 @@ fn copy_internal(&self, src: &Path, dst: &Path, dereference_symlinks: bool) {
                 src = t!(fs::canonicalize(src));
             } else {
                 let link = t!(fs::read_link(src));
-                t!(self.symlink_file(link, dst));
+                t!(self.config.symlink_file(link, dst));
                 return;
             }
         }
@@ -1525,14 +1524,6 @@ fn read_dir(&self, dir: &Path) -> impl Iterator<Item = fs::DirEntry> {
         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,
     /// exiting with a nicer error message if not.
     fn ninja(&self) -> bool {
index 3acc2d4b5c4b1093a2ab204c1e3b2861d3e864bf..07d339c067c860242ea0400a68b1b7575571895c 100644 (file)
@@ -516,7 +516,7 @@ fn run(self, builder: &Builder<'_>) -> LlvmResult {
 
             let lib_llvm = out_dir.join("build").join("lib").join(lib_name);
             if !lib_llvm.exists() {
-                t!(builder.symlink_file("libLLVM.dylib", &lib_llvm));
+                t!(builder.build.config.symlink_file("libLLVM.dylib", &lib_llvm));
             }
         }