* [gentoo-dev] RFC: new gradle.eclass @ 2023-01-06 17:20 Florian Schmaus 2023-01-06 17:20 ` [gentoo-dev] [PATCH] gradle.eclass: add new eclass Florian Schmaus ` (3 more replies) 0 siblings, 4 replies; 14+ messages in thread From: Florian Schmaus @ 2023-01-06 17:20 UTC (permalink / raw To: gentoo-dev Happy new year everyone! I'd like to as for a review of an initial eclass for gradle. This is my first eclass, so I am sure there is plenty to find. ;) The related github PR is https://github.com/gentoo/gentoo/pull/28986 - Flow ^ permalink raw reply [flat|nested] 14+ messages in thread
* [gentoo-dev] [PATCH] gradle.eclass: add new eclass 2023-01-06 17:20 [gentoo-dev] RFC: new gradle.eclass Florian Schmaus @ 2023-01-06 17:20 ` Florian Schmaus 2023-01-07 4:29 ` Sam James 2023-01-07 6:07 ` Anna 2023-01-06 17:51 ` [gentoo-dev] RFC: new gradle.eclass Maciej Barć ` (2 subsequent siblings) 3 siblings, 2 replies; 14+ messages in thread From: Florian Schmaus @ 2023-01-06 17:20 UTC (permalink / raw To: gentoo-dev; +Cc: Florian Schmaus 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 +# @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}" + +# @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"}" + +# @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}" + 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 + gradle_args+=( --parallel ) + fi + + local -x JAVA_TOOL_OPTIONS="-Duser.home=\"$T\"" + # 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 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [gentoo-dev] [PATCH] gradle.eclass: add new eclass 2023-01-06 17:20 ` [gentoo-dev] [PATCH] gradle.eclass: add new eclass Florian Schmaus @ 2023-01-07 4:29 ` Sam James 2023-01-07 10:58 ` Florian Schmaus 2023-01-07 6:07 ` Anna 1 sibling, 1 reply; 14+ messages in thread From: Sam James @ 2023-01-07 4:29 UTC (permalink / raw To: gentoo-dev; +Cc: Florian Schmaus [-- Attachment #1: Type: text/plain, Size: 1063 bytes --] > 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. [-- Attachment #2: Message signed with OpenPGP --] [-- Type: application/pgp-signature, Size: 358 bytes --] ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-dev] [PATCH] gradle.eclass: add new eclass 2023-01-07 4:29 ` Sam James @ 2023-01-07 10:58 ` Florian Schmaus 0 siblings, 0 replies; 14+ messages in thread From: Florian Schmaus @ 2023-01-07 10:58 UTC (permalink / raw To: Sam James, gentoo-dev 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-dev] [PATCH] gradle.eclass: add new eclass 2023-01-06 17:20 ` [gentoo-dev] [PATCH] gradle.eclass: add new eclass Florian Schmaus 2023-01-07 4:29 ` Sam James @ 2023-01-07 6:07 ` Anna 1 sibling, 0 replies; 14+ messages in thread From: Anna @ 2023-01-07 6:07 UTC (permalink / raw To: gentoo-dev 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 > > ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-dev] RFC: new gradle.eclass 2023-01-06 17:20 [gentoo-dev] RFC: new gradle.eclass Florian Schmaus 2023-01-06 17:20 ` [gentoo-dev] [PATCH] gradle.eclass: add new eclass Florian Schmaus @ 2023-01-06 17:51 ` Maciej Barć 2023-01-06 18:52 ` Yuan Liao (Leo) 2023-06-28 7:52 ` [gentoo-dev] [PATCH 0/2] " Florian Schmaus 3 siblings, 0 replies; 14+ messages in thread From: Maciej Barć @ 2023-01-06 17:51 UTC (permalink / raw To: gentoo-dev, Florian Schmaus [-- Attachment #1.1.1: Type: text/plain, Size: 448 bytes --] Hallelujah! Finally support for Gradle! Thank you so much for taking time to implement it! On 1/6/23 18:20, Florian Schmaus wrote: > Happy new year everyone! > > I'd like to as for a review of an initial eclass for gradle. This is my > first eclass, so I am sure there is plenty to find. ;) > > The related github PR is https://github.com/gentoo/gentoo/pull/28986 > > - Flow > > -- Have a great day! ~ Maciej XGQT Barć [-- Attachment #1.1.2: OpenPGP public key --] [-- Type: application/pgp-keys, Size: 10875 bytes --] [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 495 bytes --] ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-dev] RFC: new gradle.eclass 2023-01-06 17:20 [gentoo-dev] RFC: new gradle.eclass Florian Schmaus 2023-01-06 17:20 ` [gentoo-dev] [PATCH] gradle.eclass: add new eclass Florian Schmaus 2023-01-06 17:51 ` [gentoo-dev] RFC: new gradle.eclass Maciej Barć @ 2023-01-06 18:52 ` Yuan Liao (Leo) 2023-01-06 19:40 ` Florian Schmaus 2023-06-28 7:52 ` [gentoo-dev] [PATCH 0/2] " Florian Schmaus 3 siblings, 1 reply; 14+ messages in thread From: Yuan Liao (Leo) @ 2023-01-06 18:52 UTC (permalink / raw To: gentoo-dev While I warmly appreciate and welcome any effort to improve support for Java build systems on Gentoo, I also wonder what functionality ebuild authors who are creating a Java package might expect from an eclass called "gradle.eclass". I'm not doubting this eclass's usefulness -- to me, it looks like a convenient eclass when a Gradle project's dependencies are vendored and included in SRC_URI. Specialized eclasses are totally fine as we've already got plenty of them in the tree. But I think what an average Java ebuild author often wants is an eclass with which they can just declare all dependencies of the Gradle project in *DEPEND variables, and rely on the default pkg_* and src_* functions from the eclass to do the rest, with no or only minimal overrides necessary. They might trust the eclass to introduce any Java dependencies installed by Portage to Gradle, invoke the build system, and finally install the JARs built. Maybe we will be lucky enough to have such an eclass in the future. But should we add a remark to the eclass's description to warn that this might not be the generalized "gradle.eclass" suitable for packaging most Gradle-based projects, if that is what people would believe a "gradle.eclass" would do for them? Leo3418 On Fri, Jan 6, 2023 at 9:21 AM Florian Schmaus <flow@gentoo.org> wrote: > > Happy new year everyone! > > I'd like to as for a review of an initial eclass for gradle. This is my > first eclass, so I am sure there is plenty to find. ;) > > The related github PR is https://github.com/gentoo/gentoo/pull/28986 > > - Flow > > ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-dev] RFC: new gradle.eclass 2023-01-06 18:52 ` Yuan Liao (Leo) @ 2023-01-06 19:40 ` Florian Schmaus 0 siblings, 0 replies; 14+ messages in thread From: Florian Schmaus @ 2023-01-06 19:40 UTC (permalink / raw To: gentoo-dev On 06/01/2023 19.52, Yuan Liao (Leo) wrote: > While I warmly appreciate and welcome any effort to improve support > for Java build systems on Gentoo, I also wonder what functionality > ebuild authors who are creating a Java package might expect from an > eclass called "gradle.eclass". It is not strictly forbidden for an eclass to serve multiple use cases. However, there is an argument to separate the concerns into different eclasses (as we do already with other ecosystems). But we don't have those different concerns implemented right now. And there is IMHO a good reason this eclass should be called gradle.eclass: it provides basic functionality to discover a suitable gradle version and invoke gradle with sane defaults and in the idiomatic Gentoo way ("egradle <args>"). > I'm not doubting this eclass's usefulness -- to me, it looks like a > convenient eclass when a Gradle project's dependencies are vendored > and included in SRC_URI. The PR I mentioned migrates an openjfx ebuild from using its own gradle installation to the eclass [1]. And ::java has a ghidra ebuild [2] that uses gradle.eclass. Which was based on ::pentoo's ghidra ebuild with minor modifications to use the eclass. I recommend to look at the diff between the ::java version and ::pentoo version of the ghidra ebuild too. And the eclass, as is, is currently not only used for sideloaded dependencies. If you look at the openjfx ebuild then you will find that it consumes java libraries that are installed as Gentoo package (stringtemplate and hamcrest-core) and injects it into the Gradle build. > Specialized eclasses are totally fine as > we've already got plenty of them in the tree. But I think what an > average Java ebuild author often wants is an eclass with which they > can just declare all dependencies of the Gradle project in *DEPEND > variables, and rely on the default pkg_* and src_* functions from the > eclass to do the rest, with no or only minimal overrides necessary. > They might trust the eclass to introduce any Java dependencies > installed by Portage to Gradle, invoke the build system, and finally > install the JARs built. Yeah, that is what I also would prefer. And, in fact, this is done for many existing Java ebuilds. However, reality is that it is often not feasible to do so with modern Java build systems, as they switch from consuming Jar files to consuming Maven artifacts with POMs. I'd love to see an effort to remedy the situation and I actually believe the gradle.eclass provides basic functionality towards this, but the cruel reality is that we are far away from that (as far as I can tell) and currently do not have the manpower to make it happen. I would be happy to be proven wrong, though. Furthermore, the approach that the openjfx ebuild uses to inject libraries in the Gradle build is not generally applicable. IMHO the perfect solution would consists of a system-wide Maven repository, where Java ebuilds install their Jar files. And a robust way to tell Gradle (and Maven, …) to consume artifacts from such a system-wide Maven repository and a way to tell the build system to not perform any network activity. I think thin would be beneficial not only to Gentoo, but to other distributions too. But, again, it is a long way to get there. > Maybe we will be lucky enough to have such an eclass in the future. > But should we add a remark to the eclass's description to warn that > this might not be the generalized "gradle.eclass" suitable for > packaging most Gradle-based projects, if that is what people would > believe a "gradle.eclass" would do for them? I am not sure what such a warning is going to acomplish. But certainly, if "better" approaches are implemented, then our documentation should point them out. - Flow 1: https://github.com/gentoo/gentoo/pull/28986/commits/808197948074c1582d3e3c7877d68cb9a6fa2f72 2: https://github.com/gentoo/java-overlay/blob/master/dev-util/ghidra/ghidra-10.2.2-r2.ebuild ^ permalink raw reply [flat|nested] 14+ messages in thread
* [gentoo-dev] [PATCH 0/2] new gradle.eclass 2023-01-06 17:20 [gentoo-dev] RFC: new gradle.eclass Florian Schmaus ` (2 preceding siblings ...) 2023-01-06 18:52 ` Yuan Liao (Leo) @ 2023-06-28 7:52 ` Florian Schmaus 2023-06-28 7:52 ` [gentoo-dev] [PATCH 1/2] gradle.eclass: add new eclass Florian Schmaus ` (2 more replies) 3 siblings, 3 replies; 14+ messages in thread From: Florian Schmaus @ 2023-06-28 7:52 UTC (permalink / raw To: gentoo-dev; +Cc: Florian Schmaus I would like to propose the gradle.eclass for ::gentoo. Multiple people have shown interest in an eclass for Gradle, as it would make it easier to move Gradle-based projects into ::gentoo. For exmaple, ghidra from ::pentoo. And, as a nice bonus, the addition of the gradle eclass to ::gentoo would make it easier for overlays to use it. This, in turn, reduces the friction when migrating Gradle-based projects from overlays into ::gentoo. The second patch shows how gradle.eclass can be used in the openfjx ebuild. PR at https://github.com/gentoo/gentoo/pull/28986 Florian Schmaus (2): gradle.eclass: add new eclass dev-java/openjfx: switch to gradle.eclass dev-java/openjfx/openjfx-11.0.11_p1.ebuild | 46 ++--- eclass/gradle.eclass | 208 +++++++++++++++++++++ eclass/tests/gradle.sh | 62 ++++++ 3 files changed, 285 insertions(+), 31 deletions(-) create mode 100644 eclass/gradle.eclass create mode 100755 eclass/tests/gradle.sh -- 2.39.3 ^ permalink raw reply [flat|nested] 14+ messages in thread
* [gentoo-dev] [PATCH 1/2] gradle.eclass: add new eclass 2023-06-28 7:52 ` [gentoo-dev] [PATCH 0/2] " Florian Schmaus @ 2023-06-28 7:52 ` Florian Schmaus 2023-06-28 8:51 ` Michał Górny 2023-06-28 9:21 ` Ulrich Mueller 2023-06-28 7:52 ` [gentoo-dev] [PATCH 2/2] dev-java/openjfx: switch to gradle.eclass Florian Schmaus 2023-06-30 8:39 ` [gentoo-dev] [PATCH 0/2] new gradle.eclass Sam James 2 siblings, 2 replies; 14+ messages in thread From: Florian Schmaus @ 2023-06-28 7:52 UTC (permalink / raw To: gentoo-dev; +Cc: Florian Schmaus Signed-off-by: Florian Schmaus <flow@gentoo.org> --- 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 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 <java@gentoo.org> +# @AUTHOR: +# Florian Schmaus <flow@gentoo.org> +# @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 either +# depend on a gradle system-wide installation from a gradle ebuild, typically +# 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=7.3 +# EGRADLE_MAX_EXCLUSIVE=8 +# +# BDEPEND="|| (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=7.6 +# SRC_URI=" +# ... +# $(gradle_src_uri) +# " +# 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=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_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=true}" + +# @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"}" + +# @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="${EGRADLE_OVERWRITE}" + return + fi + + if [[ -n ${EGRADLE_BUNDLED_VER} ]]; then + EGRADLE="${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} != */gradle?(-bin)-+([.0-9]) ]]; then + continue + fi + + ver=${candidate##*-} + + if [[ -n ${EGRADLE_EXACT_VER} ]]; then + ver_test "${ver}" -ne "${EGRADLE_EXACT_VER}" && continue + + selected="${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="${candidate}" + selected_ver="${ver}" + done + + if [[ -z ${selected} ]]; then + die "Could not find (suitable) gradle installation in ${BROOT}/usr/bin" + fi + + EGRADLE="${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_BUNDLED_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=( + --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 + gradle_args+=( --parallel ) + fi + + local -x JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS} -Duser.home=\"${T}\"" + # 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.39.3 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [gentoo-dev] [PATCH 1/2] gradle.eclass: add new eclass 2023-06-28 7:52 ` [gentoo-dev] [PATCH 1/2] gradle.eclass: add new eclass Florian Schmaus @ 2023-06-28 8:51 ` Michał Górny 2023-06-28 9:21 ` Ulrich Mueller 1 sibling, 0 replies; 14+ messages in thread From: Michał Górny @ 2023-06-28 8:51 UTC (permalink / raw To: gentoo-dev; +Cc: Florian Schmaus On Wed, 2023-06-28 at 09:52 +0200, Florian Schmaus wrote: > Signed-off-by: Florian Schmaus <flow@gentoo.org> > --- > 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 > > 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 <java@gentoo.org> > +# @AUTHOR: > +# Florian Schmaus <flow@gentoo.org> > +# @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 either > +# depend on a gradle system-wide installation from a gradle ebuild, typically > +# 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=7.3 > +# EGRADLE_MAX_EXCLUSIVE=8 > +# > +# BDEPEND="|| (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=7.6 > +# SRC_URI=" > +# ... > +# $(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=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_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=true}" > + > +# @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"}" > + > +# @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="${EGRADLE_OVERWRITE}" > + return > + fi > + > + if [[ -n ${EGRADLE_BUNDLED_VER} ]]; then > + EGRADLE="${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} != */gradle?(-bin)-+([.0-9]) ]]; then > + continue > + fi > + > + ver=${candidate##*-} > + > + if [[ -n ${EGRADLE_EXACT_VER} ]]; then > + ver_test "${ver}" -ne "${EGRADLE_EXACT_VER}" && continue > + > + selected="${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="${candidate}" > + selected_ver="${ver}" > + done > + > + if [[ -z ${selected} ]]; then > + die "Could not find (suitable) gradle installation in ${BROOT}/usr/bin" > + fi > + > + EGRADLE="${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_BUNDLED_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=( > + --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 > + gradle_args+=( --parallel ) > + fi > + > + local -x JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS} -Duser.home=\"${T}\"" > + # 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 -- Best regards, Michał Górny ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-dev] [PATCH 1/2] gradle.eclass: add new eclass 2023-06-28 7:52 ` [gentoo-dev] [PATCH 1/2] gradle.eclass: add new eclass Florian Schmaus 2023-06-28 8:51 ` Michał Górny @ 2023-06-28 9:21 ` Ulrich Mueller 1 sibling, 0 replies; 14+ messages in thread From: Ulrich Mueller @ 2023-06-28 9:21 UTC (permalink / raw To: Florian Schmaus; +Cc: gentoo-dev >>>>> On Wed, 28 Jun 2023, Florian Schmaus wrote: > +# @FUNCTION: gradle-src_uri > +# @DESCRIPTION: > +# Generate SRC_URI data from EGRADLE_BUNDLED_VER. > +gradle-src_uri() { This is named gradle_src_uri (with two underscores) in the main eclass documentation. > +# @FUNCTION: gradle-src_unpack > +# @DESCRIPTION: > +# Unpack the "bundled" gradle version. You must have > +# EGRADLE_BUNDLED_VER set when calling this function. > +gradle-src_unpack() { Even if this isn't exported, is there any good reason for deviating from the normal naming convention for eclass phase functions? Ulrich ^ permalink raw reply [flat|nested] 14+ messages in thread
* [gentoo-dev] [PATCH 2/2] dev-java/openjfx: switch to gradle.eclass 2023-06-28 7:52 ` [gentoo-dev] [PATCH 0/2] " Florian Schmaus 2023-06-28 7:52 ` [gentoo-dev] [PATCH 1/2] gradle.eclass: add new eclass Florian Schmaus @ 2023-06-28 7:52 ` Florian Schmaus 2023-06-30 8:39 ` [gentoo-dev] [PATCH 0/2] new gradle.eclass Sam James 2 siblings, 0 replies; 14+ messages in thread From: Florian Schmaus @ 2023-06-28 7:52 UTC (permalink / raw To: gentoo-dev; +Cc: Florian Schmaus Signed-off-by: Florian Schmaus <flow@gentoo.org> --- dev-java/openjfx/openjfx-11.0.11_p1.ebuild | 46 +++++++--------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/dev-java/openjfx/openjfx-11.0.11_p1.ebuild b/dev-java/openjfx/openjfx-11.0.11_p1.ebuild index 7d61ff67f2c2..a99111598f7c 100644 --- a/dev-java/openjfx/openjfx-11.0.11_p1.ebuild +++ b/dev-java/openjfx/openjfx-11.0.11_p1.ebuild @@ -1,19 +1,19 @@ -# Copyright 2019-2021 Gentoo Authors +# Copyright 2019-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 -EAPI=6 +EAPI=8 MY_PV="${PV/_p/+}" SLOT="${MY_PV%%[.+]*}" -EGRADLE_VER="4.10.3" +EGRADLE_BUNDLED_VER="4.10.3" -inherit flag-o-matic java-pkg-2 multiprocessing +inherit flag-o-matic gradle java-pkg-2 multiprocessing DESCRIPTION="Java OpenJFX client application platform" HOMEPAGE="https://openjfx.io" -SRC_URI="https://hg.openjdk.java.net/${PN}/${SLOT}-dev/rt/archive/${MY_PV}.tar.bz2 -> ${P}.tar.bz2 - https://downloads.gradle.org/distributions/gradle-${EGRADLE_VER}-bin.zip +SRC_URI=" + https://hg.openjdk.java.net/${PN}/${SLOT}-dev/rt/archive/${MY_PV}.tar.bz2 -> ${P}.tar.bz2 https://repo.maven.apache.org/maven2/org/apache/lucene/lucene-sandbox/7.1.0/lucene-sandbox-7.1.0.jar https://repo.maven.apache.org/maven2/org/apache/lucene/lucene-grouping/7.1.0/lucene-grouping-7.1.0.jar https://repo.maven.apache.org/maven2/org/apache/lucene/lucene-queryparser/7.1.0/lucene-queryparser-7.1.0.jar @@ -22,6 +22,7 @@ SRC_URI="https://hg.openjdk.java.net/${PN}/${SLOT}-dev/rt/archive/${MY_PV}.tar.b https://repo.maven.apache.org/maven2/org/antlr/gunit/3.5.2/gunit-3.5.2.jar https://repo1.maven.org/maven2/org/antlr/antlr4/4.7.2/antlr4-4.7.2-complete.jar https://repo.maven.apache.org/maven2/org/antlr/ST4/4.0.8/ST4-4.0.8.jar + $(gradle-src_uri) " LICENSE="GPL-2-with-classpath-exception" @@ -84,28 +85,8 @@ PATCHES=( S="${WORKDIR}/rt-${MY_PV}" -egradle() { - local GRADLE_HOME="${WORKDIR}/gradle-${EGRADLE_VER}" - local gradle="${GRADLE_HOME}/bin/gradle" - local gradle_args=( - --info - --stacktrace - --no-build-cache - --no-daemon - --offline - --gradle-user-home "${T}/gradle_user_home" - --project-cache-dir "${T}/gradle_project_cache" - ) - - export GRADLE_HOME - - # FIXME: build.gradle believes $ANT_HOME/bin/ant shoud exist - unset ANT_HOME - - einfo "gradle "${gradle_args[@]}" ${@}" - # TERM needed, otherwise gradle may fail on terms it does not know about - TERM="xterm" "${gradle}" "${gradle_args[@]}" ${@} || die "gradle failed" -} +# Fails to build if gradle is invoked with --parallel. +EGRADLE_PARALLEL=false pkg_setup() { JAVA_PKG_WANT_BUILD_VM="openjdk-${SLOT} openjdk-bin-${SLOT}" @@ -148,7 +129,7 @@ pkg_setup() { src_unpack() { unpack "${P}.tar.bz2" - unpack "gradle-${EGRADLE_VER}-bin.zip" + gradle-src_unpack mkdir "${T}/jars" || die @@ -171,7 +152,7 @@ src_prepare() { java-pkg_jar-from --build-only --with-dependencies --into "${d}" stringtemplate java-pkg_jar-from --build-only --with-dependencies --into "${d}" hamcrest-core - sed -i "s#__gentoo_swt_jar__#$(java-pkg_getjars swt-4.10)#" "${S}"/build.gradle || die + sed -i "s#__gentoo_swt_jar__#$(java-pkg_getjars swt-4.10)#" build.gradle || die } src_configure() { @@ -189,7 +170,7 @@ src_configure() { [[ -r ${jdk_doc}/element-list ]] || die "JDK Docs not found, terminating build early" fi - cat <<- _EOF_ > "${S}"/gradle.properties + cat <<- _EOF_ > gradle.properties COMPILE_TARGETS = linux COMPILE_WEBKIT = false COMPILE_MEDIA = $(usex media true false) @@ -206,6 +187,9 @@ src_configure() { } src_compile() { + # FIXME: build.gradle believes $ANT_HOME/bin/ant shoud exist + unset ANT_HOME + egradle zips $(usex doc "" "--exclude-task javadoc") } -- 2.39.3 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [gentoo-dev] [PATCH 0/2] new gradle.eclass 2023-06-28 7:52 ` [gentoo-dev] [PATCH 0/2] " Florian Schmaus 2023-06-28 7:52 ` [gentoo-dev] [PATCH 1/2] gradle.eclass: add new eclass Florian Schmaus 2023-06-28 7:52 ` [gentoo-dev] [PATCH 2/2] dev-java/openjfx: switch to gradle.eclass Florian Schmaus @ 2023-06-30 8:39 ` Sam James 2 siblings, 0 replies; 14+ messages in thread From: Sam James @ 2023-06-30 8:39 UTC (permalink / raw To: gentoo-dev; +Cc: Florian Schmaus, java [-- Attachment #1: Type: text/plain, Size: 822 bytes --] Florian Schmaus <flow@gentoo.org> writes: > I would like to propose the gradle.eclass for ::gentoo. > > Multiple people have shown interest in an eclass for Gradle, as it would > make it easier to move Gradle-based projects into ::gentoo. For exmaple, > ghidra from ::pentoo. And, as a nice bonus, the addition of the gradle > eclass to ::gentoo would make it easier for overlays to use it. This, in > turn, reduces the friction when migrating Gradle-based projects from > overlays into ::gentoo. > > The second patch shows how gradle.eclass can be used in the openfjx ebuild. > > PR at https://github.com/gentoo/gentoo/pull/28986 Very happy to see this! I've left some remarks on the PR (can echo them here if needed), but it's nothing serious either (i.e. easily fixed, nothing sort of deep wrt design). thanks, sam [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 377 bytes --] ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2023-06-30 8:40 UTC | newest] Thread overview: 14+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-01-06 17:20 [gentoo-dev] RFC: new gradle.eclass Florian Schmaus 2023-01-06 17:20 ` [gentoo-dev] [PATCH] gradle.eclass: add new eclass Florian Schmaus 2023-01-07 4:29 ` Sam James 2023-01-07 10:58 ` Florian Schmaus 2023-01-07 6:07 ` Anna 2023-01-06 17:51 ` [gentoo-dev] RFC: new gradle.eclass Maciej Barć 2023-01-06 18:52 ` Yuan Liao (Leo) 2023-01-06 19:40 ` Florian Schmaus 2023-06-28 7:52 ` [gentoo-dev] [PATCH 0/2] " Florian Schmaus 2023-06-28 7:52 ` [gentoo-dev] [PATCH 1/2] gradle.eclass: add new eclass Florian Schmaus 2023-06-28 8:51 ` Michał Górny 2023-06-28 9:21 ` Ulrich Mueller 2023-06-28 7:52 ` [gentoo-dev] [PATCH 2/2] dev-java/openjfx: switch to gradle.eclass Florian Schmaus 2023-06-30 8:39 ` [gentoo-dev] [PATCH 0/2] new gradle.eclass Sam James
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox