]> git.lizzy.rs Git - rust.git/blobdiff - src/bootstrap/download.rs
Rollup merge of #107834 - zephaniahong:issue-107547-fix, r=albertlarsan68
[rust.git] / src / bootstrap / download.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);
         }