Gentoo Archives: gentoo-dev

From: Alec Warner <antarus@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH] go-module.eclass: Add GO_OPTIONAL flag
Date: Mon, 29 Nov 2021 04:17:58
Message-Id: CAAr7Pr_oqfYvEvWe7yeOXubO3qEOShZ4vXUX62Wwx8snvof4SQ@mail.gmail.com
In Reply to: Re: [gentoo-dev] [PATCH] go-module.eclass: Add GO_OPTIONAL flag by William Hubbs
1 On Sun, Nov 28, 2021 at 11:52 AM William Hubbs <williamh@g.o> wrote:
2 >
3 > On Sun, Nov 28, 2021 at 11:23:16AM -0800, Zac Medico wrote:
4 > > On 11/21/21 02:57, Florian Schmaus wrote:
5 > > > Following the pattern found in other eclasses, add GO_OPTIONAL to the
6 > > > go-module eclass. This allows to inherit the eclass without pulling
7 > > > its dependencies. See, e.g., bug #775779 for the motivation.
8 > > >
9 > > > Signed-off-by: Florian Schmaus <flow@g.o>
10 > > > ---
11 > > > eclass/go-module.eclass | 31 ++++++++++++++++++++++---------
12 > > > 1 file changed, 22 insertions(+), 9 deletions(-)
13 > > >
14 > > > diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass
15 > > > index 3ad8542a28ae..c9eb90ac62ea 100644
16 > > > --- a/eclass/go-module.eclass
17 > > > +++ b/eclass/go-module.eclass
18 > > > @@ -1,4 +1,4 @@
19 > > > -# Copyright 2019-2020 Gentoo Authors
20 > > > +# Copyright 2019-2021 Gentoo Authors
21 > > > # Distributed under the terms of the GNU General Public License v2
22 > > >
23 > > > # @ECLASS: go-module.eclass
24 > > > @@ -55,13 +55,17 @@ if [[ -z ${_GO_MODULE} ]]; then
25 > > >
26 > > > _GO_MODULE=1
27 > > >
28 > > > -BDEPEND=">=dev-lang/go-1.12"
29 > > > +if [[ ! ${GO_OPTIONAL} ]]; then
30 > > > + BDEPEND=">=dev-lang/go-1.12"
31 > > >
32 > > > -# Workaround for pkgcheck false positive: https://github.com/pkgcore/pkgcheck/issues/214
33 > > > -# MissingUnpackerDep: version ...: missing BDEPEND="app-arch/unzip"
34 > > > -# Added here rather than to each affected package, so it can be cleaned up just
35 > > > -# once when pkgcheck is improved.
36 > > > -BDEPEND+=" app-arch/unzip"
37 > > > + # Workaround for pkgcheck false positive: https://github.com/pkgcore/pkgcheck/issues/214
38 > > > + # MissingUnpackerDep: version ...: missing BDEPEND="app-arch/unzip"
39 > > > + # Added here rather than to each affected package, so it can be cleaned up just
40 > > > + # once when pkgcheck is improved.
41 > > > + BDEPEND+=" app-arch/unzip"
42 > > > +
43 > > > + EXPORT_FUNCTIONS src_unpack
44 > > > +fi
45 > > >
46 > > > # Force go to build in module mode.
47 > > > # In this mode the GOPATH environment variable is ignored.
48 > > > @@ -83,8 +87,6 @@ QA_FLAGS_IGNORED='.*'
49 > > > # Go packages should not be stripped with strip(1).
50 > > > RESTRICT+=" strip"
51 > > >
52 > > > -EXPORT_FUNCTIONS src_unpack
53 > > > -
54 > > > # @ECLASS-VARIABLE: EGO_SUM
55 > > > # @DESCRIPTION:
56 > > > # This is an array based on the go.sum content from inside the target package.
57 > > > @@ -147,6 +149,17 @@ EXPORT_FUNCTIONS src_unpack
58 > > > # directory structure.
59 > > > declare -A -g _GOMODULE_GOSUM_REVERSE_MAP
60 > > >
61 > > > +# @ECLASS-VARIABLE: GO_OPTIONAL
62 > > > +# @DEFAULT_UNSET
63 > > > +# @PRE_INHERIT
64 > > > +# @DESCRIPTION:
65 > > > +# If set to a non-null value before inherit, then the Go part of the
66 > > > +# ebuild will be considered optional. No dependencies will be added and
67 > > > +# no phase functions will be exported.
68 > > > +#
69 > > > +# If you enable GO_OPTIONAL, you have to set BDEPEND on >=dev-lang/go-1.12
70 > > > +# for your package and call go-module_src_unpack manually.
71 > > > +
72 > > > # @FUNCTION: go-module_set_globals
73 > > > # @DESCRIPTION:
74 > > > # Convert the information in EGO_SUM for other usage in the ebuild.
75 > > >
76 > >
77 > > How about if we also add a GO_DEPEND variable, so that eclasshi
78 > > consumers can do something like BDEPEND="go? ( ${GO_DEPEND} )" ?
79 > > --
80 > > Thanks,
81 > > Zac
82 >
83 > this is on my radar. I haven't read the bug yet, but I'll look at it, if
84 > not today, sometime this week.
85 >
86 > Without looking at the bug, I'm not sure why you would want to use this
87 > eclass without depending on dev-lang/go.
88
89 I was going to say "just read the bug" but bugs have been misbehaving
90 recently, so I will summarize.
91
92 A package has an optional component that is golang based; users can
93 enable the component via a USE flag.
94 That component needs the go eclasses to build. While we can have USE
95 flag'd components, it's a QA violation to conditionally inherit an
96 eclass. This results in packages of this type needed to always inherit
97 the golang eclasses; even if the user has not enabled the golang
98 functionality.
99 The eclass always adds a dep on dev-lang/go
100 (https://gitweb.gentoo.org/repo/gentoo.git/tree/eclass/go-module.eclass)
101 This change let's ebuild callers control that golang dep; because it
102 should only be added when it's required, not on the eclass inherit.
103
104 You could also do other stuff (like not modify DEPEND in global scope
105 in the go eclasses), which is what Zac was suggesting. Many ways to
106 skin a cat and all that.
107
108 -A
109
110 >
111 > Also, if you have to write src_unpack you can call go-module_setup_proxy
112 > in src_unpack to set things up.
113 >
114 > William
115 >