diff --git a/Cargo.lock b/Cargo.lock index aa2fd230d0d2a..cb92e50cdd399 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 19cd0928395a5..dea8d998bdeda 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 11be33ed4f001..b4b973b42479e 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 343df281fb6a0..64e25f803b27f 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 da4689098119f..98723a0bffd99 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));