Gentoo Archives: gentoo-commits

From: Aaron Swenson <titanofold@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/postgresql/eclass:master commit in: /
Date: Sun, 03 Sep 2017 14:39:26
Message-Id: 1504449555.d2c3a3108e4cfb57a9da8964bf73b4275ad5a5d6.titanofold@gentoo
1 commit: d2c3a3108e4cfb57a9da8964bf73b4275ad5a5d6
2 Author: Aaron W. Swenson <titanofold <AT> gentoo <DOT> org>
3 AuthorDate: Sun Sep 3 14:39:15 2017 +0000
4 Commit: Aaron Swenson <titanofold <AT> gentoo <DOT> org>
5 CommitDate: Sun Sep 3 14:39:15 2017 +0000
6 URL: https://gitweb.gentoo.org/proj/postgresql/eclass.git/commit/?id=d2c3a310
7
8 sync with Gentoo repo
9
10 postgres-multi.eclass | 175 +++++++++++++++++++++++++++++++++++++++++++++++++
11 postgres.eclass | 177 +++++++++++++++++++++++++++++++++++++++-----------
12 2 files changed, 314 insertions(+), 38 deletions(-)
13
14 diff --git a/postgres-multi.eclass b/postgres-multi.eclass
15 new file mode 100644
16 index 0000000..5d40a0e
17 --- /dev/null
18 +++ b/postgres-multi.eclass
19 @@ -0,0 +1,175 @@
20 +# Copyright 1999-2017 Gentoo Foundation
21 +# Distributed under the terms of the GNU General Public License v2
22 +
23 +inherit multibuild postgres
24 +EXPORT_FUNCTIONS pkg_setup src_prepare src_compile src_install src_test
25 +
26 +
27 +# @ECLASS: postgres-multi.eclass
28 +# @MAINTAINER:
29 +# PostgreSQL <pgsql-bugs@g.o>
30 +# @AUTHOR: Aaron W. Swenson <titanofold@g.o>
31 +# @BLURB: An eclass to build PostgreSQL-related packages against multiple slots
32 +# @DESCRIPTION:
33 +# postgres-multi enables ebuilds, particularly PostgreSQL extensions, to
34 +# build and install for one or more PostgreSQL slots as specified by
35 +# POSTGRES_TARGETS use flags.
36 +
37 +
38 +case ${EAPI:-0} in
39 + 5|6) ;;
40 + *) die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" ;;
41 +esac
42 +
43 +
44 +# @ECLASS-VARIABLE: POSTGRES_COMPAT
45 +# @REQUIRED
46 +# @DESCRIPTION:
47 +# A Bash array containing a list of compatible PostgreSQL slots as
48 +# defined by the developer. Must be declared before inheriting this
49 +# eclass. Example: POSTGRES_COMPAT=( 9.4 9.{5,6} )
50 +if ! declare -p POSTGRES_COMPAT &>/dev/null; then
51 + die 'Required variable POSTGRES_COMPAT not declared.'
52 +fi
53 +
54 +# @ECLASS-VARIABLE: _POSTGRES_INTERSECT_SLOTS
55 +# @INTERNAL
56 +# @DESCRIPTION:
57 +# A Bash array containing the intersect of POSTGRES_TARGETS and
58 +# POSTGRES_COMPAT.
59 +export _POSTGRES_INTERSECT_SLOTS=( )
60 +
61 +# @FUNCTION: _postgres-multi_multibuild_wrapper
62 +# @INTERNAL
63 +# @USAGE: _postgres-multi_multibuild_wrapper <command> [<arg> ...]
64 +# @DESCRIPTION:
65 +# For the given variant, set the values of the PG_SLOT, PG_CONFIG, and
66 +# PKG_CONFIG_PATH environment variables accordingly and replace any
67 +# appearance of @PG_SLOT@ in the command and arguments with value of
68 +# ${PG_SLOT}.
69 +_postgres-multi_multibuild_wrapper() {
70 + debug-print-function ${FUNCNAME} "${@}"
71 + export PG_SLOT=${MULTIBUILD_VARIANT}
72 + export PG_CONFIG=$(which pg_config${MULTIBUILD_VARIANT//./})
73 + if [[ -n ${PKG_CONFIG_PATH} ]] ; then
74 + PKG_CONFIG_PATH="$(${PG_CONFIG} --libdir)/pkgconfig:${PKG_CONFIG_PATH}"
75 + else
76 + PKG_CONFIG_PATH="$(${PG_CONFIG} --libdir)/pkgconfig"
77 + fi
78 + export PKG_CONFIG_PATH
79 +
80 + $(echo "${@}" | sed "s/@PG_SLOT@/${PG_SLOT}/g")
81 +}
82 +
83 +# @FUNCTION: postgres-multi_foreach
84 +# @USAGE: postgres-multi_foreach <command> <arg> [<arg> ...]
85 +# @DESCRIPTION:
86 +# Run the given command in the package's build directory for each
87 +# PostgreSQL slot in the intersect of POSTGRES_TARGETS and
88 +# POSTGRES_COMPAT and user-enabled slots. The PG_CONFIG and
89 +# PKG_CONFIG_PATH environment variables are updated on each iteration to
90 +# point to the matching pg_config command and pkg-config metadata files,
91 +# respectively, for the current slot. Any appearance of @PG_SLOT@ in the
92 +# command or arguments will be substituted with the slot (e.g., 9.5) of
93 +# the current iteration.
94 +postgres-multi_foreach() {
95 + local MULTIBUILD_VARIANTS=("${_POSTGRES_INTERSECT_SLOTS[@]}")
96 +
97 + multibuild_foreach_variant \
98 + _postgres-multi_multibuild_wrapper run_in_build_dir ${@}
99 +}
100 +
101 +# @FUNCTION: postgres-multi_forbest
102 +# @USAGE: postgres-multi_forbest <command> <arg> [<arg> ...]
103 +# @DESCRIPTION:
104 +# Run the given command in the package's build directory for the highest
105 +# slot in the intersect of POSTGRES_COMPAT and POSTGRES_TARGETS. The
106 +# PG_CONFIG and PKG_CONFIG_PATH environment variables are set to the
107 +# matching pg_config command and pkg-config metadata files,
108 +# respectively. Any appearance of @PG_SLOT@ in the command or arguments
109 +# will be substituted with the matching slot (e.g., 9.5).
110 +postgres-multi_forbest() {
111 + # POSTGRES_COMPAT is reverse sorted once in postgres.eclass so
112 + # element 0 has the highest slot version.
113 + local MULTIBUILD_VARIANTS=("${_POSTGRES_INTERSECT_SLOTS[0]}")
114 +
115 + multibuild_foreach_variant \
116 + _postgres-multi_multibuild_wrapper run_in_build_dir ${@}
117 +}
118 +
119 +# @FUNCTION: postgres-multi_pkg_setup
120 +# @USAGE: postgres-multi_pkg_setup
121 +# @DESCRIPTION:
122 +# Initialize internal environment variable(s). This is required if
123 +# pkg_setup() is declared in the ebuild.
124 +postgres-multi_pkg_setup() {
125 + local user_slot
126 +
127 + for user_slot in "${POSTGRES_COMPAT[@]}"; do
128 + use "postgres_targets_postgres${user_slot/\./_}" && \
129 + _POSTGRES_INTERSECT_SLOTS+=( "${user_slot}" )
130 + done
131 +
132 + if [[ "${#_POSTGRES_INTERSECT_SLOTS[@]}" -eq "0" ]]; then
133 + die "One of the postgres_targets_postgresSL_OT use flags must be enabled"
134 + fi
135 +
136 + einfo "Multibuild variants: ${_POSTGRES_INTERSECT_SLOTS[@]}"
137 +}
138 +
139 +# @FUNCTION: postgres-multi_src_prepare
140 +# @USAGE: postgres-multi_src_prepare
141 +# @DESCRIPTION:
142 +# Calls eapply_user then copies ${S} into a build directory for each
143 +# intersect of POSTGRES_TARGETS and POSTGRES_COMPAT.
144 +postgres-multi_src_prepare() {
145 + if [[ "${#_POSTGRES_INTERSECT_SLOTS[@]}" -eq "0" ]]; then
146 + eerror "Internal array _POSTGRES_INTERSECT_SLOTS is empty."
147 + die "Did you forget to call postgres-multi_pkg_setup?"
148 + fi
149 +
150 + # Check that the slot has been emerged (Should be prevented by
151 + # Portage, but won't be caught by /usr/bin/ebuild)
152 + local slot
153 + for slot in ${_POSTGRES_INTERSECT_SLOTS[@]} ; do
154 + if [[ -z $(which pg_config${slot/.} 2> /dev/null) ]] ; then
155 + eerror
156 + eerror "postgres_targets_postgres${slot/.} use flag is enabled, but hasn't been emerged."
157 + eerror
158 + die "a postgres_targets use flag is enabled, but not emerged"
159 + fi
160 + done
161 +
162 + case ${EAPI:-0} in
163 + 0|1|2|3|4|5) epatch_user ;;
164 + 6) eapply_user ;;
165 + esac
166 +
167 + local MULTIBUILD_VARIANT
168 + local MULTIBUILD_VARIANTS=("${_POSTGRES_INTERSECT_SLOTS[@]}")
169 + multibuild_copy_sources
170 +}
171 +
172 +# @FUNCTION: postgres-multi_src_compile
173 +# @USAGE: postgres-multi_src_compile
174 +# @DESCRIPTION:
175 +# Runs `emake' in each build directory
176 +postgres-multi_src_compile() {
177 + postgres-multi_foreach emake
178 +}
179 +
180 +# @FUNCTION: postgres-multi_src_install
181 +# @USAGE: postgres-multi_src_install
182 +# @DESCRIPTION:
183 +# Runs `emake install DESTDIR="${D}"' in each build directory.
184 +postgres-multi_src_install() {
185 + postgres-multi_foreach emake install DESTDIR="${D}"
186 +}
187 +
188 +# @FUNCTION: postgres-multi_src_test
189 +# @USAGE: postgres-multi_src_test
190 +# @DESCRIPTION:
191 +# Runs `emake installcheck' in each build directory.
192 +postgres-multi_src_test() {
193 + postgres-multi_foreach emake installcheck
194 +}
195
196 diff --git a/postgres.eclass b/postgres.eclass
197 index 77851c1..13483a9 100644
198 --- a/postgres.eclass
199 +++ b/postgres.eclass
200 @@ -1,58 +1,159 @@
201 -# Copyright 1999-2013 Gentoo Foundation
202 +# Copyright 1999-2017 Gentoo Foundation
203 # Distributed under the terms of the GNU General Public License v2
204 -# $Header: $
205 +
206 +inherit user
207 +EXPORT_FUNCTIONS pkg_setup
208
209 # @ECLASS: postgres.eclass
210 # @MAINTAINER:
211 -# Aaron W. Swenson <titanofold@g.o>
212 -# @BLURB: Functions to aid PostgreSQL-related packages
213 +# PostgreSQL <pgsql-bugs@g.o>
214 +# @AUTHOR: Aaron W. Swenson <titanofold@g.o>
215 +# @BLURB: An eclass for PostgreSQL-related packages
216 # @DESCRIPTION:
217 -# The postgres eclass is a suite that enable ebuilds to build against
218 -# multiple slots, properly add a new daemon user, and query
219 -# PostgreSQL-related information from the system.
220 +# This eclass provides common utility functions that many
221 +# PostgreSQL-related packages perform, such as checking that the
222 +# currently selected PostgreSQL slot is within a range, adding a system
223 +# user to the postgres system group, and generating dependencies.
224 +
225 +
226 +case ${EAPI:-0} in
227 + 5|6) ;;
228 + *) die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" ;;
229 +esac
230
231 -inherit user
232
233 -# @FUNCTION: postgres_depend
234 -# @USAGE: postgres_depend [USE,flags] [server] [server,USE,flags]
235 +# @ECLASS-VARIABLE: POSTGRES_COMPAT
236 +# @DEFAULT_UNSET
237 # @DESCRIPTION:
238 -# Called after DEPEND is declared. Takes up to two optional arguments. The 'server'
239 -postgres_depend() {
240 - if [[ -n ${POSTGRES_ONLY} ]] ; then
241 - DEPEND+=" dev-db/postgresql-base:${POSTGRES_ONLY}[${BASE_FLAGS}]"
242 - elif [[ -n ${POSTGRES_MIN} ]]
243 - if [[ -n ${POSTGRES_MAX} ]] ; then
244 +# A Bash array containing a list of compatible PostgreSQL slots as
245 +# defined by the developer. If declared, must be declared before
246 +# inheriting this eclass. Example: POSTGRES_COMPAT=( 9.4 9.{5,6} )
247
248 - else
249 - #blarg
250 - fi
251 - elif [[ -n ${POSGRES_MAX} ]] ; then
252 - #blah
253 +# @ECLASS-VARIABLE: POSTGRES_USEDEP
254 +# @DEFAULT_UNSET
255 +# @DESCRIPTION:
256 +# Add the 2-Style and/or 4-Style use dependencies without brackets to be used
257 +# for POSTGRES_DEP. If declared, must be done before inheriting this eclass.
258 +
259 +# @ECLASS-VARIABLE: POSTGRES_DEP
260 +# @DESCRIPTION:
261 +# An automatically generated dependency string suitable for use in
262 +# DEPEND and RDEPEND declarations.
263 +
264 +# @ECLASS-VARIABLE: POSTGRES_REQ_USE
265 +# @DESCRIPTION:
266 +# An automatically generated REQUIRED_USE-compatible string built upon
267 +# POSTGRES_COMPAT. REQUIRED_USE="... ${POSTGRES_REQ_USE}" is only
268 +# required if the package must build against one of the PostgreSQL slots
269 +# declared in POSTGRES_COMPAT.
270 +
271 +if declare -p POSTGRES_COMPAT &> /dev/null ; then
272 + # Reverse sort the given POSTGRES_COMPAT so that the most recent
273 + # slot is preferred over an older slot.
274 + # -- do we care if dependencies are deterministic by USE flags?
275 + readarray -t POSTGRES_COMPAT < <(printf '%s\n' "${POSTGRES_COMPAT[@]}" | sort -nr)
276 +
277 + POSTGRES_DEP=""
278 + POSTGRES_REQ_USE=" || ("
279 + for slot in "${POSTGRES_COMPAT[@]}" ; do
280 + POSTGRES_DEP+=" postgres_targets_postgres${slot/\./_}? ( dev-db/postgresql:${slot}="
281 + declare -p POSTGRES_USEDEP &>/dev/null && \
282 + POSTGRES_DEP+="[${POSTGRES_USEDEP}]"
283 + POSTGRES_DEP+=" )"
284 +
285 + IUSE+=" postgres_targets_postgres${slot/\./_}"
286 + POSTGRES_REQ_USE+=" postgres_targets_postgres${slot/\./_}"
287 + done
288 + POSTGRES_REQ_USE+=" )"
289 +else
290 + POSTGRES_DEP="dev-db/postgresql:="
291 + declare -p POSTGRES_USEDEP &>/dev/null && \
292 + POSTGRES_DEP+="[${POSTGRES_USEDEP}]"
293 +fi
294 +
295 +
296 +# @FUNCTION: postgres_check_slot
297 +# @DESCRIPTION:
298 +# Verify that the currently selected PostgreSQL slot is set to one of
299 +# the slots defined in POSTGRES_COMPAT. Automatically dies unless a
300 +# POSTGRES_COMPAT slot is selected. Should be called in pkg_pretend().
301 +postgres_check_slot() {
302 + if ! declare -p POSTGRES_COMPAT &>/dev/null; then
303 + die 'POSTGRES_COMPAT not declared.'
304 + fi
305 +
306 + # Don't die because we can't run postgresql-config during pretend.
307 + [[ "$EBUILD_PHASE" = "pretend" && -z "$(which postgresql-config 2> /dev/null)" ]] \
308 + && return 0
309 +
310 + if has $(postgresql-config show 2> /dev/null) "${POSTGRES_COMPAT[@]}"; then
311 + return 0
312 else
313 - [[POSTGRES_MAX]]
314 - [[POSTGRES_MIN]]
315 - [[POSTGRES_ONLY]]
316 + eerror "PostgreSQL slot must be set to one of: "
317 + eerror " ${POSTGRES_COMPAT[@]}"
318 + die "Incompatible PostgreSQL slot eselected"
319 fi
320 }
321
322 -length=$(expr length ${POSTGRES_MAX})
323 -
324 -pgsql_pkg_setup() {
325 +# @FUNCTION: postgres_new_user
326 +# @DESCRIPTION:
327 +# Creates the "postgres" system group and user -- which is separate from
328 +# the database user -- in addition to the developer defined user. Takes
329 +# the same arguments as "enewuser".
330 +postgres_new_user() {
331 enewgroup postgres 70
332 enewuser postgres 70 /bin/bash /var/lib/postgresql postgres
333 +
334 + if [[ $# -gt 0 ]] ; then
335 + if [[ "$1" = "postgres" ]] ; then
336 + ewarn "Username 'postgres' implied, skipping"
337 + else
338 + local groups=$5
339 + [[ -n "${groups}" ]] && groups+=",postgres" || groups="postgres"
340 + enewuser "$1" "${2:--1}" "${3:--1}" "${4:--1}" "${groups}"
341 + fi
342 + fi
343 }
344
345 -# @FUNCTION: pgsql_enewuser
346 -# @USAGE: <user> [uid] [shell] [homedir]
347 +# @FUNCTION: postgres_pkg_setup
348 +# @USAGE: postgres_pkg_setup
349 # @DESCRIPTION:
350 -# Same as enewuser, in fact it uses enewuser, you are not required to
351 -# understand how to properly add a user to the system. The only required
352 -# parameter is the username. Default uid is (pass -1 for this) next
353 -# available, default shell is /bin/false, default homedir is /dev/null,
354 -# and is assigned to the postgres group.
355 -pgsql_new_user() {
356 - local user=$1 uid=$2 shell=$3 home=$4
357 +# Initialize environment variable(s) according to the best
358 +# installed version of PostgreSQL that is also in POSTGRES_COMPAT. This
359 +# is required if pkg_setup() is declared in the ebuild.
360 +# Exports PG_SLOT, PG_CONFIG, and PKG_CONFIG_PATH.
361 +postgres_pkg_setup() {
362 + debug-print-function ${FUNCNAME} "${@}"
363 +
364 + local compat_slot
365 + local best_slot
366 + for compat_slot in "${POSTGRES_COMPAT[@]}"; do
367 + if use "postgres_targets_postgres${compat_slot/\./_}"; then
368 + best_slot="${compat_slot}"
369 + break
370 + fi
371 + done
372 +
373 + if [[ -z "${best_slot}" ]]; then
374 + local flags f
375 + for f in "${POSTGRES_COMPAT[@]}"; do
376 + flags+=" postgres${f/./_}"
377 + done
378 +
379 + eerror "POSTGRES_TARGETS must contain at least one of:"
380 + eerror " ${flags}"
381 + die "No suitable POSTGRES_TARGETS enabled."
382 + fi
383 +
384 + export PG_SLOT=${best_slot}
385 + export PG_CONFIG=$(which pg_config${best_slot//./})
386 +
387 + local pg_pkg_config_path="$(${PG_CONFIG} --libdir)/pkgconfig"
388 + if [[ -n "${PKG_CONFIG_PATH}" ]]; then
389 + export PKG_CONFIG_PATH="${pg_pkg_config_path}:${PKG_CONFIG_PATH}"
390 + else
391 + export PKG_CONFIG_PATH="${pg_pkg_config_path}"
392 + fi
393
394 - pgsql_pkg_setup
395 - enewuser $1 $2 $3 $4 postgres
396 + elog "PostgreSQL Target: ${best_slot}"
397 }