diff --git a/build.rs b/build.rs index f1a663aaf..f23642bd2 100644 --- a/build.rs +++ b/build.rs @@ -16,7 +16,7 @@ fn main() { // language server. rsconf::set_env_value( - "FISH_BUILD_DIR", + "FISH_RESOLVED_BUILD_DIR", // If set by CMake, this might include symlinks. Since we want to compare this to the // dir fish is executed in we need to canonicalize it. canonicalize(fish_build_dir()).to_str().unwrap(), diff --git a/crates/build-helper/src/lib.rs b/crates/build-helper/src/lib.rs index 529ce8f38..0831823c4 100644 --- a/crates/build-helper/src/lib.rs +++ b/crates/build-helper/src/lib.rs @@ -12,7 +12,7 @@ fn cargo_target_dir() -> Cow<'static, Path> { } pub fn fish_build_dir() -> Cow<'static, Path> { - // FISH_BUILD_DIR is set by CMake, if we are using it. + // This is set if using CMake. option_env!("FISH_BUILD_DIR") .map(|d| Cow::Borrowed(Path::new(d))) .unwrap_or(cargo_target_dir()) diff --git a/src/common.rs b/src/common.rs index 9b78c6a5d..e5a2a066f 100644 --- a/src/common.rs +++ b/src/common.rs @@ -32,6 +32,8 @@ use std::sync::{Arc, MutexGuard}; use std::time; +pub const BUILD_DIR: &str = env!("FISH_RESOLVED_BUILD_DIR"); + pub const PACKAGE_NAME: &str = env!("CARGO_PKG_NAME"); // Highest legal ASCII value. diff --git a/src/env/config_paths.rs b/src/env/config_paths.rs index 1d06cff8e..6819ce569 100644 --- a/src/env/config_paths.rs +++ b/src/env/config_paths.rs @@ -72,6 +72,8 @@ fn from_exec_path(exec_path: PathBuf) -> Self { fn from_exec_path(unresolved_exec_path: PathBuf) -> Self { use std::path::Path; + use crate::common::BUILD_DIR; + let invalid_exec_path = |exec_path: &Path| { FLOG!( config, @@ -116,7 +118,7 @@ fn from_exec_path(unresolved_exec_path: PathBuf) -> Self { } // If we're in Cargo's target directory or in CMake's build directory, use the source files. - if exec_path.starts_with(env!("FISH_BUILD_DIR")) { + if exec_path.starts_with(BUILD_DIR) { FLOG!( config, format!( diff --git a/src/path.rs b/src/path.rs index 59081ed20..5e0e55607 100644 --- a/src/path.rs +++ b/src/path.rs @@ -585,10 +585,10 @@ fn make_base_directory(xdg_var: &wstr, non_xdg_homepath: &wstr) -> BaseDirectory // the actual $HOME or $XDG_XXX directories. This prevents the tests from failing and/or stops // the tests polluting the user's actual $HOME if a sandbox environment has not been set up. { - use crate::common::str2wcstring; + use crate::common::{str2wcstring, BUILD_DIR}; use std::path::PathBuf; - let mut build_dir = PathBuf::from(env!("FISH_BUILD_DIR")); + let mut build_dir = PathBuf::from(BUILD_DIR); build_dir.push("fish-test-home"); let err = match std::fs::create_dir_all(&build_dir) { diff --git a/src/tests/mod.rs b/src/tests/mod.rs index b750bebe8..f2761bb67 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -29,7 +29,7 @@ mod wgetopt; pub mod prelude { - use crate::common::{ScopeGuard, ScopeGuarding}; + use crate::common::{ScopeGuard, ScopeGuarding, BUILD_DIR}; use crate::env::{env_init, misc_init}; use crate::parser::{CancelBehavior, Parser}; use crate::reader::{reader_deinit, reader_init}; @@ -88,9 +88,9 @@ fn deref(&self) -> &Self::Target { pub fn test_init() -> impl ScopeGuarding { static DONE: OnceCell<()> = OnceCell::new(); DONE.get_or_init(|| { - // If we are building with `cargo build` and have build w/ `cmake`, FISH_BUILD_DIR might - // not yet exist. - let mut test_dir = PathBuf::from(env!("FISH_BUILD_DIR")); + // If we are building with `cargo build` and have build w/ `cmake`, this might not + // yet exist. + let mut test_dir = PathBuf::from(BUILD_DIR); test_dir.push("fish-test"); std::fs::create_dir_all(&test_dir).unwrap(); set_current_dir(&test_dir).unwrap();