macOS: make openconnect relocatable; drive installation through make install (#668)

Co-authored-by: Kevin Yue <[email protected]>
This commit is contained in:
Ihar HrachyshkaandKevin Yue authored and GitHub committed 2026-10-12 10:12:17 +08:00
1 parent f7649898fd
commit f9965f8a35
12 files changed
+427 -162

No files matched your search

+34
View File
@@ -34,9 +34,23 @@ pub fn find_vpnc_script() -> Option<String> {
if let Some(path) = std::env::var_os("GP_VPNC_SCRIPT").filter(|path| !path.is_empty()) {
return configured_script(Path::new(&path));
}
if let Ok(executable) = std::env::current_exe()
&& let Some(script) = installed_vpnc_script(&executable)
{
return Some(script);
}
find_executable(VPNC_SCRIPT_LOCATIONS).map(str::to_owned)
}
fn installed_vpnc_script(executable: &Path) -> Option<String> {
let executable = executable.canonicalize().ok()?;
let bin = executable.parent()?;
if bin.file_name()? != "bin" {
return None;
}
configured_script(&bin.parent()?.join("libexec/gpclient/vpnc-script"))
}
fn configured_script(path: &Path) -> Option<String> {
if path.is_absolute() && path.is_file() && path.is_executable() {
return path.to_str().map(str::to_owned);
@@ -62,6 +76,26 @@ pub fn check_executable(file: &str) -> Result<(), io::Error> {
mod tests {
use super::*;
#[test]
fn installed_script_follows_the_executable_prefix_through_symlinks() {
let dir = tempfile::tempdir().unwrap();
let bin = dir.path().join("prefix/bin");
let libexec = dir.path().join("prefix/libexec/gpclient");
std::fs::create_dir_all(&bin).unwrap();
std::fs::create_dir_all(&libexec).unwrap();
std::fs::write(bin.join("gpclient"), "").unwrap();
let script = libexec.join("vpnc-script");
std::fs::write(&script, "#!/bin/sh\n").unwrap();
use std::os::unix::fs::PermissionsExt;
std::fs::set_permissions(&script, std::fs::Permissions::from_mode(0o755)).unwrap();
let link = dir.path().join("gpclient-link");
std::os::unix::fs::symlink(bin.join("gpclient"), &link).unwrap();
assert_eq!(
installed_vpnc_script(&link),
Some(script.canonicalize().unwrap().to_str().unwrap().to_owned())
);
}
#[test]
fn configured_script_requires_an_absolute_executable_path() {
assert_eq!(configured_script(Path::new("/bin/sh")), Some("/bin/sh".to_owned()));