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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id C8262158009 for ; Wed, 28 Jun 2023 08:52:08 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E129CE08EB; Wed, 28 Jun 2023 08:52:04 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 9D9FFE08D1 for ; Wed, 28 Jun 2023 08:52:04 +0000 (UTC) Message-ID: Subject: Re: [gentoo-dev] [PATCH 1/2] gradle.eclass: add new eclass From: =?UTF-8?Q?Micha=C5=82_G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: Florian Schmaus Date: Wed, 28 Jun 2023 10:51:59 +0200 In-Reply-To: <20230628075245.892402-2-flow@gentoo.org> References: <20230106172051.274199-1-flow@gentoo.org> <20230628075245.892402-1-flow@gentoo.org> <20230628075245.892402-2-flow@gentoo.org> Organization: Gentoo Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.3 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: 486a7b3e-2a88-4a63-aae5-a86ff988c256 X-Archives-Hash: a3ff4b3aac57c9df2a5c10753f9f8e19 On Wed, 2023-06-28 at 09:52 +0200, Florian Schmaus wrote: > Signed-off-by: Florian Schmaus > --- > eclass/gradle.eclass | 208 +++++++++++++++++++++++++++++++++++++++++ > eclass/tests/gradle.sh | 62 ++++++++++++ > 2 files changed, 270 insertions(+) > create mode 100644 eclass/gradle.eclass > create mode 100755 eclass/tests/gradle.sh >=20 > diff --git a/eclass/gradle.eclass b/eclass/gradle.eclass > new file mode 100644 > index 000000000000..91c8299d0c98 > --- /dev/null > +++ b/eclass/gradle.eclass > @@ -0,0 +1,208 @@ > +# Copyright 2021-2023 Gentoo Authors > +# Distributed under the terms of the GNU General Public License v2 > + > +# @ECLASS: gradle.eclass > +# @MAINTAINER: > +# Gentoo Java Project > +# @AUTHOR: > +# Florian Schmaus > +# @BLURB: common ebuild functions for gradle-based packages. > +# @DESCRIPTION: > +# This eclass provides support for the gradle build system. There > +# are currently two approaches to using gradle in ebuilds. You can eith= er > +# depend on a gradle system-wide installation from a gradle ebuild, typi= cally > +# dev-java/gradle-bin, or, bundle gradle with the ebuild. > +# > +# To use a system-wide gradle installation, set EGRADLE_MIN and > +# EGRADLE_MAX_EXCLUSIVE and declare a BDEPEND on the gradle package. > +# @CODE > +# inherit gradle > +# EGRADLE_MIN=3D7.3 > +# EGRADLE_MAX_EXCLUSIVE=3D8 > +# > +# BDEPEND=3D"|| (dev-java/gradle-bin:7.3 dev-java/gradle-bin:7.4) > +# @CODE > +# > +# To use a bundled gradle version, set EGRADLE_BUNDLED_VER and add > +# $(gradle_src_uri) to SRC_URI. > +# @CODE > +# inherit gradle > +# EGRADLE_BUNDLED_VER=3D7.6 > +# SRC_URI=3D" > +# ... > +# $(gradle_src_uri) > +# " Given that we're currently fighting major inefficiency caused by $() approach in cargo.eclass, is there a need to use that over an exported var in this new eclass? > +# src_unpack() { > +# default > +# gradle-src_unpack > +# } > +# @CODE > +# > +# Afterwards, use egradle to invoke gradle. > +# @CODE > +# src_compile() { > +# egradle build > +# } > +# @CODE > + > +case ${EAPI} in > + 7|8) ;; > + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; > +esac > + > +if [[ -z ${_GRADLE_ECLASS} ]] ; then > +_GRADLE_ECLASS=3D1 > + > +inherit edo > + > +# @ECLASS_VARIABLE: EGRADLE_MIN > +# @DEFAULT_UNSET > +# @DESCRIPTION: > +# Minimum required gradle version. > + > +# @ECLASS_VARIABLE: EGRADLE_MAX_EXCLUSIVE > +# @DEFAULT_UNSET > +# @DESCRIPTION: > +# First gradle version that is not supported. > + > +# @ECLASS_VARIABLE: EGRADLE_EXACT_VER > +# @DEFAULT_UNSET > +# @DESCRIPTION: > +# The exact required gradle version. > + > +# @ECLASS_VARIABLE: EGRADLE_BUNDLED_VER > +# @DEFAULT_UNSET > +# @DESCRIPTION: > +# The gradle version that will be bundled with this package. > + > +# @ECLASS_VARIABLE: EGRADLE_PARALLEL > +# @DESCRIPTION: > +# Set to the 'true', the default, to invoke gradle with --parallel. Set > +# to 'false' to disable parallel gradle builds. > +: "${EGRADLE_PARALLEL=3Dtrue}" > + > +# @ECLASS_VARIABLE: EGRADLE_USER_HOME > +# @DESCRIPTION: > +# Directroy used as the user's home directory by gradle. Defaults to > +# ${T}/gradle_user_home > +: "${EGRADLE_USER_HOME=3D"${T}/gradle_user_home"}" > + > +# @ECLASS_VARIABLE: EGRADLE_OVERWRITE > +# @USER_VARIABLE > +# @DEFAULT_UNSET > +# @DESCRIPTION: > +# User-specified overwrite of the used gradle binary. > + > +# @FUNCTION: gradle-set_EGRADLE > +# @DESCRIPTION: > +# Set the EGRADLE environment variable. > +gradle-set_EGRADLE() { > + [[ -n ${EGRADLE} ]] && return > + > + if [[ -n ${EGRADLE_OVERWRITE} ]]; then > + EGRADLE=3D"${EGRADLE_OVERWRITE}" > + return > + fi > + > + if [[ -n ${EGRADLE_BUNDLED_VER} ]]; then > + EGRADLE=3D"${WORKDIR}/gradle-${EGRADLE_BUNDLED_VER}/bin/gradle" > + return > + fi > + > + local candidate selected selected_ver ver > + > + for candidate in "${BROOT}"/usr/bin/gradle-; do > + if [[ ${candidate} !=3D */gradle?(-bin)-+([.0-9]) ]]; then > + continue > + fi > + > + ver=3D${candidate##*-} > + > + if [[ -n ${EGRADLE_EXACT_VER} ]]; then > + ver_test "${ver}" -ne "${EGRADLE_EXACT_VER}" && continue > + > + selected=3D"${candidate}" > + break > + fi > + > + if [[ -n ${EGRADLE_MIN} ]] \ > + && ver_test "${ver}" -lt "${EGRADLE_MIN}"; then > + # Candidate does not satisfy EGRADLE_MIN condition. > + continue > + fi > + > + if [[ -n ${EGRADLE_MAX_EXCLUSIVE} ]] \ > + && ver_test "${ver}" -ge "${EGRADLE_MAX_EXCLUSIVE}"; then > + # Candidate does not satisfy EGRADLE_MAX_EXCLUSIVE condition. > + continue > + fi > + > + if [[ -n ${selected_ver} ]] \ > + && ver_test "${selected_ver}" -gt "${ver}"; then > + # Candidate is older than the currently selected candidate. > + continue > + fi > + > + selected=3D"${candidate}" > + selected_ver=3D"${ver}" > + done > + > + if [[ -z ${selected} ]]; then > + die "Could not find (suitable) gradle installation in ${BROOT}/usr/bin= " > + fi > + > + EGRADLE=3D"${selected}" > +} > + > +# @FUNCTION: gradle-src_uri > +# @DESCRIPTION: > +# Generate SRC_URI data from EGRADLE_BUNDLED_VER. > +gradle-src_uri() { > + if [[ -z ${EGRADLE_BUNDLED_VER} ]]; then > + die "Must set EGRADLE_BUNDLED_VER when calling gradle-src_uri" > + fi > + echo "https://services.gradle.org/distributions/gradle-${EGRADLE_BUNDLE= D_VER}-bin.zip" > +} > + > +# @FUNCTION: gradle-src_unpack > +# @DESCRIPTION: > +# Unpack the "bundled" gradle version. You must have > +# EGRADLE_BUNDLED_VER set when calling this function. > +gradle-src_unpack() { > + if [[ -z ${EGRADLE_BUNDLED_VER} ]]; then > + die "Must set EGRADLE_BUNDLED_VER when calling gradle-src_unpack" > + fi > + > + unpack "gradle-${EGRADLE_BUNDLED_VER}-bin.zip" > +} > + > +# @FUNCTION: egradle > +# @USAGE: [gradle-args] > +# @DESCRIPTION: > +# Invoke gradle with the optionally provided arguments. > +egradle() { > + gradle-set_EGRADLE > + > + local gradle_args=3D( > + --console=3Dplain > + --info > + --stacktrace > + --no-daemon > + --offline > + --no-build-cache > + --gradle-user-home "${EGRADLE_USER_HOME}" > + --project-cache-dir "${T}/gradle_project_cache" > + ) > + > + if ${EGRADLE_PARALLEL}; then > + gradle_args+=3D( --parallel ) > + fi > + > + local -x JAVA_TOOL_OPTIONS=3D"${JAVA_TOOL_OPTIONS} -Duser.home=3D\"${T}= \"" > + # TERM needed, otherwise gradle may fail on terms it does not know abou= t > + TERM=3Dxterm \ > + edo \ > + "${EGRADLE}" "${gradle_args[@]}" "${@}" > +} > + > +fi > diff --git a/eclass/tests/gradle.sh b/eclass/tests/gradle.sh > new file mode 100755 > index 000000000000..61666c1bc60e > --- /dev/null > +++ b/eclass/tests/gradle.sh > @@ -0,0 +1,62 @@ > +#!/usr/bin/env bash > +# Copyright 2022-2023 Gentoo Authors > +# Distributed under the terms of the GNU General Public License v2 > + > +EAPI=3D8 > + > +SCRIPT_DIR=3D$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null = && pwd) > +cd "${SCRIPT_DIR}" > + > +source tests-common.sh || exit > + > +inherit gradle > + > +# TODO: hack because tests-common don't implement ver_cut > +EAPI=3D6 inherit eapi7-ver > + > +test_set_EGRADLE() { > + local expected_EGRADLE=3D"${1}" > + > + shift > + > + local tmpdir > + tmpdir=3D$(mktemp -d || die) > + for pseudo_gradle in "${@}"; do > + local pseudo_gradle_path=3D"${tmpdir}/${pseudo_gradle}" > + touch "${pseudo_gradle_path}" > + chmod 755 "${pseudo_gradle_path}" > + done > + > + local saved_PATH=3D"${PATH}" > + PATH=3D"${tmpdir}" > + > + local test_desc=3D( > + test_set_EGRADLE > + ) > + [[ -v EGRADLE_MIN ]] && test_desc+=3D( "EGRADLE_MIN=3D${EGRADLE_MIN}" ) > + [[ -v EGRADLE_MAX_EXCLUSIVE ]] && test_desc+=3D( "EGRADLE_MAX_EXCLUSIVE= =3D${EGRADLE_MAX_EXCLUSIVE}" ) > + test_desc+=3D( $@ ) > + > + tbegin "${test_desc[@]}" > + gradle-set_EGRADLE > + > + local saved_EGRADLE=3D"${EGRADLE}" > + unset EGRADLE > + > + PATH=3D"${saved_PATH}" > + rm -rf "${tmpdir}" > + > + [[ "${saved_EGRADLE}" =3D=3D "${expected_EGRADLE}" ]] > + tend $? > + > + if (( $? > 0 )); then > + >&2 echo -e "\t expected=3D${expected_EGRADLE} actual=3D${saved_EGRADL= E}" > + fi > +} > + > +test_set_EGRADLE gradle-2.0 gradle-1.0 gradle-2.0 > +EGRADLE_MIN=3D2.0 test_set_EGRADLE gradle-2.2.3 gradle-1.0 gradle-2.0 gr= adle-2.2.3 > +EGRADLE_MAX_EXCLUSIVE=3D2.2 test_set_EGRADLE gradle-2.0 gradle-1.0 gradl= e-2.0 gradle-2.2.3 > + > + > +texit --=20 Best regards, Micha=C5=82 G=C3=B3rny