Skip to content

Commit 7885ade

Browse files
committed
Use build/tmp instead of adding a dependency on tempfile.
1 parent 12b132d commit 7885ade

File tree

5 files changed

+19
-33
lines changed

5 files changed

+19
-33
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ dependencies = [
226226
"serde",
227227
"serde_json",
228228
"tar",
229-
"tempfile",
230229
"toml",
231230
"winapi",
232231
"xz2",

src/bootstrap/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ libc = "0.2"
4343
serde = { version = "1.0.8", features = ["derive"] }
4444
serde_json = "1.0.2"
4545
tar = "0.4"
46-
tempfile = "3"
4746
toml = "0.5"
4847
ignore = "0.4.10"
4948
opener = "0.5"

src/bootstrap/lib.rs

+8-15
Original file line numberDiff line numberDiff line change
@@ -1391,21 +1391,14 @@ impl Build {
13911391
paths
13921392
}
13931393

1394-
pub fn rename(&self, src: &Path, dst: &Path) {
1395-
if self.config.dry_run {
1396-
return;
1397-
}
1398-
self.verbose_than(1, &format!("Move {:?} to {:?}", src, dst));
1399-
if src == dst {
1400-
return;
1401-
}
1402-
if let Err(e) = fs::rename(src, dst) {
1403-
if e.raw_os_error() == Some(libc::EXDEV) {
1404-
self.copy(src, dst);
1405-
return;
1406-
}
1407-
panic!("failed to rename `{}` to `{}`: {}", src.display(), dst.display(), e);
1408-
}
1394+
/// Create a temporary directory in `out` and return its path.
1395+
///
1396+
/// NOTE: this temporary directory is shared between all steps;
1397+
/// if you need an empty directory, create a new subdirectory inside it.
1398+
fn tempdir(&self) -> PathBuf {
1399+
let tmp = self.out.join("tmp");
1400+
t!(fs::create_dir_all(&tmp));
1401+
tmp
14091402
}
14101403

14111404
/// Copies a file from `src` to `dst`

src/bootstrap/native.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,14 @@ fn fix_bin_or_dylib(builder: &Builder<'_>, fname: &Path) {
297297

298298
fn download_component(builder: &Builder<'_>, base: &str, url: &str, dest_path: &Path) {
299299
// Use a temporary file in case we crash while downloading, to avoid a corrupt download in cache/.
300-
let tempfile = t!(tempfile::NamedTempFile::new());
301-
let temppath = tempfile.path().to_owned();
302-
drop(tempfile);
303-
let tempfile_str = temppath.to_str().expect("tempdir must be valid unicode");
300+
let tempfile = builder.tempdir().join(dest_path.file_name().unwrap());
304301
// FIXME: support `do_verify` (only really needed for nightly rustfmt)
305-
download_with_retries(builder, tempfile_str, &format!("{}/{}", base, url));
306-
builder.rename(&temppath, dest_path);
302+
// FIXME: support non-utf8 paths?
303+
download_with_retries(builder, tempfile.to_str().unwrap(), &format!("{}/{}", base, url));
304+
t!(std::fs::rename(&tempfile, dest_path));
307305
}
308306

309-
fn download_with_retries(builder: &Builder<'_>, tempdir: &str, url: &str) {
307+
fn download_with_retries(builder: &Builder<'_>, tempfile: &str, url: &str) {
310308
println!("downloading {}", url);
311309

312310
// 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) {
318316
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;",
319317
&format!(
320318
"(New-Object System.Net.WebClient).DownloadFile('{}', '{}')",
321-
url, tempdir
319+
url, tempfile
322320
),
323321
])) {
324322
return;
@@ -338,7 +336,7 @@ fn download_with_retries(builder: &Builder<'_>, tempdir: &str, url: &str) {
338336
"3",
339337
"-Sf",
340338
"-o",
341-
tempdir,
339+
tempfile,
342340
url,
343341
]));
344342
}

src/bootstrap/test.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1577,9 +1577,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
15771577
cmd.env("RUSTC_PROFILER_SUPPORT", "1");
15781578
}
15791579

1580-
let tmp = builder.out.join("tmp");
1581-
std::fs::create_dir_all(&tmp).unwrap();
1582-
cmd.env("RUST_TEST_TMPDIR", tmp);
1580+
cmd.env("RUST_TEST_TMPDIR", builder.tempdir());
15831581

15841582
cmd.arg("--adb-path").arg("adb");
15851583
cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
@@ -2259,14 +2257,13 @@ impl Step for RemoteCopyLibs {
22592257
builder.ensure(compile::Std { compiler, target });
22602258

22612259
builder.info(&format!("REMOTE copy libs to emulator ({})", target));
2262-
t!(fs::create_dir_all(builder.out.join("tmp")));
22632260

22642261
let server = builder.ensure(tool::RemoteTestServer { compiler, target });
22652262

22662263
// Spawn the emulator and wait for it to come online
22672264
let tool = builder.tool_exe(Tool::RemoteTestClient);
22682265
let mut cmd = Command::new(&tool);
2269-
cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.out.join("tmp"));
2266+
cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.tempdir());
22702267
if let Some(rootfs) = builder.qemu_rootfs(target) {
22712268
cmd.arg(rootfs);
22722269
}
@@ -2300,7 +2297,7 @@ impl Step for Distcheck {
23002297
/// Runs "distcheck", a 'make check' from a tarball
23012298
fn run(self, builder: &Builder<'_>) {
23022299
builder.info("Distcheck");
2303-
let dir = builder.out.join("tmp").join("distcheck");
2300+
let dir = builder.tempdir().join("distcheck");
23042301
let _ = fs::remove_dir_all(&dir);
23052302
t!(fs::create_dir_all(&dir));
23062303

@@ -2326,7 +2323,7 @@ impl Step for Distcheck {
23262323

23272324
// Now make sure that rust-src has all of libstd's dependencies
23282325
builder.info("Distcheck rust-src");
2329-
let dir = builder.out.join("tmp").join("distcheck-src");
2326+
let dir = builder.tempdir().join("distcheck-src");
23302327
let _ = fs::remove_dir_all(&dir);
23312328
t!(fs::create_dir_all(&dir));
23322329

0 commit comments

Comments
 (0)