commit:     fdc4461cb862f6605de2331edad93c92084dad67
Author:     Itai Ferber <itai <AT> itaiferber <DOT> net>
AuthorDate: Wed Mar 26 19:43:03 2025 +0000
Commit:     David Roman <davidroman96 <AT> gmail <DOT> com>
CommitDate: Wed Mar 26 19:46:02 2025 +0000
URL:        https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=fdc4461c

dev-lang/swift: fix symlinking on install

On `pkg_postinst`, `has_version` wasn't returning the expected value in
order to symlink Swift on first install; instead, we can use `eselect
swift show` itself to be able to tell whether we're eligible to update
the symlinks.

Closes: https://bugs.gentoo.org/951175
Signed-off-by: Itai Ferber <itai <AT> itaiferber.net>

 dev-lang/swift/swift-5.10.1-r4.ebuild | 28 ++++++++++++++++++++--------
 dev-lang/swift/swift-6.0.3-r1.ebuild  | 28 ++++++++++++++++++++--------
 2 files changed, 40 insertions(+), 16 deletions(-)

diff --git a/dev-lang/swift/swift-5.10.1-r4.ebuild 
b/dev-lang/swift/swift-5.10.1-r4.ebuild
index 9884caaf1..a317fe0da 100644
--- a/dev-lang/swift/swift-5.10.1-r4.ebuild
+++ b/dev-lang/swift/swift-5.10.1-r4.ebuild
@@ -71,7 +71,7 @@ RESTRICT="strip"
 RDEPEND="
        ${PYTHON_DEPS}
        >=app-arch/zstd-1.5
-       >=app-eselect/eselect-swift-1.0
+       >=app-eselect/eselect-swift-1.0-r1
        >=dev-db/sqlite-3
        >=dev-libs/icu-69
        >=dev-libs/libedit-20221030
@@ -106,6 +106,8 @@ BDEPEND="
        ' python3_{12..13})
 "
 
+PKG_PREINST_SWIFT_INTENTIONALLY_SET='true'
+
 # Adapted from `flag-o-matic.eclass`'s `raw-ldflags`: turns GCC-style flags
 # (`-Wl,-foo`) into Clang-style flags (`-Xlinker -foo`).
 clang-ldflags() {
@@ -357,12 +359,22 @@ src_install() {
        done
 }
 
+pkg_preinst() {
+       # After installation, we ideally want the system to have the latest 
Swift
+       # version set -- but if the system already has a Swift version set and 
it
+       # isn't the latest version, that's likely an intentional decision that 
we
+       # don't want to override.
+       local current_swift_version="$(eselect swift show | tail -n1 | xargs)"
+       local latest_swift_version="$(eselect swift show --latest | tail -n1 | 
xargs)"
+       [[ "${current_swift_version}" == '(unset)' ]] \
+               || [[ "${current_swift_version}" == "${latest_swift_version}" 
]] \
+               && PKG_PREINST_SWIFT_INTENTIONALLY_SET='false'
+}
+
 pkg_postinst() {
-       # If we're installing the latest version of Swift, then update symlinks 
to
-       # it. (We don't want to call `eselect swift update` unconditionally in 
case
-       # we're installing an older version of Swift, and the user has 
intentionally
-       # selected a version other than the latest.)
-       if ! has_version ">${CATEGORY}/${P}"; then
+       # If the system doesn't have Swift intentionally set to an older 
version, we
+       # can update to the latest.
+       if [[ "${PKG_PREINST_SWIFT_INTENTIONALLY_SET}" == 'false' ]]; then
                eselect swift update
        fi
 }
@@ -370,8 +382,8 @@ pkg_postinst() {
 pkg_postrm() {
        # We don't want to leave behind symlinks pointing to this Swift version 
on
        # removal.
-       local eselect_swift_version="$(eselect swift show)"
-       if [[ "${eselect_swift_version}" == *"${P}" ]]; then
+       local current_swift_version="$(eselect swift show | tail -n1 | xargs)"
+       if [[ "${current_swift_version}" == "${P}" ]]; then
                eselect swift update
        fi
 }

diff --git a/dev-lang/swift/swift-6.0.3-r1.ebuild 
b/dev-lang/swift/swift-6.0.3-r1.ebuild
index bfbea3442..71daf387e 100644
--- a/dev-lang/swift/swift-6.0.3-r1.ebuild
+++ b/dev-lang/swift/swift-6.0.3-r1.ebuild
@@ -72,6 +72,7 @@ RDEPEND="
        ${PYTHON_DEPS}
        !~dev-lang/swift-5.10.1:0
        >=app-arch/zstd-1.5
+       >=app-eselect/eselect-swift-1.0-r1
        >=dev-db/sqlite-3
        >=dev-libs/icu-69
        >=dev-libs/libedit-20221030
@@ -79,7 +80,6 @@ RDEPEND="
        >=net-misc/curl-8.4
        >=sys-libs/ncurses-6
        >=sys-libs/zlib-1.3
-       app-eselect/eselect-swift
        dev-lang/python
        $(llvm_gen_dep 'llvm-core/lld:${LLVM_SLOT}=')
 "
@@ -114,6 +114,7 @@ BDEPEND="
 
 SWIFT_BUILD_PRESETS_INI_PATH="${S}/gentoo-build-presets.ini"
 SWIFT_BUILD_PRESET='gentoo'
+PKG_PREINST_SWIFT_INTENTIONALLY_SET='true'
 
 # Adapted from `flag-o-matic.eclass`'s `raw-ldflags`: turns GCC-style flags
 # (`-Wl,-foo`) into Clang-style flags (`-Xlinker -foo`).
@@ -276,12 +277,22 @@ src_install() {
        done
 }
 
+pkg_preinst() {
+       # After installation, we ideally want the system to have the latest 
Swift
+       # version set -- but if the system already has a Swift version set and 
it
+       # isn't the latest version, that's likely an intentional decision that 
we
+       # don't want to override.
+       local current_swift_version="$(eselect swift show | tail -n1 | xargs)"
+       local latest_swift_version="$(eselect swift show --latest | tail -n1 | 
xargs)"
+       [[ "${current_swift_version}" == '(unset)' ]] \
+               || [[ "${current_swift_version}" == "${latest_swift_version}" 
]] \
+               && PKG_PREINST_SWIFT_INTENTIONALLY_SET='false'
+}
+
 pkg_postinst() {
-       # If we're installing the latest version of Swift, then update symlinks 
to
-       # it. (We don't want to call `eselect swift update` unconditionally in 
case
-       # we're installing an older version of Swift, and the user has 
intentionally
-       # selected a version other than the latest.)
-       if ! has_version ">${CATEGORY}/${P}"; then
+       # If the system doesn't have Swift intentionally set to an older 
version, we
+       # can update to the latest.
+       if [[ "${PKG_PREINST_SWIFT_INTENTIONALLY_SET}" == 'false' ]]; then
                eselect swift update
        fi
 }
@@ -289,8 +300,9 @@ pkg_postinst() {
 pkg_postrm() {
        # We don't want to leave behind symlinks pointing to this Swift version 
on
        # removal.
-       local eselect_swift_version="$(eselect swift show)"
-       if [[ "${eselect_swift_version}" == *"${P}" ]]; then
+       local current_swift_version="$(eselect swift show | tail -n1 | xargs)"
+       if [[ "${current_swift_version}" == "${P}" ]]; then
                eselect swift update
        fi
 }
+

Reply via email to