Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: Michael Orlitzky <mjo@g.o>
Cc: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH 1/2] php-ext-source-r3.eclass: new revision supporting EAPI=6.
Date: Wed, 01 Jun 2016 17:47:56
Message-Id: 20160601194726.5d0ddb5d.mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH 1/2] php-ext-source-r3.eclass: new revision supporting EAPI=6. by Michael Orlitzky
1 On Wed, 1 Jun 2016 12:53:37 -0400
2 Michael Orlitzky <mjo@g.o> wrote:
3
4 > This is a new revision of the php-ext-source eclass that supports
5 > EAPI=6 (only) and cleans up some of the existing code. The list of
6 > user-facing changes is,
7 >
8 > * Support only EAPI=6.
9 >
10 > * PATCHES array/variable support.
11 >
12 > * DOCS array support (bug 512184).
13 >
14 > * Renamed my_conf and PHPSAPILIST variables.
15 >
16 > Some refactoring was done, but not in a way that consumers should
17 > notice. A migration guide can be found on the wiki:
18 >
19 > https://wiki.gentoo.org/wiki/Project:PHP/Php-ext-source-r3_migration_guide
20 >
21 > Gentoo-Bug: 512184
22 > ---
23 > eclass/php-ext-source-r3.eclass | 387 ++++++++++++++++++++++++++++++++++++++++
24 > 1 file changed, 387 insertions(+)
25 > create mode 100644 eclass/php-ext-source-r3.eclass
26 >
27 > diff --git a/eclass/php-ext-source-r3.eclass b/eclass/php-ext-source-r3.eclass
28 > new file mode 100644
29 > index 0000000..f3af823
30 > --- /dev/null
31 > +++ b/eclass/php-ext-source-r3.eclass
32 > @@ -0,0 +1,387 @@
33 > +# Copyright 1999-2016 Gentoo Foundation
34 > +# Distributed under the terms of the GNU General Public License v2
35 > +# $Id$
36 > +
37 > +# @ECLASS: php-ext-source-r3.eclass
38 > +# @MAINTAINER:
39 > +# Gentoo PHP team <php-bugs@g.o>
40 > +# @BLURB:
41 > +# A unified interface for compiling and installing standalone PHP
42 > +# extensions.
43 > +# @DESCRIPTION:
44 > +# A unified interface for compiling and installing standalone PHP
45 > +# extensions.
46 > +
47 > +inherit autotools
48 > +
49 > +EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install
50 > +
51 > +DEPEND=">=sys-devel/m4-1.4.3
52 > + >=sys-devel/libtool-1.5.18"
53 > +RDEPEND=""
54
55 Please move all of this below EAPI check. And I think *DEPEND would be
56 better set in one place.
57
58 > +
59 > +case ${EAPI} in
60 > + 6) ;;
61 > + *)
62 > + die "php-ext-source-r3 is not compatible with EAPI=${EAPI}"
63
64 I think you can use ${ECLASS} here btw.
65
66 > +esac
67 > +
68 > +# @ECLASS-VARIABLE: PHP_EXT_NAME
69 > +# @REQUIRED
70 > +# @DESCRIPTION:
71 > +# The extension name. This must be set, otherwise the eclass dies.
72 > +# Only automagically set by php-ext-pecl-r3.eclass, so unless your ebuild
73 > +# inherits that eclass, you must set this manually before inherit.
74 > +[[ -z "${PHP_EXT_NAME}" ]] && \
75 > + die "no extension name specified for the php-ext-source-r3 eclass"
76 > +
77 > +# @ECLASS-VARIABLE: PHP_EXT_INI
78 > +# @DESCRIPTION:
79 > +# Controls whether or not to add a line to php.ini for the extension.
80 > +# Defaults to "yes" and should not be changed in most cases.
81 > +[[ -z "${PHP_EXT_INI}" ]] && PHP_EXT_INI="yes"
82 > +
83 > +# @ECLASS-VARIABLE: PHP_EXT_ZENDEXT
84 > +# @DESCRIPTION:
85 > +# Controls whether the extension is a ZendEngine extension or not.
86 > +# Defaults to "no". If you don't know what this is, you don't need it.
87 > +[[ -z "${PHP_EXT_ZENDEXT}" ]] && PHP_EXT_ZENDEXT="no"
88 > +
89 > +# @ECLASS-VARIABLE: USE_PHP
90 > +# @REQUIRED
91 > +# @DESCRIPTION:
92 > +# Lists the PHP slots compatibile the extension is compatibile with
93
94 typo: compatible, and also appears twice ;-).
95
96 > +# Example:
97 > +# @CODE
98 > +# USE_PHP="php5-6 php7-0"
99 > +# @CODE
100 > +[[ -z "${USE_PHP}" ]] && \
101 > + die "USE_PHP is not set for the php-ext-source-r3 eclass"
102 > +
103 > +# @ECLASS-VARIABLE: PHP_EXT_OPTIONAL_USE
104 > +# @DESCRIPTION:
105 > +# If set, all of the dependencies added by this eclass will be
106 > +# conditional on USE=${PHP_EXT_OPTIONAL_USE}. This is needed when
107 > +# ebuilds have to inherit this eclass unconditionally, but only
108 > +# actually use it when (for example) the user has USE=php.
109 > +
110 > +# @ECLASS-VARIABLE: PHP_EXT_S
111 > +# @DESCRIPTION:
112 > +# The relative location of the temporary build directory for the PHP
113 > +# extension within the source package. This is useful for packages that
114 > +# bundle the PHP extension. Defaults to ${S}.
115 > +[[ -z "${PHP_EXT_S}" ]] && PHP_EXT_S="${S}"
116 > +
117 > +# @ECLASS-VARIABLE: PHP_EXT_SAPIS
118 > +# @DESCRIPTION:
119 > +# A list of SAPIs for which we'll install this extension. Formerly
120 > +# called PHPSAPILIST.
121 > +[[ -z "${PHP_EXT_SAPIS}" ]] && PHP_EXT_SAPIS="apache2 cli cgi fpm embed phpdbg"
122
123 Is this default something that might get extended in the future? I
124 think it might be worth noting that here.
125
126 > +
127 > +
128 > +# Make sure at least one target is installed. First, start a USE
129 > +# conditional like "php?", but only when PHP_EXT_OPTIONAL_USE is
130 > +# non-null. The option group "|| (..." is always started here.
131 > +REQUIRED_USE="${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }|| ( "
132 > +for target in ${USE_PHP}; do
133
134 Environment pollution! unset target, or make this local.
135
136 > + # Now loop through each USE_PHP target and add the corresponding
137 > + # dev-lang/php slot to PHPDEPEND.
138 > + IUSE="${IUSE} php_targets_${target}"
139
140 Any reason not to use += here as well?
141
142 > + # Strip "+" characters from USE_PHP???
143 > + # target=${target/+}
144 > + REQUIRED_USE+="php_targets_${target} "
145 > + slot=${target/php}
146 > + slot=${slot/-/.}
147 > + PHPDEPEND="${PHPDEPEND}
148 > + php_targets_${target}? ( dev-lang/php:${slot} )"
149 > +done
150 > +# Finally, end the optional group that we started before the loop. Close
151 > +# the USE-conditional if PHP_EXT_OPTIONAL_USE is non-null.
152 > +REQUIRED_USE+=") ${PHP_EXT_OPTIONAL_USE:+ )}"
153 > +
154 > +RDEPEND="${RDEPEND}
155 > + ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }
156 > + ${PHPDEPEND}
157 > + ${PHP_EXT_OPTIONAL_USE:+ )}"
158 > +
159 > +DEPEND="${DEPEND}
160 > + ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }
161 > + ${PHPDEPEND}
162 > + ${PHP_EXT_OPTIONAL_USE:+ )}
163 > +"
164 > +
165 > +# @ECLASS-VARIABLE: PHP_EXT_SKIP_PHPIZE
166 > +# @DESCRIPTION:
167 > +# By default, we run "phpize" in php-ext-source-r3_src_unpack(). Set
168 > +# PHP_EXT_SKIP_PHPIZE="yes" in your ebuild if you do not want to run
169 > +# phpize (and the autoreconf that becomes necessary afterwards).
170 > +
171 > +# @FUNCTION: php-ext-source-r3_src_unpack
172 > +# @DESCRIPTION:
173 > +# Runs the default src_unpack and then makes a copy for each PHP slot.
174 > +php-ext-source-r3_src_unpack() {
175 > + default_src_unpack
176 > +
177 > + local slot orig_s="${PHP_EXT_S}"
178 > + for slot in $(php_get_slots); do
179 > + cp -r "${orig_s}" "${WORKDIR}/${slot}" || \
180 > + die "failed to copy sources from ${orig_s} to ${WORKDIR}/${slot}"
181 > + done
182 > +}
183 > +
184 > +
185 > +# @FUNCTION: php-ext-source-r3_src_prepare
186 > +# @DESCRIPTION:
187 > +# For each PHP slot, we initialize the environment, run the default
188 > +# src_prepare() for PATCHES/eapply_user support, and then call
189 > +# php-ext-source-r3_phpize.
190 > +php-ext-source-r3_src_prepare() {
191 > + for slot in $(php_get_slots); do
192 > + php_init_slot_env "${slot}"
193 > + default
194 > + php-ext-source-r3_phpize
195 > + done
196 > +}
197 > +
198 > +# @FUNCTION: php-ext-source-r3_phpize
199 > +# @DESCRIPTION:
200 > +# Subject to PHP_EXT_SKIP_PHPIZE, this function runs phpize and
201 > +# autoreconf in a manner that avoids warnings.
202 > +php-ext-source-r3_phpize() {
203 > + if [[ "${PHP_EXT_SKIP_PHPIZE}" != 'yes' ]] ; then
204 > + # Create configure out of config.m4. We use autotools_run_tool
205 > + # to avoid some warnings about WANT_AUTOCONF and
206 > + # WANT_AUTOMAKE (see bugs #329071 and #549268).
207 > + autotools_run_tool "${PHPIZE}"
208 > +
209 > + # Force libtoolize to run and regenerate autotools files (bug
210 > + # #220519).
211 > + rm aclocal.m4 || die "failed to remove aclocal.m4"
212 > + eautoreconf
213 > + fi
214 > +}
215 > +
216 > +
217 > +# @ECLASS-VARIABLE: PHP_EXT_EXTRA_ECONF
218 > +# @DESCRIPTION:
219 > +# Set this in the ebuild to pass configure options to econf. Formerly
220 > +# called my_conf.
221
222 Please don't name this *EXTRA_ECONF. EXTRA_ECONF is a Portage variable
223 that's meant to be set by user in make.conf/env, and not ebuilds.
224
225 > +# @FUNCTION: php-ext-source-r3_src_configure
226 > +# @DESCRIPTION:
227 > +# Takes care of standard configure for PHP extensions (modules).
228 > +php-ext-source-r3_src_configure() {
229 > + # net-snmp creates these, bug #385403.
230 > + addpredict /usr/share/snmp/mibs/.index
231 > + addpredict /var/lib/net-snmp/mib_indexes
232 > +
233 > + local slot
234 > + for slot in $(php_get_slots); do
235 > + php_init_slot_env "${slot}"
236 > + # Set the correct config options
237 > + econf --with-php-config=${PHPCONFIG} ${PHP_EXT_EXTRA_ECONF}
238 > + done
239 > +}
240 > +
241 > +# @FUNCTION: php-ext-source-r3_src_compile
242 > +# @DESCRIPTION:
243 > +# Compile a standard standalone PHP extension.
244 > +php-ext-source-r3_src_compile() {
245 > + # net-snmp creates these, bug #324739.
246 > + addpredict /usr/share/snmp/mibs/.index
247 > + addpredict /var/lib/net-snmp/mib_indexes
248 > +
249 > + # shm extension creates a semaphore file, bug #173574.
250 > + addpredict /session_mm_cli0.sem
251 > + local slot
252 > + for slot in $(php_get_slots); do
253 > + php_init_slot_env "${slot}"
254 > + emake
255 > + done
256 > +}
257 > +
258 > +# @FUNCTION: php-ext-source-r3_src_install
259 > +# @DESCRIPTION:
260 > +# Install a standard standalone PHP extension. Uses einstalldocs()
261 > +# to support the DOCS variable/array.
262 > +php-ext-source-r3_src_install() {
263 > + local slot
264 > + for slot in $(php_get_slots); do
265 > + php_init_slot_env "${slot}"
266 > +
267 > + # Let's put the default module away. Strip $EPREFIX from
268 > + # $EXT_DIR before calling newins (which handles EPREFIX itself).
269 > + insinto "${EXT_DIR#$EPREFIX}"
270 > + newins "modules/${PHP_EXT_NAME}.so" "${PHP_EXT_NAME}.so"
271
272 Wouldn't it be more appropriate to use exeinto/doexe to have the shared
273 libs +x?
274
275 > +
276 > + INSTALL_ROOT="${D}" emake install-headers
277 > + done
278 > + einstalldocs
279 > + php-ext-source-r3_createinifiles
280 > +}
281 > +
282 > +# @FUNCTION: php_get_slots
283 > +# @DESCRIPTION:
284 > +# Get a list of PHP slots contained in both the ebuild's USE_PHP and the
285 > +# user's PHP_TARGETS.
286 > +php_get_slots() {
287 > + local s=""
288 > + local slot
289 > + for slot in ${USE_PHP}; do
290 > + use php_targets_${slot} && s+=" ${slot/-/.}"
291 > + done
292 > + echo $s
293 > +}
294 > +
295 > +# @FUNCTION: php_init_slot_env
296 > +# @DESCRIPTION:
297 > +# Takes a slot name, and initializes some global variables to values
298 > +# corresponding to that slot. For example, it sets the path to the "php"
299 > +# and "phpize" binaries, which will differ for each slot. This function
300 > +# is intended to be called while looping through a list of slots
301 > +# obtained from php_get_slots().
302
303 Please make it explicit that it changes working directory.
304
305 > +php_init_slot_env() {
306 > + local libdir=$(get_libdir)
307 > +
308 > + PHPIZE="${EPREFIX}/usr/${libdir}/${1}/bin/phpize"
309 > + PHPCONFIG="${EPREFIX}/usr/${libdir}/${1}/bin/php-config"
310 > + PHPCLI="${EPREFIX}/usr/${libdir}/${1}/bin/php"
311 > + PHPCGI="${EPREFIX}/usr/${libdir}/${1}/bin/php-cgi"
312 > + PHP_PKG="$(best_version =dev-lang/php-${1:3}*)"
313 > + PHPPREFIX="${EPREFIX}/usr/${libdir}/${slot}"
314 > + EXT_DIR="$(${PHPCONFIG} --extension-dir 2>/dev/null)"
315 > + PHP_CURRENTSLOT=${1:3}
316 > +
317 > + PHP_EXT_S="${WORKDIR}/${1}"
318 > + cd "${PHP_EXT_S}" || die "failed to change directory to ${PHP_EXT_S}"
319 > +}
320 > +
321 > +# @FUNCTION: php_slot_ini_files
322 > +# @INTERNAL
323 > +# @DESCRIPTION:
324 > +# Output a list of relative paths to INI files for the given
325 > +# slot. Usually there will be one INI file per SAPI.
326
327 Please add @USAGE to make clear what ${1} is. In fact, many functions
328 seem to miss @USAGE.
329
330 > +php_slot_ini_files() {
331 > + local slot_ini_files=""
332 > + local x
333 > + for x in ${PHP_EXT_SAPIS} ; do
334 > + if [[ -f "${EPREFIX}/etc/php/${x}-${1}/php.ini" ]] ; then
335 > + slot_ini_files+=" etc/php/${x}-${1}/ext/${PHP_EXT_NAME}.ini"
336 > + fi
337 > + done
338 > +
339 > + echo "${slot_ini_files}"
340 > +}
341 > +
342 > +# @FUNCTION: php-ext-source-r3_createinifiles
343 > +# @DESCRIPTION:
344 > +# Builds INI files for every enabled slot and SAPI.
345 > +php-ext-source-r3_createinifiles() {
346 > + local slot
347 > + for slot in $(php_get_slots); do
348 > + php_init_slot_env "${slot}"
349 > +
350 > + local file
351 > + for file in $(php_slot_ini_files "${slot}") ; do
352 > + if [[ "${PHP_EXT_INI}" = "yes" ]] ; then
353 > + # Add the needed lines to the <ext>.ini files
354 > + php-ext-source-r3_addextension "${PHP_EXT_NAME}.so" "${file}"
355 > + fi
356 > +
357 > + if [[ -n "${PHP_EXT_INIFILE}" ]] ; then
358 > + cat "${FILESDIR}/${PHP_EXT_INIFILE}" >> "${ED}/${file}"
359
360 || die
361
362 > + einfo "Added contents of ${FILESDIR}/${PHP_EXT_INIFILE}" \
363 > + "to ${file}"
364 > + fi
365 > + inidir="${file/${PHP_EXT_NAME}.ini/}"
366 > + inidir="${inidir/ext/ext-active}"
367 > + dodir "/${inidir}"
368 > + dosym "/${file}" "/${file/ext/ext-active}"
369 > + done
370 > +
371 > + # Add support for installing PHP files into a version dependent
372 > + # directory
373 > + PHP_EXT_SHARED_DIR="${EPREFIX}/usr/share/php/${PHP_EXT_NAME}"
374
375 Should this be repeated inside the loop?
376
377 > + done
378 > +}
379 > +
380 > +# @FUNCTION: php-ext-source-r3_addextension
381 > +# @INTERNAL
382 > +# @DESCRIPTION:
383 > +# Add a line to an INI file that will enable the given extension. The
384 > +# first parameter is the path to the extension (.so) file, and the
385 > +# second parameter is the name of the INI file in which it should be
386 > +# loaded. This function determines the setting name (either
387 > +# "extension=..." or "zend_extension=...") and then calls
388 > +# php-ext-source-r3_addtoinifile to do the actual work.
389 > +php-ext-source-r3_addextension() {
390 > + if [[ "${PHP_EXT_ZENDEXT}" = "yes" ]] ; then
391 > + ext_type="zend_extension"
392 > + ext_file="${EXT_DIR}/${1}" # Zend extensions need the path...
393 > + else
394 > + ext_type="extension"
395 > + ext_file="${1}"
396 > + fi
397
398 I think you want those variables local.
399
400 > +
401 > + php-ext-source-r3_addtoinifile "${2}" "${ext_type}" "${ext_file}"
402 > +}
403 > +
404 > +# @FUNCTION: php-ext-source-r3_addtoinifile
405 > +# @INTERNAL
406 > +# @DESCRIPTION:
407 > +# Add a setting=value to one INI file. The first argument is the
408 > +# relative path to the INI file. The second argument is the setting
409 > +# name, and the third argument is its value.
410 > +#
411 > +# You can also pass "[Section]" as the first parameter, to create a new
412 > +# section in the INI file. In that case, the second parameter (which
413 > +# would otherwise be the value of the setting) is ignored.
414 > +php-ext-source-r3_addtoinifile() {
415 > + local inifile="${WORKDIR}/${1}"
416 > + local inidir="$(dirname ${inifile})"
417
418 I would suggest avoiding external tools like dirname when simple bash
419 subst can do the work (e.g. ${inifile%/*}).
420
421 > + if [[ ! -d "${inidir}" ]] ; then
422 > + mkdir -p "${inidir}" || die "failed to create INI directory ${inidir}"
423
424 'mkdir -p' is safe to call when the directory exists, so I don't think
425 you need the conditional.
426
427 > + fi
428 > +
429 > + # Are we adding the name of a section?
430 > + if [[ ${2:0:1} == "[" ]] ; then
431 > + echo "${2}" >> "${inifile}"
432
433 || die
434
435 > + my_added="${2}"
436
437 Again, missing local.
438
439 > + else
440 > + echo "${2}=${3}" >> "${inifile}"
441
442 || die
443
444 > + my_added="${2}=${3}"
445 > + fi
446
447 All above considered, wouldn't it be simpler to set my_added first,
448 and then just echo it to the file outside the conditional?
449
450 > +
451 > + einfo "Added '${my_added}' to /${1}"
452 > +
453 > + insinto /$(dirname "${1}")
454 > + doins "${inifile}"
455 > +}
456 > +
457 > +# @FUNCTION: php-ext-source-r3_addtoinifiles
458 > +# @USAGE: <setting name> <setting value> [message to output]; or just [section name]
459
460 I think you are mixing '[]' meaning optional and meaning literal '[]'
461 here.
462
463 > +# @DESCRIPTION:
464 > +# Add settings to every php.ini file installed by this extension.
465 > +# You can also add new [Section]s -- see the example below.
466 > +#
467 > +# @CODE
468 > +# Add some settings for the extension:
469 > +#
470 > +# php-ext-source-r3_addtoinifiles "zend_optimizer.optimization_level" "15"
471 > +# php-ext-source-r3_addtoinifiles "zend_optimizer.enable_loader" "0"
472 > +# php-ext-source-r3_addtoinifiles "zend_optimizer.disable_licensing" "0"
473
474 Hmm... just to make it clear... is there any reason you use two
475 arguments instead of the more obvious 'foo=15'?
476
477 > +#
478 > +# Adding values to a section in php.ini file installed by the extension:
479 > +#
480 > +# php-ext-source-r3_addtoinifiles "[Debugger]"
481 > +# php-ext-source-r3_addtoinifiles "debugger.enabled" "on"
482 > +# php-ext-source-r3_addtoinifiles "debugger.profiler_enabled" "on"
483 > +# @CODE
484 > +php-ext-source-r3_addtoinifiles() {
485 > + local slot
486 > + for slot in $(php_get_slots); do
487 > + for file in $(php_slot_ini_files "${slot}") ; do
488 > + php-ext-source-r3_addtoinifile "${file}" "${1}" "${2}"
489 > + done
490 > + done
491 > +}
492
493
494
495 --
496 Best regards,
497 Michał Górny
498 <http://dev.gentoo.org/~mgorny/>

Replies