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

Generated
+1
View File
@@ -3395,6 +3395,7 @@ dependencies = [
"libc",
"log",
"pkg-config",
"tempfile",
]
[[package]]
+105 -105
View File
@@ -3,6 +3,8 @@ SHELL := /bin/sh
INCLUDE_GUI ?= 0
CARGO ?= cargo
CARGO_TARGET_DIR ?= target
CARGO_RELEASE_DIR ?= $(CARGO_TARGET_DIR)/$(if $(CARGO_BUILD_TARGET),$(CARGO_BUILD_TARGET)/)release
DISABLE_RUST_TOOLCHAIN ?= 0
RUST_VERSION ?= 1.91
IGNORE_RUST_VERSION ?= 0
@@ -33,7 +35,14 @@ BUILD_GUI_HELPER ?= 1
# Indicates whether to build embedded webview auth support into gpauth
BUILD_WEBVIEW_AUTH ?= 1
ifeq ($(shell uname -s),Linux)
PREFIX ?= /usr
GPGUI_BINARY ?= $(wildcard .build/gpgui/gpgui_*/gpgui)
else ifeq ($(shell uname -s)-$(shell uname -m),Darwin-arm64)
PREFIX ?= /opt/homebrew
else
PREFIX ?= /usr/local
endif
BSD_FLAVOR ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
GPGUI_BINARY ?= ../gpgui/target/release/gpgui
@@ -139,86 +148,66 @@ clean:
rm -rf .vendor
rm -rf apps/gpgui-helper/node_modules
install:
@echo "Installing $(PKG_NAME)..."
ifeq ($(shell uname -s),Darwin)
install: install-macos
else ifneq ($(filter FreeBSD OpenBSD,$(shell uname -s)),)
install: install-bsd
else
install: install-linux
endif
install -Dm755 target/release/gpclient $(DESTDIR)/usr/bin/gpclient
install -Dm755 target/release/gpauth $(DESTDIR)/usr/bin/gpauth
install -Dm755 target/release/gpservice $(DESTDIR)/usr/bin/gpservice
install -Dm755 target/release/gp-hip-script-installer $(DESTDIR)/usr/libexec/gpclient/gp-hip-script-installer
install -Dm755 target/release/gp-vpnc-script-installer $(DESTDIR)/usr/libexec/gpclient/gp-vpnc-script-installer
install-macos:
@echo "Installing $(PKG_NAME) for macOS under $(PREFIX)..."
install -d "$(DESTDIR)$(PREFIX)/bin" "$(DESTDIR)$(PREFIX)/lib/gpclient" "$(DESTDIR)$(PREFIX)/libexec/gpclient"
install -m 755 "$(CARGO_RELEASE_DIR)/gpclient" "$(CARGO_RELEASE_DIR)/gpauth" "$(DESTDIR)$(PREFIX)/bin/"
set -e; library=$$(sh scripts/macos-openconnect-library.sh "$(CARGO_RELEASE_DIR)/gpclient"); \
install -m 755 "$$library" "$(DESTDIR)$(PREFIX)/lib/gpclient/"; \
install_name_tool -delete_rpath "$$(dirname "$$library")" "$(DESTDIR)$(PREFIX)/bin/gpclient"; \
codesign --force --sign - "$(DESTDIR)$(PREFIX)/bin/gpclient"
install -m 755 packaging/files/usr/libexec/gpclient/vpnc-script "$(DESTDIR)$(PREFIX)/libexec/gpclient/"
# Install the GUI components if BUILD_GUI_HELPER is set to 1
if [ $(BUILD_GUI_HELPER) -eq 1 ]; then \
install -Dm755 target/release/gpgui-helper $(DESTDIR)/usr/bin/gpgui-helper; \
# Common executable and icon installation uses portable install options on Linux/BSD.
install-unix:
install -d "$(DESTDIR)$(PREFIX)/bin" "$(DESTDIR)$(PREFIX)/libexec/gpclient"
set -e; for binary in gpclient gpauth gpservice; do \
install -m 755 "$(CARGO_RELEASE_DIR)/$$binary" "$(DESTDIR)$(PREFIX)/bin/"; \
done
set -e; for binary in gp-hip-script-installer gp-vpnc-script-installer; do \
install -m 755 "$(CARGO_RELEASE_DIR)/$$binary" "$(DESTDIR)$(PREFIX)/libexec/gpclient/"; \
done
set -e; if [ "$(BUILD_GUI_HELPER)" = "1" ]; then \
install -m 755 "$(CARGO_RELEASE_DIR)/gpgui-helper" "$(DESTDIR)$(PREFIX)/bin/"; \
fi
if [ -f .build/gpgui/gpgui_*/gpgui ]; then \
install -Dm755 .build/gpgui/gpgui_*/gpgui $(DESTDIR)/usr/bin/gpgui; \
set -e; if [ -f "$(GPGUI_BINARY)" ]; then \
install -m 755 "$(GPGUI_BINARY)" "$(DESTDIR)$(PREFIX)/bin/gpgui"; \
fi
install -m 755 packaging/files/usr/libexec/gpclient/vpnc-script "$(DESTDIR)$(PREFIX)/libexec/gpclient/"
set -e; for file in packaging/files/usr/share/icons/hicolor/*/apps/gpgui.* \
packaging/files/usr/share/icons/hicolor/scalable/status/gpgui-*.svg; do \
destination="$(DESTDIR)$(PREFIX)/$${file#packaging/files/usr/}"; \
install -d "$$(dirname "$$destination")"; \
install -m 644 "$$file" "$$destination"; \
done
install -Dm755 packaging/files/usr/libexec/gpclient/vpnc-script $(DESTDIR)/usr/libexec/gpclient/vpnc-script
install-linux: install-unix
@echo "Installing Linux integration under $(PREFIX)..."
set -e; for file in share/applications/gpgui.desktop \
share/polkit-1/actions/com.yuezk.gpgui.policy \
lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down \
lib/NetworkManager/dispatcher.d/gpclient-nm-hook; do \
mode=644; case "$$file" in lib/*) mode=755 ;; esac; \
destination="$(DESTDIR)$(PREFIX)/$$file"; \
install -d "$$(dirname "$$destination")"; \
install -m "$$mode" "packaging/files/usr/$$file" "$$destination"; \
done
sh scripts/relocate-install-paths.sh "$(PREFIX)" /usr "$(DESTDIR)$(PREFIX)"
# Install the disconnect hooks
install -Dm755 packaging/files/usr/lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down $(DESTDIR)/usr/lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down
install -Dm755 packaging/files/usr/lib/NetworkManager/dispatcher.d/gpclient-nm-hook $(DESTDIR)/usr/lib/NetworkManager/dispatcher.d/gpclient-nm-hook
install -Dm644 packaging/files/usr/share/applications/gpgui.desktop $(DESTDIR)/usr/share/applications/gpgui.desktop
install -Dm644 packaging/files/usr/share/icons/hicolor/scalable/apps/gpgui.svg $(DESTDIR)/usr/share/icons/hicolor/scalable/apps/gpgui.svg
install -Dm644 packaging/files/usr/share/icons/hicolor/32x32/apps/gpgui.png $(DESTDIR)/usr/share/icons/hicolor/32x32/apps/gpgui.png
install -Dm644 packaging/files/usr/share/icons/hicolor/128x128/apps/gpgui.png $(DESTDIR)/usr/share/icons/hicolor/128x128/apps/gpgui.png
install -Dm644 packaging/files/usr/share/icons/hicolor/256x256/apps/gpgui.png $(DESTDIR)/usr/share/icons/hicolor/256x256/apps/gpgui.png
install -Dm644 packaging/files/usr/share/icons/hicolor/256x256@2/apps/gpgui.png $(DESTDIR)/usr/share/icons/hicolor/256x256@2/apps/gpgui.png
install -Dm644 packaging/files/usr/share/icons/hicolor/scalable/status/gpgui-connected-symbolic.svg $(DESTDIR)/usr/share/icons/hicolor/scalable/status/gpgui-connected-symbolic.svg
install -Dm644 packaging/files/usr/share/icons/hicolor/scalable/status/gpgui-disconnected-symbolic.svg $(DESTDIR)/usr/share/icons/hicolor/scalable/status/gpgui-disconnected-symbolic.svg
install -Dm644 packaging/files/usr/share/icons/hicolor/scalable/status/gpgui-connecting-1-symbolic.svg $(DESTDIR)/usr/share/icons/hicolor/scalable/status/gpgui-connecting-1-symbolic.svg
install -Dm644 packaging/files/usr/share/icons/hicolor/scalable/status/gpgui-connecting-2-symbolic.svg $(DESTDIR)/usr/share/icons/hicolor/scalable/status/gpgui-connecting-2-symbolic.svg
install -Dm644 packaging/files/usr/share/icons/hicolor/scalable/status/gpgui-connecting-3-symbolic.svg $(DESTDIR)/usr/share/icons/hicolor/scalable/status/gpgui-connecting-3-symbolic.svg
install -Dm644 packaging/files/usr/share/icons/hicolor/scalable/status/gpgui-connecting-4-symbolic.svg $(DESTDIR)/usr/share/icons/hicolor/scalable/status/gpgui-connecting-4-symbolic.svg
install -Dm644 packaging/files/usr/share/polkit-1/actions/com.yuezk.gpgui.policy $(DESTDIR)/usr/share/polkit-1/actions/com.yuezk.gpgui.policy
install-bsd:
@echo "Installing $(PKG_NAME) for BSD under $(PREFIX)..."
install -d $(DESTDIR)$(PREFIX)/bin
install -m 755 target/release/gpclient $(DESTDIR)$(PREFIX)/bin/gpclient
install -m 755 target/release/gpauth $(DESTDIR)$(PREFIX)/bin/gpauth
install -m 755 target/release/gpservice $(DESTDIR)$(PREFIX)/bin/gpservice
if [ "$(BUILD_GUI_HELPER)" = "1" ]; then \
install -m 755 target/release/gpgui-helper $(DESTDIR)$(PREFIX)/bin/gpgui-helper; \
fi
if [ -x "$(GPGUI_BINARY)" ]; then \
install -m 755 "$(GPGUI_BINARY)" $(DESTDIR)$(PREFIX)/bin/gpgui; \
fi
install -d $(DESTDIR)$(PREFIX)/libexec/gpclient
install -m 755 target/release/gp-hip-script-installer $(DESTDIR)$(PREFIX)/libexec/gpclient/gp-hip-script-installer
install -m 755 target/release/gp-vpnc-script-installer $(DESTDIR)$(PREFIX)/libexec/gpclient/gp-vpnc-script-installer
install -m 755 packaging/files/usr/libexec/gpclient/vpnc-script $(DESTDIR)$(PREFIX)/libexec/gpclient/vpnc-script
install -d $(DESTDIR)$(PREFIX)/share/applications
install -m 644 packaging/bsd/gpgui.desktop $(DESTDIR)$(PREFIX)/share/applications/gpgui.desktop
install -d $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/apps
install -d $(DESTDIR)$(PREFIX)/share/icons/hicolor/32x32/apps
install -d $(DESTDIR)$(PREFIX)/share/icons/hicolor/128x128/apps
install -d $(DESTDIR)$(PREFIX)/share/icons/hicolor/256x256/apps
install -d $(DESTDIR)$(PREFIX)/share/icons/hicolor/256x256@2/apps
install -d $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/status
install -m 644 packaging/files/usr/share/icons/hicolor/scalable/apps/gpgui.svg $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/apps/gpgui.svg
install -m 644 packaging/files/usr/share/icons/hicolor/32x32/apps/gpgui.png $(DESTDIR)$(PREFIX)/share/icons/hicolor/32x32/apps/gpgui.png
install -m 644 packaging/files/usr/share/icons/hicolor/128x128/apps/gpgui.png $(DESTDIR)$(PREFIX)/share/icons/hicolor/128x128/apps/gpgui.png
install -m 644 packaging/files/usr/share/icons/hicolor/256x256/apps/gpgui.png $(DESTDIR)$(PREFIX)/share/icons/hicolor/256x256/apps/gpgui.png
install -m 644 packaging/files/usr/share/icons/hicolor/256x256@2/apps/gpgui.png $(DESTDIR)$(PREFIX)/share/icons/hicolor/256x256@2/apps/gpgui.png
install -m 644 packaging/files/usr/share/icons/hicolor/scalable/status/gpgui-connected-symbolic.svg $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/status/gpgui-connected-symbolic.svg
install -m 644 packaging/files/usr/share/icons/hicolor/scalable/status/gpgui-disconnected-symbolic.svg $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/status/gpgui-disconnected-symbolic.svg
install -m 644 packaging/files/usr/share/icons/hicolor/scalable/status/gpgui-connecting-1-symbolic.svg $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/status/gpgui-connecting-1-symbolic.svg
install -m 644 packaging/files/usr/share/icons/hicolor/scalable/status/gpgui-connecting-2-symbolic.svg $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/status/gpgui-connecting-2-symbolic.svg
install -m 644 packaging/files/usr/share/icons/hicolor/scalable/status/gpgui-connecting-3-symbolic.svg $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/status/gpgui-connecting-3-symbolic.svg
install -m 644 packaging/files/usr/share/icons/hicolor/scalable/status/gpgui-connecting-4-symbolic.svg $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/status/gpgui-connecting-4-symbolic.svg
install -d $(DESTDIR)$(PREFIX)/share/polkit-1/actions
install -m 644 packaging/bsd/com.yuezk.gpgui.policy $(DESTDIR)$(PREFIX)/share/polkit-1/actions/com.yuezk.gpgui.policy
install-bsd: install-unix
@echo "Installing BSD integration under $(PREFIX)..."
install -d "$(DESTDIR)$(PREFIX)/share/applications" "$(DESTDIR)$(PREFIX)/share/polkit-1/actions"
install -m 644 packaging/bsd/gpgui.desktop "$(DESTDIR)$(PREFIX)/share/applications/"
install -m 644 packaging/bsd/com.yuezk.gpgui.policy "$(DESTDIR)$(PREFIX)/share/polkit-1/actions/"
sh scripts/relocate-install-paths.sh "$(PREFIX)" /usr/local "$(DESTDIR)$(PREFIX)"
clean-bsd-package:
rm -rf .build/$(BSD_FLAVOR)
@@ -290,42 +279,53 @@ package-openbsd: clean-bsd-package
.build/openbsd/artifacts/$(PKG_NAME)-$(VERSION)-openbsd-$$openbsd_arch.tgz
$(MAKE) bsd-gpgui-tarball BSD_FLAVOR=openbsd GPGUI_BINARY="$(GPGUI_BINARY)"
uninstall:
@echo "Uninstalling $(PKG_NAME)..."
ifeq ($(shell uname -s),Darwin)
uninstall: uninstall-macos
else ifneq ($(filter FreeBSD OpenBSD,$(shell uname -s)),)
uninstall: uninstall-bsd
else
uninstall: uninstall-linux
endif
rm -f $(DESTDIR)/usr/bin/gpclient
rm -f $(DESTDIR)/usr/bin/gpauth
rm -f $(DESTDIR)/usr/bin/gpservice
rm -f $(DESTDIR)/usr/libexec/gpclient/gp-hip-script-installer
rm -f $(DESTDIR)/usr/bin/gpgui-helper
rm -f $(DESTDIR)/usr/bin/gpgui
.PHONY: install install-macos install-unix install-linux install-bsd \
uninstall uninstall-macos uninstall-unix uninstall-linux uninstall-bsd
rm -f $(DESTDIR)/usr/libexec/gpclient/vpnc-script
rm -f $(DESTDIR)/usr/libexec/gpclient/gp-vpnc-script-installer
uninstall-macos:
@echo "Uninstalling $(PKG_NAME) for macOS under $(PREFIX)..."
rm -f "$(DESTDIR)$(PREFIX)/bin/gpclient" "$(DESTDIR)$(PREFIX)/bin/gpauth" \
"$(DESTDIR)$(PREFIX)/libexec/gpclient/vpnc-script" \
"$(DESTDIR)$(PREFIX)/lib/gpclient/"libopenconnect.*.dylib
rmdir "$(DESTDIR)$(PREFIX)/lib/gpclient" "$(DESTDIR)$(PREFIX)/libexec/gpclient" 2>/dev/null || true
rm -f $(DESTDIR)/usr/lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down
rm -f $(DESTDIR)/usr/lib/NetworkManager/dispatcher.d/gpclient-nm-hook
uninstall-unix:
@echo "Uninstalling $(PKG_NAME) under $(PREFIX)..."
set -e; for binary in gpclient gpauth gpservice gpgui-helper gpgui; do \
rm -f "$(DESTDIR)$(PREFIX)/bin/$$binary"; \
done
set -e; for file in gp-hip-script-installer gp-vpnc-script-installer vpnc-script; do \
rm -f "$(DESTDIR)$(PREFIX)/libexec/gpclient/$$file"; \
done
set -e; for file in packaging/files/usr/share/icons/hicolor/*/apps/gpgui.* \
packaging/files/usr/share/icons/hicolor/scalable/status/gpgui-*.svg; do \
rm -f "$(DESTDIR)$(PREFIX)/$${file#packaging/files/usr/}"; \
done
rm -f "$(DESTDIR)$(PREFIX)/share/applications/gpgui.desktop" \
"$(DESTDIR)$(PREFIX)/share/polkit-1/actions/com.yuezk.gpgui.policy"
rmdir "$(DESTDIR)$(PREFIX)/libexec/gpclient" 2>/dev/null || true
rm -f $(DESTDIR)/usr/share/applications/gpgui.desktop
rm -f $(DESTDIR)/usr/share/icons/hicolor/scalable/apps/gpgui.svg
rm -f $(DESTDIR)/usr/share/icons/hicolor/32x32/apps/gpgui.png
rm -f $(DESTDIR)/usr/share/icons/hicolor/128x128/apps/gpgui.png
rm -f $(DESTDIR)/usr/share/icons/hicolor/256x256/apps/gpgui.png
rm -f $(DESTDIR)/usr/share/icons/hicolor/256x256@2/apps/gpgui.png
rm -f $(DESTDIR)/usr/share/icons/hicolor/scalable/status/gpgui-connected-symbolic.svg
rm -f $(DESTDIR)/usr/share/icons/hicolor/scalable/status/gpgui-disconnected-symbolic.svg
rm -f $(DESTDIR)/usr/share/icons/hicolor/scalable/status/gpgui-connecting-1-symbolic.svg
rm -f $(DESTDIR)/usr/share/icons/hicolor/scalable/status/gpgui-connecting-2-symbolic.svg
rm -f $(DESTDIR)/usr/share/icons/hicolor/scalable/status/gpgui-connecting-3-symbolic.svg
rm -f $(DESTDIR)/usr/share/icons/hicolor/scalable/status/gpgui-connecting-4-symbolic.svg
rm -f $(DESTDIR)/usr/share/polkit-1/actions/com.yuezk.gpgui.policy
uninstall-linux: uninstall-unix
rm -f "$(DESTDIR)$(PREFIX)/lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down" \
"$(DESTDIR)$(PREFIX)/lib/NetworkManager/dispatcher.d/gpclient-nm-hook"
rm -f "$(DESTDIR)/var/lib/gpclient/gpgui" \
"$(DESTDIR)/var/lib/gpclient/scripts/vpnc-script" \
"$(DESTDIR)/var/lib/gpclient/scripts/vpnc-script.metadata"
rmdir "$(DESTDIR)/var/lib/gpclient/scripts" "$(DESTDIR)/var/lib/gpclient" 2>/dev/null || true
rm -f $(DESTDIR)/var/lib/gpclient/gpgui \
$(DESTDIR)/var/lib/gpclient/scripts/vpnc-script \
$(DESTDIR)/var/lib/gpclient/scripts/vpnc-script.metadata || \
echo "Warning: failed to remove gpclient runtime files" >&2
rmdir $(DESTDIR)/var/lib/gpclient/scripts 2>/dev/null || true
rmdir $(DESTDIR)/var/lib/gpclient 2>/dev/null || true
uninstall-bsd: uninstall-unix
rm -f "$(DESTDIR)/usr/local/libexec/gpclient/gpgui" \
"$(DESTDIR)/var/db/gpclient/scripts/vpnc-script" \
"$(DESTDIR)/var/db/gpclient/scripts/vpnc-script.metadata"
rmdir "$(DESTDIR)/var/db/gpclient/scripts" "$(DESTDIR)/var/db/gpclient" 2>/dev/null || true
clean-debian:
rm -rf .build/deb
+9
View File
@@ -4,6 +4,15 @@ const UNKNOWN_COMMIT: &str = "unknown";
const DISPLAY_COMMIT_LEN: usize = 9;
fn main() {
// Installed OpenConnect lives in the private ../lib/gpclient directory.
// Build executables also locate their exact Cargo library; installers remove that rpath.
#[cfg(target_os = "macos")]
{
println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path/../lib/gpclient");
let library_dir = env::var("DEP_OPENCONNECT_LIB_DIR").expect("OpenConnect exports its build library directory");
println!("cargo:rustc-link-arg=-Wl,-rpath,{library_dir}");
}
println!("cargo:rerun-if-env-changed=SOURCE_GIT_COMMIT");
println!("cargo:rerun-if-env-changed=GPCLIENT_GIT_COMMIT");
println!("cargo:rerun-if-env-changed=GITHUB_SHA");
+9
View File
@@ -4,6 +4,15 @@ const UNKNOWN_COMMIT: &str = "unknown";
const DISPLAY_COMMIT_LEN: usize = 9;
fn main() {
// Installed OpenConnect lives in the private ../lib/gpclient directory.
// Build executables also locate their exact Cargo library; installers remove that rpath.
#[cfg(target_os = "macos")]
{
println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path/../lib/gpclient");
let library_dir = env::var("DEP_OPENCONNECT_LIB_DIR").expect("OpenConnect exports its build library directory");
println!("cargo:rustc-link-arg=-Wl,-rpath,{library_dir}");
}
println!("cargo:rerun-if-env-changed=GPSERVICE_GIT_COMMIT");
println!("cargo:rerun-if-env-changed=SOURCE_GIT_COMMIT");
println!("cargo:rerun-if-env-changed=GITHUB_SHA");
+23
View File
@@ -93,6 +93,12 @@ fn sibling_binary_for_executable(executable: &Path, binary_name: &str) -> Option
if is_file(&binary) {
return Some(binary);
}
if matches!(binary_name, "gp-vpnc-script-installer" | "gp-hip-script-installer") {
let binary = bin_dir.parent()?.join("libexec/gpclient").join(binary_name);
if is_file(&binary) {
return Some(binary);
}
}
#[cfg(target_os = "macos")]
if let Some(binary) = macos::helper_path(&executable, binary_name)
&& is_file(&binary)
@@ -121,6 +127,23 @@ fn is_file(path: &Path) -> bool {
mod tests {
use super::*;
#[test]
fn script_installers_follow_the_installed_prefix() {
let directory = tempfile::tempdir().unwrap();
let bin = directory.path().join("bin");
let libexec = directory.path().join("libexec/gpclient");
std::fs::create_dir_all(&bin).unwrap();
std::fs::create_dir_all(&libexec).unwrap();
std::fs::write(bin.join("gpclient"), "").unwrap();
for name in ["gp-vpnc-script-installer", "gp-hip-script-installer"] {
std::fs::write(libexec.join(name), "").unwrap();
assert_eq!(
sibling_binary_for_executable(&bin.join("gpclient"), name),
Some(libexec.canonicalize().unwrap().join(name))
);
}
}
#[test]
#[cfg(target_os = "macos")]
fn desktop_resolves_helpers_in_the_actual_app_bundle_layout() {
+3
View File
@@ -15,3 +15,6 @@ cc = "1"
autotools = "0.2"
pkg-config = "0.3"
fs_extra = "1"
[dev-dependencies]
tempfile = "3"
+21
View File
@@ -137,6 +137,27 @@ fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
let lib_dir = dst.join("lib");
let include_dir = dst.join("include");
#[cfg(target_os = "macos")]
{
// Do not embed Cargo's temporary build directory in consumers of this library.
let library = std::fs::canonicalize(lib_dir.join("libopenconnect.dylib")).unwrap();
let library_name = library.file_name().unwrap().to_str().unwrap();
let status = std::process::Command::new("install_name_tool")
.arg("-id")
.arg(format!("@rpath/{library_name}"))
.arg(&library)
.status()
.expect("Failed to update the OpenConnect dylib install name");
assert!(status.success(), "Failed to update the OpenConnect dylib install name");
let status = std::process::Command::new("codesign")
.args(["--force", "--sign", "-"])
.arg(&library)
.status()
.expect("Failed to sign the OpenConnect dylib");
assert!(status.success(), "Failed to sign the OpenConnect dylib");
println!("cargo:lib_dir={}", lib_dir.display());
}
println!("cargo:rustc-link-search=native={}", lib_dir.display());
#[cfg(target_os = "macos")]
+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()));
+9 -57
View File
@@ -118,6 +118,7 @@
[
libxml2
zlib
openssl
lz4
gnutls
p11-kit
@@ -130,30 +131,10 @@
libsoup_3
webkitgtk_4_1
glib-networking
openssl
libsecret
libayatana-appindicator
];
rewriteSourceInstallPaths = lib.optionalString pkgs.stdenv.isLinux ''
substituteInPlace $out/share/applications/gpgui.desktop \
--replace-fail /usr/bin/gpclient $out/bin/gpclient
substituteInPlace $out/share/polkit-1/actions/com.yuezk.gpgui.policy \
--replace-fail /usr/bin/gpservice $out/bin/gpservice \
--replace-fail /usr/libexec/gpclient/gp-vpnc-script-installer $out/libexec/gpclient/gp-vpnc-script-installer
if [ -f $out/libexec/gpclient/gp-hip-script-installer ]; then
substituteInPlace $out/share/polkit-1/actions/com.yuezk.gpgui.policy \
--replace-fail /usr/libexec/gpclient/gp-hip-script-installer $out/libexec/gpclient/gp-hip-script-installer
fi
if [ -f $out/lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down ]; then
substituteInPlace $out/lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down \
--replace-fail /usr/bin/gpclient $out/bin/gpclient
fi
'';
installNixosPolkitRule = ''
chmod u+w $out/share $out/share/polkit-1 2>/dev/null || true
install -d $out/share/polkit-1/rules.d
@@ -182,6 +163,9 @@
# Must be set to true to avoid issues with the Tauri build process
singleStep = true;
# The Makefile installs executables together with their supporting files.
copyBins = false;
cargoBuildOptions =
old:
old
@@ -202,6 +186,9 @@
libtool
pkg-config
]
++ lib.optionals stdenv.isDarwin [
darwin.sigtool
]
++ lib.optionals stdenv.isLinux [
autoPatchelfHook
wrapGAppsHook4
@@ -211,49 +198,14 @@
preFixup = nativeRuntimeWrapping;
overrideMain =
{ ... }:
{
postPatch = ''
substituteInPlace crates/openconnect/src/vpn_utils.rs \
--replace-fail /usr/libexec/gpclient/vpnc-script $out/libexec/gpclient/vpnc-script
substituteInPlace crates/common/src/constants.rs \
--replace-fail /usr/bin/gpclient $out/bin/gpclient \
--replace-fail /usr/bin/gpauth $out/bin/gpauth \
--replace-fail /opt/homebrew/ $out/
''
+ lib.optionalString pkgs.stdenv.isLinux ''
substituteInPlace crates/common/src/constants.rs \
--replace-fail /usr/bin/gpservice $out/bin/gpservice \
--replace-fail /usr/bin/gpgui-helper $out/bin/gpgui-helper \
--replace-fail /usr/bin/gpgui $out/bin/gpgui
substituteInPlace crates/common/src/constants.rs \
--replace-fail /usr/libexec/gpclient/gp-hip-script-installer $out/libexec/gpclient/gp-hip-script-installer
'';
};
postInstall = ''
cp -r packaging/files/usr/libexec $out/libexec
make install PREFIX="$out" ${lib.optionalString pkgs.stdenv.isLinux ''GPGUI_BINARY="${gui}/gpgui"''}
''
+ lib.optionalString pkgs.stdenv.isLinux ''
for installer in gp-vpnc-script-installer gp-hip-script-installer; do
install -Dm755 "$out/bin/$installer" "$out/libexec/gpclient/$installer"
done
# Copy the prebuilt gpgui binary to the output bin directory
cp ${gui}/gpgui $out/bin/gpgui
chmod +x $out/bin/gpgui
cp -r packaging/files/usr/share $out/share
cp -r packaging/files/usr/lib $out/lib
${installNixosPolkitRule}
''
+ ''
${rewriteVpncScriptToolPaths}
${rewriteSourceInstallPaths}
'';
}) {};
@@ -288,7 +240,7 @@
install -Dm755 ${gui}/gpgui $out/bin/gpgui
${rewriteVpncScriptToolPaths}
${rewriteSourceInstallPaths}
sh ${./scripts/relocate-install-paths.sh} "$out" /usr "$out"
${installNixosPolkitRule}
runHook postInstall
+18
View File
@@ -0,0 +1,18 @@
#!/bin/sh
# Resolve the library used by this build, rather than choosing a stale Cargo output.
set -eu
binary=$1
library=$(otool -L "$binary" | awk '/^[[:space:]]+@rpath\/libopenconnect\..*\.dylib / { sub("@rpath/", "", $1); print $1 }')
test -n "$library" || { echo "No OpenConnect dependency in $binary" >&2; exit 1; }
rpaths=$(otool -l "$binary" | awk '/cmd LC_RPATH/ { rpath=1; next } rpath && $1 == "path" { sub(/^[[:space:]]*path /, ""); sub(/ \(offset [0-9]+\)$/, ""); print; rpath=0 }')
while IFS= read -r directory; do
case "$directory" in /*) ;; *) continue ;; esac
if [ -f "$directory/$library" ]; then
printf '%s\n' "$directory/$library"
exit 0
fi
done <<EOF
$rpaths
EOF
echo "Cannot resolve the OpenConnect build library for $binary" >&2
exit 1
+38
View File
@@ -0,0 +1,38 @@
#!/bin/sh
# Integration files use the runtime prefix, never the packaging staging directory.
set -eu
prefix=$1
source_prefix=$2
directory=$3
escape_replacement() {
printf '%s' "$1" | sed 's/[\\&|]/\\&/g'
}
# Each integration format has its own quoting rules.
desktop_prefix=$(printf '%s' "$prefix" | sed -e 's/\\/\\\\\\\\/g' -e 's/["`$]/\\\\&/g' -e 's/%/%%/g')
desktop_command=$(escape_replacement "\"$desktop_prefix/bin/gpclient\"")
shell_prefix=$(printf '%s' "$prefix" | sed "s/'/'\\\\''/g")
shell_command=$(escape_replacement "'$shell_prefix/bin/gpclient'")
xml_prefix=$(printf '%s' "$prefix" | sed -e 's/\&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g')
xml_replacement=$(escape_replacement "$xml_prefix")
temporary=$(mktemp)
trap 'rm -f "$temporary"' EXIT HUP INT TERM
for file in share/applications/gpgui.desktop \
share/polkit-1/actions/com.yuezk.gpgui.policy \
lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down \
lib/NetworkManager/dispatcher.d/gpclient-nm-hook; do
path="$directory/$file"
[ -f "$path" ] || continue
case "$file" in
share/applications/*)
sed "s|$source_prefix/bin/gpclient|$desktop_command|g" "$path" > "$temporary" ;;
share/polkit-1/*)
sed -e "s|$source_prefix/bin/|$xml_replacement/bin/|g" \
-e "s|$source_prefix/libexec/gpclient/|$xml_replacement/libexec/gpclient/|g" \
"$path" > "$temporary" ;;
lib/*)
sed "s|$source_prefix/bin/gpclient|$shell_command|g" "$path" > "$temporary" ;;
esac
mode=644
case "$file" in lib/*) mode=755 ;; esac
install -m "$mode" "$temporary" "$path"
done
+157
View File
@@ -0,0 +1,157 @@
#!/bin/sh
set -eu
root=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
cd "$root"
temp=$(mktemp -d)
trap 'rm -rf "$temp"' EXIT HUP INT TERM
mkdir -p "$temp/release"
for binary in gpclient gpauth gpservice gpgui gpgui-helper gp-vpnc-script-installer gp-hip-script-installer; do
printf '#!/bin/sh\nexit 0\n' > "$temp/release/$binary"
chmod 755 "$temp/release/$binary"
done
for platform in linux bsd; do
stage="$temp/$platform-stage"
make "install-$platform" PREFIX=/custom/gp DESTDIR="$stage" \
CARGO_RELEASE_DIR="$temp/release" GPGUI_BINARY="$temp/release/gpgui" > "$temp/$platform.log"
installed="$stage/custom/gp"
test -x "$installed/bin/gpclient"
test -x "$installed/libexec/gpclient/gp-vpnc-script-installer"
grep -q 'Exec="/custom/gp/bin/gpclient" ' "$installed/share/applications/gpgui.desktop"
grep -q '>/custom/gp/bin/gpservice<' "$installed/share/polkit-1/actions/com.yuezk.gpgui.policy"
grep -q '>/custom/gp/libexec/gpclient/gp-hip-script-installer<' "$installed/share/polkit-1/actions/com.yuezk.gpgui.policy"
! grep -F "$stage" "$installed/share/applications/gpgui.desktop"
if [ "$platform" = bsd ]; then
test ! -d "$installed/lib/NetworkManager"
else
test -x "$installed/lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down"
fi
runtime="$stage/var/lib/gpclient"
if [ "$platform" = bsd ]; then
runtime="$stage/var/db/gpclient"
mkdir -p "$stage/usr/local/libexec/gpclient"
cp "$temp/release/gpgui" "$stage/usr/local/libexec/gpclient/gpgui"
else
mkdir -p "$runtime"
cp "$temp/release/gpgui" "$runtime/gpgui"
fi
mkdir -p "$runtime/scripts"
touch "$runtime/scripts/vpnc-script" "$runtime/scripts/vpnc-script.metadata"
find "$stage" -type f > "$temp/$platform-installed-files"
touch "$installed/bin/unrelated" "$installed/libexec/gpclient/unrelated" "$runtime/scripts/unrelated"
# Repeat removal to cover an already-uninstalled or partial installation.
for attempt in 1 2; do
make "uninstall-$platform" PREFIX=/custom/gp DESTDIR="$stage" > "$temp/$platform-uninstall.log"
done
while IFS= read -r file; do test ! -e "$file"; done < "$temp/$platform-installed-files"
test -f "$installed/bin/unrelated"
test -f "$installed/libexec/gpclient/unrelated"
test -f "$runtime/scripts/unrelated"
done
mv "$temp/release/gpclient" "$temp/release/gpclient.saved"
if make install-linux PREFIX=/custom/gp DESTDIR="$temp/missing-client-stage" \
CARGO_RELEASE_DIR="$temp/release" > "$temp/missing-client.log" 2>&1; then
echo 'FAIL: installation succeeded without gpclient' >&2
exit 1
fi
test ! -e "$temp/missing-client-stage/custom/gp/bin/gpauth"
mv "$temp/release/gpclient.saved" "$temp/release/gpclient"
make install-linux PREFIX='/custom/gp install' DESTDIR="$temp/spaces-stage" \
CARGO_RELEASE_DIR="$temp/release" GPGUI_BINARY="$temp/release/gpgui" > "$temp/spaces-install.log"
find "$temp/spaces-stage" -type f > "$temp/spaces-installed-files"
make uninstall-linux PREFIX='/custom/gp install' DESTDIR="$temp/spaces-stage" > "$temp/spaces-uninstall.log"
while IFS= read -r file; do test ! -e "$file"; done < "$temp/spaces-installed-files"
# Execute generated commands against a harmless CLI fixture at a spaced prefix.
integration="$temp/integration prefix"
mkdir -p "$integration/bin" "$integration/share/applications" "$integration/lib/NetworkManager/dispatcher.d/pre-down.d"
printf '#!/bin/sh\nprintf "%%s\\n" "$@"\n' > "$integration/bin/gpclient"
chmod 755 "$integration/bin/gpclient"
cp packaging/files/usr/share/applications/gpgui.desktop "$integration/share/applications/"
cp packaging/files/usr/lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down "$integration/lib/NetworkManager/dispatcher.d/pre-down.d/"
sh scripts/relocate-install-paths.sh "$integration" /usr "$integration"
desktop_command=$(sed -n 's/^Exec=//p' "$integration/share/applications/gpgui.desktop")
test "$desktop_command" = "\"$integration/bin/gpclient\" launch-gui %u"
test "$(sh -c "$desktop_command")" = "$(printf 'launch-gui\n%%u')"
test "$(sh "$integration/lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down")" = "$(printf 'disconnect\n--wait\n3')"
mkdir -p "$temp/tools"
for os in FreeBSD OpenBSD; do
printf '#!/bin/sh\ncase "$1" in -s) echo %s ;; -m) echo amd64 ;; esac\n' "$os" > "$temp/tools/uname"
chmod 755 "$temp/tools/uname"
PATH="$temp/tools:$PATH" make -n install PREFIX=/custom/gp \
CARGO_RELEASE_DIR="$temp/release" BUILD_GUI_HELPER=0 GPGUI_BINARY= > "$temp/$os.log"
grep -q 'Installing BSD integration' "$temp/$os.log"
! grep -q 'Installing Linux integration' "$temp/$os.log"
PATH="$temp/tools:$PATH" make -n uninstall > "$temp/$os-uninstall.log"
grep -q '/usr/local/bin/' "$temp/$os-uninstall.log"
grep -q '/var/db/gpclient/' "$temp/$os-uninstall.log"
! grep -q 'NetworkManager' "$temp/$os-uninstall.log"
done
for platform in Linux Darwin-arm64 Darwin-x86_64; do
os=Darwin
arch=${platform#Darwin-}
prefix=/usr/local
case "$platform" in
Linux) os=Linux; arch=x86_64; prefix=/usr ;;
Darwin-arm64) prefix=/opt/homebrew ;;
esac
printf '#!/bin/sh\ncase "$1" in -s) echo %s ;; -m) echo %s ;; esac\n' "$os" "$arch" > "$temp/tools/uname"
PATH="$temp/tools:$PATH" make -n uninstall > "$temp/$platform-uninstall.log"
grep -q "$prefix/bin/" "$temp/$platform-uninstall.log"
if [ "$os" = Darwin ]; then
grep -q "$prefix/lib/gpclient/" "$temp/$platform-uninstall.log"
! grep -q 'NetworkManager\|/var/lib/gpclient' "$temp/$platform-uninstall.log"
else
grep -q '/var/lib/gpclient/' "$temp/$platform-uninstall.log"
fi
done
if [ "$(uname -s)" = Darwin ]; then
mkdir -p "$temp/build-library" "$temp/unreferenced-library" "$temp/App/Contents/Helpers"
printf 'int fixture(void) { return 0; }\n' > "$temp/lib.c"
printf 'extern int fixture(void); int main(void) { return fixture(); }\n' > "$temp/main.c"
library="$temp/build-library/libopenconnect.5.dylib"
cc -dynamiclib "$temp/lib.c" -Wl,-install_name,@rpath/libopenconnect.5.dylib -o "$library"
printf 'int main(void) { return 0; }\n' > "$temp/no-library.c"
cc "$temp/no-library.c" -o "$temp/release/gpclient"
if make install-macos PREFIX=/custom/gp DESTDIR="$temp/no-library-stage" \
CARGO_RELEASE_DIR="$temp/release" > "$temp/no-library.log" 2>&1; then
echo 'FAIL: macOS installation succeeded without an OpenConnect dependency' >&2
exit 1
fi
test ! -e "$temp/no-library-stage/custom/gp/libexec/gpclient/vpnc-script"
cc "$temp/main.c" "$library" -Wl,-rpath,@executable_path/../lib/gpclient \
-Wl,-rpath,"$temp/build-library" -o "$temp/release/gpclient"
printf 'stale library must never be selected\n' > "$temp/unreferenced-library/libopenconnect.5.dylib"
test "$(sh scripts/macos-openconnect-library.sh "$temp/release/gpclient")" = "$library"
installed="$temp/macos-stage/custom/gp"
mkdir -p "$installed/lib" "$temp/homebrew-cellar"
printf 'Homebrew-owned library\n' > "$temp/homebrew-cellar/libopenconnect.5.dylib"
ln -s "$temp/homebrew-cellar/libopenconnect.5.dylib" "$installed/lib/libopenconnect.5.dylib"
make install-macos PREFIX=/custom/gp DESTDIR="$temp/macos-stage" \
CARGO_RELEASE_DIR="$temp/release" > "$temp/macos.log"
test -f "$installed/lib/gpclient/libopenconnect.5.dylib"
test -L "$installed/lib/libopenconnect.5.dylib"
test "$(cat "$temp/homebrew-cellar/libopenconnect.5.dylib")" = 'Homebrew-owned library'
! otool -l "$temp/macos-stage/custom/gp/bin/gpclient" | grep -F "$temp/build-library"
cp "$temp/release/gpclient" "$temp/App/Contents/Helpers/gpclient"
install_name_tool -delete_rpath "$temp/build-library" "$temp/App/Contents/Helpers/gpclient"
dylibbundler --overwrite-dir --bundle-deps --search-path "$temp/build-library" \
--install-path @executable_path/../Frameworks --dest-dir "$temp/App/Contents/Frameworks" \
--fix-file "$temp/App/Contents/Helpers/gpclient" > "$temp/bundle.log"
codesign --force --sign - "$temp/App/Contents/Frameworks/libopenconnect.5.dylib"
codesign --force --sign - "$temp/App/Contents/Helpers/gpclient"
mv "$temp/build-library" "$temp/removed-build-library"
"$temp/macos-stage/custom/gp/bin/gpclient"
"$temp/App/Contents/Helpers/gpclient"
touch "$installed/lib/gpclient/unrelated" "$installed/libexec/gpclient/unrelated"
for attempt in 1 2; do
make uninstall PREFIX=/custom/gp DESTDIR="$temp/macos-stage" > "$temp/macos-uninstall.log"
done
test ! -e "$installed/bin/gpclient"
test ! -e "$installed/bin/gpauth"
test ! -e "$installed/lib/gpclient/libopenconnect.5.dylib"
test ! -e "$installed/libexec/gpclient/vpnc-script"
test -f "$installed/lib/gpclient/unrelated"
test -f "$installed/libexec/gpclient/unrelated"
test -L "$installed/lib/libopenconnect.5.dylib"
test "$(cat "$temp/homebrew-cellar/libopenconnect.5.dylib")" = 'Homebrew-owned library'
fi
echo 'PASS: install/uninstall paths, unrelated-file preservation, and native macOS library relocation'