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