From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id B72AB138334 for ; Fri, 13 Sep 2019 20:15:10 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1776AE097B; Fri, 13 Sep 2019 20:15:05 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id F3AEDE0932 for ; Fri, 13 Sep 2019 20:15:02 +0000 (UTC) Received: from pomiot (c134-66.icpnet.pl [85.221.134.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id E292034B121; Fri, 13 Sep 2019 20:15:00 +0000 (UTC) Message-ID: Subject: Re: [gentoo-dev] [PATCH] ada.eclass: New eclass for dev-ada packages From: =?UTF-8?Q?Micha=C5=82_G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: Alfredo Tupone Date: Fri, 13 Sep 2019 22:14:56 +0200 In-Reply-To: <20190905182554.17582-1-tupone@gentoo.org> References: <20190905182554.17582-1-tupone@gentoo.org> Organization: Gentoo Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-2cF1zrckQ31D1Ae+PB8H" User-Agent: Evolution 3.32.4 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 X-Archives-Salt: da1fafac-3bbd-4867-9957-e8079c1df1ae X-Archives-Hash: 7c534b6483b6ac314b945caf6fab7bdc --=-2cF1zrckQ31D1Ae+PB8H Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I'm sorry for not finding time to review this earlier. On Thu, 2019-09-05 at 20:25 +0200, Tupone Alfredo wrote: > Signed-off-by: Alfredo Tupone > --- > eclass/ada.eclass | 435 ++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 435 insertions(+) > create mode 100644 eclass/ada.eclass >=20 > diff --git a/eclass/ada.eclass b/eclass/ada.eclass > new file mode 100644 > index 000000000000..338b73bab86b > --- /dev/null > +++ b/eclass/ada.eclass > @@ -0,0 +1,435 @@ > +# Copyright 2019 Gentoo Authors > +# Distributed under the terms of the GNU General Public License v2 > + > +# @ECLASS: ada.eclass > +# @MAINTAINER: > +# Ada team > +# @AUTHOR: > +# Tupone Alfredo > +# @BLURB: An eclass for Ada packages > +# @DESCRIPTION: > +# This eclass set the IUSE and REQUIRED_USE to request the ADA_TARGET > +# when the inheriting ebuild can be supported by more than one Ada > +# implementation. It also set ADA_USEDEP and ADA_DEPS with a suitable fo= rm. > +# A common eclass providing helper functions to build and install > +# packages supporting Ada implementations. > +# > +# This eclass sets correct IUSE. Modification of REQUIRED_USE has to > +# be done by the author of the ebuild (but ADA_REQUIRED_USE is > +# provided for convenience, see below). ada exports ADA_DEPS > +# and ADA_USEDEP so you can create correct dependencies for your > +# package easily. > +# > +# Mostly copied from python-single-r1.eclass > + > +case "${EAPI:-0}" in > + 0|1|2|3|4) > + die "Unsupported EAPI=3D${EAPI:-0} (too old) for ${ECLASS}" > + ;; > + 5|6|7) > + # EAPI=3D5 is required for sane USE_EXPAND dependencies > + ;; Given that EAPI 5 is deprecated already, you shouldn't be adding any new ebuilds with it. Therefore, adding support for it is a bit pointless. > + *) > + die "Unsupported EAPI=3D${EAPI} (unknown) for ${ECLASS}" > + ;; > +esac > + > +EXPORT_FUNCTIONS pkg_setup > + > +# @ECLASS-VARIABLE: ADA_DEPS > +# @DESCRIPTION: > +# This is an eclass-generated Ada dependency string for all > +# implementations listed in ADA_COMPAT. > +# > +# The dependency string is conditional on ADA_TARGET. > +# > +# Example use: > +# @CODE > +# RDEPEND=3D"${ADA_DEPS} > +# dev-foo/mydep" > +# DEPEND=3D"${RDEPEND}" > +# @CODE > +# > + > +# @ECLASS-VARIABLE: _ADA_ALL_IMPLS > +# @INTERNAL > +# @DESCRIPTION: > +# All supported Ada implementations, most preferred last. > +_ADA_ALL_IMPLS=3D( > + gnat_2016 gnat_2017 gnat_2018 gnat_2019 > +) > +readonly _ADA_ALL_IMPLS > + > + > +# @FUNCTION: _ada_impl_supported > +# @USAGE: > +# @INTERNAL > +# @DESCRIPTION: > +# Check whether the implementation (ADA_COMPAT-form) > +# is still supported. > +# > +# Returns 0 if the implementation is valid and supported. If it is > +# unsupported, returns 1 -- and the caller should ignore the entry. > +# If it is invalid, dies with an appopriate error messages. > +_ada_impl_supported() { > + debug-print-function ${FUNCNAME} "${@}" > + > + [[ ${#} -eq 1 ]] || die "${FUNCNAME}: takes exactly 1 argument (impl)." > + > + local impl=3D${1} > + > + # keep in sync with _ADA_ALL_IMPLS! > + # (not using that list because inline patterns shall be faster) > + case "${impl}" in > + gnat_201[6789]) > + return 0 > + ;; > + *) > + [[ ${ADA_COMPAT_NO_STRICT} ]] && return 1 > + die "Invalid implementation in ADA_COMPAT: ${impl}" > + esac > +} > + > +# @FUNCTION: _ada_set_impls > +# @INTERNAL > +# @DESCRIPTION: > +# Check ADA_COMPAT for well-formedness and validity, then set > +# two global variables: > +# > +# - _ADA_SUPPORTED_IMPLS containing valid implementations supported > +# by the ebuild (ADA_COMPAT - dead implementations), > +# > +# - and _ADA_UNSUPPORTED_IMPLS containing valid implementations that > +# are not supported by the ebuild. > +# > +# Implementations in both variables are ordered using the pre-defined > +# eclass implementation ordering. > +# > +# This function must be called once in global scope by an eclass > +# utilizing ADA_COMPAT. > +_ada_set_impls() { > + local i > + > + if ! declare -p ADA_COMPAT &>/dev/null; then > + die 'ADA_COMPAT not declared.' > + fi > + if [[ $(declare -p ADA_COMPAT) !=3D "declare -a"* ]]; then > + die 'ADA_COMPAT must be an array.' > + fi > + for i in "${ADA_COMPAT[@]}"; do > + # trigger validity checks > + _ada_impl_supported "${i}" > + done > + > + local supp=3D() unsupp=3D() > + > + for i in "${_ADA_ALL_IMPLS[@]}"; do > + if has "${i}" "${ADA_COMPAT[@]}"; then > + supp+=3D( "${i}" ) > + else > + unsupp+=3D( "${i}" ) > + fi > + done > + if [[ ! ${supp[@]} ]]; then > + die "No supported implementation in ADA_COMPAT." > + fi > + > + if [[ ${_ADA_SUPPORTED_IMPLS[@]} ]]; then > + # set once already, verify integrity > + if [[ ${_ADA_SUPPORTED_IMPLS[@]} !=3D ${supp[@]} ]]; then > + eerror "Supported impls (ADA_COMPAT) changed between inherits!" > + eerror "Before: ${_ADA_SUPPORTED_IMPLS[*]}" > + eerror "Now : ${supp[*]}" > + die "_ADA_SUPPORTED_IMPLS integrity check failed" > + fi > + if [[ ${_ADA_UNSUPPORTED_IMPLS[@]} !=3D ${unsupp[@]} ]]; then > + eerror "Unsupported impls changed between inherits!" > + eerror "Before: ${_ADA_UNSUPPORTED_IMPLS[*]}" > + eerror "Now : ${unsupp[*]}" > + die "_ADA_UNSUPPORTED_IMPLS integrity check failed" > + fi > + else > + _ADA_SUPPORTED_IMPLS=3D( "${supp[@]}" ) > + _ADA_UNSUPPORTED_IMPLS=3D( "${unsupp[@]}" ) > + readonly _ADA_SUPPORTED_IMPLS _ADA_UNSUPPORTED_IMPLS > + fi > +} > + > +# @FUNCTION: ada_export For the record, I consider python_export() API a mistake. The wrapper API was added later and with it, there's really no need for _export() API, just wrapper setup and getters. > +# @USAGE: [] ... > +# @DESCRIPTION: > +# Set and export the Ada implementation-relevant variables passed > +# as parameters. > +# > +# The optional first parameter may specify the requested Ada > +# implementation (either as ADA_TARGETS value, e.g. ada2_7, > +# or an EADA one, e.g. ada2.7). If no implementation passed, > +# the current one will be obtained from ${EADA}. > +# > +# The variables which can be exported are: GCC, EADA, GNATMAKE. > +# They are described more completely in the eclass > +# variable documentation. > +ada_export() { > + debug-print-function ${FUNCNAME} "${@}" > + > + local impl var > + > + case "${1}" in > + gnat_201[6789]) > + impl=3D${1} > + shift > + ;; > + *) > + impl=3D${EADA} > + if [[ -z ${impl} ]]; then > + die "ada_export called without a ada implementation and EADA is unse= t" > + fi > + ;; > + esac > + debug-print "${FUNCNAME}: implementation: ${impl}" > + > + local gcc_pv > + case "${impl}" in > + gnat_2016) > + gcc_pv=3D4.9.4 > + ;; > + gnat_2017) > + gcc_pv=3D6.3.0 > + ;; > + gnat_2018) > + gcc_pv=3D7.3.1 > + ;; > + gnat_2019) > + gcc_pv=3D8.3.1 > + ;; > + *) > + gcc_pv=3D"9.9.9" > + ;; > + esac > + > + for var; do > + case "${var}" in > + EADA) > + export EADA=3D${impl} > + debug-print "${FUNCNAME}: EADA =3D ${EADA}" > + ;; > + GCC) > + export GCC=3D${EPREFIX}/usr/bin/gcc-${gcc_pv} > + debug-print "${FUNCNAME}: GCC =3D ${GCC}" > + ;; > + GCC_PV) > + export GCC_PV=3D${gcc_pv} > + debug-print "${FUNCNAME}: GCC_PV =3D ${GCC_PV}" > + ;; > + GNATBIND) > + export GNATBIND=3D${EPREFIX}/usr/bin/gnatbind-${gcc_pv} > + debug-print "${FUNCNAME}: GNATBIND =3D ${GNATBIND}" > + ;; > + GNATMAKE) > + export GNATMAKE=3D${EPREFIX}/usr/bin/gnatmake-${gcc_pv} > + debug-print "${FUNCNAME}: GNATMAKE =3D ${GNATMAKE}" > + ;; > + GNATLS) > + export GNATLS=3D${EPREFIX}/usr/bin/gnatls-${gcc_pv} > + debug-print "${FUNCNAME}: GNATLS =3D ${GNATLS}" > + ;; > + ADA_PKG_DEP) > + ADA_PKG_DEP=3D"dev-lang/gnat-gpl:${gcc_pv}" > + > + # use-dep > + if [[ ${ADA_REQ_USE} ]]; then > + ADA_PKG_DEP+=3D[${ADA_REQ_USE}] > + fi > + > + export ADA_PKG_DEP > + debug-print "${FUNCNAME}: ADA_PKG_DEP =3D ${ADA_PKG_DEP}" > + ;; > + *) > + die "ada_export: unknown variable ${var}" > + esac > + done > +} > + > +_ada_single_set_globals() { > + _ada_set_impls > + local i ADA_PKG_DEP > + > + local flags=3D( "${_ADA_SUPPORTED_IMPLS[@]/#/ada_target_}" ) > + local unflags=3D( "${_ADA_UNSUPPORTED_IMPLS[@]/#/-ada_target_}" ) > + local allflags=3D( ${flags[@]} ${unflags[@]} ) > + > + local optflags=3D${flags[@]/%/(-)?} > + > + IUSE=3D"${allflags[*]}" > + > + if [[ ${#_ADA_UNSUPPORTED_IMPLS[@]} -gt 0 ]]; then > + optflags+=3D,${unflags[@]/%/(-)} > + fi > + > + local deps requse usedep > + if [[ ${#_ADA_SUPPORTED_IMPLS[@]} -eq 1 ]]; then > + # There is only one supported implementation; set IUSE and other > + # variables without ADA_SINGLE_TARGET. > + requse=3D${flags[*]} > + ada_export "${_ADA_SUPPORTED_IMPLS[0]}" ADA_PKG_DEP > + deps=3D"${flags[*]}? ( ${ADA_PKG_DEP} ) " > + else > + # Multiple supported implementations; honor ADA_TARGET. > + requse=3D"^^ ( ${flags[*]} )" > + > + for i in "${_ADA_SUPPORTED_IMPLS[@]}"; do > + ada_export "${i}" ADA_PKG_DEP > + deps+=3D"ada_target_${i}? ( ${ADA_PKG_DEP} ) " > + done > + fi > + usedep=3D${optflags// /,} > + if [[ ${ADA_DEPS+1} ]]; then > + if [[ ${ADA_DEPS} !=3D "${deps}" ]]; then > + eerror "ADA_DEPS have changed between inherits (ADA_REQ_USE?)!" > + eerror "Before: ${ADA_DEPS}" > + eerror "Now : ${deps}" > + die "ADA_DEPS integrity check failed" > + fi > + > + # these two are formality -- they depend on ADA_COMPAT only > + if [[ ${ADA_REQUIRED_USE} !=3D ${requse} ]]; then > + eerror "ADA_REQUIRED_USE have changed between inherits!" > + eerror "Before: ${ADA_REQUIRED_USE}" > + eerror "Now : ${requse}" > + die "ADA_REQUIRED_USE integrity check failed" > + fi > + > + if [[ ${ADA_USEDEP} !=3D "${usedep}" ]]; then > + eerror "ADA_USEDEP have changed between inherits!" > + eerror "Before: ${ADA_USEDEP}" > + eerror "Now : ${usedep}" > + die "ADA_USEDEP integrity check failed" > + fi > + else > + ADA_DEPS=3D${deps} > + ADA_REQUIRED_USE=3D${requse} > + ADA_USEDEP=3D${usedep} > + readonly ADA_DEPS ADA_REQUIRED_USE ADA_USEDEP > + fi > +} > +_ada_single_set_globals > +unset -f _ada_single_set_globals > + > +# @FUNCTION: ada_wrapper_setup > +# @USAGE: [ []] > +# @DESCRIPTION: > +# Create proper 'ada' executable wrappers > +# in the directory named by . Set up PATH > +# appropriately. defaults to ${T}/${EADA}. > +# > +# The wrappers will be created for implementation named by , > +# or for one named by ${EADA} if no passed. > +# > +# If the named directory contains a ada symlink already, it will > +# be assumed to contain proper wrappers already and only environment > +# setup will be done. If wrapper update is requested, the directory > +# shall be removed first. > +ada_wrapper_setup() { > + debug-print-function ${FUNCNAME} "${@}" > + > + local workdir=3D${1:-${T}/${EADA}} > + local impl=3D${2:-${EADA}} > + > + [[ ${workdir} ]] || die "${FUNCNAME}: no workdir specified." > + [[ ${impl} ]] || die "${FUNCNAME}: no impl nor EADA specified." > + > + if [[ ! -x ${workdir}/bin/gnatmake ]]; then > + mkdir -p "${workdir}"/bin || die > + > + local GCC GNATMAKE GNATLS GNATBIND > + ada_export "${impl}" GCC GNATMAKE GNATLS GNATBIND This seems like basically a lot of indirection for unclear purpose. The export/getter logic in Python is there because we sometimes need those values in ebuilds. Do you expect to need them outside the wrapper? If not, it would probably be more readable to just inline proper paths here. > + > + # Ada compiler > + cat > "${workdir}/bin/gcc" <<-_EOF_ || die > + #!/bin/sh > + exec "${GCC}" "\${@}" > + _EOF_ > + chmod a+x "${workdir}/bin/gcc" || die. > + cat > "${workdir}/bin/gnatmake" <<-_EOF_ || die > + #!/bin/sh > + exec "${GNATMAKE}" "\${@}" > + _EOF_ > + chmod a+x "${workdir}/bin/gnatmake" > + cat > "${workdir}/bin/gnatls" <<-_EOF_ || die > + #!/bin/sh > + exec "${GNATLS}" "\${@}" > + _EOF_ > + chmod a+x "${workdir}/bin/gnatls" > + cat > "${workdir}/bin/gnatbind" <<-_EOF_ || die > + #!/bin/sh > + exec "${GNATBIND}" "\${@}" > + _EOF_ > + chmod a+x "${workdir}/bin/gnatbind" > + fi > + > + # Now, set the environment. > + # But note that ${workdir} may be shared with something else, > + # and thus already on top of PATH. > + if [[ ${PATH##:*} !=3D ${workdir}/bin ]]; then > + PATH=3D${workdir}/bin${PATH:+:${PATH}} > + fi > + export PATH > +} > + > +# @FUNCTION: ada_setup > +# @DESCRIPTION: > +# Determine what the selected Ada implementation is and set > +# the Ada build environment up for it. > +ada_setup() { > + debug-print-function ${FUNCNAME} "${@}" > + > + unset EADA > + > + if [[ ${#_ADA_SUPPORTED_IMPLS[@]} -eq 1 ]]; then > + if use "ada_targets_${_ADA_SUPPORTED_IMPLS[0]}"; then > + # Only one supported implementation, enable it explicitly > + ada_export "${_ADA_SUPPORTED_IMPLS[0]}" EADA GCC GCC_PV GNATMAKE Why do you export it first, then again in the wrapper setup function? > + ada_wrapper_setup > + fi > + else > + local impl > + for impl in "${_ADA_SUPPORTED_IMPLS[@]}"; do > + if use "ada_target_${impl}"; then > + if [[ ${EADA} ]]; then > + eerror "Your ADA_TARGET setting lists more than a single Ada" > + eerror "implementation. Please set it to just one value. If you nee= d" > + eerror "to override the value for a single package, please use pack= age.env" > + eerror "or an equivalent solution (man 5 portage)." > + echo > + die "More than one implementation in ADA_TARGET." > + fi > + > + ada_export "${impl}" EADA GCC GCC_PV GNATMAKE > + ada_wrapper_setup > + fi > + done > + fi > + > + if [[ ! ${EADA} ]]; then > + eerror "No Ada implementation selected for the build. Please set" > + if [[ ${#_ADA_SUPPORTED_IMPLS[@]} -eq 1 ]]; then > + eerror "the ADA_TARGETS variable in your make.conf to include one" > + else > + eerror "the ADA_SINGLE_TARGET variable in your make.conf to one" > + fi > + eerror "of the following values:" > + eerror > + eerror "${_ADA_SUPPORTED_IMPLS[@]}" > + echo > + die "No supported Ada implementation in ADA_SINGLE_TARGET/ADA_TARGETS.= " > + fi > +} > + > +# @FUNCTION: ada_pkg_setup > +# @DESCRIPTION: > +# Runs ada_setup. > +ada_pkg_setup() { > + debug-print-function ${FUNCNAME} "${@}" > + > + [[ ${MERGE_TYPE} !=3D binary ]] && ada_setup > +} --=20 Best regards, Micha=C5=82 G=C3=B3rny --=-2cF1zrckQ31D1Ae+PB8H Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQGTBAABCgB9FiEEx2qEUJQJjSjMiybFY5ra4jKeJA4FAl17+MBfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldEM3 NkE4NDUwOTQwOThEMjhDQzhCMjZDNTYzOUFEQUUyMzI5RTI0MEUACgkQY5ra4jKe JA7f6gf9EwDMTSbxOJ3VRyzDgzdt/M3vtVd0A87txDwugv5A8YHItBZwIu84Aqwe zPc986d4GtR5g379TzG2DfABuaV2FLKiRLvD16dU3uR19OpaL7epj+NP94fIUIZ2 xKUff3vPCHppw8tA0KAb1G9wzGU+FZuyAFldNzLKMRwDU8gA6P8OUFTX/vzt5t7s naaKf0BbKzSPapo9wavkCaqDPC4+7F5LPsiE5Sou1q4pgCTqjc2z5zRyIKjcCuHn /2TXdWbS0A92odp5SNyff6fCs4kGb6uFPovQZqJ2pXhiMs6TajSjr5GTKoDyu083 YHmaMAioo9Nq5Zr+y+FNGyXkWlCjjw== =rOEd -----END PGP SIGNATURE----- --=-2cF1zrckQ31D1Ae+PB8H--