about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoshua Nelson <jnelson@cloudflare.com>2022-04-10 14:24:11 -0500
committerJoshua Nelson <jnelson@cloudflare.com>2022-04-24 19:40:20 -0500
commit7885ade98434c765dc218ba7d396c8c4b7827fe8 (patch)
tree8ad0c7b24883c4c0a95ea53b04c00600e4473656
parent12b132dd8335a67d4dc88dde8ff3b82daf755d05 (diff)
downloadrust-7885ade98434c765dc218ba7d396c8c4b7827fe8.tar.gz
rust-7885ade98434c765dc218ba7d396c8c4b7827fe8.zip
Use `build/tmp` instead of adding a dependency on `tempfile`.
-rw-r--r--Cargo.lock1
-rw-r--r--src/bootstrap/Cargo.toml1
-rw-r--r--src/bootstrap/lib.rs23
-rw-r--r--src/bootstrap/native.rs16
-rw-r--r--src/bootstrap/test.rs11
5 files changed, 19 insertions, 33 deletions
diff --git a/Cargo.lock b/Cargo.lock
index aa2fd230d0d..cb92e50cdd3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -226,7 +226,6 @@ dependencies = [
  "serde",
  "serde_json",
  "tar",
- "tempfile",
  "toml",
  "winapi",
  "xz2",
diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml
index 19cd0928395..dea8d998bde 100644
--- a/src/bootstrap/Cargo.toml
+++ b/src/bootstrap/Cargo.toml
@@ -43,7 +43,6 @@ libc = "0.2"
 serde = { version = "1.0.8", features = ["derive"] }
 serde_json = "1.0.2"
 tar = "0.4"
-tempfile = "3"
 toml = "0.5"
 ignore = "0.4.10"
 opener = "0.5"
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index 11be33ed4f0..b4b973b4247 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -1391,21 +1391,14 @@ impl Build {
         paths
     }
 
-    pub fn rename(&self, src: &Path, dst: &Path) {
-        if self.config.dry_run {
-            return;
-        }
-        self.verbose_than(1, &format!("Move {:?} to {:?}", src, dst));
-        if src == dst {
-            return;
-        }
-        if let Err(e) = fs::rename(src, dst) {
-            if e.raw_os_error() == Some(libc::EXDEV) {
-                self.copy(src, dst);
-                return;
-            }
-            panic!("failed to rename `{}` to `{}`: {}", src.display(), dst.display(), e);
-        }
+    /// Create a temporary directory in `out` and return its path.
+    ///
+    /// NOTE: this temporary directory is shared between all steps;
+    /// if you need an empty directory, create a new subdirectory inside it.
+    fn tempdir(&self) -> PathBuf {
+        let tmp = self.out.join("tmp");
+        t!(fs::create_dir_all(&tmp));
+        tmp
     }
 
     /// Copies a file from `src` to `dst`
diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs
index 343df281fb6..64e25f803b2 100644
--- a/src/bootstrap/native.rs
+++ b/src/bootstrap/native.rs
@@ -297,16 +297,14 @@ fn fix_bin_or_dylib(builder: &Builder<'_>, fname: &Path) {
 
 fn download_component(builder: &Builder<'_>, base: &str, url: &str, dest_path: &Path) {
     // Use a temporary file in case we crash while downloading, to avoid a corrupt download in cache/.
-    let tempfile = t!(tempfile::NamedTempFile::new());
-    let temppath = tempfile.path().to_owned();
-    drop(tempfile);
-    let tempfile_str = temppath.to_str().expect("tempdir must be valid unicode");
+    let tempfile = builder.tempdir().join(dest_path.file_name().unwrap());
     // FIXME: support `do_verify` (only really needed for nightly rustfmt)
-    download_with_retries(builder, tempfile_str, &format!("{}/{}", base, url));
-    builder.rename(&temppath, dest_path);
+    // FIXME: support non-utf8 paths?
+    download_with_retries(builder, tempfile.to_str().unwrap(), &format!("{}/{}", base, url));
+    t!(std::fs::rename(&tempfile, dest_path));
 }
 
-fn download_with_retries(builder: &Builder<'_>, tempdir: &str, url: &str) {
+fn download_with_retries(builder: &Builder<'_>, tempfile: &str, url: &str) {
     println!("downloading {}", url);
 
     // FIXME: check if curl is installed instead of skipping straight to powershell
@@ -318,7 +316,7 @@ fn download_with_retries(builder: &Builder<'_>, tempdir: &str, url: &str) {
                 "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;",
                 &format!(
                     "(New-Object System.Net.WebClient).DownloadFile('{}', '{}')",
-                    url, tempdir
+                    url, tempfile
                 ),
             ])) {
                 return;
@@ -338,7 +336,7 @@ fn download_with_retries(builder: &Builder<'_>, tempdir: &str, url: &str) {
             "3",
             "-Sf",
             "-o",
-            tempdir,
+            tempfile,
             url,
         ]));
     }
diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs
index da468909811..98723a0bffd 100644
--- a/src/bootstrap/test.rs
+++ b/src/bootstrap/test.rs
@@ -1577,9 +1577,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
             cmd.env("RUSTC_PROFILER_SUPPORT", "1");
         }
 
-        let tmp = builder.out.join("tmp");
-        std::fs::create_dir_all(&tmp).unwrap();
-        cmd.env("RUST_TEST_TMPDIR", tmp);
+        cmd.env("RUST_TEST_TMPDIR", builder.tempdir());
 
         cmd.arg("--adb-path").arg("adb");
         cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
@@ -2259,14 +2257,13 @@ impl Step for RemoteCopyLibs {
         builder.ensure(compile::Std { compiler, target });
 
         builder.info(&format!("REMOTE copy libs to emulator ({})", target));
-        t!(fs::create_dir_all(builder.out.join("tmp")));
 
         let server = builder.ensure(tool::RemoteTestServer { compiler, target });
 
         // Spawn the emulator and wait for it to come online
         let tool = builder.tool_exe(Tool::RemoteTestClient);
         let mut cmd = Command::new(&tool);
-        cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.out.join("tmp"));
+        cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.tempdir());
         if let Some(rootfs) = builder.qemu_rootfs(target) {
             cmd.arg(rootfs);
         }
@@ -2300,7 +2297,7 @@ impl Step for Distcheck {
     /// Runs "distcheck", a 'make check' from a tarball
     fn run(self, builder: &Builder<'_>) {
         builder.info("Distcheck");
-        let dir = builder.out.join("tmp").join("distcheck");
+        let dir = builder.tempdir().join("distcheck");
         let _ = fs::remove_dir_all(&dir);
         t!(fs::create_dir_all(&dir));
 
@@ -2326,7 +2323,7 @@ impl Step for Distcheck {
 
         // Now make sure that rust-src has all of libstd's dependencies
         builder.info("Distcheck rust-src");
-        let dir = builder.out.join("tmp").join("distcheck-src");
+        let dir = builder.tempdir().join("distcheck-src");
         let _ = fs::remove_dir_all(&dir);
         t!(fs::create_dir_all(&dir));