/[gentoo-x86]/eclass/ruby-ng.eclass
Gentoo

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.36 - (show annotations) (download)
Fri Jul 22 09:08:59 2011 UTC (2 years, 8 months ago) by graaff
Branch: MAIN
Changes since 1.35: +16 -1 lines
Leverage the REQUIRED_USE mechanism to determine at dependency resolution time if this ebuild can satisfy RUBY_TARGETS. Patch by Matthew Schultz in bug 373227.

1 # Copyright 1999-2009 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-ng.eclass,v 1.35 2011/07/19 05:48:09 graaff Exp $
4 #
5 # @ECLASS: ruby-ng.eclass
6 # @MAINTAINER:
7 # Ruby herd <ruby@gentoo.org>
8 #
9 # Author: Diego E. Pettenò <flameeyes@gentoo.org>
10 #
11 # Author: Alex Legler <a3li@gentoo.org>
12 #
13 # Author: Hans de Graaff <graaff@gentoo.org>
14 #
15 # @BLURB: An eclass for installing Ruby packages with proper support for multiple Ruby slots.
16 # @DESCRIPTION:
17 # The Ruby eclass is designed to allow an easier installation of Ruby packages
18 # and their incorporation into the Gentoo Linux system.
19 #
20 # Currently available targets are:
21 # * ruby18 - Ruby (MRI) 1.8.x
22 # * ruby19 - Ruby (MRI) 1.9.x
23 # * ree18 - Ruby Enterprise Edition 1.8.x
24 # * jruby - JRuby
25 #
26 # This eclass does not define the implementation of the configure,
27 # compile, test, or install phases. Instead, the default phases are
28 # used. Specific implementations of these phases can be provided in
29 # the ebuild either to be run for each Ruby implementation, or for all
30 # Ruby implementations, as follows:
31 #
32 # * each_ruby_configure
33 # * all_ruby_configure
34
35 # @ECLASS-VARIABLE: USE_RUBY
36 # @REQUIRED
37 # @DESCRIPTION:
38 # This variable contains a space separated list of targets (see above) a package
39 # is compatible to. It must be set before the `inherit' call. There is no
40 # default. All ebuilds are expected to set this variable.
41
42 # @ECLASS-VARIABLE: RUBY_PATCHES
43 # @DEFAULT_UNSET
44 # @DESCRIPTION:
45 # A String or Array of filenames of patches to apply to all implementations.
46
47 # @ECLASS-VARIABLE: RUBY_OPTIONAL
48 # @DESCRIPTION:
49 # Set the value to "yes" to make the dependency on a Ruby interpreter optional.
50
51 # @ECLASS-VARIABLE: RUBY_S
52 # @DEFAULT_UNSET
53 # @DESCRIPTION:
54 # If defined this variable determines the source directory name after
55 # unpacking. This defaults to the name of the package. Note that this
56 # variable supports a wildcard mechanism to help with github tarballs
57 # that contain the commit hash as part of the directory name.
58
59 # @ECLASS-VARIABLE: RUBY_QA_ALLOWED_LIBS
60 # @DEFAULT_UNSET
61 # @DESCRIPTION:
62 # If defined this variable contains a whitelist of shared objects that
63 # are allowed to exist even if they don't link to libruby. This avoids
64 # the QA check that makes this mandatory. This is most likely not what
65 # you are looking for if you get the related "Missing links" QA warning,
66 # since the proper fix is almost always to make sure the shared object
67 # is linked against libruby. There are cases were this is not the case
68 # and the shared object is generic code to be used in some other way
69 # (e.g. selenium's firefox driver extension). When set this argument is
70 # passed to "grep -E" to remove reporting of these shared objects.
71
72 inherit eutils toolchain-funcs
73
74 EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_setup
75
76 case ${EAPI} in
77 0|1)
78 die "Unsupported EAPI=${EAPI} (too old) for ruby-ng.eclass" ;;
79 2|3) ;;
80 4)
81 # S is no longer automatically assigned when it doesn't exist.
82 S="${WORKDIR}"
83 ;;
84 *)
85 die "Unknown EAPI=${EAPI} for ruby-ng.eclass"
86 esac
87
88 # @FUNCTION: ruby_implementation_depend
89 # @USAGE: target [comparator [version]]
90 # @RETURN: Package atom of a Ruby implementation to be used in dependencies.
91 # @DESCRIPTION:
92 # This function returns the formal package atom for a Ruby implementation.
93 #
94 # `target' has to be one of the valid values for USE_RUBY (see above)
95 #
96 # Set `comparator' and `version' to include a comparator (=, >=, etc.) and a
97 # version string to the returned string
98 ruby_implementation_depend() {
99 local rubypn=
100 local rubyslot=
101
102 case $1 in
103 ruby18)
104 rubypn="dev-lang/ruby"
105 rubyslot=":1.8"
106 ;;
107 ruby19)
108 rubypn="dev-lang/ruby"
109 rubyslot=":1.9"
110 ;;
111 ree18)
112 rubypn="dev-lang/ruby-enterprise"
113 rubyslot=":1.8"
114 ;;
115 jruby)
116 rubypn="dev-java/jruby"
117 rubyslot=""
118 ;;
119 *) die "$1: unknown Ruby implementation"
120 esac
121
122 echo "$2${rubypn}$3${rubyslot}"
123 }
124
125 # @FUNCTION: ruby_samelib
126 # @RETURN: use flag string with current ruby implementations
127 # @DESCRIPTION:
128 # Convenience function to output the use dependency part of a
129 # dependency. Used as a building block for ruby_add_rdepend() and
130 # ruby_add_bdepend(), but may also be useful in an ebuild to specify
131 # more complex dependencies.
132 ruby_samelib() {
133 local res=
134 for _ruby_implementation in $USE_RUBY; do
135 has -${_ruby_implementation} $@ || \
136 res="${res}ruby_targets_${_ruby_implementation}?,"
137 done
138
139 echo "[${res%,}]"
140 }
141
142 _ruby_atoms_samelib_generic() {
143 eshopts_push -o noglob
144 echo "RUBYTARGET? ("
145 for token in $*; do
146 case "$token" in
147 "||" | "(" | ")" | *"?")
148 echo "${token}" ;;
149 *])
150 echo "${token%[*}[RUBYTARGET,${token/*[}" ;;
151 *)
152 echo "${token}[RUBYTARGET]" ;;
153 esac
154 done
155 echo ")"
156 eshopts_pop
157 }
158
159 # @FUNCTION: ruby_implementation_command
160 # @RETURN: the path to the given ruby implementation
161 # @DESCRIPTION:
162 # Not all implementations have the same command basename as the
163 # target; namely Ruby Enterprise 1.8 uses ree18 and rubyee18
164 # respectively. This function translate between the two
165 ruby_implementation_command() {
166 local _ruby_name=$1
167
168 # Add all USE_RUBY values where the flag name diverts from the binary here
169 case $1 in
170 ree18)
171 _ruby_name=rubyee18
172 ;;
173 esac
174
175 echo $(type -p ${_ruby_name} 2>/dev/null)
176 }
177
178 _ruby_atoms_samelib() {
179 local atoms=$(_ruby_atoms_samelib_generic "$*")
180
181 for _ruby_implementation in $USE_RUBY; do
182 echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}"
183 done
184 }
185
186 _ruby_wrap_conditions() {
187 local conditions="$1"
188 local atoms="$2"
189
190 for condition in $conditions; do
191 atoms="${condition}? ( ${atoms} )"
192 done
193
194 echo "$atoms"
195 }
196
197 # @FUNCTION: ruby_add_rdepend
198 # @USAGE: dependencies
199 # @DESCRIPTION:
200 # Adds the specified dependencies, with use condition(s) to RDEPEND,
201 # taking the current set of ruby targets into account. This makes sure
202 # that all ruby dependencies of the package are installed for the same
203 # ruby targets. Use this function for all ruby dependencies instead of
204 # setting RDEPEND yourself. The list of atoms uses the same syntax as
205 # normal dependencies.
206 #
207 # Note: runtime dependencies are also added as build-time test
208 # dependencies.
209 ruby_add_rdepend() {
210 case $# in
211 1) ;;
212 2)
213 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_rdepend for $CATEGORY/$PF"
214 ruby_add_rdepend "$(_ruby_wrap_conditions "$1" "$2")"
215 return
216 ;;
217 *)
218 die "bad number of arguments to $0"
219 ;;
220 esac
221
222 local dependency=$(_ruby_atoms_samelib "$1")
223
224 RDEPEND="${RDEPEND} $dependency"
225
226 # Add the dependency as a test-dependency since we're going to
227 # execute the code during test phase.
228 DEPEND="${DEPEND} test? ( ${dependency} )"
229 has test "$IUSE" || IUSE="${IUSE} test"
230 }
231
232 # @FUNCTION: ruby_add_bdepend
233 # @USAGE: dependencies
234 # @DESCRIPTION:
235 # Adds the specified dependencies, with use condition(s) to DEPEND,
236 # taking the current set of ruby targets into account. This makes sure
237 # that all ruby dependencies of the package are installed for the same
238 # ruby targets. Use this function for all ruby dependencies instead of
239 # setting DEPEND yourself. The list of atoms uses the same syntax as
240 # normal dependencies.
241 ruby_add_bdepend() {
242 case $# in
243 1) ;;
244 2)
245 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_bdepend for $CATEGORY/$PF"
246 ruby_add_bdepend "$(_ruby_wrap_conditions "$1" "$2")"
247 return
248 ;;
249 *)
250 die "bad number of arguments to $0"
251 ;;
252 esac
253
254 local dependency=$(_ruby_atoms_samelib "$1")
255
256 DEPEND="${DEPEND} $dependency"
257 RDEPEND="${RDEPEND}"
258 }
259
260 # @FUNCTION: ruby_get_use_targets
261 # @DESCRIPTION:
262 # Gets an array of ruby use targets that the ebuild sets
263 ruby_get_use_targets() {
264 local t implementation
265 for implementation in ${USE_RUBY}; do
266 t+=" ruby_targets_${implementation}"
267 done
268 echo $t
269 }
270
271 if [[ ${EAPI:-0} -ge 4 && ${RUBY_OPTIONAL} != "yes" ]]; then
272 REQUIRED_USE=" || ( $(ruby_get_use_targets) )"
273 fi
274
275 for _ruby_implementation in $USE_RUBY; do
276 IUSE="${IUSE} ruby_targets_${_ruby_implementation}"
277
278 # If you specify RUBY_OPTIONAL you also need to take care of
279 # ruby useflag and dependency.
280 if [[ ${RUBY_OPTIONAL} != "yes" ]]; then
281 DEPEND="${DEPEND} ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
282 RDEPEND="${RDEPEND} ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
283 fi
284 done
285
286 _ruby_invoke_environment() {
287 old_S=${S}
288 case ${EAPI} in
289 4)
290 if [ -z ${RUBY_S} ]; then
291 sub_S=${P}
292 else
293 sub_S=${RUBY_S}
294 fi
295 ;;
296 *)
297 sub_S=${S#${WORKDIR}/}
298 ;;
299 esac
300
301 # Special case, for the always-lovely GitHub fetches. With this,
302 # we allow the star glob to just expand to whatever directory it's
303 # called.
304 if [[ ${sub_S} = *"*"* ]]; then
305 case ${EAPI} in
306 2|3)
307 #The old method of setting S depends on undefined package
308 # manager behaviour, so encourage upgrading to EAPI=4.
309 eqawarn "Using * expansion of S is deprecated. Use EAPI and RUBY_S instead."
310 ;;
311 esac
312 pushd "${WORKDIR}"/all &>/dev/null
313 sub_S=$(eval ls -d ${sub_S} 2>/dev/null)
314 popd &>/dev/null
315 fi
316
317 environment=$1; shift
318
319 my_WORKDIR="${WORKDIR}"/${environment}
320 S="${my_WORKDIR}"/"${sub_S}"
321
322 if [[ -d "${S}" ]]; then
323 pushd "$S" &>/dev/null
324 elif [[ -d "${my_WORKDIR}" ]]; then
325 pushd "${my_WORKDIR}" &>/dev/null
326 else
327 pushd "${WORKDIR}" &>/dev/null
328 fi
329
330 ebegin "Running ${_PHASE:-${EBUILD_PHASE}} phase for $environment"
331 "$@"
332 popd &>/dev/null
333
334 S=${old_S}
335 }
336
337 _ruby_each_implementation() {
338 local invoked=no
339 for _ruby_implementation in ${USE_RUBY}; do
340 # only proceed if it's requested
341 use ruby_targets_${_ruby_implementation} || continue
342
343 RUBY=$(ruby_implementation_command ${_ruby_implementation})
344 invoked=yes
345
346 if [[ -n "$1" ]]; then
347 _ruby_invoke_environment ${_ruby_implementation} "$@"
348 fi
349
350 unset RUBY
351 done
352
353 [[ ${invoked} == "no" ]] && die "You need to select at least one Ruby implementation by setting RUBY_TARGETS in /etc/make.conf."
354 }
355
356 # @FUNCTION: ruby-ng_pkg_setup
357 # @DESCRIPTION:
358 # Check whether at least one ruby target implementation is present.
359 ruby-ng_pkg_setup() {
360 # This only checks that at least one implementation is present
361 # before doing anything; by leaving the parameters empty we know
362 # it's a special case.
363 _ruby_each_implementation
364 }
365
366 # @FUNCTION: ruby-ng_src_unpack
367 # @DESCRIPTION:
368 # Unpack the source archive.
369 ruby-ng_src_unpack() {
370 mkdir "${WORKDIR}"/all
371 pushd "${WORKDIR}"/all &>/dev/null
372
373 # We don't support an each-unpack, it's either all or nothing!
374 if type all_ruby_unpack &>/dev/null; then
375 _ruby_invoke_environment all all_ruby_unpack
376 else
377 [[ -n ${A} ]] && unpack ${A}
378 fi
379
380 popd &>/dev/null
381 }
382
383 _ruby_apply_patches() {
384 for patch in "${RUBY_PATCHES[@]}"; do
385 if [ -f "${patch}" ]; then
386 epatch "${patch}"
387 elif [ -f "${FILESDIR}/${patch}" ]; then
388 epatch "${FILESDIR}/${patch}"
389 else
390 die "Cannot find patch ${patch}"
391 fi
392 done
393
394 # This is a special case: instead of executing just in the special
395 # "all" environment, this will actually copy the effects on _all_
396 # the other environments, and is thus executed before the copy
397 type all_ruby_prepare &>/dev/null && all_ruby_prepare
398 }
399
400 _ruby_source_copy() {
401 # Until we actually find a reason not to, we use hardlinks, this
402 # should reduce the amount of disk space that is wasted by this.
403 cp -prl all ${_ruby_implementation} \
404 || die "Unable to copy ${_ruby_implementation} environment"
405 }
406
407 # @FUNCTION: ruby-ng_src_prepare
408 # @DESCRIPTION:
409 # Apply patches and prepare versions for each ruby target
410 # implementation. Also carry out common clean up tasks.
411 ruby-ng_src_prepare() {
412 # Way too many Ruby packages are prepared on OSX without removing
413 # the extra data forks, we do it here to avoid repeating it for
414 # almost every other ebuild.
415 find . -name '._*' -delete
416
417 _ruby_invoke_environment all _ruby_apply_patches
418
419 _PHASE="source copy" \
420 _ruby_each_implementation _ruby_source_copy
421
422 if type each_ruby_prepare &>/dev/null; then
423 _ruby_each_implementation each_ruby_prepare
424 fi
425 }
426
427 # @FUNCTION: ruby-ng_src_configure
428 # @DESCRIPTION:
429 # Configure the package.
430 ruby-ng_src_configure() {
431 if type each_ruby_configure &>/dev/null; then
432 _ruby_each_implementation each_ruby_configure
433 fi
434
435 type all_ruby_configure &>/dev/null && \
436 _ruby_invoke_environment all all_ruby_configure
437 }
438
439 # @FUNCTION: ruby-ng_src_compile
440 # @DESCRIPTION:
441 # Compile the package.
442 ruby-ng_src_compile() {
443 if type each_ruby_compile &>/dev/null; then
444 _ruby_each_implementation each_ruby_compile
445 fi
446
447 type all_ruby_compile &>/dev/null && \
448 _ruby_invoke_environment all all_ruby_compile
449 }
450
451 # @FUNCTION: ruby-ng_src_test
452 # @DESCRIPTION:
453 # Run tests for the package.
454 ruby-ng_src_test() {
455 if type each_ruby_test &>/dev/null; then
456 _ruby_each_implementation each_ruby_test
457 fi
458
459 type all_ruby_test &>/dev/null && \
460 _ruby_invoke_environment all all_ruby_test
461 }
462
463 _each_ruby_check_install() {
464 local scancmd=scanelf
465 # we have a Mach-O object here
466 [[ ${CHOST} == *-darwin ]] && scancmd=scanmacho
467
468 has "${EAPI}" 2 && ! use prefix && EPREFIX=
469
470 local libruby_basename=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["LIBRUBY_SO"]')
471 local libruby_soname=$(basename $(${scancmd} -F "%S#F" -qS "${EPREFIX}/usr/$(get_libdir)/${libruby_basename}") 2>/dev/null)
472 local sitedir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitedir"]')
473 local sitelibdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]')
474
475 # Look for wrong files in sitedir
476 # if [[ -d "${D}${sitedir}" ]]; then
477 # local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}")
478 # if [[ -n ${f} ]]; then
479 # eerror "Found files in sitedir, outsite sitelibdir:"
480 # eerror "${f}"
481 # die "Misplaced files in sitedir"
482 # fi
483 # fi
484
485 # The current implementation lacks libruby (i.e.: jruby)
486 [[ -z ${libruby_soname} ]] && return 0
487
488 # Check also the gems directory, since we could be installing compiled
489 # extensions via ruby-fakegem; make sure to check only in sitelibdir, since
490 # that's what changes between two implementations (otherwise you'd get false
491 # positives now that Ruby 1.9.2 installs with the same sitedir as 1.8)
492 ${scancmd} -qnR "${D}${sitelibdir}" "${D}${sitelibdir/site_ruby/gems}" \
493 | fgrep -v "${libruby_soname}" \
494 | grep -E -v "${RUBY_QA_ALLOWED_LIBS}" \
495 > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log
496
497 if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then
498 ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}"
499 ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log )
500 die "Missing links to ${libruby_soname}"
501 fi
502 }
503
504 # @FUNCTION: ruby-ng_src_install
505 # @DESCRIPTION:
506 # Install the package for each ruby target implementation.
507 ruby-ng_src_install() {
508 if type each_ruby_install &>/dev/null; then
509 _ruby_each_implementation each_ruby_install
510 fi
511
512 type all_ruby_install &>/dev/null && \
513 _ruby_invoke_environment all all_ruby_install
514
515 _PHASE="check install" \
516 _ruby_each_implementation _each_ruby_check_install
517 }
518
519 # @FUNCTION: ruby_rbconfig_value
520 # @USAGE: rbconfig item
521 # @RETURN: Returns the value of the given rbconfig item of the Ruby interpreter in ${RUBY}.
522 ruby_rbconfig_value() {
523 echo $(${RUBY} -rrbconfig -e "puts Config::CONFIG['$1']")
524 }
525
526 # @FUNCTION: doruby
527 # @USAGE: file [file...]
528 # @DESCRIPTION:
529 # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}.
530 doruby() {
531 [[ -z ${RUBY} ]] && die "\$RUBY is not set"
532 has "${EAPI}" 2 && ! use prefix && EPREFIX=
533 ( # don't want to pollute calling env
534 sitelibdir=$(ruby_rbconfig_value 'sitelibdir')
535 insinto ${sitelibdir#${EPREFIX}}
536 insopts -m 0644
537 doins "$@"
538 ) || die "failed to install $@"
539 }
540
541 # @FUNCTION: ruby_get_libruby
542 # @RETURN: The location of libruby*.so belonging to the Ruby interpreter in ${RUBY}.
543 ruby_get_libruby() {
544 ${RUBY} -rrbconfig -e 'puts File.join(Config::CONFIG["libdir"], Config::CONFIG["LIBRUBY"])'
545 }
546
547 # @FUNCTION: ruby_get_hdrdir
548 # @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}.
549 ruby_get_hdrdir() {
550 local rubyhdrdir=$(ruby_rbconfig_value 'rubyhdrdir')
551
552 if [[ "${rubyhdrdir}" = "nil" ]] ; then
553 rubyhdrdir=$(ruby_rbconfig_value 'archdir')
554 fi
555
556 echo "${rubyhdrdir}"
557 }
558
559 # @FUNCTION: ruby_get_version
560 # @RETURN: The version of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
561 ruby_get_version() {
562 local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
563
564 echo $(${ruby} -e 'puts RUBY_VERSION')
565 }
566
567 # @FUNCTION: ruby_get_implementation
568 # @RETURN: The implementation of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
569 ruby_get_implementation() {
570 local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
571
572 case $(${ruby} --version) in
573 *Enterprise*)
574 echo "ree"
575 ;;
576 *jruby*)
577 echo "jruby"
578 ;;
579 *)
580 echo "mri"
581 ;;
582 esac
583 }

  ViewVC Help
Powered by ViewVC 1.1.20