From 5a31fea21b16bca8013743e76e0c61c7906860c1 Mon Sep 17 00:00:00 2001 From: macayu17 Date: Wed, 5 Aug 2026 11:21:46 +0300 Subject: [PATCH 1/2] pyenv-binary: support checking FreeBSD system libraries * Handle both spaced and unspaced FreeBSD `ldconfig -r` output --- .../libexec/pyenv-binary-generate-installer | 23 +++++++++++++++---- .../pyenv-binary/test/generate-installer.bats | 13 +++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/plugins/pyenv-binary/libexec/pyenv-binary-generate-installer b/plugins/pyenv-binary/libexec/pyenv-binary-generate-installer index 3a3e8445..b0282a56 100755 --- a/plugins/pyenv-binary/libexec/pyenv-binary-generate-installer +++ b/plugins/pyenv-binary/libexec/pyenv-binary-generate-installer @@ -155,10 +155,23 @@ case "$EXPECT_LIBC" in ;; esac -# Required system libraries must already be present on the target. ldconfig -p -# lists each library as " (...) => "; match the soname column -# exactly so a longer name like libc.so.6.1 does not satisfy libc.so.6. -if command -v ldconfig &>/dev/null && cache="$(ldconfig -p)"; then +# Required system libraries must already be present on the target. Linux lists +# the soname first; FreeBSD lists it in the resolved path, so normalize that +# path before matching exact names. +cache="" +if command -v ldconfig &>/dev/null; then + case "$os" in + FreeBSD ) + cache="$(ldconfig -r 2>/dev/null)" && + cache="$(printf '%s\n' "$cache" | awk -F ' *=> *' '{ sub(/^.*\//, "", $2); print $2 }')" \ + || cache="" + ;; + * ) + cache="$(ldconfig -p 2>/dev/null)" || cache="" + ;; + esac +fi +if [ -n "$cache" ]; then missing="" for dep in $DEPS; do printf '%s\n' "$cache" | awk -v d="$dep" '$1 == d { found = 1 } END { exit !found }' \ @@ -169,7 +182,7 @@ if command -v ldconfig &>/dev/null && cache="$(ldconfig -p)"; then exit 1 fi elif [ -n "$DEPS" ]; then - echo "pyenv-binary: cannot check required system libraries (ldconfig with -p not found)" >&2 + echo "pyenv-binary: cannot check required system libraries (ldconfig cache unavailable)" >&2 fi build_package_relocate() { diff --git a/plugins/pyenv-binary/test/generate-installer.bats b/plugins/pyenv-binary/test/generate-installer.bats index e7e36c51..8f098c51 100644 --- a/plugins/pyenv-binary/test/generate-installer.bats +++ b/plugins/pyenv-binary/test/generate-installer.bats @@ -93,6 +93,19 @@ create_meta() { assert_failure "pyenv-binary: archive needs glibc 99.0 or newer, but this system has 2.31" } +@test "checks required libraries in the FreeBSD ldconfig cache" { + local out="${BATS_TEST_TMPDIR}/definition" + local meta="$(create_meta FreeBSD amd64 '')" + printf 'dep=libc.so.7\ndep=libmissing.so.1\n' >> "$meta" + pyenv-binary-generate-installer "$meta" \ + --archive-url http://example.com/a.tar.gz -o "$out" + create_stub uname 'case "$1" in -s) echo FreeBSD;; -m) echo amd64;; esac' + create_stub ldconfig '[ "$1" = "-r" ] && echo "0:-lc.7=>/lib/libc.so.7"' + + run bash "$out" + assert_failure "pyenv-binary: missing required system libraries: libmissing.so.1" +} + @test "fails when the archive is not beside the metadata" { local meta="$(create_meta)" rm "${BATS_TEST_TMPDIR}/3.12.7.tar.gz" From a6ef1e70baa7b4b9a6a04fb7eab41007fdf769ef Mon Sep 17 00:00:00 2001 From: macayu17 Date: Sat, 8 Aug 2026 22:41:11 +0530 Subject: [PATCH 2/2] Resolve version prefixes in package names --- .../pyenv-binary/libexec/pyenv-binary-package-name | 2 ++ plugins/pyenv-binary/test/package-name.bats | 11 ++++++++--- plugins/pyenv-binary/test/package.bats | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/pyenv-binary/libexec/pyenv-binary-package-name b/plugins/pyenv-binary/libexec/pyenv-binary-package-name index 7fbd9bf3..649c9925 100755 --- a/plugins/pyenv-binary/libexec/pyenv-binary-package-name +++ b/plugins/pyenv-binary/libexec/pyenv-binary-package-name @@ -28,6 +28,8 @@ case "$version" in ;; esac +version="$(pyenv-latest -f -k "$version")" + os="$(uname -s)" arch="$(uname -m)" distro="" diff --git a/plugins/pyenv-binary/test/package-name.bats b/plugins/pyenv-binary/test/package-name.bats index dadb4caf..dcd66089 100644 --- a/plugins/pyenv-binary/test/package-name.bats +++ b/plugins/pyenv-binary/test/package-name.bats @@ -2,6 +2,10 @@ load test_helper +_setup() { + create_stub pyenv-latest '[ "$1" = "-f" ] && [ "$2" = "-k" ] && shift 2 && echo "$*"' +} + @test "completion lists installable versions" { create_stub pyenv-install \ '[ "$*" = "--list --bare" ] && echo 3.13.14' @@ -40,12 +44,13 @@ load test_helper assert_success "3.13.14-macos-15.5-arm64" } -@test "generates a package name for FreeBSD" { +@test "resolves a version prefix when generating a package name" { + create_stub pyenv-latest '[ "$*" = "-f -k 3" ] && echo 3.14.7' create_stub uname \ 'case "$1" in -s) echo FreeBSD;; -m) echo amd64;; -r) echo 14.2-RELEASE-p3;; esac' - run pyenv-binary-package-name 3.13.14 - assert_success "3.13.14-freebsd-14.2-release-p3-amd64" + run pyenv-binary-package-name 3 + assert_success "3.14.7-freebsd-14.2-release-p3-amd64" } @test "rejects an invalid version name" { diff --git a/plugins/pyenv-binary/test/package.bats b/plugins/pyenv-binary/test/package.bats index a3d7ceb1..6262a8c3 100644 --- a/plugins/pyenv-binary/test/package.bats +++ b/plugins/pyenv-binary/test/package.bats @@ -7,6 +7,7 @@ load test_helper # `generate-installer' behave the same on any test host. stub_build_environment() { create_stub pyenv-install 'mkdir -p "${PYENV_ROOT}/versions/${1##*:}/bin"' + create_stub pyenv-latest '[ "$1" = "-f" ] && [ "$2" = "-k" ] && shift 2 && echo "$*"' create_stub uname 'case "$1" in -s) echo Linux;; -m) echo x86_64;; esac' create_stub getconf 'echo "glibc 2.17"' }