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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.35 - (hide annotations) (download)
Tue Jul 19 05:48:09 2011 UTC (3 years, 5 months ago) by graaff
Branch: MAIN
Changes since 1.34: +8 -1 lines
Add QA warning for deprecated * expansion in S. Use RUBY_S and EAPI=4 instead.

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

  ViewVC Help
Powered by ViewVC 1.1.20