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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.45 - (show annotations) (download)
Thu Feb 23 23:06:13 2012 UTC (2 years, 1 month ago) by a3li
Branch: MAIN
Changes since 1.44: +10 -3 lines
ruby-ng.eclass: Improve no-matching-ruby-target-error message wording wrt bug 405373.

1 # Copyright 1999-2012 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.44 2011/12/18 21:33:50 flameeyes 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 if [[ ${invoked} == "no" ]]; then
388 eerror "You need to select at least one compatible Ruby installation target via RUBY_TARGETS in make.conf."
389 eerror "Compatible targets for this package are: ${USE_RUBY}"
390 eerror
391 eerror "See http://www.gentoo.org/proj/en/prog_lang/ruby/index.xml#doc_chap3 for more information."
392 eerror
393 die "No compatible Ruby target selected."
394 fi
395 }
396
397 # @FUNCTION: ruby-ng_pkg_setup
398 # @DESCRIPTION:
399 # Check whether at least one ruby target implementation is present.
400 ruby-ng_pkg_setup() {
401 # This only checks that at least one implementation is present
402 # before doing anything; by leaving the parameters empty we know
403 # it's a special case.
404 _ruby_each_implementation
405
406 has ruby_targets_jruby ${IUSE} && use ruby_targets_jruby && java-pkg_setup-vm
407 }
408
409 # @FUNCTION: ruby-ng_src_unpack
410 # @DESCRIPTION:
411 # Unpack the source archive.
412 ruby-ng_src_unpack() {
413 mkdir "${WORKDIR}"/all
414 pushd "${WORKDIR}"/all &>/dev/null
415
416 # We don't support an each-unpack, it's either all or nothing!
417 if type all_ruby_unpack &>/dev/null; then
418 _ruby_invoke_environment all all_ruby_unpack
419 else
420 [[ -n ${A} ]] && unpack ${A}
421 fi
422
423 popd &>/dev/null
424 }
425
426 _ruby_apply_patches() {
427 for patch in "${RUBY_PATCHES[@]}"; do
428 if [ -f "${patch}" ]; then
429 epatch "${patch}"
430 elif [ -f "${FILESDIR}/${patch}" ]; then
431 epatch "${FILESDIR}/${patch}"
432 else
433 die "Cannot find patch ${patch}"
434 fi
435 done
436
437 # This is a special case: instead of executing just in the special
438 # "all" environment, this will actually copy the effects on _all_
439 # the other environments, and is thus executed before the copy
440 type all_ruby_prepare &>/dev/null && all_ruby_prepare
441 }
442
443 _ruby_source_copy() {
444 # Until we actually find a reason not to, we use hardlinks, this
445 # should reduce the amount of disk space that is wasted by this.
446 cp -prl all ${_ruby_implementation} \
447 || die "Unable to copy ${_ruby_implementation} environment"
448 }
449
450 # @FUNCTION: ruby-ng_src_prepare
451 # @DESCRIPTION:
452 # Apply patches and prepare versions for each ruby target
453 # implementation. Also carry out common clean up tasks.
454 ruby-ng_src_prepare() {
455 # Way too many Ruby packages are prepared on OSX without removing
456 # the extra data forks, we do it here to avoid repeating it for
457 # almost every other ebuild.
458 find . -name '._*' -delete
459
460 _ruby_invoke_environment all _ruby_apply_patches
461
462 _PHASE="source copy" \
463 _ruby_each_implementation _ruby_source_copy
464
465 if type each_ruby_prepare &>/dev/null; then
466 _ruby_each_implementation each_ruby_prepare
467 fi
468 }
469
470 # @FUNCTION: ruby-ng_src_configure
471 # @DESCRIPTION:
472 # Configure the package.
473 ruby-ng_src_configure() {
474 if type each_ruby_configure &>/dev/null; then
475 _ruby_each_implementation each_ruby_configure
476 fi
477
478 type all_ruby_configure &>/dev/null && \
479 _ruby_invoke_environment all all_ruby_configure
480 }
481
482 # @FUNCTION: ruby-ng_src_compile
483 # @DESCRIPTION:
484 # Compile the package.
485 ruby-ng_src_compile() {
486 if type each_ruby_compile &>/dev/null; then
487 _ruby_each_implementation each_ruby_compile
488 fi
489
490 type all_ruby_compile &>/dev/null && \
491 _ruby_invoke_environment all all_ruby_compile
492 }
493
494 # @FUNCTION: ruby-ng_src_test
495 # @DESCRIPTION:
496 # Run tests for the package.
497 ruby-ng_src_test() {
498 if type each_ruby_test &>/dev/null; then
499 _ruby_each_implementation each_ruby_test
500 fi
501
502 type all_ruby_test &>/dev/null && \
503 _ruby_invoke_environment all all_ruby_test
504 }
505
506 _each_ruby_check_install() {
507 local scancmd=scanelf
508 # we have a Mach-O object here
509 [[ ${CHOST} == *-darwin ]] && scancmd=scanmacho
510
511 has "${EAPI}" 2 && ! use prefix && EPREFIX=
512
513 local libruby_basename=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["LIBRUBY_SO"]')
514 local libruby_soname=$(basename $(${scancmd} -F "%S#F" -qS "${EPREFIX}/usr/$(get_libdir)/${libruby_basename}") 2>/dev/null)
515 local sitedir=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["sitedir"]')
516 local sitelibdir=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["sitelibdir"]')
517
518 # Look for wrong files in sitedir
519 # if [[ -d "${D}${sitedir}" ]]; then
520 # local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}")
521 # if [[ -n ${f} ]]; then
522 # eerror "Found files in sitedir, outsite sitelibdir:"
523 # eerror "${f}"
524 # die "Misplaced files in sitedir"
525 # fi
526 # fi
527
528 # The current implementation lacks libruby (i.e.: jruby)
529 [[ -z ${libruby_soname} ]] && return 0
530
531 # Check also the gems directory, since we could be installing compiled
532 # extensions via ruby-fakegem; make sure to check only in sitelibdir, since
533 # that's what changes between two implementations (otherwise you'd get false
534 # positives now that Ruby 1.9.2 installs with the same sitedir as 1.8)
535 ${scancmd} -qnR "${D}${sitelibdir}" "${D}${sitelibdir/site_ruby/gems}" \
536 | fgrep -v "${libruby_soname}" \
537 | grep -E -v "${RUBY_QA_ALLOWED_LIBS}" \
538 > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log
539
540 if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then
541 ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}"
542 ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log )
543 die "Missing links to ${libruby_soname}"
544 fi
545 }
546
547 # @FUNCTION: ruby-ng_src_install
548 # @DESCRIPTION:
549 # Install the package for each ruby target implementation.
550 ruby-ng_src_install() {
551 if type each_ruby_install &>/dev/null; then
552 _ruby_each_implementation each_ruby_install
553 fi
554
555 type all_ruby_install &>/dev/null && \
556 _ruby_invoke_environment all all_ruby_install
557
558 _PHASE="check install" \
559 _ruby_each_implementation _each_ruby_check_install
560 }
561
562 # @FUNCTION: ruby_rbconfig_value
563 # @USAGE: rbconfig item
564 # @RETURN: Returns the value of the given rbconfig item of the Ruby interpreter in ${RUBY}.
565 ruby_rbconfig_value() {
566 echo $(${RUBY} -rrbconfig -e "puts RbConfig::CONFIG['$1']")
567 }
568
569 # @FUNCTION: doruby
570 # @USAGE: file [file...]
571 # @DESCRIPTION:
572 # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}.
573 doruby() {
574 [[ -z ${RUBY} ]] && die "\$RUBY is not set"
575 has "${EAPI}" 2 && ! use prefix && EPREFIX=
576 ( # don't want to pollute calling env
577 sitelibdir=$(ruby_rbconfig_value 'sitelibdir')
578 insinto ${sitelibdir#${EPREFIX}}
579 insopts -m 0644
580 doins "$@"
581 ) || die "failed to install $@"
582 }
583
584 # @FUNCTION: ruby_get_libruby
585 # @RETURN: The location of libruby*.so belonging to the Ruby interpreter in ${RUBY}.
586 ruby_get_libruby() {
587 ${RUBY} -rrbconfig -e 'puts File.join(RbConfig::CONFIG["libdir"], RbConfig::CONFIG["LIBRUBY"])'
588 }
589
590 # @FUNCTION: ruby_get_hdrdir
591 # @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}.
592 ruby_get_hdrdir() {
593 local rubyhdrdir=$(ruby_rbconfig_value 'rubyhdrdir')
594
595 if [[ "${rubyhdrdir}" = "nil" ]] ; then
596 rubyhdrdir=$(ruby_rbconfig_value 'archdir')
597 fi
598
599 echo "${rubyhdrdir}"
600 }
601
602 # @FUNCTION: ruby_get_version
603 # @RETURN: The version of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
604 ruby_get_version() {
605 local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
606
607 echo $(${ruby} -e 'puts RUBY_VERSION')
608 }
609
610 # @FUNCTION: ruby_get_implementation
611 # @RETURN: The implementation of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
612 ruby_get_implementation() {
613 local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
614
615 case $(${ruby} --version) in
616 *Enterprise*)
617 echo "ree"
618 ;;
619 *jruby*)
620 echo "jruby"
621 ;;
622 *rubinius*)
623 echo "rbx"
624 ;;
625 *)
626 echo "mri"
627 ;;
628 esac
629 }

  ViewVC Help
Powered by ViewVC 1.1.20