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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.34 - (hide annotations) (download)
Sat Jul 16 09:50:05 2011 UTC (3 years, 1 month ago) by graaff
Branch: MAIN
Changes since 1.33: +15 -1 lines
Add RUBY_QA_ALLOWED_LIBS, bug 347433.

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

  ViewVC Help
Powered by ViewVC 1.1.20