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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.50 - (hide annotations) (download)
Mon Aug 13 22:21:26 2012 UTC (2 years ago) by flameeyes
Branch: MAIN
Changes since 1.49: +6 -1 lines
Add support for cucumber as a test recipe. This allows abstracting some of the work needed to skip it over on JRuby.

1 a3li 1.45 # Copyright 1999-2012 Gentoo Foundation
2 graaff 1.1 # Distributed under the terms of the GNU General Public License v2
3 flameeyes 1.50 # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-ng.eclass,v 1.49 2012/08/13 21:18:41 flameeyes 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     # * ree18 - Ruby Enterprise Edition 1.8.x
21     # * jruby - JRuby
22 graaff 1.41 # * rbx - Rubinius
23 graaff 1.1 #
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 graaff 1.26 # @REQUIRED
35 graaff 1.1 # @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 graaff 1.26 # @DEFAULT_UNSET
42 graaff 1.1 # @DESCRIPTION:
43     # A String or Array of filenames of patches to apply to all implementations.
44    
45     # @ECLASS-VARIABLE: RUBY_OPTIONAL
46     # @DESCRIPTION:
47 graaff 1.38 # 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 graaff 1.1
51 graaff 1.31 # @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 graaff 1.34 # @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 zmedico 1.46 inherit eutils java-utils-2 multilib toolchain-funcs
73 graaff 1.1
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 flameeyes 1.24 2|3) ;;
80 graaff 1.31 4)
81     # S is no longer automatically assigned when it doesn't exist.
82     S="${WORKDIR}"
83     ;;
84 graaff 1.1 *)
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 graaff 1.41 rbx)
120     rubypn="dev-lang/rubinius"
121     rubyslot=""
122     ;;
123 graaff 1.1 *) 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 flameeyes 1.17 _ruby_atoms_samelib_generic() {
147 flameeyes 1.18 eshopts_push -o noglob
148 flameeyes 1.17 echo "RUBYTARGET? ("
149 flameeyes 1.14 for token in $*; do
150     case "$token" in
151 flameeyes 1.16 "||" | "(" | ")" | *"?")
152 flameeyes 1.14 echo "${token}" ;;
153 flameeyes 1.21 *])
154     echo "${token%[*}[RUBYTARGET,${token/*[}" ;;
155 flameeyes 1.14 *)
156 flameeyes 1.17 echo "${token}[RUBYTARGET]" ;;
157 flameeyes 1.14 esac
158     done
159 flameeyes 1.17 echo ")"
160 flameeyes 1.18 eshopts_pop
161 flameeyes 1.17 }
162    
163 flameeyes 1.27 # @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 flameeyes 1.17 _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 flameeyes 1.14 }
189    
190 flameeyes 1.16 _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 graaff 1.1 # @FUNCTION: ruby_add_rdepend
202 flameeyes 1.16 # @USAGE: dependencies
203 graaff 1.1 # @DESCRIPTION:
204 flameeyes 1.16 # 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 graaff 1.1 ruby_add_rdepend() {
214     case $# in
215 flameeyes 1.16 1) ;;
216 graaff 1.1 2)
217 flameeyes 1.16 [[ "${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 graaff 1.1 ;;
221     *)
222     die "bad number of arguments to $0"
223     ;;
224     esac
225    
226 flameeyes 1.16 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 flameeyes 1.20 DEPEND="${DEPEND} test? ( ${dependency} )"
233 ssuominen 1.33 has test "$IUSE" || IUSE="${IUSE} test"
234 graaff 1.1 }
235    
236     # @FUNCTION: ruby_add_bdepend
237 flameeyes 1.16 # @USAGE: dependencies
238 graaff 1.1 # @DESCRIPTION:
239 flameeyes 1.16 # 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 graaff 1.1 ruby_add_bdepend() {
246     case $# in
247 flameeyes 1.16 1) ;;
248 graaff 1.1 2)
249 flameeyes 1.16 [[ "${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 graaff 1.1 ;;
253     *)
254     die "bad number of arguments to $0"
255     ;;
256     esac
257    
258 flameeyes 1.16 local dependency=$(_ruby_atoms_samelib "$1")
259    
260     DEPEND="${DEPEND} $dependency"
261 flameeyes 1.19 RDEPEND="${RDEPEND}"
262 graaff 1.1 }
263    
264 graaff 1.37 # @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 graaff 1.36 # @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 graaff 1.38 # @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 flameeyes 1.44 IUSE+=" $(ruby_get_use_targets)"
311 graaff 1.38 # 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 flameeyes 1.44
317     [[ ${EAPI:-0} -ge 4 ]] && REQUIRED_USE+=" || ( $(ruby_get_use_targets) )"
318 graaff 1.38 fi
319 graaff 1.1
320     _ruby_invoke_environment() {
321     old_S=${S}
322 graaff 1.31 case ${EAPI} in
323     4)
324 graaff 1.32 if [ -z ${RUBY_S} ]; then
325     sub_S=${P}
326     else
327     sub_S=${RUBY_S}
328     fi
329 graaff 1.31 ;;
330     *)
331     sub_S=${S#${WORKDIR}/}
332     ;;
333     esac
334 flameeyes 1.12
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 flameeyes 1.28 if [[ ${sub_S} = *"*"* ]]; then
339 graaff 1.35 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 flameeyes 1.12 pushd "${WORKDIR}"/all &>/dev/null
347 flameeyes 1.13 sub_S=$(eval ls -d ${sub_S} 2>/dev/null)
348 flameeyes 1.12 popd &>/dev/null
349     fi
350 graaff 1.1
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 flameeyes 1.27 RUBY=$(ruby_implementation_command ${_ruby_implementation})
378 graaff 1.1 invoked=yes
379    
380     if [[ -n "$1" ]]; then
381 flameeyes 1.27 _ruby_invoke_environment ${_ruby_implementation} "$@"
382 graaff 1.1 fi
383    
384     unset RUBY
385     done
386    
387 a3li 1.45 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 graaff 1.1 }
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 graaff 1.40
406 scarabeus 1.42 has ruby_targets_jruby ${IUSE} && use ruby_targets_jruby && java-pkg_setup-vm
407 graaff 1.1 }
408    
409     # @FUNCTION: ruby-ng_src_unpack
410     # @DESCRIPTION:
411 graaff 1.5 # Unpack the source archive.
412 graaff 1.1 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 fauli 1.30 cp -prl all ${_ruby_implementation} \
447 graaff 1.1 || 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 flameeyes 1.7 _PHASE="source copy" \
463     _ruby_each_implementation _ruby_source_copy
464 graaff 1.1
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 flameeyes 1.24 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 graaff 1.43 local libruby_basename=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["LIBRUBY_SO"]')
514 flameeyes 1.25 local libruby_soname=$(basename $(${scancmd} -F "%S#F" -qS "${EPREFIX}/usr/$(get_libdir)/${libruby_basename}") 2>/dev/null)
515 graaff 1.43 local sitedir=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["sitedir"]')
516     local sitelibdir=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["sitelibdir"]')
517 flameeyes 1.2
518     # Look for wrong files in sitedir
519 flameeyes 1.22 # 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 graaff 1.1
528     # The current implementation lacks libruby (i.e.: jruby)
529     [[ -z ${libruby_soname} ]] && return 0
530    
531 flameeyes 1.23 # 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 flameeyes 1.24 ${scancmd} -qnR "${D}${sitelibdir}" "${D}${sitelibdir/site_ruby/gems}" \
536 graaff 1.1 | fgrep -v "${libruby_soname}" \
537 graaff 1.34 | grep -E -v "${RUBY_QA_ALLOWED_LIBS}" \
538 graaff 1.1 > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log
539    
540     if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then
541 flameeyes 1.15 ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}"
542 graaff 1.1 ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log )
543 flameeyes 1.15 die "Missing links to ${libruby_soname}"
544 graaff 1.1 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 a3li 1.11 # @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 graaff 1.43 echo $(${RUBY} -rrbconfig -e "puts RbConfig::CONFIG['$1']")
567 a3li 1.11 }
568    
569 graaff 1.1 # @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 flameeyes 1.4 [[ -z ${RUBY} ]] && die "\$RUBY is not set"
575 flameeyes 1.24 has "${EAPI}" 2 && ! use prefix && EPREFIX=
576 graaff 1.1 ( # don't want to pollute calling env
577 flameeyes 1.24 sitelibdir=$(ruby_rbconfig_value 'sitelibdir')
578     insinto ${sitelibdir#${EPREFIX}}
579 graaff 1.1 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 graaff 1.43 ${RUBY} -rrbconfig -e 'puts File.join(RbConfig::CONFIG["libdir"], RbConfig::CONFIG["LIBRUBY"])'
588 graaff 1.1 }
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 a3li 1.11 local rubyhdrdir=$(ruby_rbconfig_value 'rubyhdrdir')
594 graaff 1.1
595     if [[ "${rubyhdrdir}" = "nil" ]] ; then
596 a3li 1.11 rubyhdrdir=$(ruby_rbconfig_value 'archdir')
597 graaff 1.1 fi
598    
599     echo "${rubyhdrdir}"
600     }
601 a3li 1.10
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 graaff 1.41 *rubinius*)
623     echo "rbx"
624     ;;
625 a3li 1.10 *)
626     echo "mri"
627     ;;
628     esac
629     }
630 flameeyes 1.47
631     # @FUNCTION: ruby-ng_rspec
632     # @DESCRIPTION:
633     # This is simply a wrapper around the rspec command (executed by $RUBY})
634     # which also respects TEST_VERBOSE and NOCOLOR environment variables.
635     ruby-ng_rspec() {
636     if [[ ${DEPEND} != *"dev-ruby/rspec"* ]]; then
637     ewarn "Missing dev-ruby/rspec in \${DEPEND}"
638     fi
639    
640     local rspec_params=
641     case ${NOCOLOR} in
642     1|yes|true)
643     rspec_params+=" --no-color"
644     ;;
645     *)
646     rspec_params+=" --color"
647     ;;
648     esac
649    
650     case ${TEST_VERBOSE} in
651     1|yes|true)
652     rspec_params+=" --format documentation"
653     ;;
654     *)
655     rspec_params+=" --format progress"
656     ;;
657     esac
658    
659     ${RUBY} -S rspec ${rspec_params} "$@" || die "rspec failed"
660     }
661 flameeyes 1.48
662 flameeyes 1.49 # @FUNCTION: ruby-ng_cucumber
663     # @DESCRIPTION:
664     # This is simply a wrapper around the cucumber command (executed by $RUBY})
665     # which also respects TEST_VERBOSE and NOCOLOR environment variables.
666     ruby-ng_cucumber() {
667     if [[ ${DEPEND} != *"dev-util/cucumber"* ]]; then
668     ewarn "Missing dev-util/cucumber in \${DEPEND}"
669     fi
670    
671     local cucumber_params=
672     case ${NOCOLOR} in
673     1|yes|true)
674     cucumber_params+=" --no-color"
675     ;;
676     *)
677     cucumber_params+=" --color"
678     ;;
679     esac
680    
681     case ${TEST_VERBOSE} in
682     1|yes|true)
683     cucumber_params+=" --format pretty"
684     ;;
685     *)
686     cucumber_params+=" --format progress"
687     ;;
688     esac
689    
690 flameeyes 1.50 if [[ ${RUBY} == *jruby ]]; then
691     ewarn "Skipping cucumber tests on JRuby (unsupported)."
692     return 0
693     fi
694    
695 flameeyes 1.49 ${RUBY} -S cucumber ${cucumber_params} "$@" || die "cucumber failed"
696     }
697    
698 flameeyes 1.48 # @FUNCTION: ruby-ng_testrb-2
699     # @DESCRIPTION:
700     # This is simply a replacement for the testrb command that load the test
701     # files and execute them, with test-unit 2.x. This actually requires
702     # either an old test-unit-2 version or 2.5.1-r1 or later, as they remove
703     # their script and we installed a broken wrapper for a while.
704     # This also respects TEST_VERBOSE and NOCOLOR environment variables.
705     ruby-ng_testrb-2() {
706     if [[ ${DEPEND} != *"dev-ruby/test-unit"* ]]; then
707     ewarn "Missing dev-ruby/test-unit in \${DEPEND}"
708     fi
709    
710     local testrb_params=
711     case ${NOCOLOR} in
712     1|yes|true)
713     testrb_params+=" --no-use-color"
714     ;;
715     *)
716     testrb_params+=" --use-color=auto"
717     ;;
718     esac
719    
720     case ${TEST_VERBOSE} in
721     1|yes|true)
722     testrb_params+=" --verbose=verbose"
723     ;;
724     *)
725     testrb_params+=" --verbose=normal"
726     ;;
727     esac
728    
729     ${RUBY} -S testrb-2 ${testrb_params} "$@" || die "testrb-2 failed"
730     }

  ViewVC Help
Powered by ViewVC 1.1.20