| 1 | # Copyright 1999-2009 Gentoo Foundation |
1 | # Copyright 1999-2011 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-ng.eclass,v 1.21 2010/07/08 04:00:57 flameeyes Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-ng.eclass,v 1.40 2011/10/05 17:46:20 graaff Exp $ |
| 4 | # |
4 | |
| 5 | # @ECLASS: ruby-ng.eclass |
5 | # @ECLASS: ruby-ng.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # Ruby herd <ruby@gentoo.org> |
7 | # Ruby herd <ruby@gentoo.org> |
| 8 | # |
8 | # @AUTHOR: |
| 9 | # Author: Diego E. Pettenò <flameeyes@gentoo.org> |
9 | # Author: Diego E. Pettenò <flameeyes@gentoo.org> |
| 10 | # |
|
|
| 11 | # Author: Alex Legler <a3li@gentoo.org> |
10 | # Author: Alex Legler <a3li@gentoo.org> |
| 12 | # |
|
|
| 13 | # Author: Hans de Graaff <graaff@gentoo.org> |
11 | # Author: Hans de Graaff <graaff@gentoo.org> |
| 14 | # |
|
|
| 15 | # @BLURB: An eclass for installing Ruby packages with proper support for multiple Ruby slots. |
12 | # @BLURB: An eclass for installing Ruby packages with proper support for multiple Ruby slots. |
| 16 | # @DESCRIPTION: |
13 | # @DESCRIPTION: |
| 17 | # The Ruby eclass is designed to allow an easier installation of Ruby packages |
14 | # The Ruby eclass is designed to allow an easier installation of Ruby packages |
| 18 | # and their incorporation into the Gentoo Linux system. |
15 | # and their incorporation into the Gentoo Linux system. |
| 19 | # |
16 | # |
| … | |
… | |
| 31 | # |
28 | # |
| 32 | # * each_ruby_configure |
29 | # * each_ruby_configure |
| 33 | # * all_ruby_configure |
30 | # * all_ruby_configure |
| 34 | |
31 | |
| 35 | # @ECLASS-VARIABLE: USE_RUBY |
32 | # @ECLASS-VARIABLE: USE_RUBY |
|
|
33 | # @REQUIRED |
| 36 | # @DESCRIPTION: |
34 | # @DESCRIPTION: |
| 37 | # This variable contains a space separated list of targets (see above) a package |
35 | # This variable contains a space separated list of targets (see above) a package |
| 38 | # is compatible to. It must be set before the `inherit' call. There is no |
36 | # is compatible to. It must be set before the `inherit' call. There is no |
| 39 | # default. All ebuilds are expected to set this variable. |
37 | # default. All ebuilds are expected to set this variable. |
| 40 | |
38 | |
| 41 | # @ECLASS-VARIABLE: RUBY_PATCHES |
39 | # @ECLASS-VARIABLE: RUBY_PATCHES |
|
|
40 | # @DEFAULT_UNSET |
| 42 | # @DESCRIPTION: |
41 | # @DESCRIPTION: |
| 43 | # A String or Array of filenames of patches to apply to all implementations. |
42 | # A String or Array of filenames of patches to apply to all implementations. |
| 44 | |
43 | |
| 45 | # @ECLASS-VARIABLE: RUBY_OPTIONAL |
44 | # @ECLASS-VARIABLE: RUBY_OPTIONAL |
| 46 | # @DESCRIPTION: |
45 | # @DESCRIPTION: |
| 47 | # Set the value to "yes" to make the dependency on a Ruby interpreter optional. |
46 | # Set the value to "yes" to make the dependency on a Ruby interpreter |
|
|
47 | # optional and then ruby_implementations_depend() to help populate |
|
|
48 | # DEPEND and RDEPEND. |
| 48 | |
49 | |
|
|
50 | # @ECLASS-VARIABLE: RUBY_S |
|
|
51 | # @DEFAULT_UNSET |
|
|
52 | # @DESCRIPTION: |
|
|
53 | # If defined this variable determines the source directory name after |
|
|
54 | # unpacking. This defaults to the name of the package. Note that this |
|
|
55 | # variable supports a wildcard mechanism to help with github tarballs |
|
|
56 | # that contain the commit hash as part of the directory name. |
|
|
57 | |
|
|
58 | # @ECLASS-VARIABLE: RUBY_QA_ALLOWED_LIBS |
|
|
59 | # @DEFAULT_UNSET |
|
|
60 | # @DESCRIPTION: |
|
|
61 | # If defined this variable contains a whitelist of shared objects that |
|
|
62 | # are allowed to exist even if they don't link to libruby. This avoids |
|
|
63 | # the QA check that makes this mandatory. This is most likely not what |
|
|
64 | # you are looking for if you get the related "Missing links" QA warning, |
|
|
65 | # since the proper fix is almost always to make sure the shared object |
|
|
66 | # is linked against libruby. There are cases were this is not the case |
|
|
67 | # and the shared object is generic code to be used in some other way |
|
|
68 | # (e.g. selenium's firefox driver extension). When set this argument is |
|
|
69 | # passed to "grep -E" to remove reporting of these shared objects. |
|
|
70 | |
| 49 | inherit eutils toolchain-funcs |
71 | inherit eutils java-utils-2 toolchain-funcs |
| 50 | |
72 | |
| 51 | EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_setup |
73 | EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_setup |
| 52 | |
74 | |
| 53 | case ${EAPI} in |
75 | case ${EAPI} in |
| 54 | 0|1) |
76 | 0|1) |
| 55 | die "Unsupported EAPI=${EAPI} (too old) for ruby-ng.eclass" ;; |
77 | die "Unsupported EAPI=${EAPI} (too old) for ruby-ng.eclass" ;; |
| 56 | 2) ;; |
78 | 2|3) ;; |
|
|
79 | 4) |
|
|
80 | # S is no longer automatically assigned when it doesn't exist. |
|
|
81 | S="${WORKDIR}" |
|
|
82 | ;; |
| 57 | *) |
83 | *) |
| 58 | die "Unknown EAPI=${EAPI} for ruby-ng.eclass" |
84 | die "Unknown EAPI=${EAPI} for ruby-ng.eclass" |
| 59 | esac |
85 | esac |
| 60 | |
86 | |
| 61 | # @FUNCTION: ruby_implementation_depend |
87 | # @FUNCTION: ruby_implementation_depend |
| … | |
… | |
| 127 | done |
153 | done |
| 128 | echo ")" |
154 | echo ")" |
| 129 | eshopts_pop |
155 | eshopts_pop |
| 130 | } |
156 | } |
| 131 | |
157 | |
|
|
158 | # @FUNCTION: ruby_implementation_command |
|
|
159 | # @RETURN: the path to the given ruby implementation |
|
|
160 | # @DESCRIPTION: |
|
|
161 | # Not all implementations have the same command basename as the |
|
|
162 | # target; namely Ruby Enterprise 1.8 uses ree18 and rubyee18 |
|
|
163 | # respectively. This function translate between the two |
|
|
164 | ruby_implementation_command() { |
|
|
165 | local _ruby_name=$1 |
|
|
166 | |
|
|
167 | # Add all USE_RUBY values where the flag name diverts from the binary here |
|
|
168 | case $1 in |
|
|
169 | ree18) |
|
|
170 | _ruby_name=rubyee18 |
|
|
171 | ;; |
|
|
172 | esac |
|
|
173 | |
|
|
174 | echo $(type -p ${_ruby_name} 2>/dev/null) |
|
|
175 | } |
|
|
176 | |
| 132 | _ruby_atoms_samelib() { |
177 | _ruby_atoms_samelib() { |
| 133 | local atoms=$(_ruby_atoms_samelib_generic "$*") |
178 | local atoms=$(_ruby_atoms_samelib_generic "$*") |
| 134 | |
179 | |
| 135 | for _ruby_implementation in $USE_RUBY; do |
180 | for _ruby_implementation in $USE_RUBY; do |
| 136 | echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}" |
181 | echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}" |
| … | |
… | |
| 178 | RDEPEND="${RDEPEND} $dependency" |
223 | RDEPEND="${RDEPEND} $dependency" |
| 179 | |
224 | |
| 180 | # Add the dependency as a test-dependency since we're going to |
225 | # Add the dependency as a test-dependency since we're going to |
| 181 | # execute the code during test phase. |
226 | # execute the code during test phase. |
| 182 | DEPEND="${DEPEND} test? ( ${dependency} )" |
227 | DEPEND="${DEPEND} test? ( ${dependency} )" |
| 183 | hasq test "$IUSE" || IUSE="${IUSE} test" |
228 | has test "$IUSE" || IUSE="${IUSE} test" |
| 184 | } |
229 | } |
| 185 | |
230 | |
| 186 | # @FUNCTION: ruby_add_bdepend |
231 | # @FUNCTION: ruby_add_bdepend |
| 187 | # @USAGE: dependencies |
232 | # @USAGE: dependencies |
| 188 | # @DESCRIPTION: |
233 | # @DESCRIPTION: |
| … | |
… | |
| 209 | |
254 | |
| 210 | DEPEND="${DEPEND} $dependency" |
255 | DEPEND="${DEPEND} $dependency" |
| 211 | RDEPEND="${RDEPEND}" |
256 | RDEPEND="${RDEPEND}" |
| 212 | } |
257 | } |
| 213 | |
258 | |
|
|
259 | # @FUNCTION: ruby_get_use_implementations |
|
|
260 | # @DESCRIPTION: |
|
|
261 | # Gets an array of ruby use targets enabled by the user |
|
|
262 | ruby_get_use_implementations() { |
|
|
263 | local i implementation |
|
|
264 | for implementation in ${USE_RUBY}; do |
|
|
265 | use ruby_targets_${implementation} && i+=" ${implementation}" |
|
|
266 | done |
|
|
267 | echo $i |
|
|
268 | } |
|
|
269 | |
|
|
270 | # @FUNCTION: ruby_get_use_targets |
|
|
271 | # @DESCRIPTION: |
|
|
272 | # Gets an array of ruby use targets that the ebuild sets |
|
|
273 | ruby_get_use_targets() { |
|
|
274 | local t implementation |
|
|
275 | for implementation in ${USE_RUBY}; do |
|
|
276 | t+=" ruby_targets_${implementation}" |
|
|
277 | done |
|
|
278 | echo $t |
|
|
279 | } |
|
|
280 | |
|
|
281 | if [[ ${EAPI:-0} -ge 4 && ${RUBY_OPTIONAL} != "yes" ]]; then |
|
|
282 | REQUIRED_USE=" || ( $(ruby_get_use_targets) )" |
|
|
283 | fi |
|
|
284 | |
|
|
285 | # @FUNCTION: ruby_implementations_depend |
|
|
286 | # @RETURN: Dependencies suitable for injection into DEPEND and RDEPEND. |
|
|
287 | # @DESCRIPTION: |
|
|
288 | # Produces the dependency string for the various implementations of ruby |
|
|
289 | # which the package is being built against. This should not be used when |
|
|
290 | # RUBY_OPTIONAL is unset but must be used if RUBY_OPTIONAL=yes. Do not |
|
|
291 | # confuse this function with ruby_implementation_depend(). |
|
|
292 | # |
|
|
293 | # @EXAMPLE: |
|
|
294 | # EAPI=4 |
|
|
295 | # RUBY_OPTIONAL=yes |
|
|
296 | # |
|
|
297 | # inherit ruby-ng |
|
|
298 | # ... |
|
|
299 | # DEPEND="ruby? ( $(ruby_implementations_depend) )" |
|
|
300 | # RDEPEND="${DEPEND}" |
|
|
301 | ruby_implementations_depend() { |
|
|
302 | local depend |
|
|
303 | for _ruby_implementation in ${USE_RUBY}; do |
|
|
304 | depend="${depend}${depend+ }ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )" |
|
|
305 | done |
|
|
306 | echo "${depend}" |
|
|
307 | } |
|
|
308 | |
| 214 | for _ruby_implementation in $USE_RUBY; do |
309 | for _ruby_implementation in ${USE_RUBY}; do |
| 215 | IUSE="${IUSE} ruby_targets_${_ruby_implementation}" |
310 | IUSE="${IUSE} ruby_targets_${_ruby_implementation}" |
| 216 | |
|
|
| 217 | # If you specify RUBY_OPTIONAL you also need to take care of |
|
|
| 218 | # ruby useflag and dependency. |
|
|
| 219 | if [[ ${RUBY_OPTIONAL} != "yes" ]]; then |
|
|
| 220 | DEPEND="${DEPEND} ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )" |
|
|
| 221 | RDEPEND="${RDEPEND} ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )" |
|
|
| 222 | fi |
|
|
| 223 | done |
311 | done |
|
|
312 | # If you specify RUBY_OPTIONAL you also need to take care of |
|
|
313 | # ruby useflag and dependency. |
|
|
314 | if [[ ${RUBY_OPTIONAL} != yes ]]; then |
|
|
315 | DEPEND="${DEPEND} $(ruby_implementations_depend)" |
|
|
316 | RDEPEND="${RDEPEND} $(ruby_implementations_depend)" |
|
|
317 | fi |
| 224 | |
318 | |
| 225 | _ruby_invoke_environment() { |
319 | _ruby_invoke_environment() { |
| 226 | old_S=${S} |
320 | old_S=${S} |
|
|
321 | case ${EAPI} in |
|
|
322 | 4) |
|
|
323 | if [ -z ${RUBY_S} ]; then |
|
|
324 | sub_S=${P} |
|
|
325 | else |
|
|
326 | sub_S=${RUBY_S} |
|
|
327 | fi |
|
|
328 | ;; |
|
|
329 | *) |
| 227 | sub_S=${S#${WORKDIR}/} |
330 | sub_S=${S#${WORKDIR}/} |
|
|
331 | ;; |
|
|
332 | esac |
| 228 | |
333 | |
| 229 | # Special case, for the always-lovely GitHub fetches. With this, |
334 | # Special case, for the always-lovely GitHub fetches. With this, |
| 230 | # we allow the star glob to just expand to whatever directory it's |
335 | # we allow the star glob to just expand to whatever directory it's |
| 231 | # called. |
336 | # called. |
| 232 | if [[ ${sub_S} = *"*" ]]; then |
337 | if [[ ${sub_S} = *"*"* ]]; then |
|
|
338 | case ${EAPI} in |
|
|
339 | 2|3) |
|
|
340 | #The old method of setting S depends on undefined package |
|
|
341 | # manager behaviour, so encourage upgrading to EAPI=4. |
|
|
342 | eqawarn "Using * expansion of S is deprecated. Use EAPI and RUBY_S instead." |
|
|
343 | ;; |
|
|
344 | esac |
| 233 | pushd "${WORKDIR}"/all &>/dev/null |
345 | pushd "${WORKDIR}"/all &>/dev/null |
| 234 | sub_S=$(eval ls -d ${sub_S} 2>/dev/null) |
346 | sub_S=$(eval ls -d ${sub_S} 2>/dev/null) |
| 235 | popd &>/dev/null |
347 | popd &>/dev/null |
| 236 | fi |
348 | fi |
| 237 | |
349 | |
| … | |
… | |
| 259 | local invoked=no |
371 | local invoked=no |
| 260 | for _ruby_implementation in ${USE_RUBY}; do |
372 | for _ruby_implementation in ${USE_RUBY}; do |
| 261 | # only proceed if it's requested |
373 | # only proceed if it's requested |
| 262 | use ruby_targets_${_ruby_implementation} || continue |
374 | use ruby_targets_${_ruby_implementation} || continue |
| 263 | |
375 | |
| 264 | local _ruby_name=$_ruby_implementation |
376 | RUBY=$(ruby_implementation_command ${_ruby_implementation}) |
| 265 | |
|
|
| 266 | # Add all USE_RUBY values where the flag name diverts from the binary here |
|
|
| 267 | case $_ruby_implementation in |
|
|
| 268 | ree18) |
|
|
| 269 | _ruby_name=rubyee18 |
|
|
| 270 | ;; |
|
|
| 271 | esac |
|
|
| 272 | |
|
|
| 273 | RUBY=$(type -p $_ruby_name 2>/dev/null) |
|
|
| 274 | invoked=yes |
377 | invoked=yes |
| 275 | |
378 | |
| 276 | if [[ -n "$1" ]]; then |
379 | if [[ -n "$1" ]]; then |
| 277 | _ruby_invoke_environment $_ruby_implementation "$@" |
380 | _ruby_invoke_environment ${_ruby_implementation} "$@" |
| 278 | fi |
381 | fi |
| 279 | |
382 | |
| 280 | unset RUBY |
383 | unset RUBY |
| 281 | done |
384 | done |
| 282 | |
385 | |
| … | |
… | |
| 289 | ruby-ng_pkg_setup() { |
392 | ruby-ng_pkg_setup() { |
| 290 | # This only checks that at least one implementation is present |
393 | # This only checks that at least one implementation is present |
| 291 | # before doing anything; by leaving the parameters empty we know |
394 | # before doing anything; by leaving the parameters empty we know |
| 292 | # it's a special case. |
395 | # it's a special case. |
| 293 | _ruby_each_implementation |
396 | _ruby_each_implementation |
|
|
397 | |
|
|
398 | use ruby_targets_jruby && java-pkg_setup-vm |
| 294 | } |
399 | } |
| 295 | |
400 | |
| 296 | # @FUNCTION: ruby-ng_src_unpack |
401 | # @FUNCTION: ruby-ng_src_unpack |
| 297 | # @DESCRIPTION: |
402 | # @DESCRIPTION: |
| 298 | # Unpack the source archive. |
403 | # Unpack the source archive. |
| … | |
… | |
| 389 | type all_ruby_test &>/dev/null && \ |
494 | type all_ruby_test &>/dev/null && \ |
| 390 | _ruby_invoke_environment all all_ruby_test |
495 | _ruby_invoke_environment all all_ruby_test |
| 391 | } |
496 | } |
| 392 | |
497 | |
| 393 | _each_ruby_check_install() { |
498 | _each_ruby_check_install() { |
|
|
499 | local scancmd=scanelf |
|
|
500 | # we have a Mach-O object here |
|
|
501 | [[ ${CHOST} == *-darwin ]] && scancmd=scanmacho |
|
|
502 | |
|
|
503 | has "${EAPI}" 2 && ! use prefix && EPREFIX= |
|
|
504 | |
| 394 | local libruby_basename=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["LIBRUBY_SO"]') |
505 | local libruby_basename=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["LIBRUBY_SO"]') |
| 395 | local libruby_soname=$(scanelf -qS "/usr/$(get_libdir)/${libruby_basename}" | awk '{ print $1 }') |
506 | local libruby_soname=$(basename $(${scancmd} -F "%S#F" -qS "${EPREFIX}/usr/$(get_libdir)/${libruby_basename}") 2>/dev/null) |
| 396 | local sitedir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitedir"]') |
507 | local sitedir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitedir"]') |
| 397 | local sitelibdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]') |
508 | local sitelibdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]') |
| 398 | |
509 | |
| 399 | # Look for wrong files in sitedir |
510 | # Look for wrong files in sitedir |
| 400 | if [[ -d "${D}${sitedir}" ]]; then |
511 | # if [[ -d "${D}${sitedir}" ]]; then |
| 401 | local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}") |
512 | # local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}") |
| 402 | if [[ -n ${f} ]]; then |
513 | # if [[ -n ${f} ]]; then |
| 403 | eerror "Found files in sitedir, outsite sitelibdir:" |
514 | # eerror "Found files in sitedir, outsite sitelibdir:" |
| 404 | eerror "${f}" |
515 | # eerror "${f}" |
| 405 | die "Misplaced files in sitedir" |
516 | # die "Misplaced files in sitedir" |
| 406 | fi |
517 | # fi |
| 407 | fi |
518 | # fi |
| 408 | |
519 | |
| 409 | # The current implementation lacks libruby (i.e.: jruby) |
520 | # The current implementation lacks libruby (i.e.: jruby) |
| 410 | [[ -z ${libruby_soname} ]] && return 0 |
521 | [[ -z ${libruby_soname} ]] && return 0 |
| 411 | |
522 | |
| 412 | scanelf -qnR "${D}${sitedir}" \ |
523 | # Check also the gems directory, since we could be installing compiled |
|
|
524 | # extensions via ruby-fakegem; make sure to check only in sitelibdir, since |
|
|
525 | # that's what changes between two implementations (otherwise you'd get false |
|
|
526 | # positives now that Ruby 1.9.2 installs with the same sitedir as 1.8) |
|
|
527 | ${scancmd} -qnR "${D}${sitelibdir}" "${D}${sitelibdir/site_ruby/gems}" \ |
| 413 | | fgrep -v "${libruby_soname}" \ |
528 | | fgrep -v "${libruby_soname}" \ |
|
|
529 | | grep -E -v "${RUBY_QA_ALLOWED_LIBS}" \ |
| 414 | > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log |
530 | > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log |
| 415 | |
531 | |
| 416 | if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then |
532 | if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then |
| 417 | ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}" |
533 | ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}" |
| 418 | ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ) |
534 | ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ) |
| … | |
… | |
| 446 | # @USAGE: file [file...] |
562 | # @USAGE: file [file...] |
| 447 | # @DESCRIPTION: |
563 | # @DESCRIPTION: |
| 448 | # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}. |
564 | # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}. |
| 449 | doruby() { |
565 | doruby() { |
| 450 | [[ -z ${RUBY} ]] && die "\$RUBY is not set" |
566 | [[ -z ${RUBY} ]] && die "\$RUBY is not set" |
|
|
567 | has "${EAPI}" 2 && ! use prefix && EPREFIX= |
| 451 | ( # don't want to pollute calling env |
568 | ( # don't want to pollute calling env |
| 452 | insinto $(ruby_rbconfig_value 'sitelibdir') |
569 | sitelibdir=$(ruby_rbconfig_value 'sitelibdir') |
|
|
570 | insinto ${sitelibdir#${EPREFIX}} |
| 453 | insopts -m 0644 |
571 | insopts -m 0644 |
| 454 | doins "$@" |
572 | doins "$@" |
| 455 | ) || die "failed to install $@" |
573 | ) || die "failed to install $@" |
| 456 | } |
574 | } |
| 457 | |
575 | |