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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.19 - (hide annotations) (download)
Sat May 22 13:15:40 2010 UTC (4 years, 3 months ago) by flameeyes
Branch: MAIN
Changes since 1.18: +2 -1 lines
Set RDEPEND="${RDEPEND}" to avoid depend to filter through rdepend.

1 a3li 1.6 # Copyright 1999-2009 Gentoo Foundation
2 graaff 1.1 # Distributed under the terms of the GNU General Public License v2
3 flameeyes 1.19 # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-ng.eclass,v 1.18 2010/05/22 12:45:03 flameeyes Exp $
4 graaff 1.1 #
5     # @ECLASS: ruby-ng.eclass
6     # @MAINTAINER:
7     # Ruby herd <ruby@gentoo.org>
8     #
9     # Author: Diego E. Pettenò <flameeyes@gentoo.org>
10     #
11     # Author: Alex Legler <a3li@gentoo.org>
12     #
13     # Author: Hans de Graaff <graaff@gentoo.org>
14     #
15     # @BLURB: An eclass for installing Ruby packages with proper support for multiple Ruby slots.
16     # @DESCRIPTION:
17     # The Ruby eclass is designed to allow an easier installation of Ruby packages
18     # and their incorporation into the Gentoo Linux system.
19     #
20     # Currently available targets are:
21     # * ruby18 - Ruby (MRI) 1.8.x
22     # * ruby19 - Ruby (MRI) 1.9.x
23     # * ree18 - Ruby Enterprise Edition 1.8.x
24     # * jruby - JRuby
25     #
26     # This eclass does not define the implementation of the configure,
27     # compile, test, or install phases. Instead, the default phases are
28     # used. Specific implementations of these phases can be provided in
29     # the ebuild either to be run for each Ruby implementation, or for all
30     # Ruby implementations, as follows:
31     #
32     # * each_ruby_configure
33     # * all_ruby_configure
34    
35     # @ECLASS-VARIABLE: USE_RUBY
36     # @DESCRIPTION:
37     # This variable contains a space separated list of targets (see above) a package
38     # is compatible to. It must be set before the `inherit' call. There is no
39     # default. All ebuilds are expected to set this variable.
40    
41     # @ECLASS-VARIABLE: RUBY_PATCHES
42     # @DESCRIPTION:
43     # A String or Array of filenames of patches to apply to all implementations.
44    
45     # @ECLASS-VARIABLE: RUBY_OPTIONAL
46     # @DESCRIPTION:
47     # Set the value to "yes" to make the dependency on a Ruby interpreter optional.
48    
49     inherit eutils toolchain-funcs
50    
51     EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_setup
52    
53     case ${EAPI} in
54     0|1)
55     die "Unsupported EAPI=${EAPI} (too old) for ruby-ng.eclass" ;;
56     2) ;;
57     *)
58     die "Unknown EAPI=${EAPI} for ruby-ng.eclass"
59     esac
60    
61     # @FUNCTION: ruby_implementation_depend
62     # @USAGE: target [comparator [version]]
63     # @RETURN: Package atom of a Ruby implementation to be used in dependencies.
64     # @DESCRIPTION:
65     # This function returns the formal package atom for a Ruby implementation.
66     #
67     # `target' has to be one of the valid values for USE_RUBY (see above)
68     #
69     # Set `comparator' and `version' to include a comparator (=, >=, etc.) and a
70     # version string to the returned string
71     ruby_implementation_depend() {
72     local rubypn=
73     local rubyslot=
74    
75     case $1 in
76     ruby18)
77     rubypn="dev-lang/ruby"
78     rubyslot=":1.8"
79     ;;
80     ruby19)
81     rubypn="dev-lang/ruby"
82     rubyslot=":1.9"
83     ;;
84     ree18)
85     rubypn="dev-lang/ruby-enterprise"
86     rubyslot=":1.8"
87     ;;
88     jruby)
89     rubypn="dev-java/jruby"
90     rubyslot=""
91     ;;
92     *) die "$1: unknown Ruby implementation"
93     esac
94    
95     echo "$2${rubypn}$3${rubyslot}"
96     }
97    
98     # @FUNCTION: ruby_samelib
99     # @RETURN: use flag string with current ruby implementations
100     # @DESCRIPTION:
101     # Convenience function to output the use dependency part of a
102     # dependency. Used as a building block for ruby_add_rdepend() and
103     # ruby_add_bdepend(), but may also be useful in an ebuild to specify
104     # more complex dependencies.
105     ruby_samelib() {
106     local res=
107     for _ruby_implementation in $USE_RUBY; do
108     has -${_ruby_implementation} $@ || \
109     res="${res}ruby_targets_${_ruby_implementation}?,"
110     done
111    
112     echo "[${res%,}]"
113     }
114    
115 flameeyes 1.17 _ruby_atoms_samelib_generic() {
116 flameeyes 1.18 eshopts_push -o noglob
117 flameeyes 1.17 echo "RUBYTARGET? ("
118 flameeyes 1.14 for token in $*; do
119     case "$token" in
120 flameeyes 1.16 "||" | "(" | ")" | *"?")
121 flameeyes 1.14 echo "${token}" ;;
122     *)
123 flameeyes 1.17 # TODO we need to deal with merging USE-based
124     # dependencies
125     echo "${token}[RUBYTARGET]" ;;
126 flameeyes 1.14 esac
127     done
128 flameeyes 1.17 echo ")"
129 flameeyes 1.18 eshopts_pop
130 flameeyes 1.17 }
131    
132     _ruby_atoms_samelib() {
133     local atoms=$(_ruby_atoms_samelib_generic "$*")
134    
135     for _ruby_implementation in $USE_RUBY; do
136     echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}"
137     done
138 flameeyes 1.14 }
139    
140 flameeyes 1.16 _ruby_wrap_conditions() {
141     local conditions="$1"
142     local atoms="$2"
143    
144     for condition in $conditions; do
145     hasq $condition "$IUSE" || IUSE="${IUSE} $condition"
146     atoms="${condition}? ( ${atoms} )"
147     done
148    
149     echo "$atoms"
150     }
151    
152 graaff 1.1 # @FUNCTION: ruby_add_rdepend
153 flameeyes 1.16 # @USAGE: dependencies
154 graaff 1.1 # @DESCRIPTION:
155 flameeyes 1.16 # Adds the specified dependencies, with use condition(s) to RDEPEND,
156     # taking the current set of ruby targets into account. This makes sure
157     # that all ruby dependencies of the package are installed for the same
158     # ruby targets. Use this function for all ruby dependencies instead of
159     # setting RDEPEND yourself. The list of atoms uses the same syntax as
160     # normal dependencies.
161     #
162     # Note: runtime dependencies are also added as build-time test
163     # dependencies.
164 graaff 1.1 ruby_add_rdepend() {
165     case $# in
166 flameeyes 1.16 1) ;;
167 graaff 1.1 2)
168 flameeyes 1.16 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_rdepend for $CATEGORY/$PF"
169     ruby_add_rdepend "$(_ruby_wrap_conditions "$1" "$2")"
170     return
171 graaff 1.1 ;;
172     *)
173     die "bad number of arguments to $0"
174     ;;
175     esac
176    
177 flameeyes 1.16 local dependency=$(_ruby_atoms_samelib "$1")
178    
179     RDEPEND="${RDEPEND} $dependency"
180    
181     # Add the dependency as a test-dependency since we're going to
182     # execute the code during test phase.
183     DEPEND="${DEPEND} $(_ruby_wrap_conditions test "${dependency}")"
184 graaff 1.1 }
185    
186     # @FUNCTION: ruby_add_bdepend
187 flameeyes 1.16 # @USAGE: dependencies
188 graaff 1.1 # @DESCRIPTION:
189 flameeyes 1.16 # Adds the specified dependencies, with use condition(s) to DEPEND,
190     # taking the current set of ruby targets into account. This makes sure
191     # that all ruby dependencies of the package are installed for the same
192     # ruby targets. Use this function for all ruby dependencies instead of
193     # setting DEPEND yourself. The list of atoms uses the same syntax as
194     # normal dependencies.
195 graaff 1.1 ruby_add_bdepend() {
196     case $# in
197 flameeyes 1.16 1) ;;
198 graaff 1.1 2)
199 flameeyes 1.16 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_bdepend for $CATEGORY/$PF"
200     ruby_add_bdepend "$(_ruby_wrap_conditions "$1" "$2")"
201     return
202 graaff 1.1 ;;
203     *)
204     die "bad number of arguments to $0"
205     ;;
206     esac
207    
208 flameeyes 1.16 local dependency=$(_ruby_atoms_samelib "$1")
209    
210     DEPEND="${DEPEND} $dependency"
211 flameeyes 1.19 RDEPEND="${RDEPEND}"
212 graaff 1.1 }
213    
214     for _ruby_implementation in $USE_RUBY; do
215     IUSE="${IUSE} ruby_targets_${_ruby_implementation}"
216    
217     # If you specify RUBY_OPTIONAL you also need to take care of
218     # ruby useflag and dependency.
219     if [[ ${RUBY_OPTIONAL} != "yes" ]]; then
220     DEPEND="${DEPEND} ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
221     RDEPEND="${RDEPEND} ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
222     fi
223     done
224    
225     _ruby_invoke_environment() {
226     old_S=${S}
227 flameeyes 1.12 sub_S=${S#${WORKDIR}/}
228    
229     # Special case, for the always-lovely GitHub fetches. With this,
230     # we allow the star glob to just expand to whatever directory it's
231     # called.
232     if [[ ${sub_S} = *"*" ]]; then
233     pushd "${WORKDIR}"/all &>/dev/null
234 flameeyes 1.13 sub_S=$(eval ls -d ${sub_S} 2>/dev/null)
235 flameeyes 1.12 popd &>/dev/null
236     fi
237 graaff 1.1
238     environment=$1; shift
239    
240     my_WORKDIR="${WORKDIR}"/${environment}
241     S="${my_WORKDIR}"/"${sub_S}"
242    
243     if [[ -d "${S}" ]]; then
244     pushd "$S" &>/dev/null
245     elif [[ -d "${my_WORKDIR}" ]]; then
246     pushd "${my_WORKDIR}" &>/dev/null
247     else
248     pushd "${WORKDIR}" &>/dev/null
249     fi
250    
251     ebegin "Running ${_PHASE:-${EBUILD_PHASE}} phase for $environment"
252     "$@"
253     popd &>/dev/null
254    
255     S=${old_S}
256     }
257    
258     _ruby_each_implementation() {
259     local invoked=no
260     for _ruby_implementation in ${USE_RUBY}; do
261     # only proceed if it's requested
262     use ruby_targets_${_ruby_implementation} || continue
263    
264 a3li 1.9 local _ruby_name=$_ruby_implementation
265    
266     # Add all USE_RUBY values where the flag name diverts from the binary here
267     case $_ruby_implementation in
268     ree18)
269     _ruby_name=rubyee18
270     ;;
271     esac
272    
273     RUBY=$(type -p $_ruby_name 2>/dev/null)
274 graaff 1.1 invoked=yes
275    
276     if [[ -n "$1" ]]; then
277     _ruby_invoke_environment $_ruby_implementation "$@"
278     fi
279    
280     unset RUBY
281     done
282    
283     [[ ${invoked} == "no" ]] && die "You need to select at least one Ruby implementation by setting RUBY_TARGETS in /etc/make.conf."
284     }
285    
286     # @FUNCTION: ruby-ng_pkg_setup
287     # @DESCRIPTION:
288     # Check whether at least one ruby target implementation is present.
289     ruby-ng_pkg_setup() {
290     # This only checks that at least one implementation is present
291     # before doing anything; by leaving the parameters empty we know
292     # it's a special case.
293     _ruby_each_implementation
294     }
295    
296     # @FUNCTION: ruby-ng_src_unpack
297     # @DESCRIPTION:
298 graaff 1.5 # Unpack the source archive.
299 graaff 1.1 ruby-ng_src_unpack() {
300     mkdir "${WORKDIR}"/all
301     pushd "${WORKDIR}"/all &>/dev/null
302    
303     # We don't support an each-unpack, it's either all or nothing!
304     if type all_ruby_unpack &>/dev/null; then
305     _ruby_invoke_environment all all_ruby_unpack
306     else
307     [[ -n ${A} ]] && unpack ${A}
308     fi
309    
310     popd &>/dev/null
311     }
312    
313     _ruby_apply_patches() {
314     for patch in "${RUBY_PATCHES[@]}"; do
315     if [ -f "${patch}" ]; then
316     epatch "${patch}"
317     elif [ -f "${FILESDIR}/${patch}" ]; then
318     epatch "${FILESDIR}/${patch}"
319     else
320     die "Cannot find patch ${patch}"
321     fi
322     done
323    
324     # This is a special case: instead of executing just in the special
325     # "all" environment, this will actually copy the effects on _all_
326     # the other environments, and is thus executed before the copy
327     type all_ruby_prepare &>/dev/null && all_ruby_prepare
328     }
329    
330     _ruby_source_copy() {
331     # Until we actually find a reason not to, we use hardlinks, this
332     # should reduce the amount of disk space that is wasted by this.
333     cp -prl all ${_ruby_implementation} \
334     || die "Unable to copy ${_ruby_implementation} environment"
335     }
336    
337     # @FUNCTION: ruby-ng_src_prepare
338     # @DESCRIPTION:
339     # Apply patches and prepare versions for each ruby target
340     # implementation. Also carry out common clean up tasks.
341     ruby-ng_src_prepare() {
342     # Way too many Ruby packages are prepared on OSX without removing
343     # the extra data forks, we do it here to avoid repeating it for
344     # almost every other ebuild.
345     find . -name '._*' -delete
346    
347     _ruby_invoke_environment all _ruby_apply_patches
348    
349 flameeyes 1.7 _PHASE="source copy" \
350     _ruby_each_implementation _ruby_source_copy
351 graaff 1.1
352     if type each_ruby_prepare &>/dev/null; then
353     _ruby_each_implementation each_ruby_prepare
354     fi
355     }
356    
357     # @FUNCTION: ruby-ng_src_configure
358     # @DESCRIPTION:
359     # Configure the package.
360     ruby-ng_src_configure() {
361     if type each_ruby_configure &>/dev/null; then
362     _ruby_each_implementation each_ruby_configure
363     fi
364    
365     type all_ruby_configure &>/dev/null && \
366     _ruby_invoke_environment all all_ruby_configure
367     }
368    
369     # @FUNCTION: ruby-ng_src_compile
370     # @DESCRIPTION:
371     # Compile the package.
372     ruby-ng_src_compile() {
373     if type each_ruby_compile &>/dev/null; then
374     _ruby_each_implementation each_ruby_compile
375     fi
376    
377     type all_ruby_compile &>/dev/null && \
378     _ruby_invoke_environment all all_ruby_compile
379     }
380    
381     # @FUNCTION: ruby-ng_src_test
382     # @DESCRIPTION:
383     # Run tests for the package.
384     ruby-ng_src_test() {
385     if type each_ruby_test &>/dev/null; then
386     _ruby_each_implementation each_ruby_test
387     fi
388    
389     type all_ruby_test &>/dev/null && \
390     _ruby_invoke_environment all all_ruby_test
391     }
392    
393     _each_ruby_check_install() {
394     local libruby_basename=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["LIBRUBY_SO"]')
395     local libruby_soname=$(scanelf -qS "/usr/$(get_libdir)/${libruby_basename}" | awk '{ print $1 }')
396 flameeyes 1.2 local sitedir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitedir"]')
397     local sitelibdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]')
398    
399     # Look for wrong files in sitedir
400     if [[ -d "${D}${sitedir}" ]]; then
401     local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}")
402     if [[ -n ${f} ]]; then
403     eerror "Found files in sitedir, outsite sitelibdir:"
404     eerror "${f}"
405     die "Misplaced files in sitedir"
406     fi
407     fi
408 graaff 1.1
409     # The current implementation lacks libruby (i.e.: jruby)
410     [[ -z ${libruby_soname} ]] && return 0
411    
412 flameeyes 1.3 scanelf -qnR "${D}${sitedir}" \
413 graaff 1.1 | fgrep -v "${libruby_soname}" \
414     > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log
415    
416     if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then
417 flameeyes 1.15 ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}"
418 graaff 1.1 ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log )
419 flameeyes 1.15 die "Missing links to ${libruby_soname}"
420 graaff 1.1 fi
421     }
422    
423     # @FUNCTION: ruby-ng_src_install
424     # @DESCRIPTION:
425     # Install the package for each ruby target implementation.
426     ruby-ng_src_install() {
427     if type each_ruby_install &>/dev/null; then
428     _ruby_each_implementation each_ruby_install
429     fi
430    
431     type all_ruby_install &>/dev/null && \
432     _ruby_invoke_environment all all_ruby_install
433    
434     _PHASE="check install" \
435     _ruby_each_implementation _each_ruby_check_install
436     }
437    
438 a3li 1.11 # @FUNCTION: ruby_rbconfig_value
439     # @USAGE: rbconfig item
440     # @RETURN: Returns the value of the given rbconfig item of the Ruby interpreter in ${RUBY}.
441     ruby_rbconfig_value() {
442     echo $(${RUBY} -rrbconfig -e "puts Config::CONFIG['$1']")
443     }
444    
445 graaff 1.1 # @FUNCTION: doruby
446     # @USAGE: file [file...]
447     # @DESCRIPTION:
448     # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}.
449     doruby() {
450 flameeyes 1.4 [[ -z ${RUBY} ]] && die "\$RUBY is not set"
451 graaff 1.1 ( # don't want to pollute calling env
452 a3li 1.11 insinto $(ruby_rbconfig_value 'sitelibdir')
453 graaff 1.1 insopts -m 0644
454     doins "$@"
455     ) || die "failed to install $@"
456     }
457    
458     # @FUNCTION: ruby_get_libruby
459     # @RETURN: The location of libruby*.so belonging to the Ruby interpreter in ${RUBY}.
460     ruby_get_libruby() {
461     ${RUBY} -rrbconfig -e 'puts File.join(Config::CONFIG["libdir"], Config::CONFIG["LIBRUBY"])'
462     }
463    
464     # @FUNCTION: ruby_get_hdrdir
465     # @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}.
466     ruby_get_hdrdir() {
467 a3li 1.11 local rubyhdrdir=$(ruby_rbconfig_value 'rubyhdrdir')
468 graaff 1.1
469     if [[ "${rubyhdrdir}" = "nil" ]] ; then
470 a3li 1.11 rubyhdrdir=$(ruby_rbconfig_value 'archdir')
471 graaff 1.1 fi
472    
473     echo "${rubyhdrdir}"
474     }
475 a3li 1.10
476     # @FUNCTION: ruby_get_version
477     # @RETURN: The version of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
478     ruby_get_version() {
479     local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
480    
481     echo $(${ruby} -e 'puts RUBY_VERSION')
482     }
483    
484     # @FUNCTION: ruby_get_implementation
485     # @RETURN: The implementation of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
486     ruby_get_implementation() {
487     local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
488    
489     case $(${ruby} --version) in
490     *Enterprise*)
491     echo "ree"
492     ;;
493     *jruby*)
494     echo "jruby"
495     ;;
496     *)
497     echo "mri"
498     ;;
499     esac
500     }

  ViewVC Help
Powered by ViewVC 1.1.20