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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.31 - (hide annotations) (download)
Mon Apr 25 06:27:22 2011 UTC (3 years, 7 months ago) by graaff
Branch: MAIN
Changes since 1.30: +21 -2 lines
Support EAPI=4 in ruby-ng.eclass, fixing bug 358349.

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

  ViewVC Help
Powered by ViewVC 1.1.20