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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.44 - (show annotations) (download)
Sun Dec 18 21:33:50 2011 UTC (2 years, 8 months ago) by flameeyes
Branch: MAIN
Changes since 1.43: +4 -8 lines
Reorder setting of REQUIRED_USE to stay near IUSE setting; also use ruby_get_use_targets to set IUSE.

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.43 2011/10/24 18:20:05 graaff 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 # * rbx - Rubinius
23 #
24 # This eclass does not define the implementation of the configure,
25 # compile, test, or install phases. Instead, the default phases are
26 # used. Specific implementations of these phases can be provided in
27 # the ebuild either to be run for each Ruby implementation, or for all
28 # Ruby implementations, as follows:
29 #
30 # * each_ruby_configure
31 # * all_ruby_configure
32
33 # @ECLASS-VARIABLE: USE_RUBY
34 # @REQUIRED
35 # @DESCRIPTION:
36 # This variable contains a space separated list of targets (see above) a package
37 # is compatible to. It must be set before the `inherit' call. There is no
38 # default. All ebuilds are expected to set this variable.
39
40 # @ECLASS-VARIABLE: RUBY_PATCHES
41 # @DEFAULT_UNSET
42 # @DESCRIPTION:
43 # A String or Array of filenames of patches to apply to all implementations.
44
45 # @ECLASS-VARIABLE: RUBY_OPTIONAL
46 # @DESCRIPTION:
47 # Set the value to "yes" to make the dependency on a Ruby interpreter
48 # optional and then ruby_implementations_depend() to help populate
49 # DEPEND and RDEPEND.
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 java-utils-2 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 rbx)
120 rubypn="dev-lang/rubinius"
121 rubyslot=""
122 ;;
123 *) die "$1: unknown Ruby implementation"
124 esac
125
126 echo "$2${rubypn}$3${rubyslot}"
127 }
128
129 # @FUNCTION: ruby_samelib
130 # @RETURN: use flag string with current ruby implementations
131 # @DESCRIPTION:
132 # Convenience function to output the use dependency part of a
133 # dependency. Used as a building block for ruby_add_rdepend() and
134 # ruby_add_bdepend(), but may also be useful in an ebuild to specify
135 # more complex dependencies.
136 ruby_samelib() {
137 local res=
138 for _ruby_implementation in $USE_RUBY; do
139 has -${_ruby_implementation} $@ || \
140 res="${res}ruby_targets_${_ruby_implementation}?,"
141 done
142
143 echo "[${res%,}]"
144 }
145
146 _ruby_atoms_samelib_generic() {
147 eshopts_push -o noglob
148 echo "RUBYTARGET? ("
149 for token in $*; do
150 case "$token" in
151 "||" | "(" | ")" | *"?")
152 echo "${token}" ;;
153 *])
154 echo "${token%[*}[RUBYTARGET,${token/*[}" ;;
155 *)
156 echo "${token}[RUBYTARGET]" ;;
157 esac
158 done
159 echo ")"
160 eshopts_pop
161 }
162
163 # @FUNCTION: ruby_implementation_command
164 # @RETURN: the path to the given ruby implementation
165 # @DESCRIPTION:
166 # Not all implementations have the same command basename as the
167 # target; namely Ruby Enterprise 1.8 uses ree18 and rubyee18
168 # respectively. This function translate between the two
169 ruby_implementation_command() {
170 local _ruby_name=$1
171
172 # Add all USE_RUBY values where the flag name diverts from the binary here
173 case $1 in
174 ree18)
175 _ruby_name=rubyee18
176 ;;
177 esac
178
179 echo $(type -p ${_ruby_name} 2>/dev/null)
180 }
181
182 _ruby_atoms_samelib() {
183 local atoms=$(_ruby_atoms_samelib_generic "$*")
184
185 for _ruby_implementation in $USE_RUBY; do
186 echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}"
187 done
188 }
189
190 _ruby_wrap_conditions() {
191 local conditions="$1"
192 local atoms="$2"
193
194 for condition in $conditions; do
195 atoms="${condition}? ( ${atoms} )"
196 done
197
198 echo "$atoms"
199 }
200
201 # @FUNCTION: ruby_add_rdepend
202 # @USAGE: dependencies
203 # @DESCRIPTION:
204 # Adds the specified dependencies, with use condition(s) to RDEPEND,
205 # taking the current set of ruby targets into account. This makes sure
206 # that all ruby dependencies of the package are installed for the same
207 # ruby targets. Use this function for all ruby dependencies instead of
208 # setting RDEPEND yourself. The list of atoms uses the same syntax as
209 # normal dependencies.
210 #
211 # Note: runtime dependencies are also added as build-time test
212 # dependencies.
213 ruby_add_rdepend() {
214 case $# in
215 1) ;;
216 2)
217 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_rdepend for $CATEGORY/$PF"
218 ruby_add_rdepend "$(_ruby_wrap_conditions "$1" "$2")"
219 return
220 ;;
221 *)
222 die "bad number of arguments to $0"
223 ;;
224 esac
225
226 local dependency=$(_ruby_atoms_samelib "$1")
227
228 RDEPEND="${RDEPEND} $dependency"
229
230 # Add the dependency as a test-dependency since we're going to
231 # execute the code during test phase.
232 DEPEND="${DEPEND} test? ( ${dependency} )"
233 has test "$IUSE" || IUSE="${IUSE} test"
234 }
235
236 # @FUNCTION: ruby_add_bdepend
237 # @USAGE: dependencies
238 # @DESCRIPTION:
239 # Adds the specified dependencies, with use condition(s) to DEPEND,
240 # taking the current set of ruby targets into account. This makes sure
241 # that all ruby dependencies of the package are installed for the same
242 # ruby targets. Use this function for all ruby dependencies instead of
243 # setting DEPEND yourself. The list of atoms uses the same syntax as
244 # normal dependencies.
245 ruby_add_bdepend() {
246 case $# in
247 1) ;;
248 2)
249 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_bdepend for $CATEGORY/$PF"
250 ruby_add_bdepend "$(_ruby_wrap_conditions "$1" "$2")"
251 return
252 ;;
253 *)
254 die "bad number of arguments to $0"
255 ;;
256 esac
257
258 local dependency=$(_ruby_atoms_samelib "$1")
259
260 DEPEND="${DEPEND} $dependency"
261 RDEPEND="${RDEPEND}"
262 }
263
264 # @FUNCTION: ruby_get_use_implementations
265 # @DESCRIPTION:
266 # Gets an array of ruby use targets enabled by the user
267 ruby_get_use_implementations() {
268 local i implementation
269 for implementation in ${USE_RUBY}; do
270 use ruby_targets_${implementation} && i+=" ${implementation}"
271 done
272 echo $i
273 }
274
275 # @FUNCTION: ruby_get_use_targets
276 # @DESCRIPTION:
277 # Gets an array of ruby use targets that the ebuild sets
278 ruby_get_use_targets() {
279 local t implementation
280 for implementation in ${USE_RUBY}; do
281 t+=" ruby_targets_${implementation}"
282 done
283 echo $t
284 }
285
286 # @FUNCTION: ruby_implementations_depend
287 # @RETURN: Dependencies suitable for injection into DEPEND and RDEPEND.
288 # @DESCRIPTION:
289 # Produces the dependency string for the various implementations of ruby
290 # which the package is being built against. This should not be used when
291 # RUBY_OPTIONAL is unset but must be used if RUBY_OPTIONAL=yes. Do not
292 # confuse this function with ruby_implementation_depend().
293 #
294 # @EXAMPLE:
295 # EAPI=4
296 # RUBY_OPTIONAL=yes
297 #
298 # inherit ruby-ng
299 # ...
300 # DEPEND="ruby? ( $(ruby_implementations_depend) )"
301 # RDEPEND="${DEPEND}"
302 ruby_implementations_depend() {
303 local depend
304 for _ruby_implementation in ${USE_RUBY}; do
305 depend="${depend}${depend+ }ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
306 done
307 echo "${depend}"
308 }
309
310 IUSE+=" $(ruby_get_use_targets)"
311 # If you specify RUBY_OPTIONAL you also need to take care of
312 # ruby useflag and dependency.
313 if [[ ${RUBY_OPTIONAL} != yes ]]; then
314 DEPEND="${DEPEND} $(ruby_implementations_depend)"
315 RDEPEND="${RDEPEND} $(ruby_implementations_depend)"
316
317 [[ ${EAPI:-0} -ge 4 ]] && REQUIRED_USE+=" || ( $(ruby_get_use_targets) )"
318 fi
319
320 _ruby_invoke_environment() {
321 old_S=${S}
322 case ${EAPI} in
323 4)
324 if [ -z ${RUBY_S} ]; then
325 sub_S=${P}
326 else
327 sub_S=${RUBY_S}
328 fi
329 ;;
330 *)
331 sub_S=${S#${WORKDIR}/}
332 ;;
333 esac
334
335 # Special case, for the always-lovely GitHub fetches. With this,
336 # we allow the star glob to just expand to whatever directory it's
337 # called.
338 if [[ ${sub_S} = *"*"* ]]; then
339 case ${EAPI} in
340 2|3)
341 #The old method of setting S depends on undefined package
342 # manager behaviour, so encourage upgrading to EAPI=4.
343 eqawarn "Using * expansion of S is deprecated. Use EAPI and RUBY_S instead."
344 ;;
345 esac
346 pushd "${WORKDIR}"/all &>/dev/null
347 sub_S=$(eval ls -d ${sub_S} 2>/dev/null)
348 popd &>/dev/null
349 fi
350
351 environment=$1; shift
352
353 my_WORKDIR="${WORKDIR}"/${environment}
354 S="${my_WORKDIR}"/"${sub_S}"
355
356 if [[ -d "${S}" ]]; then
357 pushd "$S" &>/dev/null
358 elif [[ -d "${my_WORKDIR}" ]]; then
359 pushd "${my_WORKDIR}" &>/dev/null
360 else
361 pushd "${WORKDIR}" &>/dev/null
362 fi
363
364 ebegin "Running ${_PHASE:-${EBUILD_PHASE}} phase for $environment"
365 "$@"
366 popd &>/dev/null
367
368 S=${old_S}
369 }
370
371 _ruby_each_implementation() {
372 local invoked=no
373 for _ruby_implementation in ${USE_RUBY}; do
374 # only proceed if it's requested
375 use ruby_targets_${_ruby_implementation} || continue
376
377 RUBY=$(ruby_implementation_command ${_ruby_implementation})
378 invoked=yes
379
380 if [[ -n "$1" ]]; then
381 _ruby_invoke_environment ${_ruby_implementation} "$@"
382 fi
383
384 unset RUBY
385 done
386
387 [[ ${invoked} == "no" ]] && die "You need to select at least one Ruby implementation by setting RUBY_TARGETS in /etc/make.conf."
388 }
389
390 # @FUNCTION: ruby-ng_pkg_setup
391 # @DESCRIPTION:
392 # Check whether at least one ruby target implementation is present.
393 ruby-ng_pkg_setup() {
394 # This only checks that at least one implementation is present
395 # before doing anything; by leaving the parameters empty we know
396 # it's a special case.
397 _ruby_each_implementation
398
399 has ruby_targets_jruby ${IUSE} && use ruby_targets_jruby && java-pkg_setup-vm
400 }
401
402 # @FUNCTION: ruby-ng_src_unpack
403 # @DESCRIPTION:
404 # Unpack the source archive.
405 ruby-ng_src_unpack() {
406 mkdir "${WORKDIR}"/all
407 pushd "${WORKDIR}"/all &>/dev/null
408
409 # We don't support an each-unpack, it's either all or nothing!
410 if type all_ruby_unpack &>/dev/null; then
411 _ruby_invoke_environment all all_ruby_unpack
412 else
413 [[ -n ${A} ]] && unpack ${A}
414 fi
415
416 popd &>/dev/null
417 }
418
419 _ruby_apply_patches() {
420 for patch in "${RUBY_PATCHES[@]}"; do
421 if [ -f "${patch}" ]; then
422 epatch "${patch}"
423 elif [ -f "${FILESDIR}/${patch}" ]; then
424 epatch "${FILESDIR}/${patch}"
425 else
426 die "Cannot find patch ${patch}"
427 fi
428 done
429
430 # This is a special case: instead of executing just in the special
431 # "all" environment, this will actually copy the effects on _all_
432 # the other environments, and is thus executed before the copy
433 type all_ruby_prepare &>/dev/null && all_ruby_prepare
434 }
435
436 _ruby_source_copy() {
437 # Until we actually find a reason not to, we use hardlinks, this
438 # should reduce the amount of disk space that is wasted by this.
439 cp -prl all ${_ruby_implementation} \
440 || die "Unable to copy ${_ruby_implementation} environment"
441 }
442
443 # @FUNCTION: ruby-ng_src_prepare
444 # @DESCRIPTION:
445 # Apply patches and prepare versions for each ruby target
446 # implementation. Also carry out common clean up tasks.
447 ruby-ng_src_prepare() {
448 # Way too many Ruby packages are prepared on OSX without removing
449 # the extra data forks, we do it here to avoid repeating it for
450 # almost every other ebuild.
451 find . -name '._*' -delete
452
453 _ruby_invoke_environment all _ruby_apply_patches
454
455 _PHASE="source copy" \
456 _ruby_each_implementation _ruby_source_copy
457
458 if type each_ruby_prepare &>/dev/null; then
459 _ruby_each_implementation each_ruby_prepare
460 fi
461 }
462
463 # @FUNCTION: ruby-ng_src_configure
464 # @DESCRIPTION:
465 # Configure the package.
466 ruby-ng_src_configure() {
467 if type each_ruby_configure &>/dev/null; then
468 _ruby_each_implementation each_ruby_configure
469 fi
470
471 type all_ruby_configure &>/dev/null && \
472 _ruby_invoke_environment all all_ruby_configure
473 }
474
475 # @FUNCTION: ruby-ng_src_compile
476 # @DESCRIPTION:
477 # Compile the package.
478 ruby-ng_src_compile() {
479 if type each_ruby_compile &>/dev/null; then
480 _ruby_each_implementation each_ruby_compile
481 fi
482
483 type all_ruby_compile &>/dev/null && \
484 _ruby_invoke_environment all all_ruby_compile
485 }
486
487 # @FUNCTION: ruby-ng_src_test
488 # @DESCRIPTION:
489 # Run tests for the package.
490 ruby-ng_src_test() {
491 if type each_ruby_test &>/dev/null; then
492 _ruby_each_implementation each_ruby_test
493 fi
494
495 type all_ruby_test &>/dev/null && \
496 _ruby_invoke_environment all all_ruby_test
497 }
498
499 _each_ruby_check_install() {
500 local scancmd=scanelf
501 # we have a Mach-O object here
502 [[ ${CHOST} == *-darwin ]] && scancmd=scanmacho
503
504 has "${EAPI}" 2 && ! use prefix && EPREFIX=
505
506 local libruby_basename=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["LIBRUBY_SO"]')
507 local libruby_soname=$(basename $(${scancmd} -F "%S#F" -qS "${EPREFIX}/usr/$(get_libdir)/${libruby_basename}") 2>/dev/null)
508 local sitedir=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["sitedir"]')
509 local sitelibdir=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["sitelibdir"]')
510
511 # Look for wrong files in sitedir
512 # if [[ -d "${D}${sitedir}" ]]; then
513 # local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}")
514 # if [[ -n ${f} ]]; then
515 # eerror "Found files in sitedir, outsite sitelibdir:"
516 # eerror "${f}"
517 # die "Misplaced files in sitedir"
518 # fi
519 # fi
520
521 # The current implementation lacks libruby (i.e.: jruby)
522 [[ -z ${libruby_soname} ]] && return 0
523
524 # Check also the gems directory, since we could be installing compiled
525 # extensions via ruby-fakegem; make sure to check only in sitelibdir, since
526 # that's what changes between two implementations (otherwise you'd get false
527 # positives now that Ruby 1.9.2 installs with the same sitedir as 1.8)
528 ${scancmd} -qnR "${D}${sitelibdir}" "${D}${sitelibdir/site_ruby/gems}" \
529 | fgrep -v "${libruby_soname}" \
530 | grep -E -v "${RUBY_QA_ALLOWED_LIBS}" \
531 > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log
532
533 if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then
534 ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}"
535 ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log )
536 die "Missing links to ${libruby_soname}"
537 fi
538 }
539
540 # @FUNCTION: ruby-ng_src_install
541 # @DESCRIPTION:
542 # Install the package for each ruby target implementation.
543 ruby-ng_src_install() {
544 if type each_ruby_install &>/dev/null; then
545 _ruby_each_implementation each_ruby_install
546 fi
547
548 type all_ruby_install &>/dev/null && \
549 _ruby_invoke_environment all all_ruby_install
550
551 _PHASE="check install" \
552 _ruby_each_implementation _each_ruby_check_install
553 }
554
555 # @FUNCTION: ruby_rbconfig_value
556 # @USAGE: rbconfig item
557 # @RETURN: Returns the value of the given rbconfig item of the Ruby interpreter in ${RUBY}.
558 ruby_rbconfig_value() {
559 echo $(${RUBY} -rrbconfig -e "puts RbConfig::CONFIG['$1']")
560 }
561
562 # @FUNCTION: doruby
563 # @USAGE: file [file...]
564 # @DESCRIPTION:
565 # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}.
566 doruby() {
567 [[ -z ${RUBY} ]] && die "\$RUBY is not set"
568 has "${EAPI}" 2 && ! use prefix && EPREFIX=
569 ( # don't want to pollute calling env
570 sitelibdir=$(ruby_rbconfig_value 'sitelibdir')
571 insinto ${sitelibdir#${EPREFIX}}
572 insopts -m 0644
573 doins "$@"
574 ) || die "failed to install $@"
575 }
576
577 # @FUNCTION: ruby_get_libruby
578 # @RETURN: The location of libruby*.so belonging to the Ruby interpreter in ${RUBY}.
579 ruby_get_libruby() {
580 ${RUBY} -rrbconfig -e 'puts File.join(RbConfig::CONFIG["libdir"], RbConfig::CONFIG["LIBRUBY"])'
581 }
582
583 # @FUNCTION: ruby_get_hdrdir
584 # @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}.
585 ruby_get_hdrdir() {
586 local rubyhdrdir=$(ruby_rbconfig_value 'rubyhdrdir')
587
588 if [[ "${rubyhdrdir}" = "nil" ]] ; then
589 rubyhdrdir=$(ruby_rbconfig_value 'archdir')
590 fi
591
592 echo "${rubyhdrdir}"
593 }
594
595 # @FUNCTION: ruby_get_version
596 # @RETURN: The version of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
597 ruby_get_version() {
598 local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
599
600 echo $(${ruby} -e 'puts RUBY_VERSION')
601 }
602
603 # @FUNCTION: ruby_get_implementation
604 # @RETURN: The implementation of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
605 ruby_get_implementation() {
606 local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
607
608 case $(${ruby} --version) in
609 *Enterprise*)
610 echo "ree"
611 ;;
612 *jruby*)
613 echo "jruby"
614 ;;
615 *rubinius*)
616 echo "rbx"
617 ;;
618 *)
619 echo "mri"
620 ;;
621 esac
622 }

  ViewVC Help
Powered by ViewVC 1.1.20