Gentoo Archives: gentoo-dev

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

Replies