From c3740b85be4c04efc3e8e988ccb35924666766fa Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Thu, 12 Jun 2025 00:06:31 +0200 Subject: [PATCH] config_paths: fix compiled-in locale dir Fish uses this logic to find paths to functions etc.: 1. if $(status fish-path) starts with $CARGO_MANIFEST_DIR, we use $CARGO_MANIFEST_DIR/share etc. Aside: this also has the unintended effect that "cmake -DCMAKE_INSTALL_PREFIX=$PWD/prefix" will not use "$PWD/prefix/share" but "$PWD/share", at least since eacbd6156d9 (Port and adopt main written in Rust, 2023-08-18). 2. Else if $(status fish-path) ends with "bin/fish", and $(status fish-path)/../share/fish exists, we use that, since 4912967eabc (Large set of changes related to making fish relocatable, and improving the build and install story, 2012-07-08) 3. Else if $(status fish-path) ends in "fish" (which is very likely), and $(status fish-path)/share exists, we use that, since c2a8de48735 (Make fish find config directories in source tree, 2016-09-23). I think this is for running (without installing) in-tree builds ("cmake ."); this is not recommended but it is used, see https://github.com/fish-shell/fish-shell/pull/10330 4. If none of the above worked, either because the fish binary has been moved into a weird directory, or if we fail to get $(status fish-path) (e.g. on OpenBSD, where "argv[0]" is not available), then we fall back to reasonable default paths determined at compiled time. These paths include data_dir=$PREFIX/share. We recently added locale_dir too in bf65b9e3a74 (Change `gettext` paths to be relocatable (#11195), 2025-03-30). In case 1, we use locale: manifest_dir.join("share/locale"), In case 2 and 3, we use locale: data_dir.join("locale"), In case 4, we use locale: data_dir.join("share"), The last one seems wrong (there is not "/usr/share/share"). Fix that. Alternatively, we could revert bf65b9e3a74 (and redo the parts we want to keep). --- src/env/config_paths.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/env/config_paths.rs b/src/env/config_paths.rs index 604cda9c3..5ed7507c1 100644 --- a/src/env/config_paths.rs +++ b/src/env/config_paths.rs @@ -7,6 +7,7 @@ const DATA_DIR: &str = env!("DATADIR"); const DATA_DIR_SUBDIR: &str = env!("DATADIR_SUBDIR"); const SYSCONF_DIR: &str = env!("SYSCONFDIR"); +const LOCALE_DIR: &str = env!("LOCALEDIR"); const BIN_DIR: &str = env!("BINDIR"); pub static CONFIG_PATHS: Lazy = Lazy::new(|| { @@ -108,6 +109,11 @@ } else { Some(PathBuf::from(BIN_DIR)) }; + let locale = if cfg!(feature = "embed-data") { + None + } else { + Some(PathBuf::from(LOCALE_DIR)) + }; FLOG!(config, "Using compiled in paths:"); paths = ConfigPaths { @@ -115,7 +121,7 @@ sysconf: PathBuf::from(SYSCONF_DIR).join("fish"), doc: DOC_DIR.into(), bin, - locale: data.map(|x| x.join("share")), + locale, } }