mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-04-20 16:11:14 -03:00
Extract constant for resolved build directory
Also use a different name than for the CMake variable, to reduce
confusion.
(cherry picked from commit a0b22077a5)
This commit is contained in:
2
build.rs
2
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(),
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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.
|
||||
|
||||
4
src/env/config_paths.rs
vendored
4
src/env/config_paths.rs
vendored
@@ -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!(
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<Target = ()> {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user