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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.40 - (show annotations) (download)
Wed Oct 5 17:46:20 2011 UTC (3 years, 1 month ago) by graaff
Branch: MAIN
Changes since 1.39: +4 -2 lines
Set up java vm properly when using jruby. Fixes problems reported in bug 384901. Thanks to matsuu for diagnosis and patch.

1 # Copyright 1999-2011 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.39 2011/08/22 04:46:32 vapier Exp $
4
5 # @ECLASS: ruby-ng.eclass
6 # @MAINTAINER:
7 # Ruby herd <ruby@gentoo.org>
8 # @AUTHOR:
9 # Author: Diego E. Pettenò <flameeyes@gentoo.org>
10 # Author: Alex Legler <a3li@gentoo.org>
11 # Author: Hans de Graaff <graaff@gentoo.org>
12 # @BLURB: An eclass for installing Ruby packages with proper support for multiple Ruby slots.
13 # @DESCRIPTION:
14 # The Ruby eclass is designed to allow an easier installation of Ruby packages
15 # and their incorporation into the Gentoo Linux system.
16 #
17 # Currently available targets are:
18 # * ruby18 - Ruby (MRI) 1.8.x
19 # * ruby19 - Ruby (MRI) 1.9.x
20 # * ree18 - Ruby Enterprise Edition 1.8.x
21 # * jruby - JRuby
22 #
23 # This eclass does not define the implementation of the configure,
24 # compile, test, or install phases. Instead, the default phases are
25 # used. Specific implementations of these phases can be provided in
26 # the ebuild either to be run for each Ruby implementation, or for all
27 # Ruby implementations, as follows:
28 #
29 # * each_ruby_configure
30 # * all_ruby_configure
31
32 # @ECLASS-VARIABLE: USE_RUBY
33 # @REQUIRED
34 # @DESCRIPTION:
35 # This variable contains a space separated list of targets (see above) a package
36 # is compatible to. It must be set before the `inherit' call. There is no
37 # default. All ebuilds are expected to set this variable.
38
39 # @ECLASS-VARIABLE: RUBY_PATCHES
40 # @DEFAULT_UNSET
41 # @DESCRIPTION:
42 # A String or Array of filenames of patches to apply to all implementations.
43
44 # @ECLASS-VARIABLE: RUBY_OPTIONAL
45 # @DESCRIPTION:
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.
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
71 inherit eutils java-utils-2 toolchain-funcs
72
73 EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_setup
74
75 case ${EAPI} in
76 0|1)
77 die "Unsupported EAPI=${EAPI} (too old) for ruby-ng.eclass" ;;
78 2|3) ;;
79 4)
80 # S is no longer automatically assigned when it doesn't exist.
81 S="${WORKDIR}"
82 ;;
83 *)
84 die "Unknown EAPI=${EAPI} for ruby-ng.eclass"
85 esac
86
87 # @FUNCTION: ruby_implementation_depend
88 # @USAGE: target [comparator [version]]
89 # @RETURN: Package atom of a Ruby implementation to be used in dependencies.
90 # @DESCRIPTION:
91 # This function returns the formal package atom for a Ruby implementation.
92 #
93 # `target' has to be one of the valid values for USE_RUBY (see above)
94 #
95 # Set `comparator' and `version' to include a comparator (=, >=, etc.) and a
96 # version string to the returned string
97 ruby_implementation_depend() {
98 local rubypn=
99 local rubyslot=
100
101 case $1 in
102 ruby18)
103 rubypn="dev-lang/ruby"
104 rubyslot=":1.8"
105 ;;
106 ruby19)
107 rubypn="dev-lang/ruby"
108 rubyslot=":1.9"
109 ;;
110 ree18)
111 rubypn="dev-lang/ruby-enterprise"
112 rubyslot=":1.8"
113 ;;
114 jruby)
115 rubypn="dev-java/jruby"
116 rubyslot=""
117 ;;
118 *) die "$1: unknown Ruby implementation"
119 esac
120
121 echo "$2${rubypn}$3${rubyslot}"
122 }
123
124 # @FUNCTION: ruby_samelib
125 # @RETURN: use flag string with current ruby implementations
126 # @DESCRIPTION:
127 # Convenience function to output the use dependency part of a
128 # dependency. Used as a building block for ruby_add_rdepend() and
129 # ruby_add_bdepend(), but may also be useful in an ebuild to specify
130 # more complex dependencies.
131 ruby_samelib() {
132 local res=
133 for _ruby_implementation in $USE_RUBY; do
134 has -${_ruby_implementation} $@ || \
135 res="${res}ruby_targets_${_ruby_implementation}?,"
136 done
137
138 echo "[${res%,}]"
139 }
140
141 _ruby_atoms_samelib_generic() {
142 eshopts_push -o noglob
143 echo "RUBYTARGET? ("
144 for token in $*; do
145 case "$token" in
146 "||" | "(" | ")" | *"?")
147 echo "${token}" ;;
148 *])
149 echo "${token%[*}[RUBYTARGET,${token/*[}" ;;
150 *)
151 echo "${token}[RUBYTARGET]" ;;
152 esac
153 done
154 echo ")"
155 eshopts_pop
156 }
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
177 _ruby_atoms_samelib() {
178 local atoms=$(_ruby_atoms_samelib_generic "$*")
179
180 for _ruby_implementation in $USE_RUBY; do
181 echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}"
182 done
183 }
184
185 _ruby_wrap_conditions() {
186 local conditions="$1"
187 local atoms="$2"
188
189 for condition in $conditions; do
190 atoms="${condition}? ( ${atoms} )"
191 done
192
193 echo "$atoms"
194 }
195
196 # @FUNCTION: ruby_add_rdepend
197 # @USAGE: dependencies
198 # @DESCRIPTION:
199 # Adds the specified dependencies, with use condition(s) to RDEPEND,
200 # taking the current set of ruby targets into account. This makes sure
201 # that all ruby dependencies of the package are installed for the same
202 # ruby targets. Use this function for all ruby dependencies instead of
203 # setting RDEPEND yourself. The list of atoms uses the same syntax as
204 # normal dependencies.
205 #
206 # Note: runtime dependencies are also added as build-time test
207 # dependencies.
208 ruby_add_rdepend() {
209 case $# in
210 1) ;;
211 2)
212 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_rdepend for $CATEGORY/$PF"
213 ruby_add_rdepend "$(_ruby_wrap_conditions "$1" "$2")"
214 return
215 ;;
216 *)
217 die "bad number of arguments to $0"
218 ;;
219 esac
220
221 local dependency=$(_ruby_atoms_samelib "$1")
222
223 RDEPEND="${RDEPEND} $dependency"
224
225 # Add the dependency as a test-dependency since we're going to
226 # execute the code during test phase.
227 DEPEND="${DEPEND} test? ( ${dependency} )"
228 has test "$IUSE" || IUSE="${IUSE} test"
229 }
230
231 # @FUNCTION: ruby_add_bdepend
232 # @USAGE: dependencies
233 # @DESCRIPTION:
234 # Adds the specified dependencies, with use condition(s) to DEPEND,
235 # taking the current set of ruby targets into account. This makes sure
236 # that all ruby dependencies of the package are installed for the same
237 # ruby targets. Use this function for all ruby dependencies instead of
238 # setting DEPEND yourself. The list of atoms uses the same syntax as
239 # normal dependencies.
240 ruby_add_bdepend() {
241 case $# in
242 1) ;;
243 2)
244 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_bdepend for $CATEGORY/$PF"
245 ruby_add_bdepend "$(_ruby_wrap_conditions "$1" "$2")"
246 return
247 ;;
248 *)
249 die "bad number of arguments to $0"
250 ;;
251 esac
252
253 local dependency=$(_ruby_atoms_samelib "$1")
254
255 DEPEND="${DEPEND} $dependency"
256 RDEPEND="${RDEPEND}"
257 }
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
309 for _ruby_implementation in ${USE_RUBY}; do
310 IUSE="${IUSE} ruby_targets_${_ruby_implementation}"
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
318
319 _ruby_invoke_environment() {
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 *)
330 sub_S=${S#${WORKDIR}/}
331 ;;
332 esac
333
334 # Special case, for the always-lovely GitHub fetches. With this,
335 # we allow the star glob to just expand to whatever directory it's
336 # called.
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
345 pushd "${WORKDIR}"/all &>/dev/null
346 sub_S=$(eval ls -d ${sub_S} 2>/dev/null)
347 popd &>/dev/null
348 fi
349
350 environment=$1; shift
351
352 my_WORKDIR="${WORKDIR}"/${environment}
353 S="${my_WORKDIR}"/"${sub_S}"
354
355 if [[ -d "${S}" ]]; then
356 pushd "$S" &>/dev/null
357 elif [[ -d "${my_WORKDIR}" ]]; then
358 pushd "${my_WORKDIR}" &>/dev/null
359 else
360 pushd "${WORKDIR}" &>/dev/null
361 fi
362
363 ebegin "Running ${_PHASE:-${EBUILD_PHASE}} phase for $environment"
364 "$@"
365 popd &>/dev/null
366
367 S=${old_S}
368 }
369
370 _ruby_each_implementation() {
371 local invoked=no
372 for _ruby_implementation in ${USE_RUBY}; do
373 # only proceed if it's requested
374 use ruby_targets_${_ruby_implementation} || continue
375
376 RUBY=$(ruby_implementation_command ${_ruby_implementation})
377 invoked=yes
378
379 if [[ -n "$1" ]]; then
380 _ruby_invoke_environment ${_ruby_implementation} "$@"
381 fi
382
383 unset RUBY
384 done
385
386 [[ ${invoked} == "no" ]] && die "You need to select at least one Ruby implementation by setting RUBY_TARGETS in /etc/make.conf."
387 }
388
389 # @FUNCTION: ruby-ng_pkg_setup
390 # @DESCRIPTION:
391 # Check whether at least one ruby target implementation is present.
392 ruby-ng_pkg_setup() {
393 # This only checks that at least one implementation is present
394 # before doing anything; by leaving the parameters empty we know
395 # it's a special case.
396 _ruby_each_implementation
397
398 use ruby_targets_jruby && java-pkg_setup-vm
399 }
400
401 # @FUNCTION: ruby-ng_src_unpack
402 # @DESCRIPTION:
403 # Unpack the source archive.
404 ruby-ng_src_unpack() {
405 mkdir "${WORKDIR}"/all
406 pushd "${WORKDIR}"/all &>/dev/null
407
408 # We don't support an each-unpack, it's either all or nothing!
409 if type all_ruby_unpack &>/dev/null; then
410 _ruby_invoke_environment all all_ruby_unpack
411 else
412 [[ -n ${A} ]] && unpack ${A}
413 fi
414
415 popd &>/dev/null
416 }
417
418 _ruby_apply_patches() {
419 for patch in "${RUBY_PATCHES[@]}"; do
420 if [ -f "${patch}" ]; then
421 epatch "${patch}"
422 elif [ -f "${FILESDIR}/${patch}" ]; then
423 epatch "${FILESDIR}/${patch}"
424 else
425 die "Cannot find patch ${patch}"
426 fi
427 done
428
429 # This is a special case: instead of executing just in the special
430 # "all" environment, this will actually copy the effects on _all_
431 # the other environments, and is thus executed before the copy
432 type all_ruby_prepare &>/dev/null && all_ruby_prepare
433 }
434
435 _ruby_source_copy() {
436 # Until we actually find a reason not to, we use hardlinks, this
437 # should reduce the amount of disk space that is wasted by this.
438 cp -prl all ${_ruby_implementation} \
439 || die "Unable to copy ${_ruby_implementation} environment"
440 }
441
442 # @FUNCTION: ruby-ng_src_prepare
443 # @DESCRIPTION:
444 # Apply patches and prepare versions for each ruby target
445 # implementation. Also carry out common clean up tasks.
446 ruby-ng_src_prepare() {
447 # Way too many Ruby packages are prepared on OSX without removing
448 # the extra data forks, we do it here to avoid repeating it for
449 # almost every other ebuild.
450 find . -name '._*' -delete
451
452 _ruby_invoke_environment all _ruby_apply_patches
453
454 _PHASE="source copy" \
455 _ruby_each_implementation _ruby_source_copy
456
457 if type each_ruby_prepare &>/dev/null; then
458 _ruby_each_implementation each_ruby_prepare
459 fi
460 }
461
462 # @FUNCTION: ruby-ng_src_configure
463 # @DESCRIPTION:
464 # Configure the package.
465 ruby-ng_src_configure() {
466 if type each_ruby_configure &>/dev/null; then
467 _ruby_each_implementation each_ruby_configure
468 fi
469
470 type all_ruby_configure &>/dev/null && \
471 _ruby_invoke_environment all all_ruby_configure
472 }
473
474 # @FUNCTION: ruby-ng_src_compile
475 # @DESCRIPTION:
476 # Compile the package.
477 ruby-ng_src_compile() {
478 if type each_ruby_compile &>/dev/null; then
479 _ruby_each_implementation each_ruby_compile
480 fi
481
482 type all_ruby_compile &>/dev/null && \
483 _ruby_invoke_environment all all_ruby_compile
484 }
485
486 # @FUNCTION: ruby-ng_src_test
487 # @DESCRIPTION:
488 # Run tests for the package.
489 ruby-ng_src_test() {
490 if type each_ruby_test &>/dev/null; then
491 _ruby_each_implementation each_ruby_test
492 fi
493
494 type all_ruby_test &>/dev/null && \
495 _ruby_invoke_environment all all_ruby_test
496 }
497
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
505 local libruby_basename=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["LIBRUBY_SO"]')
506 local libruby_soname=$(basename $(${scancmd} -F "%S#F" -qS "${EPREFIX}/usr/$(get_libdir)/${libruby_basename}") 2>/dev/null)
507 local sitedir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitedir"]')
508 local sitelibdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]')
509
510 # Look for wrong files in sitedir
511 # if [[ -d "${D}${sitedir}" ]]; then
512 # local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}")
513 # if [[ -n ${f} ]]; then
514 # eerror "Found files in sitedir, outsite sitelibdir:"
515 # eerror "${f}"
516 # die "Misplaced files in sitedir"
517 # fi
518 # fi
519
520 # The current implementation lacks libruby (i.e.: jruby)
521 [[ -z ${libruby_soname} ]] && return 0
522
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}" \
528 | fgrep -v "${libruby_soname}" \
529 | grep -E -v "${RUBY_QA_ALLOWED_LIBS}" \
530 > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log
531
532 if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then
533 ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}"
534 ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log )
535 die "Missing links to ${libruby_soname}"
536 fi
537 }
538
539 # @FUNCTION: ruby-ng_src_install
540 # @DESCRIPTION:
541 # Install the package for each ruby target implementation.
542 ruby-ng_src_install() {
543 if type each_ruby_install &>/dev/null; then
544 _ruby_each_implementation each_ruby_install
545 fi
546
547 type all_ruby_install &>/dev/null && \
548 _ruby_invoke_environment all all_ruby_install
549
550 _PHASE="check install" \
551 _ruby_each_implementation _each_ruby_check_install
552 }
553
554 # @FUNCTION: ruby_rbconfig_value
555 # @USAGE: rbconfig item
556 # @RETURN: Returns the value of the given rbconfig item of the Ruby interpreter in ${RUBY}.
557 ruby_rbconfig_value() {
558 echo $(${RUBY} -rrbconfig -e "puts Config::CONFIG['$1']")
559 }
560
561 # @FUNCTION: doruby
562 # @USAGE: file [file...]
563 # @DESCRIPTION:
564 # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}.
565 doruby() {
566 [[ -z ${RUBY} ]] && die "\$RUBY is not set"
567 has "${EAPI}" 2 && ! use prefix && EPREFIX=
568 ( # don't want to pollute calling env
569 sitelibdir=$(ruby_rbconfig_value 'sitelibdir')
570 insinto ${sitelibdir#${EPREFIX}}
571 insopts -m 0644
572 doins "$@"
573 ) || die "failed to install $@"
574 }
575
576 # @FUNCTION: ruby_get_libruby
577 # @RETURN: The location of libruby*.so belonging to the Ruby interpreter in ${RUBY}.
578 ruby_get_libruby() {
579 ${RUBY} -rrbconfig -e 'puts File.join(Config::CONFIG["libdir"], Config::CONFIG["LIBRUBY"])'
580 }
581
582 # @FUNCTION: ruby_get_hdrdir
583 # @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}.
584 ruby_get_hdrdir() {
585 local rubyhdrdir=$(ruby_rbconfig_value 'rubyhdrdir')
586
587 if [[ "${rubyhdrdir}" = "nil" ]] ; then
588 rubyhdrdir=$(ruby_rbconfig_value 'archdir')
589 fi
590
591 echo "${rubyhdrdir}"
592 }
593
594 # @FUNCTION: ruby_get_version
595 # @RETURN: The version of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
596 ruby_get_version() {
597 local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
598
599 echo $(${ruby} -e 'puts RUBY_VERSION')
600 }
601
602 # @FUNCTION: ruby_get_implementation
603 # @RETURN: The implementation of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
604 ruby_get_implementation() {
605 local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
606
607 case $(${ruby} --version) in
608 *Enterprise*)
609 echo "ree"
610 ;;
611 *jruby*)
612 echo "jruby"
613 ;;
614 *)
615 echo "mri"
616 ;;
617 esac
618 }

  ViewVC Help
Powered by ViewVC 1.1.20