From a0ff0f623aac99f6198f9ca39ecaab5202dde7b7 Mon Sep 17 00:00:00 2001 From: knight42 Date: Thu, 8 Dec 2016 12:26:08 +0800 Subject: [PATCH] Temporary fix for errors in testing The errors were caused by the missing env $OUT_DIR which should be set by cargo. [Related issue](https://github.com/rust-lang/cargo/issues/3368). --- build.rs | 4 ++++ tests/common/util.rs | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 1548858b4..0856b4e0d 100644 --- a/build.rs +++ b/build.rs @@ -4,6 +4,10 @@ use std::io::Write; use std::path::Path; pub fn main() { + if let Ok(profile) = env::var("PROFILE") { + println!("cargo:rustc-cfg=build={:?}", profile); + } + let feature_prefix = "CARGO_FEATURE_"; let out_dir = env::var("OUT_DIR").unwrap(); diff --git a/tests/common/util.rs b/tests/common/util.rs index 91d472986..9e9e0b08e 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -374,7 +374,15 @@ impl TestScenario { // Instead of hardcoding the path relative to the current // directory, use Cargo's OUT_DIR to find path to executable. // This allows tests to be run using profiles other than debug. - let target_dir = path_concat!(env::var("OUT_DIR").unwrap(), "..", "..", "..", PROGNAME); + // let target_dir = path_concat!(env::var("OUT_DIR").unwrap(), "..", "..", "..", PROGNAME); + let target_dir; + // FIXME: $OUT_DIR is not set by nightly cargo + // See also: https://github.com/rust-lang/cargo/issues/3368 + if cfg!(build = "release") { + target_dir = path_concat!(env!("CARGO_MANIFEST_DIR"), "target", "release", PROGNAME); + } else { + target_dir = path_concat!(env!("CARGO_MANIFEST_DIR"), "target", "debug", PROGNAME); + } PathBuf::from(AtPath::new(Path::new(&target_dir)).root_dir_resolved()) }, util_name: String::from(util_name),