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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.56 - (hide annotations) (download)
Sun Dec 28 07:23:56 2014 UTC (2 months ago) by graaff
Branch: MAIN
CVS Tags: HEAD
Changes since 1.55: +16 -3 lines
Use rspec-2 wrapper for the rspec recipe.

1 graaff 1.54 # Copyright 1999-2014 Gentoo Foundation
2 graaff 1.1 # Distributed under the terms of the GNU General Public License v2
3 graaff 1.56 # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-ng.eclass,v 1.55 2014/12/27 20:04:21 graaff Exp $
4 vapier 1.39
5 graaff 1.1 # @ECLASS: ruby-ng.eclass
6     # @MAINTAINER:
7     # Ruby herd <ruby@gentoo.org>
8 vapier 1.39 # @AUTHOR:
9 graaff 1.1 # 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 graaff 1.52 # * ruby20 - Ruby (MRI) 2.0.x
21 graaff 1.53 # * ruby21 - Ruby (MRI) 2.1.x
22 graaff 1.55 # * ruby22 - Ruby (MRI) 2.2.x
23 graaff 1.1 # * ree18 - Ruby Enterprise Edition 1.8.x
24     # * jruby - JRuby
25 graaff 1.41 # * rbx - Rubinius
26 graaff 1.1 #
27     # This eclass does not define the implementation of the configure,
28     # compile, test, or install phases. Instead, the default phases are
29     # used. Specific implementations of these phases can be provided in
30     # the ebuild either to be run for each Ruby implementation, or for all
31     # Ruby implementations, as follows:
32     #
33     # * each_ruby_configure
34     # * all_ruby_configure
35    
36     # @ECLASS-VARIABLE: USE_RUBY
37 graaff 1.26 # @REQUIRED
38 graaff 1.1 # @DESCRIPTION:
39     # This variable contains a space separated list of targets (see above) a package
40     # is compatible to. It must be set before the `inherit' call. There is no
41     # default. All ebuilds are expected to set this variable.
42    
43     # @ECLASS-VARIABLE: RUBY_PATCHES
44 graaff 1.26 # @DEFAULT_UNSET
45 graaff 1.1 # @DESCRIPTION:
46     # A String or Array of filenames of patches to apply to all implementations.
47    
48     # @ECLASS-VARIABLE: RUBY_OPTIONAL
49     # @DESCRIPTION:
50 graaff 1.38 # Set the value to "yes" to make the dependency on a Ruby interpreter
51     # optional and then ruby_implementations_depend() to help populate
52     # DEPEND and RDEPEND.
53 graaff 1.1
54 graaff 1.31 # @ECLASS-VARIABLE: RUBY_S
55     # @DEFAULT_UNSET
56     # @DESCRIPTION:
57     # If defined this variable determines the source directory name after
58     # unpacking. This defaults to the name of the package. Note that this
59     # variable supports a wildcard mechanism to help with github tarballs
60     # that contain the commit hash as part of the directory name.
61    
62 graaff 1.34 # @ECLASS-VARIABLE: RUBY_QA_ALLOWED_LIBS
63     # @DEFAULT_UNSET
64     # @DESCRIPTION:
65     # If defined this variable contains a whitelist of shared objects that
66     # are allowed to exist even if they don't link to libruby. This avoids
67     # the QA check that makes this mandatory. This is most likely not what
68     # you are looking for if you get the related "Missing links" QA warning,
69     # since the proper fix is almost always to make sure the shared object
70     # is linked against libruby. There are cases were this is not the case
71     # and the shared object is generic code to be used in some other way
72     # (e.g. selenium's firefox driver extension). When set this argument is
73     # passed to "grep -E" to remove reporting of these shared objects.
74    
75 zmedico 1.46 inherit eutils java-utils-2 multilib toolchain-funcs
76 graaff 1.1
77     EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_setup
78    
79     case ${EAPI} in
80     0|1)
81     die "Unsupported EAPI=${EAPI} (too old) for ruby-ng.eclass" ;;
82 flameeyes 1.24 2|3) ;;
83 axs 1.51 4|5)
84 graaff 1.31 # S is no longer automatically assigned when it doesn't exist.
85     S="${WORKDIR}"
86     ;;
87 graaff 1.1 *)
88     die "Unknown EAPI=${EAPI} for ruby-ng.eclass"
89     esac
90    
91     # @FUNCTION: ruby_implementation_depend
92     # @USAGE: target [comparator [version]]
93     # @RETURN: Package atom of a Ruby implementation to be used in dependencies.
94     # @DESCRIPTION:
95     # This function returns the formal package atom for a Ruby implementation.
96     #
97     # `target' has to be one of the valid values for USE_RUBY (see above)
98     #
99     # Set `comparator' and `version' to include a comparator (=, >=, etc.) and a
100     # version string to the returned string
101     ruby_implementation_depend() {
102     local rubypn=
103     local rubyslot=
104    
105     case $1 in
106     ruby18)
107     rubypn="dev-lang/ruby"
108     rubyslot=":1.8"
109     ;;
110     ruby19)
111     rubypn="dev-lang/ruby"
112     rubyslot=":1.9"
113     ;;
114 graaff 1.52 ruby20)
115     rubypn="dev-lang/ruby"
116     rubyslot=":2.0"
117     ;;
118 graaff 1.53 ruby21)
119     rubypn="dev-lang/ruby"
120     rubyslot=":2.1"
121     ;;
122 graaff 1.55 ruby22)
123     rubypn="dev-lang/ruby"
124     rubyslot=":2.2"
125     ;;
126 graaff 1.1 ree18)
127     rubypn="dev-lang/ruby-enterprise"
128     rubyslot=":1.8"
129     ;;
130     jruby)
131     rubypn="dev-java/jruby"
132     rubyslot=""
133     ;;
134 graaff 1.41 rbx)
135     rubypn="dev-lang/rubinius"
136     rubyslot=""
137     ;;
138 graaff 1.1 *) die "$1: unknown Ruby implementation"
139     esac
140    
141     echo "$2${rubypn}$3${rubyslot}"
142     }
143    
144     # @FUNCTION: ruby_samelib
145     # @RETURN: use flag string with current ruby implementations
146     # @DESCRIPTION:
147     # Convenience function to output the use dependency part of a
148     # dependency. Used as a building block for ruby_add_rdepend() and
149     # ruby_add_bdepend(), but may also be useful in an ebuild to specify
150     # more complex dependencies.
151     ruby_samelib() {
152     local res=
153     for _ruby_implementation in $USE_RUBY; do
154     has -${_ruby_implementation} $@ || \
155     res="${res}ruby_targets_${_ruby_implementation}?,"
156     done
157    
158     echo "[${res%,}]"
159     }
160    
161 flameeyes 1.17 _ruby_atoms_samelib_generic() {
162 flameeyes 1.18 eshopts_push -o noglob
163 flameeyes 1.17 echo "RUBYTARGET? ("
164 flameeyes 1.14 for token in $*; do
165     case "$token" in
166 flameeyes 1.16 "||" | "(" | ")" | *"?")
167 flameeyes 1.14 echo "${token}" ;;
168 flameeyes 1.21 *])
169     echo "${token%[*}[RUBYTARGET,${token/*[}" ;;
170 flameeyes 1.14 *)
171 flameeyes 1.17 echo "${token}[RUBYTARGET]" ;;
172 flameeyes 1.14 esac
173     done
174 flameeyes 1.17 echo ")"
175 flameeyes 1.18 eshopts_pop
176 flameeyes 1.17 }
177    
178 flameeyes 1.27 # @FUNCTION: ruby_implementation_command
179     # @RETURN: the path to the given ruby implementation
180     # @DESCRIPTION:
181     # Not all implementations have the same command basename as the
182     # target; namely Ruby Enterprise 1.8 uses ree18 and rubyee18
183     # respectively. This function translate between the two
184     ruby_implementation_command() {
185     local _ruby_name=$1
186    
187     # Add all USE_RUBY values where the flag name diverts from the binary here
188     case $1 in
189     ree18)
190     _ruby_name=rubyee18
191     ;;
192     esac
193    
194     echo $(type -p ${_ruby_name} 2>/dev/null)
195     }
196    
197 flameeyes 1.17 _ruby_atoms_samelib() {
198     local atoms=$(_ruby_atoms_samelib_generic "$*")
199    
200     for _ruby_implementation in $USE_RUBY; do
201     echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}"
202     done
203 flameeyes 1.14 }
204    
205 flameeyes 1.16 _ruby_wrap_conditions() {
206     local conditions="$1"
207     local atoms="$2"
208    
209     for condition in $conditions; do
210     atoms="${condition}? ( ${atoms} )"
211     done
212    
213     echo "$atoms"
214     }
215    
216 graaff 1.1 # @FUNCTION: ruby_add_rdepend
217 flameeyes 1.16 # @USAGE: dependencies
218 graaff 1.1 # @DESCRIPTION:
219 flameeyes 1.16 # Adds the specified dependencies, with use condition(s) to RDEPEND,
220     # taking the current set of ruby targets into account. This makes sure
221     # that all ruby dependencies of the package are installed for the same
222     # ruby targets. Use this function for all ruby dependencies instead of
223     # setting RDEPEND yourself. The list of atoms uses the same syntax as
224     # normal dependencies.
225     #
226     # Note: runtime dependencies are also added as build-time test
227     # dependencies.
228 graaff 1.1 ruby_add_rdepend() {
229     case $# in
230 flameeyes 1.16 1) ;;
231 graaff 1.1 2)
232 flameeyes 1.16 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_rdepend for $CATEGORY/$PF"
233     ruby_add_rdepend "$(_ruby_wrap_conditions "$1" "$2")"
234     return
235 graaff 1.1 ;;
236     *)
237     die "bad number of arguments to $0"
238     ;;
239     esac
240    
241 flameeyes 1.16 local dependency=$(_ruby_atoms_samelib "$1")
242    
243     RDEPEND="${RDEPEND} $dependency"
244    
245     # Add the dependency as a test-dependency since we're going to
246     # execute the code during test phase.
247 flameeyes 1.20 DEPEND="${DEPEND} test? ( ${dependency} )"
248 ssuominen 1.33 has test "$IUSE" || IUSE="${IUSE} test"
249 graaff 1.1 }
250    
251     # @FUNCTION: ruby_add_bdepend
252 flameeyes 1.16 # @USAGE: dependencies
253 graaff 1.1 # @DESCRIPTION:
254 flameeyes 1.16 # Adds the specified dependencies, with use condition(s) to DEPEND,
255     # taking the current set of ruby targets into account. This makes sure
256     # that all ruby dependencies of the package are installed for the same
257     # ruby targets. Use this function for all ruby dependencies instead of
258     # setting DEPEND yourself. The list of atoms uses the same syntax as
259     # normal dependencies.
260 graaff 1.1 ruby_add_bdepend() {
261     case $# in
262 flameeyes 1.16 1) ;;
263 graaff 1.1 2)
264 flameeyes 1.16 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_bdepend for $CATEGORY/$PF"
265     ruby_add_bdepend "$(_ruby_wrap_conditions "$1" "$2")"
266     return
267 graaff 1.1 ;;
268     *)
269     die "bad number of arguments to $0"
270     ;;
271     esac
272    
273 flameeyes 1.16 local dependency=$(_ruby_atoms_samelib "$1")
274    
275     DEPEND="${DEPEND} $dependency"
276 flameeyes 1.19 RDEPEND="${RDEPEND}"
277 graaff 1.1 }
278    
279 graaff 1.37 # @FUNCTION: ruby_get_use_implementations
280     # @DESCRIPTION:
281     # Gets an array of ruby use targets enabled by the user
282     ruby_get_use_implementations() {
283     local i implementation
284     for implementation in ${USE_RUBY}; do
285     use ruby_targets_${implementation} && i+=" ${implementation}"
286     done
287     echo $i
288     }
289    
290 graaff 1.36 # @FUNCTION: ruby_get_use_targets
291     # @DESCRIPTION:
292     # Gets an array of ruby use targets that the ebuild sets
293     ruby_get_use_targets() {
294     local t implementation
295     for implementation in ${USE_RUBY}; do
296     t+=" ruby_targets_${implementation}"
297     done
298     echo $t
299     }
300    
301 graaff 1.38 # @FUNCTION: ruby_implementations_depend
302     # @RETURN: Dependencies suitable for injection into DEPEND and RDEPEND.
303     # @DESCRIPTION:
304     # Produces the dependency string for the various implementations of ruby
305     # which the package is being built against. This should not be used when
306     # RUBY_OPTIONAL is unset but must be used if RUBY_OPTIONAL=yes. Do not
307     # confuse this function with ruby_implementation_depend().
308     #
309     # @EXAMPLE:
310     # EAPI=4
311     # RUBY_OPTIONAL=yes
312     #
313     # inherit ruby-ng
314     # ...
315     # DEPEND="ruby? ( $(ruby_implementations_depend) )"
316     # RDEPEND="${DEPEND}"
317     ruby_implementations_depend() {
318     local depend
319     for _ruby_implementation in ${USE_RUBY}; do
320     depend="${depend}${depend+ }ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
321     done
322     echo "${depend}"
323     }
324    
325 flameeyes 1.44 IUSE+=" $(ruby_get_use_targets)"
326 graaff 1.38 # If you specify RUBY_OPTIONAL you also need to take care of
327     # ruby useflag and dependency.
328     if [[ ${RUBY_OPTIONAL} != yes ]]; then
329     DEPEND="${DEPEND} $(ruby_implementations_depend)"
330     RDEPEND="${RDEPEND} $(ruby_implementations_depend)"
331 flameeyes 1.44
332 axs 1.51 case ${EAPI:-0} in
333     4|5)
334     REQUIRED_USE+=" || ( $(ruby_get_use_targets) )"
335     ;;
336     esac
337 graaff 1.38 fi
338 graaff 1.1
339     _ruby_invoke_environment() {
340     old_S=${S}
341 graaff 1.31 case ${EAPI} in
342 axs 1.51 4|5)
343 graaff 1.32 if [ -z ${RUBY_S} ]; then
344     sub_S=${P}
345     else
346     sub_S=${RUBY_S}
347     fi
348 graaff 1.31 ;;
349     *)
350     sub_S=${S#${WORKDIR}/}
351     ;;
352     esac
353 flameeyes 1.12
354     # Special case, for the always-lovely GitHub fetches. With this,
355     # we allow the star glob to just expand to whatever directory it's
356     # called.
357 flameeyes 1.28 if [[ ${sub_S} = *"*"* ]]; then
358 graaff 1.35 case ${EAPI} in
359     2|3)
360     #The old method of setting S depends on undefined package
361     # manager behaviour, so encourage upgrading to EAPI=4.
362     eqawarn "Using * expansion of S is deprecated. Use EAPI and RUBY_S instead."
363     ;;
364     esac
365 flameeyes 1.12 pushd "${WORKDIR}"/all &>/dev/null
366 flameeyes 1.13 sub_S=$(eval ls -d ${sub_S} 2>/dev/null)
367 flameeyes 1.12 popd &>/dev/null
368     fi
369 graaff 1.1
370     environment=$1; shift
371    
372     my_WORKDIR="${WORKDIR}"/${environment}
373     S="${my_WORKDIR}"/"${sub_S}"
374    
375     if [[ -d "${S}" ]]; then
376     pushd "$S" &>/dev/null
377     elif [[ -d "${my_WORKDIR}" ]]; then
378     pushd "${my_WORKDIR}" &>/dev/null
379     else
380     pushd "${WORKDIR}" &>/dev/null
381     fi
382    
383     ebegin "Running ${_PHASE:-${EBUILD_PHASE}} phase for $environment"
384     "$@"
385     popd &>/dev/null
386    
387     S=${old_S}
388     }
389    
390     _ruby_each_implementation() {
391     local invoked=no
392     for _ruby_implementation in ${USE_RUBY}; do
393     # only proceed if it's requested
394     use ruby_targets_${_ruby_implementation} || continue
395    
396 flameeyes 1.27 RUBY=$(ruby_implementation_command ${_ruby_implementation})
397 graaff 1.1 invoked=yes
398    
399     if [[ -n "$1" ]]; then
400 flameeyes 1.27 _ruby_invoke_environment ${_ruby_implementation} "$@"
401 graaff 1.1 fi
402    
403     unset RUBY
404     done
405    
406 a3li 1.45 if [[ ${invoked} == "no" ]]; then
407     eerror "You need to select at least one compatible Ruby installation target via RUBY_TARGETS in make.conf."
408     eerror "Compatible targets for this package are: ${USE_RUBY}"
409     eerror
410     eerror "See http://www.gentoo.org/proj/en/prog_lang/ruby/index.xml#doc_chap3 for more information."
411     eerror
412     die "No compatible Ruby target selected."
413     fi
414 graaff 1.1 }
415    
416     # @FUNCTION: ruby-ng_pkg_setup
417     # @DESCRIPTION:
418     # Check whether at least one ruby target implementation is present.
419     ruby-ng_pkg_setup() {
420     # This only checks that at least one implementation is present
421     # before doing anything; by leaving the parameters empty we know
422     # it's a special case.
423     _ruby_each_implementation
424 graaff 1.40
425 scarabeus 1.42 has ruby_targets_jruby ${IUSE} && use ruby_targets_jruby && java-pkg_setup-vm
426 graaff 1.1 }
427    
428     # @FUNCTION: ruby-ng_src_unpack
429     # @DESCRIPTION:
430 graaff 1.5 # Unpack the source archive.
431 graaff 1.1 ruby-ng_src_unpack() {
432     mkdir "${WORKDIR}"/all
433     pushd "${WORKDIR}"/all &>/dev/null
434    
435     # We don't support an each-unpack, it's either all or nothing!
436     if type all_ruby_unpack &>/dev/null; then
437     _ruby_invoke_environment all all_ruby_unpack
438     else
439     [[ -n ${A} ]] && unpack ${A}
440     fi
441    
442     popd &>/dev/null
443     }
444    
445     _ruby_apply_patches() {
446     for patch in "${RUBY_PATCHES[@]}"; do
447     if [ -f "${patch}" ]; then
448     epatch "${patch}"
449     elif [ -f "${FILESDIR}/${patch}" ]; then
450     epatch "${FILESDIR}/${patch}"
451     else
452     die "Cannot find patch ${patch}"
453     fi
454     done
455    
456     # This is a special case: instead of executing just in the special
457     # "all" environment, this will actually copy the effects on _all_
458     # the other environments, and is thus executed before the copy
459     type all_ruby_prepare &>/dev/null && all_ruby_prepare
460     }
461    
462     _ruby_source_copy() {
463     # Until we actually find a reason not to, we use hardlinks, this
464     # should reduce the amount of disk space that is wasted by this.
465 graaff 1.54 cp -prlP all ${_ruby_implementation} \
466 graaff 1.1 || die "Unable to copy ${_ruby_implementation} environment"
467     }
468    
469     # @FUNCTION: ruby-ng_src_prepare
470     # @DESCRIPTION:
471     # Apply patches and prepare versions for each ruby target
472     # implementation. Also carry out common clean up tasks.
473     ruby-ng_src_prepare() {
474     # Way too many Ruby packages are prepared on OSX without removing
475     # the extra data forks, we do it here to avoid repeating it for
476     # almost every other ebuild.
477     find . -name '._*' -delete
478    
479     _ruby_invoke_environment all _ruby_apply_patches
480    
481 flameeyes 1.7 _PHASE="source copy" \
482     _ruby_each_implementation _ruby_source_copy
483 graaff 1.1
484     if type each_ruby_prepare &>/dev/null; then
485     _ruby_each_implementation each_ruby_prepare
486     fi
487     }
488    
489     # @FUNCTION: ruby-ng_src_configure
490     # @DESCRIPTION:
491     # Configure the package.
492     ruby-ng_src_configure() {
493     if type each_ruby_configure &>/dev/null; then
494     _ruby_each_implementation each_ruby_configure
495     fi
496    
497     type all_ruby_configure &>/dev/null && \
498     _ruby_invoke_environment all all_ruby_configure
499     }
500    
501     # @FUNCTION: ruby-ng_src_compile
502     # @DESCRIPTION:
503     # Compile the package.
504     ruby-ng_src_compile() {
505     if type each_ruby_compile &>/dev/null; then
506     _ruby_each_implementation each_ruby_compile
507     fi
508    
509     type all_ruby_compile &>/dev/null && \
510     _ruby_invoke_environment all all_ruby_compile
511     }
512    
513     # @FUNCTION: ruby-ng_src_test
514     # @DESCRIPTION:
515     # Run tests for the package.
516     ruby-ng_src_test() {
517     if type each_ruby_test &>/dev/null; then
518     _ruby_each_implementation each_ruby_test
519     fi
520    
521     type all_ruby_test &>/dev/null && \
522     _ruby_invoke_environment all all_ruby_test
523     }
524    
525     _each_ruby_check_install() {
526 flameeyes 1.24 local scancmd=scanelf
527     # we have a Mach-O object here
528     [[ ${CHOST} == *-darwin ]] && scancmd=scanmacho
529    
530     has "${EAPI}" 2 && ! use prefix && EPREFIX=
531    
532 graaff 1.43 local libruby_basename=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["LIBRUBY_SO"]')
533 flameeyes 1.25 local libruby_soname=$(basename $(${scancmd} -F "%S#F" -qS "${EPREFIX}/usr/$(get_libdir)/${libruby_basename}") 2>/dev/null)
534 graaff 1.43 local sitedir=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["sitedir"]')
535     local sitelibdir=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["sitelibdir"]')
536 flameeyes 1.2
537     # Look for wrong files in sitedir
538 flameeyes 1.22 # if [[ -d "${D}${sitedir}" ]]; then
539     # local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}")
540     # if [[ -n ${f} ]]; then
541     # eerror "Found files in sitedir, outsite sitelibdir:"
542     # eerror "${f}"
543     # die "Misplaced files in sitedir"
544     # fi
545     # fi
546 graaff 1.1
547     # The current implementation lacks libruby (i.e.: jruby)
548     [[ -z ${libruby_soname} ]] && return 0
549    
550 flameeyes 1.23 # Check also the gems directory, since we could be installing compiled
551     # extensions via ruby-fakegem; make sure to check only in sitelibdir, since
552     # that's what changes between two implementations (otherwise you'd get false
553     # positives now that Ruby 1.9.2 installs with the same sitedir as 1.8)
554 flameeyes 1.24 ${scancmd} -qnR "${D}${sitelibdir}" "${D}${sitelibdir/site_ruby/gems}" \
555 graaff 1.1 | fgrep -v "${libruby_soname}" \
556 graaff 1.34 | grep -E -v "${RUBY_QA_ALLOWED_LIBS}" \
557 graaff 1.1 > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log
558    
559     if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then
560 flameeyes 1.15 ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}"
561 graaff 1.1 ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log )
562 flameeyes 1.15 die "Missing links to ${libruby_soname}"
563 graaff 1.1 fi
564     }
565    
566     # @FUNCTION: ruby-ng_src_install
567     # @DESCRIPTION:
568     # Install the package for each ruby target implementation.
569     ruby-ng_src_install() {
570     if type each_ruby_install &>/dev/null; then
571     _ruby_each_implementation each_ruby_install
572     fi
573    
574     type all_ruby_install &>/dev/null && \
575     _ruby_invoke_environment all all_ruby_install
576    
577     _PHASE="check install" \
578     _ruby_each_implementation _each_ruby_check_install
579     }
580    
581 a3li 1.11 # @FUNCTION: ruby_rbconfig_value
582     # @USAGE: rbconfig item
583     # @RETURN: Returns the value of the given rbconfig item of the Ruby interpreter in ${RUBY}.
584     ruby_rbconfig_value() {
585 graaff 1.43 echo $(${RUBY} -rrbconfig -e "puts RbConfig::CONFIG['$1']")
586 a3li 1.11 }
587    
588 graaff 1.1 # @FUNCTION: doruby
589     # @USAGE: file [file...]
590     # @DESCRIPTION:
591     # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}.
592     doruby() {
593 flameeyes 1.4 [[ -z ${RUBY} ]] && die "\$RUBY is not set"
594 flameeyes 1.24 has "${EAPI}" 2 && ! use prefix && EPREFIX=
595 graaff 1.1 ( # don't want to pollute calling env
596 flameeyes 1.24 sitelibdir=$(ruby_rbconfig_value 'sitelibdir')
597     insinto ${sitelibdir#${EPREFIX}}
598 graaff 1.1 insopts -m 0644
599     doins "$@"
600     ) || die "failed to install $@"
601     }
602    
603     # @FUNCTION: ruby_get_libruby
604     # @RETURN: The location of libruby*.so belonging to the Ruby interpreter in ${RUBY}.
605     ruby_get_libruby() {
606 graaff 1.43 ${RUBY} -rrbconfig -e 'puts File.join(RbConfig::CONFIG["libdir"], RbConfig::CONFIG["LIBRUBY"])'
607 graaff 1.1 }
608    
609     # @FUNCTION: ruby_get_hdrdir
610     # @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}.
611     ruby_get_hdrdir() {
612 a3li 1.11 local rubyhdrdir=$(ruby_rbconfig_value 'rubyhdrdir')
613 graaff 1.1
614     if [[ "${rubyhdrdir}" = "nil" ]] ; then
615 a3li 1.11 rubyhdrdir=$(ruby_rbconfig_value 'archdir')
616 graaff 1.1 fi
617    
618     echo "${rubyhdrdir}"
619     }
620 a3li 1.10
621     # @FUNCTION: ruby_get_version
622     # @RETURN: The version of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
623     ruby_get_version() {
624     local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
625    
626     echo $(${ruby} -e 'puts RUBY_VERSION')
627     }
628    
629     # @FUNCTION: ruby_get_implementation
630     # @RETURN: The implementation of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
631     ruby_get_implementation() {
632     local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
633    
634     case $(${ruby} --version) in
635     *Enterprise*)
636     echo "ree"
637     ;;
638     *jruby*)
639     echo "jruby"
640     ;;
641 graaff 1.41 *rubinius*)
642     echo "rbx"
643     ;;
644 a3li 1.10 *)
645     echo "mri"
646     ;;
647     esac
648     }
649 flameeyes 1.47
650 graaff 1.56 # @FUNCTION: ruby-ng_rspec <arguments>
651 flameeyes 1.47 # @DESCRIPTION:
652     # This is simply a wrapper around the rspec command (executed by $RUBY})
653     # which also respects TEST_VERBOSE and NOCOLOR environment variables.
654 graaff 1.56 # Optionally takes arguments to pass on to the rspec invocation. The
655     # environment variable RSPEC_VERSION can be used to control the specific
656     # rspec version that must be executed. It defaults to 2 for historical
657     # compatibility.
658 flameeyes 1.47 ruby-ng_rspec() {
659 graaff 1.56 local version=${RSPEC_VERSION-2}
660     local files="$@"
661    
662     # Explicitly pass the expected spec directory since the versioned
663     # rspec wrappers don't handle this automatically.
664     if [ ${#@} -eq 0 ]; then
665     files="spec"
666     fi
667    
668 flameeyes 1.47 if [[ ${DEPEND} != *"dev-ruby/rspec"* ]]; then
669     ewarn "Missing dev-ruby/rspec in \${DEPEND}"
670     fi
671    
672     local rspec_params=
673     case ${NOCOLOR} in
674     1|yes|true)
675     rspec_params+=" --no-color"
676     ;;
677     *)
678     rspec_params+=" --color"
679     ;;
680     esac
681    
682     case ${TEST_VERBOSE} in
683     1|yes|true)
684     rspec_params+=" --format documentation"
685     ;;
686     *)
687     rspec_params+=" --format progress"
688     ;;
689     esac
690    
691 graaff 1.56 ${RUBY} -S rspec-${version} ${rspec_params} ${files} || die "rspec failed"
692 flameeyes 1.47 }
693 flameeyes 1.48
694 flameeyes 1.49 # @FUNCTION: ruby-ng_cucumber
695     # @DESCRIPTION:
696     # This is simply a wrapper around the cucumber command (executed by $RUBY})
697     # which also respects TEST_VERBOSE and NOCOLOR environment variables.
698     ruby-ng_cucumber() {
699     if [[ ${DEPEND} != *"dev-util/cucumber"* ]]; then
700     ewarn "Missing dev-util/cucumber in \${DEPEND}"
701     fi
702    
703     local cucumber_params=
704     case ${NOCOLOR} in
705     1|yes|true)
706     cucumber_params+=" --no-color"
707     ;;
708     *)
709     cucumber_params+=" --color"
710     ;;
711     esac
712    
713     case ${TEST_VERBOSE} in
714     1|yes|true)
715     cucumber_params+=" --format pretty"
716     ;;
717     *)
718     cucumber_params+=" --format progress"
719     ;;
720     esac
721    
722 flameeyes 1.50 if [[ ${RUBY} == *jruby ]]; then
723     ewarn "Skipping cucumber tests on JRuby (unsupported)."
724     return 0
725     fi
726    
727 flameeyes 1.49 ${RUBY} -S cucumber ${cucumber_params} "$@" || die "cucumber failed"
728     }
729    
730 flameeyes 1.48 # @FUNCTION: ruby-ng_testrb-2
731     # @DESCRIPTION:
732     # This is simply a replacement for the testrb command that load the test
733     # files and execute them, with test-unit 2.x. This actually requires
734     # either an old test-unit-2 version or 2.5.1-r1 or later, as they remove
735     # their script and we installed a broken wrapper for a while.
736     # This also respects TEST_VERBOSE and NOCOLOR environment variables.
737     ruby-ng_testrb-2() {
738     if [[ ${DEPEND} != *"dev-ruby/test-unit"* ]]; then
739     ewarn "Missing dev-ruby/test-unit in \${DEPEND}"
740     fi
741    
742     local testrb_params=
743     case ${NOCOLOR} in
744     1|yes|true)
745     testrb_params+=" --no-use-color"
746     ;;
747     *)
748     testrb_params+=" --use-color=auto"
749     ;;
750     esac
751    
752     case ${TEST_VERBOSE} in
753     1|yes|true)
754     testrb_params+=" --verbose=verbose"
755     ;;
756     *)
757     testrb_params+=" --verbose=normal"
758     ;;
759     esac
760    
761     ${RUBY} -S testrb-2 ${testrb_params} "$@" || die "testrb-2 failed"
762     }

  ViewVC Help
Powered by ViewVC 1.1.20