Gentoo Archives: gentoo-dev

From: Michael Orlitzky <mjo@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH 1/2] php-ext-source-r3.eclass: new revision supporting EAPI=6.
Date: Mon, 20 Jun 2016 23:41:14
Message-Id: 57687F13.9010508@gentoo.org
In Reply to: Re: [gentoo-dev] [PATCH 1/2] php-ext-source-r3.eclass: new revision supporting EAPI=6. by "Michał Górny"
1 On 06/08/2016 03:34 PM, Michał Górny wrote:
2 >
3 > Next time, please inline and don't attach. It's awfully hard to reply
4 > to both the reply and the attachment.
5
6 Sorry, I was trying to hide the fact that I can't work Thunderbird.
7
8
9
10 >>>> + newins "modules/${PHP_EXT_NAME}.so" "${PHP_EXT_NAME}.so"
11 >>>
12 >>> Wouldn't it be more appropriate to use exeinto/doexe to have the shared
13 >>> libs +x?
14 >>
15 >> I'd never heard this before... why? I suppose the only trade-off is that
16 >> having them -x prevents them from showing up in bash's tab-completion
17 >> for executables.
18 >
19 > To be honest, I never dived into figuring out why it's like that -- but
20 > all libraries on my system are +x, and that's how the compiler creates
21 > them. So I'd rather follow that.
22
23 *shrug* done.
24
25
26
27 >>>> + PHP_EXT_SHARED_DIR="${EPREFIX}/usr/share/php/${PHP_EXT_NAME}"
28 >>>
29 >>> Should this be repeated inside the loop?
30 >>
31 >> There's a longer answer to that question, but the fact that it's outside
32 >> of the loop is intentional and consistent with -r2.
33 >
34 > Sorry, I wasn't clear. I was asking why it's inside the outer loop,
35 > rather than at the end of the function, after both loops?
36
37 Oh, right. That variable doesn't belong in that function at all, but for now
38 I've moved it out of the loops. I collected all of the improvements that I'm
39 opting not to make at this time in,
40
41 https://bugs.gentoo.org/show_bug.cgi?id=586446
42
43
44 >>>> +# php-ext-source-r3_addtoinifiles "zend_optimizer.disable_licensing" "0"
45 >>>
46 >>> Hmm... just to make it clear... is there any reason you use two
47 >>> arguments instead of the more obvious 'foo=15'?
48 >>
49 >> It's weird, but it's not wrong, and that's the way -r2 did it. There are
50 >> a few ebuilds (not maintained by the PHP team) that call
51 >> *addtoinifiles() themselves, and I don't want to annoy those people too
52 >> much for cosmetic changes.
53 >
54 > I'd say you could support both, and prefer the simpler ;-).
55
56 But that function is already a mess, and I don't want to make it worse. We'll
57 fix this properly in the future by making addtoinifiles() take a string and
58 simply add that string to the INI files. It's noted on that bug above.
59
60
61
62 >> cp -r "${orig_s}" "${WORKDIR}/${slot}" || \
63 >> die "failed to copy sources from ${orig_s} to ${WORKDIR}/${slot}"
64 >
65 > Not sure if this is relevant but I think this breaks mtime guarantees.
66 > In other words, output files may end up being 'earlier' than input files
67 > depending on copy order.
68 >
69 > In multibuild.eclass, I used 'cp -p -R' to preserve timestamps and modes.
70 >
71
72 Fixed.
73
74
75
76 >> # @FUNCTION: php-ext-source-r3_src_prepare
77 >> # @DESCRIPTION:
78 >> # For each PHP slot, we initialize the environment, run the default
79 >> # src_prepare() for PATCHES/eapply_user support, and then call
80 >> # php-ext-source-r3_phpize.
81 >> php-ext-source-r3_src_prepare() {
82 >> for slot in $(php_get_slots); do
83 >> php_init_slot_env "${slot}"
84 >> default
85 >> php-ext-source-r3_phpize
86 >> done
87 >> }
88 >
89 > Thinking about it... wouldn't it be better to:
90 >
91 > ...
92 >
93 > apply patches first, then copy; rather than copying, then
94 > applying patches to each copy separately.
95 >
96
97 Yeah, but this is another change that will annoy people. Ebuilds that
98 override src_unpack/src_prepare would need to be rewritten. We'll fix
99 it in a later revision.
100
101
102
103 >> econf --with-php-config=${PHPCONFIG} ${PHP_EXT_ECONF_ARGS}
104 >
105 > I think PHPCONFIG would be better off quoted, and it would be good to
106 > support PHP_EXT_ECONF_ARGS as an array in case someone needs to pass
107 > whitespace there.
108
109 Both done. Please check the hack I used to support both arrays/strings.
110
111
112
113 >> newins "modules/${PHP_EXT_NAME}.so" "${PHP_EXT_NAME}.so"
114 >
115 > Wouldn't doins/doexe do the same btw? It seems to be that the name is
116 > not changed.
117
118 Yup, fixed.
119
120
121
122 >> php_init_slot_env() {
123 >> local libdir=$(get_libdir)
124 >>
125 >> PHPIZE="${EPREFIX}/usr/${libdir}/${1}/bin/phpize"
126 >> PHPCONFIG="${EPREFIX}/usr/${libdir}/${1}/bin/php-config"
127 >> PHPCLI="${EPREFIX}/usr/${libdir}/${1}/bin/php"
128 >> PHPCGI="${EPREFIX}/usr/${libdir}/${1}/bin/php-cgi"
129 >> PHP_PKG="$(best_version =dev-lang/php-${1:3}*)"
130 >> PHPPREFIX="${EPREFIX}/usr/${libdir}/${slot}"
131 >
132 > A reason why you are using ${1} before, and ${slot} here?
133
134 No, that's just broken. I think it's picking up $slot from the REQUIRED_USE
135 loop at the top, so this involves two fixes. First, I make PHPPREFIX use the
136 function argument instead of the global $slot. And second, I don't pollute
137 the environment with a global $slot in the first place -- I namespaced that
138 variable and unset it afterwards.
139
140
141
142 >> local my_added="${2}=${3}"
143 >> if [[ ${2:0:1} == "[" ]] ; then
144 >> # Ok, it's a section name.
145 >> my_added="${2}"
146 >> fi
147 >
148 > How about:
149 >
150 > my_added=${2}${3+=${3}}
151
152 Sure, done.
153
154
155
156 >> echo "${my_added}" >> "${inifile}" || die "failed to append to ${inifile}"
157 >> einfo "Added '${my_added}' to /${1}"
158 >>
159 >> insinto "/${1%/*}"
160 >> doins "${inifile}"
161 >
162 > Not that I like re-doinsing the files every time a line is inserted,
163 > but I guess improving this is not worth the effort.
164
165 I'll need to think a little bit about this, I added it to the bug.
166
167 Here's the latest revision.
168
169
170 # Copyright 1999-2016 Gentoo Foundation
171 # Distributed under the terms of the GNU General Public License v2
172 # $Id$
173
174 # @ECLASS: php-ext-source-r3.eclass
175 # @MAINTAINER:
176 # Gentoo PHP team <php-bugs@g.o>
177 # @BLURB: Compile and install standalone PHP extensions.
178 # @DESCRIPTION:
179 # A unified interface for compiling and installing standalone PHP
180 # extensions.
181
182 inherit autotools
183
184 EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install
185
186 case ${EAPI} in
187 6) ;;
188 *)
189 die "${ECLASS} is not compatible with EAPI=${EAPI}"
190 esac
191
192 # @ECLASS-VARIABLE: PHP_EXT_NAME
193 # @REQUIRED
194 # @DESCRIPTION:
195 # The extension name. This must be set, otherwise the eclass dies.
196 # Only automagically set by php-ext-pecl-r3.eclass, so unless your ebuild
197 # inherits that eclass, you must set this manually before inherit.
198 [[ -z "${PHP_EXT_NAME}" ]] && \
199 die "no extension name specified for the php-ext-source-r3 eclass"
200
201 # @ECLASS-VARIABLE: PHP_EXT_INI
202 # @DESCRIPTION:
203 # Controls whether or not to add a line to php.ini for the extension.
204 # Defaults to "yes" and should not be changed in most cases.
205 [[ -z "${PHP_EXT_INI}" ]] && PHP_EXT_INI="yes"
206
207 # @ECLASS-VARIABLE: PHP_EXT_ZENDEXT
208 # @DESCRIPTION:
209 # Controls whether the extension is a ZendEngine extension or not.
210 # Defaults to "no". If you don't know what this is, you don't need it.
211 [[ -z "${PHP_EXT_ZENDEXT}" ]] && PHP_EXT_ZENDEXT="no"
212
213 # @ECLASS-VARIABLE: USE_PHP
214 # @REQUIRED
215 # @DESCRIPTION:
216 # Lists the PHP slots compatible the extension is compatible with.
217 # Example:
218 # @CODE
219 # USE_PHP="php5-6 php7-0"
220 # @CODE
221 [[ -z "${USE_PHP}" ]] && \
222 die "USE_PHP is not set for the php-ext-source-r3 eclass"
223
224 # @ECLASS-VARIABLE: PHP_EXT_OPTIONAL_USE
225 # @DEFAULT_UNSET
226 # @DESCRIPTION:
227 # If set, all of the dependencies added by this eclass will be
228 # conditional on USE=${PHP_EXT_OPTIONAL_USE}. This is needed when
229 # ebuilds have to inherit this eclass unconditionally, but only
230 # actually use it when (for example) the user has USE=php.
231
232 # @ECLASS-VARIABLE: PHP_EXT_S
233 # @DESCRIPTION:
234 # The relative location of the temporary build directory for the PHP
235 # extension within the source package. This is useful for packages that
236 # bundle the PHP extension. Defaults to ${S}.
237 [[ -z "${PHP_EXT_S}" ]] && PHP_EXT_S="${S}"
238
239 # @ECLASS-VARIABLE: PHP_EXT_SAPIS
240 # @DESCRIPTION:
241 # A list of SAPIs for which we will install this extension. Formerly
242 # called PHPSAPILIST. The default includes every SAPI currently used in
243 # the tree.
244 [[ -z "${PHP_EXT_SAPIS}" ]] && PHP_EXT_SAPIS="apache2 cli cgi fpm embed phpdbg"
245
246
247 # Make sure at least one target is installed. First, start a USE
248 # conditional like "php?", but only when PHP_EXT_OPTIONAL_USE is
249 # non-null. The option group "|| (..." is always started here.
250 REQUIRED_USE="${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }|| ( "
251 for _php_target in ${USE_PHP}; do
252 # Now loop through each USE_PHP target and add the corresponding
253 # dev-lang/php slot to PHPDEPEND.
254 IUSE+=" php_targets_${_php_target}"
255 REQUIRED_USE+="php_targets_${_php_target} "
256 _php_slot=${_php_target/php}
257 _php_slot=${_php_slot/-/.}
258 PHPDEPEND+=" php_targets_${_php_target}? ( dev-lang/php:${_php_slot} )"
259 done
260
261 # Don't pollute the environment with our loop variables.
262 unset _php_slot _php_target
263
264 # Finally, end the optional group that we started before the loop. Close
265 # the USE-conditional if PHP_EXT_OPTIONAL_USE is non-null.
266 REQUIRED_USE+=") ${PHP_EXT_OPTIONAL_USE:+ )}"
267
268 RDEPEND="${RDEPEND}
269 ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }
270 ${PHPDEPEND}
271 ${PHP_EXT_OPTIONAL_USE:+ )}"
272
273 DEPEND="${DEPEND}
274 sys-devel/m4
275 sys-devel/libtool
276 ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }
277 ${PHPDEPEND}
278 ${PHP_EXT_OPTIONAL_USE:+ )}
279 "
280
281 # @ECLASS-VARIABLE: PHP_EXT_SKIP_PHPIZE
282 # @DEFAULT_UNSET
283 # @DESCRIPTION:
284 # By default, we run "phpize" in php-ext-source-r3_src_unpack(). Set
285 # PHP_EXT_SKIP_PHPIZE="yes" in your ebuild if you do not want to run
286 # phpize (and the autoreconf that becomes necessary afterwards).
287
288 # @FUNCTION: php-ext-source-r3_src_unpack
289 # @DESCRIPTION:
290 # Runs the default src_unpack and then makes a copy for each PHP slot.
291 php-ext-source-r3_src_unpack() {
292 default
293
294 local slot orig_s="${PHP_EXT_S}"
295 for slot in $(php_get_slots); do
296 cp --recursive --preserve "${orig_s}" "${WORKDIR}/${slot}" || \
297 die "failed to copy sources from ${orig_s} to ${WORKDIR}/${slot}"
298 done
299 }
300
301
302 # @FUNCTION: php-ext-source-r3_src_prepare
303 # @DESCRIPTION:
304 # For each PHP slot, we initialize the environment, run the default
305 # src_prepare() for PATCHES/eapply_user support, and then call
306 # php-ext-source-r3_phpize.
307 php-ext-source-r3_src_prepare() {
308 for slot in $(php_get_slots); do
309 php_init_slot_env "${slot}"
310 default
311 php-ext-source-r3_phpize
312 done
313 }
314
315 # @FUNCTION: php-ext-source-r3_phpize
316 # @DESCRIPTION:
317 # Subject to PHP_EXT_SKIP_PHPIZE, this function runs phpize and
318 # autoreconf in a manner that avoids warnings.
319 php-ext-source-r3_phpize() {
320 if [[ "${PHP_EXT_SKIP_PHPIZE}" != 'yes' ]] ; then
321 # Create configure out of config.m4. We use autotools_run_tool
322 # to avoid some warnings about WANT_AUTOCONF and
323 # WANT_AUTOMAKE (see bugs #329071 and #549268).
324 autotools_run_tool "${PHPIZE}"
325
326 # Force libtoolize to run and regenerate autotools files (bug
327 # #220519).
328 rm aclocal.m4 || die "failed to remove aclocal.m4"
329 eautoreconf
330 fi
331 }
332
333
334 # @ECLASS-VARIABLE: PHP_EXT_ECONF_ARGS
335 # @DEFAULT_UNSET
336 # @DESCRIPTION:
337 # Set this in the ebuild to pass additional configure options to
338 # econf. Formerly called my_conf. Either a string or an array of
339 # --flag=value parameters is supported.
340
341 # @FUNCTION: php-ext-source-r3_src_configure
342 # @DESCRIPTION:
343 # Takes care of standard configure for PHP extensions (modules).
344 php-ext-source-r3_src_configure() {
345 # net-snmp creates these, bug #385403.
346 addpredict /usr/share/snmp/mibs/.index
347 addpredict /var/lib/net-snmp/mib_indexes
348
349 # Support either a string or an array for PHP_EXT_ECONF_ARGS.
350 local econf_args
351 if [[ $(declare -p PHP_EXT_ECONF_ARGS) == "declare -a"* ]]; then
352 econf_args=( "${PHP_EXT_ECONF_ARGS[@]}" )
353 else
354 econf_args=( ${PHP_EXT_ECONF_ARGS} )
355 fi
356
357 local slot
358 for slot in $(php_get_slots); do
359 php_init_slot_env "${slot}"
360 econf --with-php-config="${PHPCONFIG}" "${econf_args[@]}"
361 done
362 }
363
364 # @FUNCTION: php-ext-source-r3_src_compile
365 # @DESCRIPTION:
366 # Compile a standard standalone PHP extension.
367 php-ext-source-r3_src_compile() {
368 # net-snmp creates these, bug #324739.
369 addpredict /usr/share/snmp/mibs/.index
370 addpredict /var/lib/net-snmp/mib_indexes
371
372 # shm extension creates a semaphore file, bug #173574.
373 addpredict /session_mm_cli0.sem
374 local slot
375 for slot in $(php_get_slots); do
376 php_init_slot_env "${slot}"
377 emake
378 done
379 }
380
381 # @FUNCTION: php-ext-source-r3_src_install
382 # @DESCRIPTION:
383 # Install a standard standalone PHP extension. Uses einstalldocs()
384 # to support the DOCS variable/array.
385 php-ext-source-r3_src_install() {
386 local slot
387 for slot in $(php_get_slots); do
388 php_init_slot_env "${slot}"
389
390 # Strip $EPREFIX from $EXT_DIR before calling doexe (which
391 # handles EPREFIX itself). Shared libs are +x by convention,
392 # although nothing seems to depend on that.
393 exeinto "${EXT_DIR#$EPREFIX}"
394 doexe "modules/${PHP_EXT_NAME}.so"
395
396 INSTALL_ROOT="${D}" emake install-headers
397 done
398 einstalldocs
399 php-ext-source-r3_createinifiles
400 }
401
402 # @FUNCTION: php_get_slots
403 # @DESCRIPTION:
404 # Get a list of PHP slots contained in both the ebuild's USE_PHP and the
405 # user's PHP_TARGETS.
406 php_get_slots() {
407 local s=""
408 local slot
409 for slot in ${USE_PHP}; do
410 use php_targets_${slot} && s+=" ${slot/-/.}"
411 done
412 echo $s
413 }
414
415 # @FUNCTION: php_init_slot_env
416 # @USAGE: <slot>
417 # @DESCRIPTION:
418 # Takes a slot name, and initializes some global variables to values
419 # corresponding to that slot. For example, it sets the path to the "php"
420 # and "phpize" binaries, which will differ for each slot. This function
421 # is intended to be called while looping through a list of slots
422 # obtained from php_get_slots().
423 #
424 # Calling this function will change the working directory to the
425 # temporary build directory for the given slot.
426 php_init_slot_env() {
427 local libdir=$(get_libdir)
428 local slot="${1}"
429
430 PHPPREFIX="${EPREFIX}/usr/${libdir}/${slot}"
431 PHPIZE="${PHPPREFIX}/bin/phpize"
432 PHPCONFIG="${PHPPREFIX}/bin/php-config"
433 PHPCLI="${PHPPREFIX}/bin/php"
434 PHPCGI="${PHPPREFIX}/bin/php-cgi"
435 PHP_PKG="$(best_version =dev-lang/php-${1:3}*)"
436
437 EXT_DIR="$(${PHPCONFIG} --extension-dir 2>/dev/null)"
438 PHP_CURRENTSLOT=${1:3}
439
440 PHP_EXT_S="${WORKDIR}/${slot}"
441 cd "${PHP_EXT_S}" || die "failed to change directory to ${PHP_EXT_S}"
442 }
443
444 # @FUNCTION: php_slot_ini_files
445 # @USAGE: <slot>
446 # @INTERNAL
447 # @DESCRIPTION:
448 # Output a list of relative paths to INI files for the given
449 # slot. Usually there will be one INI file per SAPI.
450 php_slot_ini_files() {
451 local slot_ini_files=""
452 local x
453 for x in ${PHP_EXT_SAPIS} ; do
454 if [[ -f "${EPREFIX}/etc/php/${x}-${1}/php.ini" ]] ; then
455 slot_ini_files+=" etc/php/${x}-${1}/ext/${PHP_EXT_NAME}.ini"
456 fi
457 done
458
459 echo "${slot_ini_files}"
460 }
461
462 # @FUNCTION: php-ext-source-r3_createinifiles
463 # @DESCRIPTION:
464 # Builds INI files for every enabled slot and SAPI.
465 php-ext-source-r3_createinifiles() {
466 local slot
467 for slot in $(php_get_slots); do
468 php_init_slot_env "${slot}"
469
470 local file
471 for file in $(php_slot_ini_files "${slot}") ; do
472 if [[ "${PHP_EXT_INI}" = "yes" ]] ; then
473 # Add the needed lines to the <ext>.ini files
474 php-ext-source-r3_addextension "${PHP_EXT_NAME}.so" "${file}"
475 fi
476
477 if [[ -n "${PHP_EXT_INIFILE}" ]] ; then
478 cat "${FILESDIR}/${PHP_EXT_INIFILE}" >> "${ED}/${file}" \
479 || die "failed to append to ${ED}/${file}"
480
481 einfo "Added contents of ${FILESDIR}/${PHP_EXT_INIFILE}" \
482 "to ${file}"
483 fi
484 inidir="${file/${PHP_EXT_NAME}.ini/}"
485 inidir="${inidir/ext/ext-active}"
486 dodir "/${inidir}"
487 dosym "/${file}" "/${file/ext/ext-active}"
488 done
489 done
490
491 # A location where PHP code for this extension can be stored,
492 # independent of the PHP or extension versions. This will be part of
493 # PHP's include_path, configured in php.ini. For example, pecl-apcu
494 # installs an "apc.php" file which you are supposed to load with
495 #
496 # require('apcu/apc.php');
497 #
498 PHP_EXT_SHARED_DIR="${EPREFIX}/usr/share/php/${PHP_EXT_NAME}"
499 }
500
501 # @FUNCTION: php-ext-source-r3_addextension
502 # @USAGE: <extension-path> <ini-file>
503 # @INTERNAL
504 # @DESCRIPTION:
505 # Add a line to an INI file that will enable the given extension. The
506 # first parameter is the path to the extension (.so) file, and the
507 # second parameter is the name of the INI file in which it should be
508 # loaded. This function determines the setting name (either
509 # "extension=..." or "zend_extension=...") and then calls
510 # php-ext-source-r3_addtoinifile to do the actual work.
511 php-ext-source-r3_addextension() {
512 local ext_type="extension"
513 local ext_file="${1}"
514
515 if [[ "${PHP_EXT_ZENDEXT}" = "yes" ]] ; then
516 ext_type="zend_extension"
517 ext_file="${EXT_DIR}/${1}" # Zend extensions need the path...
518 fi
519
520 php-ext-source-r3_addtoinifile "${2}" "${ext_type}" "${ext_file}"
521 }
522
523 # @FUNCTION: php-ext-source-r3_addtoinifile
524 # @USAGE: <relative-ini-path> <setting-or-section-name> [setting-value]
525 # @INTERNAL
526 # @DESCRIPTION:
527 # Add a setting=value to one INI file. The first argument is the
528 # relative path to the INI file. The second argument is the setting
529 # name, and the third argument is its value.
530 #
531 # You can also pass "[Section]" as the second parameter, to create a new
532 # section in the INI file. In that case, the third parameter (which
533 # would otherwise be the value of the setting) is ignored.
534 php-ext-source-r3_addtoinifile() {
535 local inifile="${WORKDIR}/${1}"
536 local inidir="${inifile%/*}"
537
538 mkdir -p "${inidir}" || die "failed to create INI directory ${inidir}"
539
540 # Are we adding the name of a section? Assume not by default.
541 local my_added="${2}=${3}"
542 if [[ ${2:0:1} == "[" ]] ; then
543 # Ok, it's a section name.
544 my_added="${2}"
545 fi
546 echo "${my_added}" >> "${inifile}" || die "failed to append to ${inifile}"
547 einfo "Added '${my_added}' to /${1}"
548
549 insinto "/${1%/*}"
550 doins "${inifile}"
551 }
552
553 # @FUNCTION: php-ext-source-r3_addtoinifiles
554 # @USAGE: <setting-or-section-name> [setting-value] [message]
555 # @DESCRIPTION:
556 # Add settings to every php.ini file installed by this extension.
557 # You can also add new [Section]s -- see the example below.
558 #
559 # @CODE
560 # Add some settings for the extension:
561 #
562 # php-ext-source-r3_addtoinifiles "zend_optimizer.optimization_level" "15"
563 # php-ext-source-r3_addtoinifiles "zend_optimizer.enable_loader" "0"
564 # php-ext-source-r3_addtoinifiles "zend_optimizer.disable_licensing" "0"
565 #
566 # Adding values to a section in php.ini file installed by the extension:
567 #
568 # php-ext-source-r3_addtoinifiles "[Debugger]"
569 # php-ext-source-r3_addtoinifiles "debugger.enabled" "on"
570 # php-ext-source-r3_addtoinifiles "debugger.profiler_enabled" "on"
571 # @CODE
572 php-ext-source-r3_addtoinifiles() {
573 local slot
574 for slot in $(php_get_slots); do
575 for file in $(php_slot_ini_files "${slot}") ; do
576 php-ext-source-r3_addtoinifile "${file}" "${1}" "${2}"
577 done
578 done
579 }