Mailing List Archive

[PATCH] go-module.eclass: Add GO_OPTIONAL flag
Following the pattern found in other eclasses, add GO_OPTIONAL to the
go-module eclass. This allows to inherit the eclass without pulling
its dependencies. See, e.g., bug #775779 for the motivation.

Signed-off-by: Florian Schmaus <flow@gentoo.org>
---
eclass/go-module.eclass | 31 ++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass
index 3ad8542a28ae..c9eb90ac62ea 100644
--- a/eclass/go-module.eclass
+++ b/eclass/go-module.eclass
@@ -1,4 +1,4 @@
-# Copyright 2019-2020 Gentoo Authors
+# Copyright 2019-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# @ECLASS: go-module.eclass
@@ -55,13 +55,17 @@ if [[ -z ${_GO_MODULE} ]]; then

_GO_MODULE=1

-BDEPEND=">=dev-lang/go-1.12"
+if [[ ! ${GO_OPTIONAL} ]]; then
+ BDEPEND=">=dev-lang/go-1.12"

-# Workaround for pkgcheck false positive: https://github.com/pkgcore/pkgcheck/issues/214
-# MissingUnpackerDep: version ...: missing BDEPEND="app-arch/unzip"
-# Added here rather than to each affected package, so it can be cleaned up just
-# once when pkgcheck is improved.
-BDEPEND+=" app-arch/unzip"
+ # Workaround for pkgcheck false positive: https://github.com/pkgcore/pkgcheck/issues/214
+ # MissingUnpackerDep: version ...: missing BDEPEND="app-arch/unzip"
+ # Added here rather than to each affected package, so it can be cleaned up just
+ # once when pkgcheck is improved.
+ BDEPEND+=" app-arch/unzip"
+
+ EXPORT_FUNCTIONS src_unpack
+fi

# Force go to build in module mode.
# In this mode the GOPATH environment variable is ignored.
@@ -83,8 +87,6 @@ QA_FLAGS_IGNORED='.*'
# Go packages should not be stripped with strip(1).
RESTRICT+=" strip"

-EXPORT_FUNCTIONS src_unpack
-
# @ECLASS-VARIABLE: EGO_SUM
# @DESCRIPTION:
# This is an array based on the go.sum content from inside the target package.
@@ -147,6 +149,17 @@ EXPORT_FUNCTIONS src_unpack
# directory structure.
declare -A -g _GOMODULE_GOSUM_REVERSE_MAP

+# @ECLASS-VARIABLE: GO_OPTIONAL
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# If set to a non-null value before inherit, then the Go part of the
+# ebuild will be considered optional. No dependencies will be added and
+# no phase functions will be exported.
+#
+# If you enable GO_OPTIONAL, you have to set BDEPEND on >=dev-lang/go-1.12
+# for your package and call go-module_src_unpack manually.
+
# @FUNCTION: go-module_set_globals
# @DESCRIPTION:
# Convert the information in EGO_SUM for other usage in the ebuild.
--
2.32.0
Re: [PATCH] go-module.eclass: Add GO_OPTIONAL flag [ In reply to ]
On 11/21/21 02:57, Florian Schmaus wrote:
> Following the pattern found in other eclasses, add GO_OPTIONAL to the
> go-module eclass. This allows to inherit the eclass without pulling
> its dependencies. See, e.g., bug #775779 for the motivation.
>
> Signed-off-by: Florian Schmaus <flow@gentoo.org>
> ---
> eclass/go-module.eclass | 31 ++++++++++++++++++++++---------
> 1 file changed, 22 insertions(+), 9 deletions(-)
>
> diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass
> index 3ad8542a28ae..c9eb90ac62ea 100644
> --- a/eclass/go-module.eclass
> +++ b/eclass/go-module.eclass
> @@ -1,4 +1,4 @@
> -# Copyright 2019-2020 Gentoo Authors
> +# Copyright 2019-2021 Gentoo Authors
> # Distributed under the terms of the GNU General Public License v2
>
> # @ECLASS: go-module.eclass
> @@ -55,13 +55,17 @@ if [[ -z ${_GO_MODULE} ]]; then
>
> _GO_MODULE=1
>
> -BDEPEND=">=dev-lang/go-1.12"
> +if [[ ! ${GO_OPTIONAL} ]]; then
> + BDEPEND=">=dev-lang/go-1.12"
>
> -# Workaround for pkgcheck false positive: https://github.com/pkgcore/pkgcheck/issues/214
> -# MissingUnpackerDep: version ...: missing BDEPEND="app-arch/unzip"
> -# Added here rather than to each affected package, so it can be cleaned up just
> -# once when pkgcheck is improved.
> -BDEPEND+=" app-arch/unzip"
> + # Workaround for pkgcheck false positive: https://github.com/pkgcore/pkgcheck/issues/214
> + # MissingUnpackerDep: version ...: missing BDEPEND="app-arch/unzip"
> + # Added here rather than to each affected package, so it can be cleaned up just
> + # once when pkgcheck is improved.
> + BDEPEND+=" app-arch/unzip"
> +
> + EXPORT_FUNCTIONS src_unpack
> +fi
>
> # Force go to build in module mode.
> # In this mode the GOPATH environment variable is ignored.
> @@ -83,8 +87,6 @@ QA_FLAGS_IGNORED='.*'
> # Go packages should not be stripped with strip(1).
> RESTRICT+=" strip"
>
> -EXPORT_FUNCTIONS src_unpack
> -
> # @ECLASS-VARIABLE: EGO_SUM
> # @DESCRIPTION:
> # This is an array based on the go.sum content from inside the target package.
> @@ -147,6 +149,17 @@ EXPORT_FUNCTIONS src_unpack
> # directory structure.
> declare -A -g _GOMODULE_GOSUM_REVERSE_MAP
>
> +# @ECLASS-VARIABLE: GO_OPTIONAL
> +# @DEFAULT_UNSET
> +# @PRE_INHERIT
> +# @DESCRIPTION:
> +# If set to a non-null value before inherit, then the Go part of the
> +# ebuild will be considered optional. No dependencies will be added and
> +# no phase functions will be exported.
> +#
> +# If you enable GO_OPTIONAL, you have to set BDEPEND on >=dev-lang/go-1.12
> +# for your package and call go-module_src_unpack manually.
> +
> # @FUNCTION: go-module_set_globals
> # @DESCRIPTION:
> # Convert the information in EGO_SUM for other usage in the ebuild.
>

How about if we also add a GO_DEPEND variable, so that eclasshi
consumers can do something like BDEPEND="go? ( ${GO_DEPEND} )" ?
--
Thanks,
Zac
Re: [PATCH] go-module.eclass: Add GO_OPTIONAL flag [ In reply to ]
On Sun, Nov 28, 2021 at 11:23:16AM -0800, Zac Medico wrote:
> On 11/21/21 02:57, Florian Schmaus wrote:
> > Following the pattern found in other eclasses, add GO_OPTIONAL to the
> > go-module eclass. This allows to inherit the eclass without pulling
> > its dependencies. See, e.g., bug #775779 for the motivation.
> >
> > Signed-off-by: Florian Schmaus <flow@gentoo.org>
> > ---
> > eclass/go-module.eclass | 31 ++++++++++++++++++++++---------
> > 1 file changed, 22 insertions(+), 9 deletions(-)
> >
> > diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass
> > index 3ad8542a28ae..c9eb90ac62ea 100644
> > --- a/eclass/go-module.eclass
> > +++ b/eclass/go-module.eclass
> > @@ -1,4 +1,4 @@
> > -# Copyright 2019-2020 Gentoo Authors
> > +# Copyright 2019-2021 Gentoo Authors
> > # Distributed under the terms of the GNU General Public License v2
> >
> > # @ECLASS: go-module.eclass
> > @@ -55,13 +55,17 @@ if [[ -z ${_GO_MODULE} ]]; then
> >
> > _GO_MODULE=1
> >
> > -BDEPEND=">=dev-lang/go-1.12"
> > +if [[ ! ${GO_OPTIONAL} ]]; then
> > + BDEPEND=">=dev-lang/go-1.12"
> >
> > -# Workaround for pkgcheck false positive: https://github.com/pkgcore/pkgcheck/issues/214
> > -# MissingUnpackerDep: version ...: missing BDEPEND="app-arch/unzip"
> > -# Added here rather than to each affected package, so it can be cleaned up just
> > -# once when pkgcheck is improved.
> > -BDEPEND+=" app-arch/unzip"
> > + # Workaround for pkgcheck false positive: https://github.com/pkgcore/pkgcheck/issues/214
> > + # MissingUnpackerDep: version ...: missing BDEPEND="app-arch/unzip"
> > + # Added here rather than to each affected package, so it can be cleaned up just
> > + # once when pkgcheck is improved.
> > + BDEPEND+=" app-arch/unzip"
> > +
> > + EXPORT_FUNCTIONS src_unpack
> > +fi
> >
> > # Force go to build in module mode.
> > # In this mode the GOPATH environment variable is ignored.
> > @@ -83,8 +87,6 @@ QA_FLAGS_IGNORED='.*'
> > # Go packages should not be stripped with strip(1).
> > RESTRICT+=" strip"
> >
> > -EXPORT_FUNCTIONS src_unpack
> > -
> > # @ECLASS-VARIABLE: EGO_SUM
> > # @DESCRIPTION:
> > # This is an array based on the go.sum content from inside the target package.
> > @@ -147,6 +149,17 @@ EXPORT_FUNCTIONS src_unpack
> > # directory structure.
> > declare -A -g _GOMODULE_GOSUM_REVERSE_MAP
> >
> > +# @ECLASS-VARIABLE: GO_OPTIONAL
> > +# @DEFAULT_UNSET
> > +# @PRE_INHERIT
> > +# @DESCRIPTION:
> > +# If set to a non-null value before inherit, then the Go part of the
> > +# ebuild will be considered optional. No dependencies will be added and
> > +# no phase functions will be exported.
> > +#
> > +# If you enable GO_OPTIONAL, you have to set BDEPEND on >=dev-lang/go-1.12
> > +# for your package and call go-module_src_unpack manually.
> > +
> > # @FUNCTION: go-module_set_globals
> > # @DESCRIPTION:
> > # Convert the information in EGO_SUM for other usage in the ebuild.
> >
>
> How about if we also add a GO_DEPEND variable, so that eclasshi
> consumers can do something like BDEPEND="go? ( ${GO_DEPEND} )" ?
> --
> Thanks,
> Zac

this is on my radar. I haven't read the bug yet, but I'll look at it, if
not today, sometime this week.

Without looking at the bug, I'm not sure why you would want to use this
eclass without depending on dev-lang/go.

Also, if you have to write src_unpack you can call go-module_setup_proxy
in src_unpack to set things up.

William
Re: [PATCH] go-module.eclass: Add GO_OPTIONAL flag [ In reply to ]
On Sun, Nov 28, 2021 at 11:52 AM William Hubbs <williamh@gentoo.org> wrote:
>
> On Sun, Nov 28, 2021 at 11:23:16AM -0800, Zac Medico wrote:
> > On 11/21/21 02:57, Florian Schmaus wrote:
> > > Following the pattern found in other eclasses, add GO_OPTIONAL to the
> > > go-module eclass. This allows to inherit the eclass without pulling
> > > its dependencies. See, e.g., bug #775779 for the motivation.
> > >
> > > Signed-off-by: Florian Schmaus <flow@gentoo.org>
> > > ---
> > > eclass/go-module.eclass | 31 ++++++++++++++++++++++---------
> > > 1 file changed, 22 insertions(+), 9 deletions(-)
> > >
> > > diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass
> > > index 3ad8542a28ae..c9eb90ac62ea 100644
> > > --- a/eclass/go-module.eclass
> > > +++ b/eclass/go-module.eclass
> > > @@ -1,4 +1,4 @@
> > > -# Copyright 2019-2020 Gentoo Authors
> > > +# Copyright 2019-2021 Gentoo Authors
> > > # Distributed under the terms of the GNU General Public License v2
> > >
> > > # @ECLASS: go-module.eclass
> > > @@ -55,13 +55,17 @@ if [[ -z ${_GO_MODULE} ]]; then
> > >
> > > _GO_MODULE=1
> > >
> > > -BDEPEND=">=dev-lang/go-1.12"
> > > +if [[ ! ${GO_OPTIONAL} ]]; then
> > > + BDEPEND=">=dev-lang/go-1.12"
> > >
> > > -# Workaround for pkgcheck false positive: https://github.com/pkgcore/pkgcheck/issues/214
> > > -# MissingUnpackerDep: version ...: missing BDEPEND="app-arch/unzip"
> > > -# Added here rather than to each affected package, so it can be cleaned up just
> > > -# once when pkgcheck is improved.
> > > -BDEPEND+=" app-arch/unzip"
> > > + # Workaround for pkgcheck false positive: https://github.com/pkgcore/pkgcheck/issues/214
> > > + # MissingUnpackerDep: version ...: missing BDEPEND="app-arch/unzip"
> > > + # Added here rather than to each affected package, so it can be cleaned up just
> > > + # once when pkgcheck is improved.
> > > + BDEPEND+=" app-arch/unzip"
> > > +
> > > + EXPORT_FUNCTIONS src_unpack
> > > +fi
> > >
> > > # Force go to build in module mode.
> > > # In this mode the GOPATH environment variable is ignored.
> > > @@ -83,8 +87,6 @@ QA_FLAGS_IGNORED='.*'
> > > # Go packages should not be stripped with strip(1).
> > > RESTRICT+=" strip"
> > >
> > > -EXPORT_FUNCTIONS src_unpack
> > > -
> > > # @ECLASS-VARIABLE: EGO_SUM
> > > # @DESCRIPTION:
> > > # This is an array based on the go.sum content from inside the target package.
> > > @@ -147,6 +149,17 @@ EXPORT_FUNCTIONS src_unpack
> > > # directory structure.
> > > declare -A -g _GOMODULE_GOSUM_REVERSE_MAP
> > >
> > > +# @ECLASS-VARIABLE: GO_OPTIONAL
> > > +# @DEFAULT_UNSET
> > > +# @PRE_INHERIT
> > > +# @DESCRIPTION:
> > > +# If set to a non-null value before inherit, then the Go part of the
> > > +# ebuild will be considered optional. No dependencies will be added and
> > > +# no phase functions will be exported.
> > > +#
> > > +# If you enable GO_OPTIONAL, you have to set BDEPEND on >=dev-lang/go-1.12
> > > +# for your package and call go-module_src_unpack manually.
> > > +
> > > # @FUNCTION: go-module_set_globals
> > > # @DESCRIPTION:
> > > # Convert the information in EGO_SUM for other usage in the ebuild.
> > >
> >
> > How about if we also add a GO_DEPEND variable, so that eclasshi
> > consumers can do something like BDEPEND="go? ( ${GO_DEPEND} )" ?
> > --
> > Thanks,
> > Zac
>
> this is on my radar. I haven't read the bug yet, but I'll look at it, if
> not today, sometime this week.
>
> Without looking at the bug, I'm not sure why you would want to use this
> eclass without depending on dev-lang/go.

I was going to say "just read the bug" but bugs have been misbehaving
recently, so I will summarize.

A package has an optional component that is golang based; users can
enable the component via a USE flag.
That component needs the go eclasses to build. While we can have USE
flag'd components, it's a QA violation to conditionally inherit an
eclass. This results in packages of this type needed to always inherit
the golang eclasses; even if the user has not enabled the golang
functionality.
The eclass always adds a dep on dev-lang/go
(https://gitweb.gentoo.org/repo/gentoo.git/tree/eclass/go-module.eclass)
This change let's ebuild callers control that golang dep; because it
should only be added when it's required, not on the eclass inherit.

You could also do other stuff (like not modify DEPEND in global scope
in the go eclasses), which is what Zac was suggesting. Many ways to
skin a cat and all that.

-A

>
> Also, if you have to write src_unpack you can call go-module_setup_proxy
> in src_unpack to set things up.
>
> William
>
Re: [PATCH] go-module.eclass: Add GO_OPTIONAL flag [ In reply to ]
> On 28 Nov 2021, at 19:23, Zac Medico <zmedico@gentoo.org> wrote:
>
>> [snip]
>
> How about if we also add a GO_DEPEND variable, so that eclasshi consumers can do something like BDEPEND="go? ( ${GO_DEPEND} )" ?
> --

My preference is to go with what we've been doing more recently (do _OPTIONAL) so that
consumers handle things properly and we don't have to try account for various cases
(this was the problem with eclass variables which add a USE flag or depend only
if a USE flag is set).

But that said, I can't immediately think of any such annoying edge
cases with this idea. It'd be additional to GO_OPTIONAL and it'd
ensure a sane baseline Go version is chosen. So, why not?
Re: [PATCH] go-module.eclass: Add GO_OPTIONAL flag [ In reply to ]
On 28/11/2021 20.52, William Hubbs wrote:
> this is on my radar. I haven't read the bug yet, but I'll look at it, if
> not today, sometime this week.

Friendly reminder: where are we with that patch?

- Flow
Re: [PATCH] go-module.eclass: Add GO_OPTIONAL flag [ In reply to ]
This is committed.

Thanks,

William