build.rs: fix fallback PATH when embed-data is enabled

On a system where _CS_PATH is not defined (tested by removing that
code path), we get:

	$ cargo b && env -u PATH HOME=$PWD target/debug/fish -c 'set -S PATH'
	$PATH[1]: |.local//bin|
	$PATH[2]: |/usr/bin|
	$PATH[3]: |/bin|

The relative $PATH[1] makes no sense; probably it's an
accident. Restore the traditional $PATH[1]=/usr/local/bin.
This commit is contained in:
Johannes Altmanninger
2025-09-06 22:28:38 +02:00
parent 35d791ed49
commit aaf5ed7f11

View File

@@ -252,18 +252,7 @@ fn get_path(name: &str, default: &str, onvar: &Path) -> PathBuf {
var
}
let (prefix_from_home, prefix) = if let Ok(pre) = env::var("PREFIX") {
(false, PathBuf::from(pre))
} else {
(true, PathBuf::from(".local/"))
};
// If someone gives us a $PREFIX, we need it to be absolute.
// Otherwise we would try to get it from $HOME and that won't really work.
if !prefix_from_home && prefix.is_relative() {
panic!("Can't have relative prefix");
}
let prefix = PathBuf::from(env::var("PREFIX").unwrap_or("/usr/local".to_string()));
rsconf::rebuild_if_env_changed("PREFIX");
rsconf::set_env_value("PREFIX", prefix.to_str().unwrap());
@@ -277,9 +266,12 @@ fn get_path(name: &str, default: &str, onvar: &Path) -> PathBuf {
let sysconfdir = get_path(
"SYSCONFDIR",
// If we get our prefix from $HOME, we should use the system's /etc/
// ~/.local/share/etc/ makes no sense
if prefix_from_home { "/etc/" } else { "etc/" },
// Embedded builds use "/etc," not "./share/etc".
if cfg!(feature = "embed-data") {
"/etc/"
} else {
"etc/"
},
&datadir,
);
rsconf::set_env_value("SYSCONFDIR", sysconfdir.to_str().unwrap());