• [gentoo-dev] [PATCH] gradle.eclass: add new eclass

    From Florian Schmaus@21:1/5 to All on Fri Jan 6 18:30:01 2023
    Signed-off-by: Florian Schmaus <flow@gentoo.org>
    ---
    eclass/gradle.eclass | 149 +++++++++++++++++++++++++++++++++++++++++
    eclass/tests/gradle.sh | 62 +++++++++++++++++
    2 files changed, 211 insertions(+)
    create mode 100644 eclass/gradle.eclass
    create mode 100755 eclass/tests/gradle.sh

    diff --git a/eclass/gradle.eclass b/eclass/gradle.eclass
    new file mode 100644
    index 000000000000..a321262612d0
    --- /dev/null
    +++ b/eclass/gradle.eclass
    @@ -0,0 +1,149 @@
    +# Copyright 2021-2023 Gentoo Authors
    +# Distributed under the terms of the GNU General Public License v2
    +
    +# @ECLASS: gradle.eclass
    +# @MAINTAINER:
    +# Gentoo Java Project <java@gentoo.org>
    +# @AUTHOR:
    +# Florian Schmaus <flow@gentoo.org>
    +# @BLURB: Utility functions for the gradle build system.
    +# @DESCRIPTION:
    +# Utility functions for the gradle build system.
    +
    +case ${EAPI} in
    + 7|8) ;;
    + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
    +esac
    +
    +if [[ -z ${_GRADLE_ECLASS} ]] ; then
    +_GRADLE_ECLASS=1
    +
    +inherit edo
    +
    +# @ECLASS_VARIABLE: EGRADLE_MIN
    +# @DEFAUL
  • From Sam James@21:1/5 to All on Sat Jan 7 05:30:01 2023
    On 6 Jan 2023, at 17:20, Florian Schmaus <flow@gentoo.org> wrote:

    Signed-off-by: Florian Schmaus <flow@gentoo.org>
    ---
    eclass/gradle.eclass | 149 +++++++++++++++++++++++++++++++++++++++++ eclass/tests/gradle.sh | 62 +++++++++++++++++
    2 files changed, 211 insertions(+)
    create mode 100644 eclass/gradle.eclass
    create mode 100755 eclass/tests/gradle.sh

    diff --git a/eclass/gradle.eclass b/eclass/gradle.eclass
    [...]

    +
    +# @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.
    +

    It feels a pity to not use the now-somewhat standard PYTHON_COMPAT/LUA_COMPAT-style API.

    Is there a reason not to?

    If it doesn't fit how Gradle versioning works / the
    number of targets is likely to be far too high,
    It's fine as-is.


    -----BEGIN PGP SIGNATURE-----

    iNUEARYKAH0WIQQlpruI3Zt2TGtVQcJzhAn1IN+RkAUCY7j1HV8UgAAAAAAuAChp c3N1ZXItZnByQG5vdGF0aW9ucy5vcGVucGdwLmZpZnRoaG9yc2VtYW4ubmV0MjVB NkJCODhERDlCNzY0QzZCNTU0MUMyNzM4NDA5RjUyMERGOTE5MAAKCRBzhAn1IN+R kKpeAQCBH5smqDdTCY02jTfwoewf5um/Un4LHRiMeIerXuCmzwEAjHkDVgLj12Vu XtlA1yTKXGB/SwFdoaWVsWYfQ0FcKQ0=
    =W5ln
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anna@21:1/5 to Florian Schmaus on Sat Jan 7 07:10:01 2023
    On 2023-01-06 18:20, Florian Schmaus wrote:
    Signed-off-by: Florian Schmaus <flow@gentoo.org>
    ---
    eclass/gradle.eclass | 149 +++++++++++++++++++++++++++++++++++++++++
    eclass/tests/gradle.sh | 62 +++++++++++++++++
    2 files changed, 211 insertions(+)
    create mode 100644 eclass/gradle.eclass
    create mode 100755 eclass/tests/gradle.sh

    diff --git a/eclass/gradle.eclass b/eclass/gradle.eclass
    new file mode 100644
    index 000000000000..a321262612d0
    --- /dev/null
    +++ b/eclass/gradle.eclass
    @@ -0,0 +1,149 @@
    +# Copyright 2021-2023 Gentoo Authors
    +# Distributed under the terms of the GNU General Public License v2
    +
    +# @ECLASS: gradle.eclass

    I think "gradle-utils" is a better name since the eclass does not export
    any phase functions or set metadata variables (this should be noted in
    the description btw).

    +# @MAINTAINER:
    +# Gentoo Java Project <java@gentoo.org>
    +# @AUTHOR:
    +# Florian Schmaus <flow@gentoo.org>
    +# @BLURB: Utility functions for the gradle build system.

    First letter should not be capitalized (for manpage reasons).

    +# @DESCRIPTION:
    +# Utility functions for the gradle build system.

    Either drop description or don't repeat blurb here.

    +
    +case ${EAPI} in
    + 7|8) ;;
    + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
    +esac
    +
    +if [[ -z ${_GRADLE_ECLASS} ]] ; then
    +_GRADLE_ECLASS=1
    +
    +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_PARALLEL
    +# @DESCRIPTION:
    +# Set to the 'true', the default, to invoke gradle with --parallel. Set
    +# to 'false' to disable parallel gradle builds.
    +: "${EGRADLE_PARALLEL=true}"

    Can be deduced indeirectly (when "makeopts_jobs" equals to 1).

    +
    +# @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="${T}/gradle_user_home"}"

    Can it be just ${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
    + export EGRADLE="${EGRADLE_OVERWRITE}"

    Any reason to export?

    + return
    + fi
    +
    + local candidates candidate selected selected_ver
    +
    + candidates=$(compgen -c gradle-)
    + for candidate in ${candidates}; do
    + if [[ ! ${candidate} =~ gradle(-bin)?-([.0-9]+) ]]; then
    + continue
    + fi
    +
    + local ver
    + if (( ${#BASH_REMATCH[@]} == 3 )); then
    + ver="${BASH_REMATCH[2]}"
    + else
    + ver="${BASH_REMATCH[1]}"
    + fi
    +
    + if [[ -n ${EGRADLE_EXACT_VER} ]]; then
    + ver_test "${ver}" -ne "${EGRADLE_EXACT_VER}" && continue
    +
    + selected="${candidate}"
    + selected_ver="${ver}"
    + 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="${candidate}"
    + selected_ver="${ver}"
    + done
    +
    + if [[ -z ${selected} ]]; then
    + die "Could not find (suitable) gradle installation in PATH"
    + fi
    +
    + export EGRADLE="${selected}"
    + export EGRADLE_VER="${ver}"
    +}
    +
    +# @FUNCTION: egradle
    +# @USAGE: [gradle-args]
    +# @DESCRIPTION:
    +# Invoke gradle with the optionally provided arguments.
    +egradle() {
    + gradle-set_EGRADLE
    +
    + local gradle_args=(
    + --console=plain
    + --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

    ${Braces}

    + gradle_args+=( --parallel )
    + fi
    +
    + local -x JAVA_TOOL_OPTIONS="-Duser.home=\"$T\""

    ${Braces}

    + # TERM needed, otherwise gradle may fail on terms it does not know about
    + TERM=xterm \
    + 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=8
    +
    +SCRIPT_DIR=$(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=6 inherit eapi7-ver
    +
    +test_set_EGRADLE() {
    + local expected_EGRADLE="${1}"
    +
    + shift
    +
    + local tmpdir
    + tmpdir=$(mktemp -d || die)
    + for pseudo_gradle in "${@}"; do
    + local pseudo_gradle_path="${tmpdir}/${pseudo_gradle}"
    + touch "${pseudo_gradle_path}"
    + chmod 755 "${pseudo_gradle_path}"
    + done
    +
    + local saved_PATH="${PATH}"
    + PATH="${tmpdir}"
    +
    + local test_desc=(
    + test_set_EGRADLE
    + )
    + [[ -v EGRADLE_MIN ]] && test_desc+=( "EGRADLE_MIN=${EGRADLE_MIN}" )
    + [[ -v EGRADLE_MAX_EXCLUSIVE ]] && test_desc+=( "EGRADLE_MAX_EXCLUSIVE=${EGRADLE_MAX_EXCLUSIVE}" )
    + test_desc+=( $@ )
    +
    + tbegin "${test_desc[@]}"
    + gradle-set_EGRADLE
    +
    + local saved_EGRADLE="${EGRADLE}"
    + unset EGRADLE
    +
    + PATH="${saved_PATH}"
    + rm -rf "${tmpdir}"
    +
    + [[ "${saved_EGRADLE}" == "${expected_EGRADLE}" ]]
    + tend $?
    +
    + if (( $? > 0 )); then
    + >&2 echo -e "\t expected=${expected_EGRADLE} actual=${saved_EGRADLE}"
    + fi
    +}
    +
    +test_set_EGRADLE gradle-2.0 gradle-1.0 gradle-2.0
    +EGRADLE_MIN=2.0 test_set_EGRADLE gradle-2.2.3 gradle-1.0 gradle-2.0 gradle-2.2.3
    +EGRADLE_MAX_EXCLUSIVE=2.2 test_set_EGRADLE gradle-2.0 gradle-1.0 gradle-2.0 gradle-2.2.3
    +
    +
    +texit
    --
    2.38.2



    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Florian Schmaus@21:1/5 to Sam James on Sat Jan 7 12:00:01 2023
    On 07/01/2023 05.29, Sam James wrote:


    On 6 Jan 2023, at 17:20, Florian Schmaus <flow@gentoo.org> wrote:

    Signed-off-by: Florian Schmaus <flow@gentoo.org>
    ---
    eclass/gradle.eclass | 149 +++++++++++++++++++++++++++++++++++++++++
    eclass/tests/gradle.sh | 62 +++++++++++++++++
    2 files changed, 211 insertions(+)
    create mode 100644 eclass/gradle.eclass
    create mode 100755 eclass/tests/gradle.sh

    diff --git a/eclass/gradle.eclass b/eclass/gradle.eclass
    [...]

    +
    +# @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.
    +

    It feels a pity to not use the now-somewhat standard PYTHON_COMPAT/LUA_COMPAT-style API.

    Is there a reason not to?

    If it doesn't fit how Gradle versioning works / the
    number of targets is likely to be far too high,
    It's fine as-is.

    The _COMPAT-style API would work for Java LTS versions, but not for fast
    moving targets like Gradle versions.

    Gradle has overall a good compatibility story, breaking changes are
    typically just introduced in new major versions. But sometimes you need
    a particular Gradle version range, like [6.2,6.8) due the mixins of
    Gradle plugins.

    I expect that the number of Java projects that use Gradle will continue
    to grow. Because of that we probably need to provide a diverse range of
    Gradle versions.

    - Flow

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)