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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.51 - (hide annotations) (download)
Thu Sep 27 16:35:41 2012 UTC (22 months, 3 weeks ago) by axs
Branch: MAIN
Changes since 1.50: +8 -4 lines
naive bump of all EAPI-specific checks in eclasses to permit EAPI=5 where EAPI=4 was previously allowed

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 axs 1.51 # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-ng.eclass,v 1.50 2012/08/13 22:21:26 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 axs 1.51 4|5)
81 graaff 1.31 # 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 axs 1.51 case ${EAPI:-0} in
318     4|5)
319     REQUIRED_USE+=" || ( $(ruby_get_use_targets) )"
320     ;;
321     esac
322 graaff 1.38 fi
323 graaff 1.1
324     _ruby_invoke_environment() {
325     old_S=${S}
326 graaff 1.31 case ${EAPI} in
327 axs 1.51 4|5)
328 graaff 1.32 if [ -z ${RUBY_S} ]; then
329     sub_S=${P}
330     else
331     sub_S=${RUBY_S}
332     fi
333 graaff 1.31 ;;
334     *)
335     sub_S=${S#${WORKDIR}/}
336     ;;
337     esac
338 flameeyes 1.12
339     # Special case, for the always-lovely GitHub fetches. With this,
340     # we allow the star glob to just expand to whatever directory it's
341     # called.
342 flameeyes 1.28 if [[ ${sub_S} = *"*"* ]]; then
343 graaff 1.35 case ${EAPI} in
344     2|3)
345     #The old method of setting S depends on undefined package
346     # manager behaviour, so encourage upgrading to EAPI=4.
347     eqawarn "Using * expansion of S is deprecated. Use EAPI and RUBY_S instead."
348     ;;
349     esac
350 flameeyes 1.12 pushd "${WORKDIR}"/all &>/dev/null
351 flameeyes 1.13 sub_S=$(eval ls -d ${sub_S} 2>/dev/null)
352 flameeyes 1.12 popd &>/dev/null
353     fi
354 graaff 1.1
355     environment=$1; shift
356    
357     my_WORKDIR="${WORKDIR}"/${environment}
358     S="${my_WORKDIR}"/"${sub_S}"
359    
360     if [[ -d "${S}" ]]; then
361     pushd "$S" &>/dev/null
362     elif [[ -d "${my_WORKDIR}" ]]; then
363     pushd "${my_WORKDIR}" &>/dev/null
364     else
365     pushd "${WORKDIR}" &>/dev/null
366     fi
367    
368     ebegin "Running ${_PHASE:-${EBUILD_PHASE}} phase for $environment"
369     "$@"
370     popd &>/dev/null
371    
372     S=${old_S}
373     }
374    
375     _ruby_each_implementation() {
376     local invoked=no
377     for _ruby_implementation in ${USE_RUBY}; do
378     # only proceed if it's requested
379     use ruby_targets_${_ruby_implementation} || continue
380    
381 flameeyes 1.27 RUBY=$(ruby_implementation_command ${_ruby_implementation})
382 graaff 1.1 invoked=yes
383    
384     if [[ -n "$1" ]]; then
385 flameeyes 1.27 _ruby_invoke_environment ${_ruby_implementation} "$@"
386 graaff 1.1 fi
387    
388     unset RUBY
389     done
390    
391 a3li 1.45 if [[ ${invoked} == "no" ]]; then
392     eerror "You need to select at least one compatible Ruby installation target via RUBY_TARGETS in make.conf."
393     eerror "Compatible targets for this package are: ${USE_RUBY}"
394     eerror
395     eerror "See http://www.gentoo.org/proj/en/prog_lang/ruby/index.xml#doc_chap3 for more information."
396     eerror
397     die "No compatible Ruby target selected."
398     fi
399 graaff 1.1 }
400    
401     # @FUNCTION: ruby-ng_pkg_setup
402     # @DESCRIPTION:
403     # Check whether at least one ruby target implementation is present.
404     ruby-ng_pkg_setup() {
405     # This only checks that at least one implementation is present
406     # before doing anything; by leaving the parameters empty we know
407     # it's a special case.
408     _ruby_each_implementation
409 graaff 1.40
410 scarabeus 1.42 has ruby_targets_jruby ${IUSE} && use ruby_targets_jruby && java-pkg_setup-vm
411 graaff 1.1 }
412    
413     # @FUNCTION: ruby-ng_src_unpack
414     # @DESCRIPTION:
415 graaff 1.5 # Unpack the source archive.
416 graaff 1.1 ruby-ng_src_unpack() {
417     mkdir "${WORKDIR}"/all
418     pushd "${WORKDIR}"/all &>/dev/null
419    
420     # We don't support an each-unpack, it's either all or nothing!
421     if type all_ruby_unpack &>/dev/null; then
422     _ruby_invoke_environment all all_ruby_unpack
423     else
424     [[ -n ${A} ]] && unpack ${A}
425     fi
426    
427     popd &>/dev/null
428     }
429    
430     _ruby_apply_patches() {
431     for patch in "${RUBY_PATCHES[@]}"; do
432     if [ -f "${patch}" ]; then
433     epatch "${patch}"
434     elif [ -f "${FILESDIR}/${patch}" ]; then
435     epatch "${FILESDIR}/${patch}"
436     else
437     die "Cannot find patch ${patch}"
438     fi
439     done
440    
441     # This is a special case: instead of executing just in the special
442     # "all" environment, this will actually copy the effects on _all_
443     # the other environments, and is thus executed before the copy
444     type all_ruby_prepare &>/dev/null && all_ruby_prepare
445     }
446    
447     _ruby_source_copy() {
448     # Until we actually find a reason not to, we use hardlinks, this
449     # should reduce the amount of disk space that is wasted by this.
450 fauli 1.30 cp -prl all ${_ruby_implementation} \
451 graaff 1.1 || die "Unable to copy ${_ruby_implementation} environment"
452     }
453    
454     # @FUNCTION: ruby-ng_src_prepare
455     # @DESCRIPTION:
456     # Apply patches and prepare versions for each ruby target
457     # implementation. Also carry out common clean up tasks.
458     ruby-ng_src_prepare() {
459     # Way too many Ruby packages are prepared on OSX without removing
460     # the extra data forks, we do it here to avoid repeating it for
461     # almost every other ebuild.
462     find . -name '._*' -delete
463    
464     _ruby_invoke_environment all _ruby_apply_patches
465    
466 flameeyes 1.7 _PHASE="source copy" \
467     _ruby_each_implementation _ruby_source_copy
468 graaff 1.1
469     if type each_ruby_prepare &>/dev/null; then
470     _ruby_each_implementation each_ruby_prepare
471     fi
472     }
473    
474     # @FUNCTION: ruby-ng_src_configure
475     # @DESCRIPTION:
476     # Configure the package.
477     ruby-ng_src_configure() {
478     if type each_ruby_configure &>/dev/null; then
479     _ruby_each_implementation each_ruby_configure
480     fi
481    
482     type all_ruby_configure &>/dev/null && \
483     _ruby_invoke_environment all all_ruby_configure
484     }
485    
486     # @FUNCTION: ruby-ng_src_compile
487     # @DESCRIPTION:
488     # Compile the package.
489     ruby-ng_src_compile() {
490     if type each_ruby_compile &>/dev/null; then
491     _ruby_each_implementation each_ruby_compile
492     fi
493    
494     type all_ruby_compile &>/dev/null && \
495     _ruby_invoke_environment all all_ruby_compile
496     }
497    
498     # @FUNCTION: ruby-ng_src_test
499     # @DESCRIPTION:
500     # Run tests for the package.
501     ruby-ng_src_test() {
502     if type each_ruby_test &>/dev/null; then
503     _ruby_each_implementation each_ruby_test
504     fi
505    
506     type all_ruby_test &>/dev/null && \
507     _ruby_invoke_environment all all_ruby_test
508     }
509    
510     _each_ruby_check_install() {
511 flameeyes 1.24 local scancmd=scanelf
512     # we have a Mach-O object here
513     [[ ${CHOST} == *-darwin ]] && scancmd=scanmacho
514    
515     has "${EAPI}" 2 && ! use prefix && EPREFIX=
516    
517 graaff 1.43 local libruby_basename=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["LIBRUBY_SO"]')
518 flameeyes 1.25 local libruby_soname=$(basename $(${scancmd} -F "%S#F" -qS "${EPREFIX}/usr/$(get_libdir)/${libruby_basename}") 2>/dev/null)
519 graaff 1.43 local sitedir=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["sitedir"]')
520     local sitelibdir=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["sitelibdir"]')
521 flameeyes 1.2
522     # Look for wrong files in sitedir
523 flameeyes 1.22 # if [[ -d "${D}${sitedir}" ]]; then
524     # local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}")
525     # if [[ -n ${f} ]]; then
526     # eerror "Found files in sitedir, outsite sitelibdir:"
527     # eerror "${f}"
528     # die "Misplaced files in sitedir"
529     # fi
530     # fi
531 graaff 1.1
532     # The current implementation lacks libruby (i.e.: jruby)
533     [[ -z ${libruby_soname} ]] && return 0
534    
535 flameeyes 1.23 # Check also the gems directory, since we could be installing compiled
536     # extensions via ruby-fakegem; make sure to check only in sitelibdir, since
537     # that's what changes between two implementations (otherwise you'd get false
538     # positives now that Ruby 1.9.2 installs with the same sitedir as 1.8)
539 flameeyes 1.24 ${scancmd} -qnR "${D}${sitelibdir}" "${D}${sitelibdir/site_ruby/gems}" \
540 graaff 1.1 | fgrep -v "${libruby_soname}" \
541 graaff 1.34 | grep -E -v "${RUBY_QA_ALLOWED_LIBS}" \
542 graaff 1.1 > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log
543    
544     if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then
545 flameeyes 1.15 ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}"
546 graaff 1.1 ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log )
547 flameeyes 1.15 die "Missing links to ${libruby_soname}"
548 graaff 1.1 fi
549     }
550    
551     # @FUNCTION: ruby-ng_src_install
552     # @DESCRIPTION:
553     # Install the package for each ruby target implementation.
554     ruby-ng_src_install() {
555     if type each_ruby_install &>/dev/null; then
556     _ruby_each_implementation each_ruby_install
557     fi
558    
559     type all_ruby_install &>/dev/null && \
560     _ruby_invoke_environment all all_ruby_install
561    
562     _PHASE="check install" \
563     _ruby_each_implementation _each_ruby_check_install
564     }
565    
566 a3li 1.11 # @FUNCTION: ruby_rbconfig_value
567     # @USAGE: rbconfig item
568     # @RETURN: Returns the value of the given rbconfig item of the Ruby interpreter in ${RUBY}.
569     ruby_rbconfig_value() {
570 graaff 1.43 echo $(${RUBY} -rrbconfig -e "puts RbConfig::CONFIG['$1']")
571 a3li 1.11 }
572    
573 graaff 1.1 # @FUNCTION: doruby
574     # @USAGE: file [file...]
575     # @DESCRIPTION:
576     # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}.
577     doruby() {
578 flameeyes 1.4 [[ -z ${RUBY} ]] && die "\$RUBY is not set"
579 flameeyes 1.24 has "${EAPI}" 2 && ! use prefix && EPREFIX=
580 graaff 1.1 ( # don't want to pollute calling env
581 flameeyes 1.24 sitelibdir=$(ruby_rbconfig_value 'sitelibdir')
582     insinto ${sitelibdir#${EPREFIX}}
583 graaff 1.1 insopts -m 0644
584     doins "$@"
585     ) || die "failed to install $@"
586     }
587    
588     # @FUNCTION: ruby_get_libruby
589     # @RETURN: The location of libruby*.so belonging to the Ruby interpreter in ${RUBY}.
590     ruby_get_libruby() {
591 graaff 1.43 ${RUBY} -rrbconfig -e 'puts File.join(RbConfig::CONFIG["libdir"], RbConfig::CONFIG["LIBRUBY"])'
592 graaff 1.1 }
593    
594     # @FUNCTION: ruby_get_hdrdir
595     # @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}.
596     ruby_get_hdrdir() {
597 a3li 1.11 local rubyhdrdir=$(ruby_rbconfig_value 'rubyhdrdir')
598 graaff 1.1
599     if [[ "${rubyhdrdir}" = "nil" ]] ; then
600 a3li 1.11 rubyhdrdir=$(ruby_rbconfig_value 'archdir')
601 graaff 1.1 fi
602    
603     echo "${rubyhdrdir}"
604     }
605 a3li 1.10
606     # @FUNCTION: ruby_get_version
607     # @RETURN: The version of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
608     ruby_get_version() {
609     local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
610    
611     echo $(${ruby} -e 'puts RUBY_VERSION')
612     }
613    
614     # @FUNCTION: ruby_get_implementation
615     # @RETURN: The implementation of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
616     ruby_get_implementation() {
617     local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
618    
619     case $(${ruby} --version) in
620     *Enterprise*)
621     echo "ree"
622     ;;
623     *jruby*)
624     echo "jruby"
625     ;;
626 graaff 1.41 *rubinius*)
627     echo "rbx"
628     ;;
629 a3li 1.10 *)
630     echo "mri"
631     ;;
632     esac
633     }
634 flameeyes 1.47
635     # @FUNCTION: ruby-ng_rspec
636     # @DESCRIPTION:
637     # This is simply a wrapper around the rspec command (executed by $RUBY})
638     # which also respects TEST_VERBOSE and NOCOLOR environment variables.
639     ruby-ng_rspec() {
640     if [[ ${DEPEND} != *"dev-ruby/rspec"* ]]; then
641     ewarn "Missing dev-ruby/rspec in \${DEPEND}"
642     fi
643    
644     local rspec_params=
645     case ${NOCOLOR} in
646     1|yes|true)
647     rspec_params+=" --no-color"
648     ;;
649     *)
650     rspec_params+=" --color"
651     ;;
652     esac
653    
654     case ${TEST_VERBOSE} in
655     1|yes|true)
656     rspec_params+=" --format documentation"
657     ;;
658     *)
659     rspec_params+=" --format progress"
660     ;;
661     esac
662    
663     ${RUBY} -S rspec ${rspec_params} "$@" || die "rspec failed"
664     }
665 flameeyes 1.48
666 flameeyes 1.49 # @FUNCTION: ruby-ng_cucumber
667     # @DESCRIPTION:
668     # This is simply a wrapper around the cucumber command (executed by $RUBY})
669     # which also respects TEST_VERBOSE and NOCOLOR environment variables.
670     ruby-ng_cucumber() {
671     if [[ ${DEPEND} != *"dev-util/cucumber"* ]]; then
672     ewarn "Missing dev-util/cucumber in \${DEPEND}"
673     fi
674    
675     local cucumber_params=
676     case ${NOCOLOR} in
677     1|yes|true)
678     cucumber_params+=" --no-color"
679     ;;
680     *)
681     cucumber_params+=" --color"
682     ;;
683     esac
684    
685     case ${TEST_VERBOSE} in
686     1|yes|true)
687     cucumber_params+=" --format pretty"
688     ;;
689     *)
690     cucumber_params+=" --format progress"
691     ;;
692     esac
693    
694 flameeyes 1.50 if [[ ${RUBY} == *jruby ]]; then
695     ewarn "Skipping cucumber tests on JRuby (unsupported)."
696     return 0
697     fi
698    
699 flameeyes 1.49 ${RUBY} -S cucumber ${cucumber_params} "$@" || die "cucumber failed"
700     }
701    
702 flameeyes 1.48 # @FUNCTION: ruby-ng_testrb-2
703     # @DESCRIPTION:
704     # This is simply a replacement for the testrb command that load the test
705     # files and execute them, with test-unit 2.x. This actually requires
706     # either an old test-unit-2 version or 2.5.1-r1 or later, as they remove
707     # their script and we installed a broken wrapper for a while.
708     # This also respects TEST_VERBOSE and NOCOLOR environment variables.
709     ruby-ng_testrb-2() {
710     if [[ ${DEPEND} != *"dev-ruby/test-unit"* ]]; then
711     ewarn "Missing dev-ruby/test-unit in \${DEPEND}"
712     fi
713    
714     local testrb_params=
715     case ${NOCOLOR} in
716     1|yes|true)
717     testrb_params+=" --no-use-color"
718     ;;
719     *)
720     testrb_params+=" --use-color=auto"
721     ;;
722     esac
723    
724     case ${TEST_VERBOSE} in
725     1|yes|true)
726     testrb_params+=" --verbose=verbose"
727     ;;
728     *)
729     testrb_params+=" --verbose=normal"
730     ;;
731     esac
732    
733     ${RUBY} -S testrb-2 ${testrb_params} "$@" || die "testrb-2 failed"
734     }

  ViewVC Help
Powered by ViewVC 1.1.20