1
Fork 0

Use build/tmp instead of adding a dependency on tempfile.

This commit is contained in:
Joshua Nelson 2022-04-10 14:24:11 -05:00
parent 12b132dd83
commit 7885ade984
5 changed files with 19 additions and 33 deletions

View file

@ -226,7 +226,6 @@ dependencies = [
"serde",
"serde_json",
"tar",
"tempfile",
"toml",
"winapi",
"xz2",

View file

@ -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"

View file

@ -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`

View file

@ -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,
]));
}

View file

@ -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));