Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop current_exe pop hack in favor of CARGO_TARGET_DIR #8711

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Drop current_exe pop hack in favor of CARGO_TARGET_DIR
  • Loading branch information
dtolnay committed Sep 18, 2020
commit ff1bde787e35da1c41d5f146c032fc934191adbb
18 changes: 18 additions & 0 deletions crates/cargo-test-support/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::env;
use std::fs;
use std::path::Path;

static CARGO_INTEGRATION_TEST_DIR: &str = "cit";

fn main() {
let target_dir = env::var_os("CARGO_TARGET_DIR").unwrap();
let test_dir = Path::new(&target_dir).join(CARGO_INTEGRATION_TEST_DIR);
if let Err(e) = fs::create_dir_all(&test_dir) {
panic!(
"failed to create directory for integration tests ({}): {}",
test_dir.display(),
e,
);
}
println!("cargo:rustc-env=GLOBAL_ROOT={}", test_dir.display());
}
23 changes: 1 addition & 22 deletions crates/cargo-test-support/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,7 @@ use std::process::Command;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Mutex;

static CARGO_INTEGRATION_TEST_DIR: &str = "cit";

lazy_static! {
static ref GLOBAL_ROOT: PathBuf = {
let mut path = t!(env::current_exe());
path.pop(); // chop off exe name
path.pop(); // chop off 'debug'

// If `cargo test` is run manually then our path looks like
// `target/debug/foo`, in which case our `path` is already pointing at
// `target`. If, however, `cargo test --target $target` is used then the
// output is `target/$target/debug/foo`, so our path is pointing at
// `target/$target`. Here we conditionally pop the `$target` name.
if path.file_name().and_then(|s| s.to_str()) != Some("target") {
path.pop();
}

path.push(CARGO_INTEGRATION_TEST_DIR);
path.mkdir_p();
path
};

static ref TEST_ROOTS: Mutex<HashMap<String, PathBuf>> = Default::default();
}

Expand Down Expand Up @@ -80,7 +59,7 @@ pub fn root() -> PathBuf {
order to be able to use the crate root.",
)
});
GLOBAL_ROOT.join(&format!("t{}", id))
Path::new(env!("GLOBAL_ROOT")).join(format!("t{}", id))
}

pub fn home() -> PathBuf {
Expand Down