Skip to content

python-build: honor explicitly configured OpenSSL on macOS - #3541

Open
aprylewu wants to merge 3 commits into
pyenv:masterfrom
aprylewu:fix/explicit-openssl-selection
Open

python-build: honor explicitly configured OpenSSL on macOS#3541
aprylewu wants to merge 3 commits into
pyenv:masterfrom
aprylewu:fix/explicit-openssl-selection

Conversation

@aprylewu

@aprylewu aprylewu commented Sep 11, 2026

Copy link
Copy Markdown

When a macOS build supplies --with-openssl, Python-Build still selects an OpenSSL installation from Homebrew and prepends its include, library, and runtime search paths. The explicit configure option survives, but the injected flags can refer to a different installation.

Skip automatic OpenSSL selection when an explicit --with-openssl argument is present. Recognize both argument forms in CONFIGURE_OPTS, PYTHON_CONFIGURE_OPTS, and definition-provided package options. The check also covers definitions that call the Homebrew/MacPorts OpenSSL selectors directly or repeatedly. A standalone --with-openssl-rpath still allows automatic selection. General dependency-prefix flags are unchanged.

Prerequisite

Tests

  • Added four original regressions through the python-build entry point using tiny local source fixtures and stubbed build commands, plus four direct/repeated-selector regressions requested during review. The original cases fail on the base revision; the four follow-up cases fail on the previous PR head. All pass with this change.
  • Covered automatic Homebrew selection with --with-openssl-rpath alone and the bundled fallback when no OpenSSL location is configured or found.
  • Bash 3.2 syntax check with extglob enabled and git diff --check.
  • make test on macOS with Bash 3.2 and Bats 1.10.0: 470 passed, 9 skipped (fish/PowerShell are unavailable; the Linux ldconfig -p case does not apply).

The fixtures inspect configure arguments and compiler flags; no CPython or OpenSSL compilation is performed locally.

Implementation and regression tests were prepared with assistance from OpenAI Codex.


Summary by cubic

Honors an explicitly configured OpenSSL on macOS so automatic Homebrew or MacPorts selection no longer overrides it.

python-build now treats --with-openssl and --with-openssl=... in CONFIGURE_OPTS, PYTHON_CONFIGURE_OPTS, and package options as an explicit choice. It skips Homebrew/MacPorts discovery, skips the bundled OpenSSL fallback, and still allows automatic selection when only --with-openssl-rpath is present. The guard also applies when definitions call the Homebrew or MacPorts selectors directly or repeatedly. Closes pyenv/pyenv issue #2852.

Tests

  • Adds regression tests for explicit Homebrew/MacPorts bypass, direct and repeated selector calls, rpath-only behavior, and the bundled fallback.

Written for commit f5c262e. Summary will update on new commits.

Review in cubic

Skip automatic OpenSSL selection when configure options supply --with-openssl, while keeping rpath-only options on the existing detection path.

Assisted-by: OpenAI Codex
Signed-off-by: Mingyang Wu <129849514+aprylewu@users.noreply.github.com>
@aprylewu
aprylewu requested review from a team as code owners September 11, 2026 17:17

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@native-api native-api left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this also prevent picking OpenSSL from Homebrew/MacPorts?
IIRC after has_broken_mac_openssl, OpenSSL search triggers again at some point.

FWIW, scripts aren't required to call has_broken_mac_openssl at all.

Share the explicit OpenSSL check between the broken-system predicate and both package-manager selectors. Return success without discovery when already configured so custom definitions cannot fall through to another OpenSSL installation.

Signed-off-by: Mingyang Wu <129849514+aprylewu@users.noreply.github.com>
@aprylewu

Copy link
Copy Markdown
Author

Good point: the original guard only covered has_broken_mac_openssl. I traced the later standard-build steps: they call the general use_homebrew/use_macports dependency-prefix setup, not the OpenSSL selectors again. But a definition can call either OpenSSL selector directly, bypassing that guard.

Commit b567c52 factors out the option check and applies it to both use_homebrew_openssl and use_macports_openssl too. They return success without probing or modifying options/flags when OpenSSL is already configured, matching the existing readline convention and avoiding fallback to another installation. The predicate still skips the bundled OpenSSL build. General dependency-prefix flags remain unchanged; this specifically prevents OpenSSL selection and its extra arguments/flags.

Added four regressions for direct calls without the predicate and repeated calls after it, covering both package managers. All four fail on the previous head and pass now. All 10 OpenSSL cases and the full suite pass on Bash 3.2 (470 passed, 9 skipped); no CPython/OpenSSL compilation was needed.

Comment thread plugins/python-build/bin/python-build Outdated
}

use_homebrew_openssl() {
configured_with_openssl && return 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be 1, no?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, changed both to return 1 in f5c262e. has_broken_mac_openssl still has its own guard to skip the bundled build.

Comment thread plugins/python-build/bin/python-build Outdated
local arg
for arg in ${CONFIGURE_OPTS} ${PYTHON_CONFIGURE_OPTS} "${PYTHON_CONFIGURE_OPTS_ARRAY[@]}"; do
[[ "$arg" = --with-openssl || "$arg" = --with-openssl=* ]] && return 1
[[ "$arg" = --with-openssl || "$arg" = --with-openssl=* ]] && return 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with =~ --with-openssl[ =] ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to ^--with-openssl(=|$) per argument. That also handles --with-openssl /path, while keeping --with-openssl-rpath out.

Return nonzero when neither package-manager selector selects an OpenSSL
installation. Keep the separate explicit-config guard in the bundled
build predicate and use an anchored regex for each configure argument.

Signed-off-by: Mingyang Wu <129849514+aprylewu@users.noreply.github.com>

@native-api native-api left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking through the code, I confirmed that indeed, OpenSSL search is indeed currently only triggered from has_broken_mac_openssl.
We probably need to do that more like the Tcl-related code does.
Maybe even refactor all OpenSSL search logic into a subroutine like #3399 suggests.

@aprylewu

Copy link
Copy Markdown
Author

Agreed. OpenSSL discovery being a side effect of has_broken_mac_openssl is harder to follow than the Tcl/Tk build step.

I read through #3399. A shared selection routine needs to preserve the version constraints, source-build fallback and custom definitions. I'd suggest keeping that refactor separate and this PR focused on honoring explicit --with-openssl options. If you'd prefer the OpenSSL extraction first, I can adjust this PR.

@native-api

Copy link
Copy Markdown
Member

Here's the design I had in mind: add probing of OpenSSL within package_build_standard in the same fashion as other libraries:

 plugins/python-build/bin/python-build | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/plugins/python-build/bin/python-build b/plugins/python-build/bin/python-build
index 6a651ed0..0a802722 100755
--- a/plugins/python-build/bin/python-build
+++ b/plugins/python-build/bin/python-build
@@ -873,6 +873,7 @@ build_package_standard_build() {
 
   if [ "$package_var_name" = "PYTHON" ]; then
     if can_use_homebrew; then
+      configured_with_openssl || use_homebrew_openssl || true
       use_custom_tcltk || use_homebrew_tcltk || true
       use_homebrew_readline || true
       use_homebrew_ncurses || true
@@ -885,6 +886,7 @@ build_package_standard_build() {
       fi
     fi
     if can_use_macports; then
+      configured_with_openssl || use_macports_openssl || true
       use_custom_tcltk || true
       use_macports_readline || true
       use_macports_ncurses || true
@@ -1729,7 +1731,6 @@ has_broken_mac_openssl() {
 }
 
 use_homebrew_openssl() {
-  configured_with_openssl && return 1
   can_use_homebrew || return 1
   command -v brew >/dev/null || return 1
   for openssl in ${PYTHON_BUILD_HOMEBREW_OPENSSL_FORMULA:-openssl}; do
@@ -1768,7 +1769,6 @@ use_homebrew_openssl() {
 }
 
 use_macports_openssl() {
-  configured_with_openssl && return 1
   can_use_macports || return 1
   command -v port >/dev/null || return 1
   local port_location="$(command -v port)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants