commit:     cd4189a259b3f34d0da39851931dc1a6a6a631f2
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Sep 30 02:14:13 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Sep 30 02:14:13 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=cd4189a2

toolchain.eclass: move Ada and D logic into their own functions

Signed-off-by: Sam James <sam <AT> gentoo.org>

 eclass/toolchain.eclass | 285 +++++++++++++++++++++++++-----------------------
 1 file changed, 149 insertions(+), 136 deletions(-)

diff --git a/eclass/toolchain.eclass b/eclass/toolchain.eclass
index f64128baef48..41f51b1bb747 100644
--- a/eclass/toolchain.eclass
+++ b/eclass/toolchain.eclass
@@ -819,100 +819,62 @@ setup_multilib_osdirnames() {
        sed -i "${sed_args[@]}" "${S}"/gcc/config/${config} || die
 }
 
-#---->> src_configure <<----
-
-toolchain_src_configure() {
-       BUILD_CONFIG_TARGETS=()
-       is-flagq '-O3' && BUILD_CONFIG_TARGETS+=( bootstrap-O3 )
-
-       downgrade_arch_flags
-       gcc_do_filter_flags
-
-       if ! tc_version_is_at_least 11 && [[ $(gcc-major-version) -ge 12 ]] ; 
then
-               # https://gcc.gnu.org/PR105695
-               # bug #849359
-               export ac_cv_std_swap_in_utility=no
-       fi
-
-       einfo "CFLAGS=\"${CFLAGS}\""
-       einfo "CXXFLAGS=\"${CXXFLAGS}\""
-       einfo "LDFLAGS=\"${LDFLAGS}\""
-
-       # Force internal zip based jar script to avoid random
-       # issues with 3rd party jar implementations. bug #384291
-       export JAR=no
+# @FUNCTION: toolchain_setup_ada
+# @INTERNAL
+# @DESCRIPTION:
+# Determine the most suitable GNAT (Ada compiler) for bootstrapping
+# and setup the environment, including wrappers, for building.
+toolchain_setup_ada() {
+       local latest_gcc=$(best_version -b "sys-devel/gcc")
+       latest_gcc="${latest_gcc#sys-devel/gcc-}"
+       latest_gcc=$(ver_cut 1 ${latest_gcc})
+
+       local ada_bootstrap
+       local ada_candidate
+       # GNAT can usually be built using the last major version and
+       # the current version, at least.
+       #
+       # We always prefer the version being built if possible
+       # as it has the greatest chance of success. Failing that,
+       # try GCC 10 and iterate upwards.
+       for ada_candidate in ${SLOT} $(seq 10 ${latest_gcc}) ; do
+               has_version -b "sys-devel/gcc:${ada_candidate}" || continue
 
-       local confgcc=( --host=${CHOST} )
+               ebegin "Testing sys-devel/gcc:${ada_candidate} for Ada"
+               if has_version -b "sys-devel/gcc:${ada_candidate}[ada(-)]" ; 
then
+                       ada_bootstrap=${ada_candidate}
 
-       if is_crosscompile || tc-is-cross-compiler ; then
-               # Straight from the GCC install doc:
-               # "GCC has code to correctly determine the correct value for 
target
-               # for nearly all native systems. Therefore, we highly recommend 
you
-               # not provide a configure target when configuring a native 
compiler."
-               confgcc+=( --target=${CTARGET} )
-       fi
-       [[ -n ${CBUILD} ]] && confgcc+=( --build=${CBUILD} )
-
-       _need_ada_bootstrap_mangling() {
-               if [[ ${CATEGORY}/${PN} == dev-lang/gnat-gpl ]] ; then
-                       _tc_use_if_iuse system-bootstrap && return 0
-                       return 1
+                       eend 0
+                       break
                fi
+               eend 1
+       done
 
-               _tc_use_if_iuse ada
-       }
-
-       if _need_ada_bootstrap_mangling ; then
-               local latest_gcc=$(best_version -b "sys-devel/gcc")
-               latest_gcc="${latest_gcc#sys-devel/gcc-}"
-               latest_gcc=$(ver_cut 1 ${latest_gcc})
-
-               local ada_bootstrap
-               local ada_candidate
-               # GNAT can usually be built using the last major version and
-               # the current version, at least.
-               #
-               # We always prefer the version being built if possible
-               # as it has the greatest chance of success. Failing that,
-               # try GCC 10 and iterate upwards.
-               for ada_candidate in ${SLOT} $(seq 10 ${latest_gcc}) ; do
-                       has_version -b "sys-devel/gcc:${ada_candidate}" || 
continue
-
-                       ebegin "Testing sys-devel/gcc:${ada_candidate} for Ada"
-                       if has_version -b 
"sys-devel/gcc:${ada_candidate}[ada(-)]" ; then
-                               ada_bootstrap=${ada_candidate}
-
-                               eend 0
-                               break
-                       fi
+       # As a last resort, use dev-lang/gnat-gpl.
+       # TODO: Make gnat-gpl coinstallable with gcc:10 (bug #940471).
+       if ver_test ${ada_bootstrap} -gt ${PV} || [[ -z ${ada_bootstrap} ]] ; 
then
+               ebegin "Testing dev-lang/gnat-gpl for Ada"
+               if has_version -b "dev-lang/gnat-gpl" ; then
+                       ada_bootstrap=10
+                       eend 0
+               else
                        eend 1
-               done
-
-               # As a last resort, use dev-lang/gnat-gpl.
-               # TODO: Make gnat-gpl coinstallable with gcc:10 (bug #940471).
-               if ver_test ${ada_bootstrap} -gt ${PV} || [[ -z 
${ada_bootstrap} ]] ; then
-                       ebegin "Testing dev-lang/gnat-gpl for Ada"
-                       if has_version -b "dev-lang/gnat-gpl" ; then
-                               ada_bootstrap=10
-                               eend 0
-                       else
-                               eend 1
-                       fi
                fi
+       fi
 
-               # OK, even gnat-gpl didn't work. Give up for now.
-               # TODO: Source a newer, or build our own, bootstrap tarball 
(bug #940472).
-               if [[ -z ${ada_bootstrap} ]] ; then
-                       eerror "Couldn't find a suitable GNAT compiler for Ada!"
-                       eerror "Please try installing dev-lang/gnat-gpl."
-                       eerror "For other platforms, you may need to use 
crossdev."
-                       die "Fallback ada-bootstrap path not yet implemented!"
+       # OK, even gnat-gpl didn't work. Give up for now.
+       # TODO: Source a newer, or build our own, bootstrap tarball (bug 
#940472).
+       if [[ -z ${ada_bootstrap} ]] ; then
+               eerror "Couldn't find a suitable GNAT compiler for Ada!"
+               eerror "Please try installing dev-lang/gnat-gpl."
+               eerror "For other platforms, you may need to use crossdev."
+               die "Fallback ada-bootstrap path not yet implemented!"
 
-                       #einfo "Using bootstrap GNAT compiler..."
-                       #export 
PATH="${BROOT}/opt/ada-bootstrap-${GCCMAJOR}/bin:${PATH}"
-               fi
+               #einfo "Using bootstrap GNAT compiler..."
+               #export 
PATH="${BROOT}/opt/ada-bootstrap-${GCCMAJOR}/bin:${PATH}"
+       fi
 
-               cat <<-"EOF" > "${T}"/ada.spec || die
+       cat <<-"EOF" > "${T}"/ada.spec || die
                # Extracted from gcc/ada/gcc-interface/lang-specs.h
                .adb:
                @ada
@@ -957,69 +919,120 @@ toolchain_src_configure() {
                        %{gnatc*|gnats*: -o %j} %{-param*}
                EOF
 
-               # Easier to substitute these values in rather than escape
-               # lots of bits above in heredoc.
-               sed -i \
-                       -e "s:\${BROOT}:${BROOT}:" \
-                       -e "s:\${CBUILD}:${CBUILD}:" \
-                       -e "s:\${ada_bootstrap}:${ada_bootstrap}:" \
-                       "${T}"/ada.spec || die
-
-               # The Makefile tries to find libgnat by querying $(CC) which
-               # won't work for us as the stage1 compiler doesn't necessarily
-               # have Ada support. Substitute the Ada compiler we found 
earlier.
-               local adalib
-               adalib=$(${CBUILD}-gcc-${ada_bootstrap} -print-libgcc-file-name 
|| die "Finding adalib dir failed")
-               adalib="${adalib%/*}/adalib"
-               sed -i \
-                       -e "s:adalib=.*:adalib=${adalib}:" \
-                       "${S}"/gcc/ada/gcc-interface/Make-lang.in || die
-
-               # Create bin wrappers because not all of the build system
-               # respects GNATBIND or GNATMAKE.
-               mkdir "${T}"/ada-wrappers || die
-               local tool
-               for tool in gnat{,bind,chop,clean,kr,link,ls,make,name,prep} ; 
do
-                       cat <<-EOF > "${T}"/ada-wrappers/${tool} || die
+       # Easier to substitute these values in rather than escape
+       # lots of bits above in heredoc.
+       sed -i \
+               -e "s:\${BROOT}:${BROOT}:" \
+               -e "s:\${CBUILD}:${CBUILD}:" \
+               -e "s:\${ada_bootstrap}:${ada_bootstrap}:" \
+               "${T}"/ada.spec || die
+
+       # The Makefile tries to find libgnat by querying $(CC) which
+       # won't work for us as the stage1 compiler doesn't necessarily
+       # have Ada support. Substitute the Ada compiler we found earlier.
+       local adalib
+       adalib=$(${CBUILD}-gcc-${ada_bootstrap} -print-libgcc-file-name || die 
"Finding adalib dir failed")
+       adalib="${adalib%/*}/adalib"
+       sed -i \
+               -e "s:adalib=.*:adalib=${adalib}:" \
+               "${S}"/gcc/ada/gcc-interface/Make-lang.in || die
+
+       # Create bin wrappers because not all of the build system
+       # respects GNATBIND or GNATMAKE.
+       mkdir "${T}"/ada-wrappers || die
+       local tool
+       for tool in gnat{,bind,chop,clean,kr,link,ls,make,name,prep} ; do
+               cat <<-EOF > "${T}"/ada-wrappers/${tool} || die
                        #!/bin/sh
                        exec $(type -P ${CBUILD}-${tool}-${ada_bootstrap}) 
-specs=${T}/ada.spec "\$@"
                        EOF
-                       chmod +x "${T}"/ada-wrappers/${tool} || die
+               chmod +x "${T}"/ada-wrappers/${tool} || die
 
-                       export "${tool^^}"=${CBUILD}-${tool}-${ada_bootstrap}
-               done
+               export "${tool^^}"=${CBUILD}-${tool}-${ada_bootstrap}
+       done
+
+       export PATH="${T}/ada-wrappers:${PATH}"
+       export CC="$(tc-getCC) -specs=${T}/ada.spec"
+}
+
+# @FUNCTION: toolchain_setup_d
+# @INTERNAL
+# @DESCRIPTION:
+# Determine the most suitable GDC (D compiler) for bootstrapping
+# and setup the environment for building.
+toolchain_setup_d() {
+       local latest_gcc=$(best_version -b "sys-devel/gcc")
+       latest_gcc="${latest_gcc#sys-devel/gcc-}"
+       latest_gcc=$(ver_cut 1 ${latest_gcc})
+
+       local d_bootstrap
+       local d_candidate
+       # We always prefer the version being built if possible
+       # as it has the greatest chance of success. Failing that,
+       # try GCC 10 and iterate upwards.
+       for d_candidate in ${SLOT} $(seq 10 ${latest_gcc}) ; do
+               has_version -b "sys-devel/gcc:${d_candidate}" || continue
+
+               ebegin "Testing sys-devel/gcc:${d_candidate} for D"
+               if has_version -b "sys-devel/gcc:${d_candidate}[d(-)]" ; then
+                       d_bootstrap=${d_candidate}
+
+                       eend 0
+                       break
+               fi
+               eend 1
+       done
 
-               export PATH="${T}/ada-wrappers:${PATH}"
-               export CC="$(tc-getCC) -specs=${T}/ada.spec"
+       if [[ -n ${d_bootstrap} ]] ; then
+               export GDC="${BROOT}/usr/${CTARGET}/gcc-bin/${d_bootstrap}/gdc"
        fi
+}
 
-       if _tc_use_if_iuse d ; then
-               local latest_gcc=$(best_version -b "sys-devel/gcc")
-               latest_gcc="${latest_gcc#sys-devel/gcc-}"
-               latest_gcc=$(ver_cut 1 ${latest_gcc})
+#---->> src_configure <<----
 
-               local d_bootstrap
-               local d_candidate
-               # We always prefer the version being built if possible
-               # as it has the greatest chance of success. Failing that,
-               # try GCC 10 and iterate upwards.
-               for d_candidate in ${SLOT} $(seq 10 ${latest_gcc}) ; do
-                       has_version -b "sys-devel/gcc:${d_candidate}" || 
continue
+toolchain_src_configure() {
+       BUILD_CONFIG_TARGETS=()
+       is-flagq '-O3' && BUILD_CONFIG_TARGETS+=( bootstrap-O3 )
 
-                       ebegin "Testing sys-devel/gcc:${d_candidate} for D"
-                       if has_version -b "sys-devel/gcc:${d_candidate}[d(-)]" 
; then
-                               d_bootstrap=${d_candidate}
+       downgrade_arch_flags
+       gcc_do_filter_flags
 
-                               eend 0
-                               break
-                       fi
-                       eend 1
-               done
+       if ! tc_version_is_at_least 11 && [[ $(gcc-major-version) -ge 12 ]] ; 
then
+               # https://gcc.gnu.org/PR105695
+               # bug #849359
+               export ac_cv_std_swap_in_utility=no
+       fi
 
-               if [[ -n ${d_bootstrap} ]] ; then
-                       export 
GDC="${BROOT}/usr/${CTARGET}/gcc-bin/${d_bootstrap}/gdc"
-               fi
+       einfo "CFLAGS=\"${CFLAGS}\""
+       einfo "CXXFLAGS=\"${CXXFLAGS}\""
+       einfo "LDFLAGS=\"${LDFLAGS}\""
+
+       # Force internal zip based jar script to avoid random
+       # issues with 3rd party jar implementations. bug #384291
+       export JAR=no
+
+       local confgcc=( --host=${CHOST} )
+
+       if is_crosscompile || tc-is-cross-compiler ; then
+               # Straight from the GCC install doc:
+               # "GCC has code to correctly determine the correct value for 
target
+               # for nearly all native systems. Therefore, we highly recommend 
you
+               # not provide a configure target when configuring a native 
compiler."
+               confgcc+=( --target=${CTARGET} )
        fi
+       [[ -n ${CBUILD} ]] && confgcc+=( --build=${CBUILD} )
+
+       _need_ada_bootstrap_mangling() {
+               if [[ ${CATEGORY}/${PN} == dev-lang/gnat-gpl ]] ; then
+                       _tc_use_if_iuse system-bootstrap && return 0
+                       return 1
+               fi
+
+               _tc_use_if_iuse ada
+       }
+
+       _need_ada_bootstrap_mangling && toolchain_setup_ada
+       _tc_use_if_iuse d && toolchain_setup_d
 
        confgcc+=(
                --prefix="${PREFIX}"

Reply via email to