]> git.lizzy.rs Git - rust.git/blob - tests/cargo/mod.rs
Fix run-pass tests when CARGO_TARGET_DIR is not set
[rust.git] / tests / cargo / mod.rs
1 use cargo_metadata::MetadataCommand;
2 use lazy_static::lazy_static;
3 use std::env;
4 use std::path::PathBuf;
5
6 lazy_static! {
7     pub static ref CARGO_TARGET_DIR: PathBuf = {
8         match env::var_os("CARGO_TARGET_DIR") {
9             Some(v) => v.into(),
10             None => MetadataCommand::new().exec().unwrap().target_directory,
11         }
12     };
13     pub static ref TARGET_LIB: PathBuf = {
14         if let Some(path) = option_env!("TARGET_LIBS") {
15             path.into()
16         } else {
17             let mut dir = CARGO_TARGET_DIR.clone();
18             if let Some(target) = env::var_os("CARGO_BUILD_TARGET") {
19                 dir.push(target);
20             }
21             dir.push(env!("PROFILE"));
22             dir
23         }
24     };
25 }
26
27 #[must_use]
28 pub fn is_rustc_test_suite() -> bool {
29     option_env!("RUSTC_TEST_SUITE").is_some()
30 }