Skip to content

Commit

Permalink
replace tmp_dir().join(_) with tmp_path(_)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed May 30, 2024
1 parent 91c0823 commit 20ad958
Show file tree
Hide file tree
Showing 39 changed files with 102 additions and 96 deletions.
10 changes: 6 additions & 4 deletions src/tools/run-make-support/src/cc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use std::env;
use std::path::Path;
use std::process::Command;

use crate::{bin_name, cygpath_windows, handle_failed_output, is_msvc, is_windows, tmp_dir, uname};
use crate::{
bin_name, cygpath_windows, handle_failed_output, is_msvc, is_windows, tmp_path, uname,
};

/// Construct a new platform-specific C compiler invocation.
///
Expand Down Expand Up @@ -68,13 +70,13 @@ impl Cc {
// ```

if is_msvc() {
let fe_path = cygpath_windows(tmp_dir().join(bin_name(name)));
let fo_path = cygpath_windows(tmp_dir().join(format!("{name}.obj")));
let fe_path = cygpath_windows(tmp_path(bin_name(name)));
let fo_path = cygpath_windows(tmp_path(format!("{name}.obj")));
self.cmd.arg(format!("-Fe:{fe_path}"));
self.cmd.arg(format!("-Fo:{fo_path}"));
} else {
self.cmd.arg("-o");
self.cmd.arg(tmp_dir().join(name));
self.cmd.arg(tmp_path(name));
}

self
Expand Down
4 changes: 2 additions & 2 deletions src/tools/run-make-support/src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::env;
use std::path::Path;
use std::process::Command;

use crate::{bin_name, handle_failed_output, tmp_dir};
use crate::{bin_name, handle_failed_output, tmp_path};

/// Construct a new `clang` invocation. `clang` is not always available for all targets.
pub fn clang() -> Clang {
Expand Down Expand Up @@ -36,7 +36,7 @@ impl Clang {
/// extension will be determined by [`bin_name`].
pub fn out_exe(&mut self, name: &str) -> &mut Self {
self.cmd.arg("-o");
self.cmd.arg(tmp_dir().join(bin_name(name)));
self.cmd.arg(tmp_path(bin_name(name)));
self
}

Expand Down
10 changes: 7 additions & 3 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pub fn tmp_dir() -> PathBuf {
env::var_os("TMPDIR").unwrap().into()
}

pub fn tmp_path<P: AsRef<Path>>(path: P) -> PathBuf {
tmp_dir().join(path.as_ref())
}

/// `TARGET`
pub fn target() -> String {
env::var("TARGET").unwrap()
Expand All @@ -58,7 +62,7 @@ pub fn is_darwin() -> bool {
/// Construct a path to a static library under `$TMPDIR` given the library name. This will return a
/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
pub fn static_lib(name: &str) -> PathBuf {
tmp_dir().join(static_lib_name(name))
tmp_path(static_lib_name(name))
}

pub fn python_command() -> Command {
Expand Down Expand Up @@ -103,7 +107,7 @@ pub fn static_lib_name(name: &str) -> String {
/// Construct a path to a dynamic library under `$TMPDIR` given the library name. This will return a
/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
pub fn dynamic_lib(name: &str) -> PathBuf {
tmp_dir().join(dynamic_lib_name(name))
tmp_path(dynamic_lib_name(name))
}

/// Construct the dynamic library name based on the platform.
Expand Down Expand Up @@ -135,7 +139,7 @@ pub fn dynamic_lib_name(name: &str) -> String {
/// Construct a path to a rust library (rlib) under `$TMPDIR` given the library name. This will return a
/// path with `$TMPDIR` joined with the library name.
pub fn rust_lib(name: &str) -> PathBuf {
tmp_dir().join(rust_lib_name(name))
tmp_path(rust_lib_name(name))
}

/// Generate the name a rust library (rlib) would have. If you want the complete path, use
Expand Down
8 changes: 4 additions & 4 deletions tests/run-make/compiler-builtins/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use run_make_support::object::ObjectSection;
use run_make_support::object::ObjectSymbol;
use run_make_support::object::RelocationTarget;
use run_make_support::set_host_rpath;
use run_make_support::tmp_dir;
use run_make_support::tmp_path;
use std::collections::HashSet;

const MANIFEST: &str = r#"
Expand All @@ -34,15 +34,15 @@ edition = "2021"
path = "lib.rs""#;

fn main() {
let target_dir = tmp_dir().join("target");
let target_dir = tmp_path("target");
let target = std::env::var("TARGET").unwrap();

println!("Testing compiler_builtins for {}", target);

// Set up the tiniest Cargo project: An empty no_std library. Just enough to run -Zbuild-std.
let manifest_path = tmp_dir().join("Cargo.toml");
let manifest_path = tmp_path("Cargo.toml");
std::fs::write(&manifest_path, MANIFEST.as_bytes()).unwrap();
std::fs::write(tmp_dir().join("lib.rs"), b"#![no_std]").unwrap();
std::fs::write(tmp_path("lib.rs"), b"#![no_std]").unwrap();

let path = std::env::var("PATH").unwrap();
let rustc = std::env::var("RUSTC").unwrap();
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/core-no-oom-handling/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// when the no_global_oom_handling feature is turned on.
// See https://github.com/rust-lang/rust/pull/110649

use run_make_support::{rustc, tmp_dir};
use run_make_support::{rustc, tmp_path};

fn main() {
rustc()
.edition("2021")
.arg("-Dwarnings")
.crate_type("rlib")
.input("../../../library/core/src/lib.rs")
.sysroot(tmp_dir().join("fakeroot"))
.sysroot(tmp_path("fakeroot"))
.cfg("no_global_oom_handling")
.run();
}
6 changes: 3 additions & 3 deletions tests/run-make/cross-lang-lto-riscv-abi/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//@ needs-matching-clang
//@ needs-llvm-components riscv

use run_make_support::{bin_name, clang, llvm_readobj, rustc, tmp_dir};
use run_make_support::{bin_name, clang, llvm_readobj, rustc, tmp_path};
use std::{
env,
path::PathBuf,
Expand All @@ -30,11 +30,11 @@ fn check_target(target: &str, clang_target: &str, carch: &str, is_double_float:
.no_stdlib()
.out_exe("riscv-xlto")
.input("cstart.c")
.input(tmp_dir().join("libriscv_xlto.rlib"))
.input(tmp_path("libriscv_xlto.rlib"))
.run();

// Check that the built binary has correct float abi
let executable = tmp_dir().join(bin_name("riscv-xlto"));
let executable = tmp_path(bin_name("riscv-xlto"));
let output = llvm_readobj().input(&executable).file_header().run();
let stdout = String::from_utf8_lossy(&output.stdout);
eprintln!("obj:\n{}", stdout);
Expand Down
8 changes: 4 additions & 4 deletions tests/run-make/doctests-keep-binaries/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Check that valid binaries are persisted by running them, regardless of whether the
// --run or --no-run option is used.

use run_make_support::{run, rustc, rustdoc, tmp_dir};
use run_make_support::{run, rustc, rustdoc, tmp_dir, tmp_path};
use std::fs::{create_dir, remove_dir_all};
use std::path::Path;

fn setup_test_env<F: FnOnce(&Path, &Path)>(callback: F) {
let out_dir = tmp_dir().join("doctests");
let out_dir = tmp_path("doctests");
create_dir(&out_dir).expect("failed to create doctests folder");
rustc().input("t.rs").crate_type("rlib").run();
callback(&out_dir, &tmp_dir().join("libt.rlib"));
callback(&out_dir, &tmp_path("libt.rlib"));
remove_dir_all(out_dir);
}

Expand Down Expand Up @@ -45,7 +45,7 @@ fn main() {
// Behavior with --test-run-directory with relative paths.
setup_test_env(|_out_dir, extern_path| {
let run_dir = "rundir";
let run_dir_path = tmp_dir().join("rundir");
let run_dir_path = tmp_path("rundir");
create_dir(&run_dir_path).expect("failed to create rundir folder");

rustdoc()
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/doctests-runtool/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Tests behavior of rustdoc `--runtool`.

use run_make_support::{rustc, rustdoc, tmp_dir};
use run_make_support::{rustc, rustdoc, tmp_dir, tmp_path};
use std::env::current_dir;
use std::fs::{create_dir, remove_dir_all};
use std::path::PathBuf;

fn mkdir(name: &str) -> PathBuf {
let dir = tmp_dir().join(name);
let dir = tmp_path(name);
create_dir(&dir).expect("failed to create doctests folder");
dir
}
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/exit-code/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Test that we exit with the correct exit code for successful / unsuccessful / ICE compilations

use run_make_support::{rustc, rustdoc, tmp_dir};
use run_make_support::{rustc, rustdoc, tmp_path};

fn main() {
rustc().arg("success.rs").run();
Expand All @@ -15,7 +15,7 @@ fn main() {
.arg("compile-error.rs")
.run_fail_assert_exit_code(101);

rustdoc().arg("success.rs").output(tmp_dir().join("exit-code")).run();
rustdoc().arg("success.rs").output(tmp_path("exit-code")).run();

rustdoc().arg("--invalid-arg-foo").run_fail_assert_exit_code(1);

Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/issue-107495-archive-permissions/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[cfg(unix)]
extern crate libc;

use run_make_support::{aux_build, tmp_dir};
use run_make_support::{aux_build, tmp_path};
use std::fs;
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
Expand All @@ -16,7 +16,7 @@ fn main() {
}

aux_build().arg("foo.rs").run();
verify(&tmp_dir().join("libfoo.rlib"));
verify(&tmp_path("libfoo.rlib"));
}

fn verify(path: &Path) {
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/no-intermediate-extras/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

//@ ignore-cross-compile

use run_make_support::{rustc, tmp_dir};
use run_make_support::{rustc, tmp_path};
use std::fs;

fn main() {
rustc().crate_type("rlib").arg("--test").input("foo.rs").run();
assert!(
fs::remove_file(tmp_dir().join("foo.bc")).is_err(),
fs::remove_file(tmp_path("foo.bc")).is_err(),
"An unwanted .bc file was created by run-make/no-intermediate-extras."
);
}
8 changes: 4 additions & 4 deletions tests/run-make/non-unicode-in-incremental-dir/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use run_make_support::{rustc, tmp_dir};
use run_make_support::{rustc, tmp_path};

fn main() {
#[cfg(unix)]
let non_unicode: &std::ffi::OsStr = std::os::unix::ffi::OsStrExt::from_bytes(&[0xFF]);
#[cfg(windows)]
let non_unicode: std::ffi::OsString = std::os::windows::ffi::OsStringExt::from_wide(&[0xD800]);
match std::fs::create_dir(tmp_dir().join(&non_unicode)) {
match std::fs::create_dir(tmp_path(&non_unicode)) {
// If an error occurs, check if creating a directory with a valid Unicode name would
// succeed.
Err(e) if std::fs::create_dir(tmp_dir().join("valid_unicode")).is_ok() => {
Err(e) if std::fs::create_dir(tmp_path("valid_unicode")).is_ok() => {
// Filesystem doesn't appear support non-Unicode paths.
return;
}
Err(e) => panic!("error creating non-Unicode directory: {e}"),
_ => {}
}
let incr_dir = tmp_dir().join("incr-dir");
let incr_dir = tmp_path("incr-dir");
rustc().input("foo.rs").incremental(&incr_dir).run();
for crate_dir in std::fs::read_dir(&incr_dir).unwrap() {
std::fs::create_dir(crate_dir.unwrap().path().join(&non_unicode)).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/print-cfg/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::ffi::OsString;
use std::io::BufRead;
use std::iter::FromIterator;

use run_make_support::{rustc, tmp_dir};
use run_make_support::{rustc, tmp_path};

struct PrintCfg {
target: &'static str,
Expand Down Expand Up @@ -91,7 +91,7 @@ fn check(PrintCfg { target, includes, disallow }: PrintCfg) {

// --print=cfg=PATH
{
let tmp_path = tmp_dir().join(format!("{target}.cfg"));
let tmp_path = tmp_path(format!("{target}.cfg"));
let mut print_arg = OsString::from("--print=cfg=");
print_arg.push(tmp_path.as_os_str());

Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/print-to-output/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::ffi::OsString;

use run_make_support::{rustc, target, tmp_dir};
use run_make_support::{rustc, target, tmp_path};

struct Option<'a> {
target: &'a str,
Expand Down Expand Up @@ -46,7 +46,7 @@ fn check(args: Option) {

// --print={option}=PATH
let output = {
let tmp_path = tmp_dir().join(format!("{}.txt", args.option));
let tmp_path = tmp_path(format!("{}.txt", args.option));
let mut print_arg = OsString::from(format!("--print={}=", args.option));
print_arg.push(tmp_path.as_os_str());

Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/repr128-dwarf/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

use gimli::{AttributeValue, Dwarf, EndianRcSlice, Reader, RunTimeEndian};
use object::{Object, ObjectSection};
use run_make_support::{gimli, object, rustc, tmp_dir};
use run_make_support::{gimli, object, rustc, tmp_path};
use std::borrow::Cow;
use std::collections::HashMap;
use std::rc::Rc;

fn main() {
let output = tmp_dir().join("repr128");
let output = tmp_path("repr128");
rustc().input("main.rs").output(&output).arg("-Cdebuginfo=2").run();
// Mach-O uses packed debug info
let dsym_location = output
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/reset-codegen-1/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

//@ ignore-cross-compile

use run_make_support::{rustc, tmp_dir};
use run_make_support::{rustc, tmp_path};
use std::fs;

fn compile(output_file: &str, emit: Option<&str>) {
let mut rustc = rustc();
let rustc = rustc.codegen_units(4).output(tmp_dir().join(output_file)).input("foo.rs");
let rustc = rustc.codegen_units(4).output(tmp_path(output_file)).input("foo.rs");
if let Some(emit) = emit {
rustc.emit(emit);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/run-make/rustdoc-determinism/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Assert that the search index is generated deterministically, regardless of the
// order that crates are documented in.

use run_make_support::{diff, rustdoc, tmp_dir};
use run_make_support::{diff, rustdoc, tmp_path};

fn main() {
let foo_first = tmp_dir().join("foo_first");
let foo_first = tmp_path("foo_first");
rustdoc().input("foo.rs").output(&foo_first).run();
rustdoc().input("bar.rs").output(&foo_first).run();

let bar_first = tmp_dir().join("bar_first");
let bar_first = tmp_path("bar_first");
rustdoc().input("bar.rs").output(&bar_first).run();
rustdoc().input("foo.rs").output(&bar_first).run();

Expand Down
2 changes: 1 addition & 1 deletion tests/run-make/rustdoc-map-file/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use run_make_support::{python_command, rustdoc, tmp_dir};

fn main() {
let out_dir = tmp_dir().join("out");
let out_dir = tmp_path("out");
rustdoc()
.input("foo.rs")
.arg("-Zunstable-options")
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/rustdoc-output-path/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Checks that if the output folder doesn't exist, rustdoc will create it.

use run_make_support::{rustdoc, tmp_dir};
use run_make_support::{rustdoc, tmp_path};

fn main() {
let out_dir = tmp_dir().join("foo/bar/doc");
let out_dir = tmp_path("foo/bar/doc");
rustdoc().input("foo.rs").output(&out_dir).run();
assert!(out_dir.exists());
}
4 changes: 2 additions & 2 deletions tests/run-make/rustdoc-scrape-examples-remap/scrape.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use run_make_support::{htmldocck, rustc, rustdoc, source_path, tmp_dir};
use run_make_support::{htmldocck, rustc, rustdoc, source_path, tmp_dir, tmp_path};
use std::fs::read_dir;
use std::path::Path;

pub fn scrape(extra_args: &[&str]) {
let lib_dir = tmp_dir();
let out_dir = tmp_dir().join("rustdoc");
let out_dir = tmp_path("rustdoc");
let crate_name = "foobar";
let deps = read_dir("examples")
.unwrap()
Expand Down
Loading

0 comments on commit 20ad958

Please sign in to comment.