Skip to content

Commit 28563f3

Browse files
committed
Fix using system openssl v1.x with pkg-config
System openssl version reported by `pkg-config --modversion openssl` might end with a letter, e.g. "1.0.2k", due to OpenSSL versioning policy prior to OpenSSL v3: https://www.openssl-library.org/policies/general/versioning-policy/#history The letter would trip up the normalize_semver function due to it only handling numbers. This change switches to semver parsing via awk instead of doing it clumsily in bash. This also changes the multiplication factor of major version numbers, from 100000 to 10000, and adjusts static version comparisons accodingly.
1 parent 2d5ef5b commit 28563f3

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

bin/ruby-build

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ build_package_standard() {
673673
if [ "$package_var_name" = "RUBY" ]; then
674674
# shellcheck disable=SC2155
675675
local ruby_semver="$(normalize_semver "${package_name#ruby-}")"
676-
if [[ "$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--with-readline-dir=* && "$ruby_semver" -lt 300300 ]]; then
676+
if [[ "$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--with-readline-dir=* && "$ruby_semver" -lt 30300 ]]; then
677677
# Ruby 3.3+ does not need external readline: https://github.com/rbenv/ruby-build/issues/2330
678678
use_homebrew_readline || use_freebsd_readline || true
679679
fi
@@ -691,7 +691,7 @@ build_package_standard() {
691691
# use openssl installed from Ports Collection
692692
package_option ruby configure --with-openssl-dir="/usr/local"
693693
fi
694-
elif [ "$ruby_semver" -lt 200707 ]; then
694+
elif [ "$ruby_semver" -lt 20707 ]; then
695695
local opt
696696
for opt in $RUBY_CONFIGURE_OPTS "${RUBY_CONFIGURE_OPTS_ARRAY[@]}"; do
697697
if [[ $opt == --with-openssl-dir=* ]]; then
@@ -709,7 +709,7 @@ build_package_standard() {
709709
fi
710710
if [[ "$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--with-ext* &&
711711
"$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--without-ext* &&
712-
"$ruby_semver" -ge 200500 ]]; then
712+
"$ruby_semver" -ge 20500 ]]; then
713713
# For Ruby 2.5+, fail the `make` step if any of these extensions were not compiled.
714714
# Otherwise, the build would have succeeded, but Ruby would be useless at runtime.
715715
# https://github.com/ruby/ruby/commit/b58a30e1c14e971adba4096104274d5d692492e9
@@ -722,7 +722,7 @@ build_package_standard() {
722722
fi
723723
if [ -z "$CC" ] && is_mac 1010; then
724724
export CC=clang
725-
elif [ "$ruby_semver" -lt 300200 ] && is_fedora 42; then
725+
elif [ "$ruby_semver" -lt 30200 ] && is_fedora 42; then
726726
# Fedora 42+ has updated to GCC v15. GCC v15 changed the default
727727
# mode from gnu17 to gnu23: https://gcc.gnu.org/gcc-15/changes.html#c
728728
#
@@ -1146,13 +1146,10 @@ homebrew_openssl_versions() {
11461146
}
11471147

11481148
# Normalizes "X.Y.Z" into a comparable numeric value. Does not support prereleases.
1149+
# Example: 3.1.23 -> 30123
11491150
# See also osx_version, require_java
11501151
normalize_semver() {
1151-
local ver
1152-
IFS=. read -d "" -r -a ver <<<"$1" || true
1153-
IFS="$OLDIFS"
1154-
# 3.1.23 -> 300_123
1155-
echo $(( ver[0]*100000 + ver[1]*100 + ver[2] ))
1152+
awk -F. '{print $1 * 10000 + $2 * 100 + $3}' <<<"$1"
11561153
}
11571154

11581155
# Checks if system OpenSSL does NOT satisfy the version requirement

test/build.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,13 @@ OUT
374374
@test "use pkg-config OpenSSL" {
375375
cached_tarball "ruby-3.2.0" configure
376376

377-
openssl_libdir="$TMP/opt/local/libexec/openssl3"
377+
openssl_libdir="$TMP/opt/local/libexec/openssl"
378378

379379
stub_repeated uname '-s : echo Linux'
380380
stub_repeated brew false
381381
stub pkg-config \
382382
"--variable=prefix openssl : echo '$openssl_libdir'" \
383-
"--modversion openssl : echo 3.0.0"
383+
"--modversion openssl : echo 1.0.2k"
384384
stub_make_install
385385

386386
run_inline_definition <<DEF

0 commit comments

Comments
 (0)