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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.33 - (hide annotations) (download)
Fri Jul 8 11:35:01 2011 UTC (2 years, 9 months ago) by ssuominen
Branch: MAIN
Changes since 1.32: +2 -2 lines
Convert every instance of hasq to has.

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 ssuominen 1.33 # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-ng.eclass,v 1.32 2011/04/25 08:37:26 graaff 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 ssuominen 1.33 has 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 graaff 1.32 if [ -z ${RUBY_S} ]; then
263     sub_S=${P}
264     else
265     sub_S=${RUBY_S}
266     fi
267 graaff 1.31 ;;
268     *)
269     sub_S=${S#${WORKDIR}/}
270     ;;
271     esac
272 flameeyes 1.12
273     # Special case, for the always-lovely GitHub fetches. With this,
274     # we allow the star glob to just expand to whatever directory it's
275     # called.
276 flameeyes 1.28 if [[ ${sub_S} = *"*"* ]]; then
277 flameeyes 1.12 pushd "${WORKDIR}"/all &>/dev/null
278 flameeyes 1.13 sub_S=$(eval ls -d ${sub_S} 2>/dev/null)
279 flameeyes 1.12 popd &>/dev/null
280     fi
281 graaff 1.1
282     environment=$1; shift
283    
284     my_WORKDIR="${WORKDIR}"/${environment}
285     S="${my_WORKDIR}"/"${sub_S}"
286    
287     if [[ -d "${S}" ]]; then
288     pushd "$S" &>/dev/null
289     elif [[ -d "${my_WORKDIR}" ]]; then
290     pushd "${my_WORKDIR}" &>/dev/null
291     else
292     pushd "${WORKDIR}" &>/dev/null
293     fi
294    
295     ebegin "Running ${_PHASE:-${EBUILD_PHASE}} phase for $environment"
296     "$@"
297     popd &>/dev/null
298    
299     S=${old_S}
300     }
301    
302     _ruby_each_implementation() {
303     local invoked=no
304     for _ruby_implementation in ${USE_RUBY}; do
305     # only proceed if it's requested
306     use ruby_targets_${_ruby_implementation} || continue
307    
308 flameeyes 1.27 RUBY=$(ruby_implementation_command ${_ruby_implementation})
309 graaff 1.1 invoked=yes
310    
311     if [[ -n "$1" ]]; then
312 flameeyes 1.27 _ruby_invoke_environment ${_ruby_implementation} "$@"
313 graaff 1.1 fi
314    
315     unset RUBY
316     done
317    
318     [[ ${invoked} == "no" ]] && die "You need to select at least one Ruby implementation by setting RUBY_TARGETS in /etc/make.conf."
319     }
320    
321     # @FUNCTION: ruby-ng_pkg_setup
322     # @DESCRIPTION:
323     # Check whether at least one ruby target implementation is present.
324     ruby-ng_pkg_setup() {
325     # This only checks that at least one implementation is present
326     # before doing anything; by leaving the parameters empty we know
327     # it's a special case.
328     _ruby_each_implementation
329     }
330    
331     # @FUNCTION: ruby-ng_src_unpack
332     # @DESCRIPTION:
333 graaff 1.5 # Unpack the source archive.
334 graaff 1.1 ruby-ng_src_unpack() {
335     mkdir "${WORKDIR}"/all
336     pushd "${WORKDIR}"/all &>/dev/null
337    
338     # We don't support an each-unpack, it's either all or nothing!
339     if type all_ruby_unpack &>/dev/null; then
340     _ruby_invoke_environment all all_ruby_unpack
341     else
342     [[ -n ${A} ]] && unpack ${A}
343     fi
344    
345     popd &>/dev/null
346     }
347    
348     _ruby_apply_patches() {
349     for patch in "${RUBY_PATCHES[@]}"; do
350     if [ -f "${patch}" ]; then
351     epatch "${patch}"
352     elif [ -f "${FILESDIR}/${patch}" ]; then
353     epatch "${FILESDIR}/${patch}"
354     else
355     die "Cannot find patch ${patch}"
356     fi
357     done
358    
359     # This is a special case: instead of executing just in the special
360     # "all" environment, this will actually copy the effects on _all_
361     # the other environments, and is thus executed before the copy
362     type all_ruby_prepare &>/dev/null && all_ruby_prepare
363     }
364    
365     _ruby_source_copy() {
366     # Until we actually find a reason not to, we use hardlinks, this
367     # should reduce the amount of disk space that is wasted by this.
368 fauli 1.30 cp -prl all ${_ruby_implementation} \
369 graaff 1.1 || die "Unable to copy ${_ruby_implementation} environment"
370     }
371    
372     # @FUNCTION: ruby-ng_src_prepare
373     # @DESCRIPTION:
374     # Apply patches and prepare versions for each ruby target
375     # implementation. Also carry out common clean up tasks.
376     ruby-ng_src_prepare() {
377     # Way too many Ruby packages are prepared on OSX without removing
378     # the extra data forks, we do it here to avoid repeating it for
379     # almost every other ebuild.
380     find . -name '._*' -delete
381    
382     _ruby_invoke_environment all _ruby_apply_patches
383    
384 flameeyes 1.7 _PHASE="source copy" \
385     _ruby_each_implementation _ruby_source_copy
386 graaff 1.1
387     if type each_ruby_prepare &>/dev/null; then
388     _ruby_each_implementation each_ruby_prepare
389     fi
390     }
391    
392     # @FUNCTION: ruby-ng_src_configure
393     # @DESCRIPTION:
394     # Configure the package.
395     ruby-ng_src_configure() {
396     if type each_ruby_configure &>/dev/null; then
397     _ruby_each_implementation each_ruby_configure
398     fi
399    
400     type all_ruby_configure &>/dev/null && \
401     _ruby_invoke_environment all all_ruby_configure
402     }
403    
404     # @FUNCTION: ruby-ng_src_compile
405     # @DESCRIPTION:
406     # Compile the package.
407     ruby-ng_src_compile() {
408     if type each_ruby_compile &>/dev/null; then
409     _ruby_each_implementation each_ruby_compile
410     fi
411    
412     type all_ruby_compile &>/dev/null && \
413     _ruby_invoke_environment all all_ruby_compile
414     }
415    
416     # @FUNCTION: ruby-ng_src_test
417     # @DESCRIPTION:
418     # Run tests for the package.
419     ruby-ng_src_test() {
420     if type each_ruby_test &>/dev/null; then
421     _ruby_each_implementation each_ruby_test
422     fi
423    
424     type all_ruby_test &>/dev/null && \
425     _ruby_invoke_environment all all_ruby_test
426     }
427    
428     _each_ruby_check_install() {
429 flameeyes 1.24 local scancmd=scanelf
430     # we have a Mach-O object here
431     [[ ${CHOST} == *-darwin ]] && scancmd=scanmacho
432    
433     has "${EAPI}" 2 && ! use prefix && EPREFIX=
434    
435 graaff 1.1 local libruby_basename=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["LIBRUBY_SO"]')
436 flameeyes 1.25 local libruby_soname=$(basename $(${scancmd} -F "%S#F" -qS "${EPREFIX}/usr/$(get_libdir)/${libruby_basename}") 2>/dev/null)
437 flameeyes 1.2 local sitedir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitedir"]')
438     local sitelibdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]')
439    
440     # Look for wrong files in sitedir
441 flameeyes 1.22 # if [[ -d "${D}${sitedir}" ]]; then
442     # local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}")
443     # if [[ -n ${f} ]]; then
444     # eerror "Found files in sitedir, outsite sitelibdir:"
445     # eerror "${f}"
446     # die "Misplaced files in sitedir"
447     # fi
448     # fi
449 graaff 1.1
450     # The current implementation lacks libruby (i.e.: jruby)
451     [[ -z ${libruby_soname} ]] && return 0
452    
453 flameeyes 1.23 # Check also the gems directory, since we could be installing compiled
454     # extensions via ruby-fakegem; make sure to check only in sitelibdir, since
455     # that's what changes between two implementations (otherwise you'd get false
456     # positives now that Ruby 1.9.2 installs with the same sitedir as 1.8)
457 flameeyes 1.24 ${scancmd} -qnR "${D}${sitelibdir}" "${D}${sitelibdir/site_ruby/gems}" \
458 graaff 1.1 | fgrep -v "${libruby_soname}" \
459     > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log
460    
461     if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then
462 flameeyes 1.15 ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}"
463 graaff 1.1 ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log )
464 flameeyes 1.15 die "Missing links to ${libruby_soname}"
465 graaff 1.1 fi
466     }
467    
468     # @FUNCTION: ruby-ng_src_install
469     # @DESCRIPTION:
470     # Install the package for each ruby target implementation.
471     ruby-ng_src_install() {
472     if type each_ruby_install &>/dev/null; then
473     _ruby_each_implementation each_ruby_install
474     fi
475    
476     type all_ruby_install &>/dev/null && \
477     _ruby_invoke_environment all all_ruby_install
478    
479     _PHASE="check install" \
480     _ruby_each_implementation _each_ruby_check_install
481     }
482    
483 a3li 1.11 # @FUNCTION: ruby_rbconfig_value
484     # @USAGE: rbconfig item
485     # @RETURN: Returns the value of the given rbconfig item of the Ruby interpreter in ${RUBY}.
486     ruby_rbconfig_value() {
487     echo $(${RUBY} -rrbconfig -e "puts Config::CONFIG['$1']")
488     }
489    
490 graaff 1.1 # @FUNCTION: doruby
491     # @USAGE: file [file...]
492     # @DESCRIPTION:
493     # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}.
494     doruby() {
495 flameeyes 1.4 [[ -z ${RUBY} ]] && die "\$RUBY is not set"
496 flameeyes 1.24 has "${EAPI}" 2 && ! use prefix && EPREFIX=
497 graaff 1.1 ( # don't want to pollute calling env
498 flameeyes 1.24 sitelibdir=$(ruby_rbconfig_value 'sitelibdir')
499     insinto ${sitelibdir#${EPREFIX}}
500 graaff 1.1 insopts -m 0644
501     doins "$@"
502     ) || die "failed to install $@"
503     }
504    
505     # @FUNCTION: ruby_get_libruby
506     # @RETURN: The location of libruby*.so belonging to the Ruby interpreter in ${RUBY}.
507     ruby_get_libruby() {
508     ${RUBY} -rrbconfig -e 'puts File.join(Config::CONFIG["libdir"], Config::CONFIG["LIBRUBY"])'
509     }
510    
511     # @FUNCTION: ruby_get_hdrdir
512     # @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}.
513     ruby_get_hdrdir() {
514 a3li 1.11 local rubyhdrdir=$(ruby_rbconfig_value 'rubyhdrdir')
515 graaff 1.1
516     if [[ "${rubyhdrdir}" = "nil" ]] ; then
517 a3li 1.11 rubyhdrdir=$(ruby_rbconfig_value 'archdir')
518 graaff 1.1 fi
519    
520     echo "${rubyhdrdir}"
521     }
522 a3li 1.10
523     # @FUNCTION: ruby_get_version
524     # @RETURN: The version of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
525     ruby_get_version() {
526     local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
527    
528     echo $(${ruby} -e 'puts RUBY_VERSION')
529     }
530    
531     # @FUNCTION: ruby_get_implementation
532     # @RETURN: The implementation of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
533     ruby_get_implementation() {
534     local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
535    
536     case $(${ruby} --version) in
537     *Enterprise*)
538     echo "ree"
539     ;;
540     *jruby*)
541     echo "jruby"
542     ;;
543     *)
544     echo "mri"
545     ;;
546     esac
547     }

  ViewVC Help
Powered by ViewVC 1.1.20