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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations) (download)
Fri Jan 15 12:58:20 2010 UTC (4 years, 10 months ago) by flameeyes
Branch: MAIN
Changes since 1.7: +3 -1 lines
When adding a conditional dependency, make sure that the condition is in IUSE.

This in particular fixes the problem of test USE flag not declared
when adding runtime dependencies.

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.8 # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-ng.eclass,v 1.7 2009/12/25 18:01:34 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     _ruby_implementation_depend() {
116     echo "ruby_targets_${1}? ( ${2}[ruby_targets_${1}] )"
117     }
118    
119     _ruby_add_bdepend() {
120     local atom=$1
121     local conditions=$2
122    
123     for condition in $conditions; do
124 flameeyes 1.8 hasq $condition "$IUSE" || IUSE="${IUSE} $condition"
125 graaff 1.1 atom="${condition}? ( ${atom} )"
126     done
127    
128     DEPEND="${DEPEND} ${atom}"
129     RDEPEND="${RDEPEND}"
130     }
131    
132     _ruby_add_rdepend() {
133     local atom=$1
134     local conditions=$2
135    
136     for condition in $conditions; do
137 flameeyes 1.8 hasq $condition "$IUSE" || IUSE="${IUSE} $condition"
138 graaff 1.1 atom="${condition}? ( ${atom} )"
139     done
140    
141     RDEPEND="${RDEPEND} ${atom}"
142     _ruby_add_bdepend "$atom" test
143     }
144    
145     # @FUNCTION: ruby_add_rdepend
146     # @USAGE: [conditions] atom
147     # @DESCRIPTION:
148     # Adds the specified atom(s) with optional use condition(s) to
149     # RDEPEND, taking the current set of ruby targets into account. This
150     # makes sure that all ruby dependencies of the package are installed
151     # for the same ruby targets. Use this function for all ruby
152     # dependencies instead of setting RDEPEND yourself. Both atom and
153     # conditions can be a space-separated list of atoms or conditions.
154     ruby_add_rdepend() {
155     local atoms=
156     local conditions=
157     case $# in
158     1)
159     atoms=$1
160     ;;
161     2)
162     conditions=$1
163     atoms=$2
164     ;;
165     *)
166     die "bad number of arguments to $0"
167     ;;
168     esac
169    
170     for atom in $atoms; do
171     _ruby_add_rdepend "${atom}$(ruby_samelib)" "$conditions"
172     done
173     }
174    
175     # @FUNCTION: ruby_add_bdepend
176     # @USAGE: [conditions] atom
177     # @DESCRIPTION:
178     # Adds the specified atom(s) with optional use condition(s) to both
179     # DEPEND and RDEPEND, taking the current set of ruby targets into
180     # account. This makes sure that all ruby dependencies of the package
181     # are installed for the same ruby targets. Use this function for all
182     # ruby dependencies instead of setting DEPEND and RDEPEND
183     # yourself. Both atom and conditions can be a space-separated list of
184     # atoms or conditions.
185     ruby_add_bdepend() {
186     local atoms=
187     local conditions=
188     case $# in
189     1)
190     atoms=$1
191     ;;
192     2)
193     conditions=$1
194     atoms=$2
195     ;;
196     *)
197     die "bad number of arguments to $0"
198     ;;
199     esac
200    
201     for atom in $atoms; do
202     _ruby_add_bdepend "${atom}$(ruby_samelib)" "$conditions"
203     done
204     }
205    
206     for _ruby_implementation in $USE_RUBY; do
207     IUSE="${IUSE} ruby_targets_${_ruby_implementation}"
208    
209     # If you specify RUBY_OPTIONAL you also need to take care of
210     # ruby useflag and dependency.
211     if [[ ${RUBY_OPTIONAL} != "yes" ]]; then
212     DEPEND="${DEPEND} ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
213     RDEPEND="${RDEPEND} ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
214     fi
215     done
216    
217     _ruby_invoke_environment() {
218     old_S=${S}
219     sub_S=${S#${WORKDIR}}
220    
221     environment=$1; shift
222    
223     my_WORKDIR="${WORKDIR}"/${environment}
224     S="${my_WORKDIR}"/"${sub_S}"
225    
226     if [[ -d "${S}" ]]; then
227     pushd "$S" &>/dev/null
228     elif [[ -d "${my_WORKDIR}" ]]; then
229     pushd "${my_WORKDIR}" &>/dev/null
230     else
231     pushd "${WORKDIR}" &>/dev/null
232     fi
233    
234     ebegin "Running ${_PHASE:-${EBUILD_PHASE}} phase for $environment"
235     "$@"
236     popd &>/dev/null
237    
238     S=${old_S}
239     }
240    
241     _ruby_each_implementation() {
242     local invoked=no
243     for _ruby_implementation in ${USE_RUBY}; do
244     # only proceed if it's requested
245     use ruby_targets_${_ruby_implementation} || continue
246    
247     RUBY=$(type -p $_ruby_implementation 2>/dev/null)
248     invoked=yes
249    
250     if [[ -n "$1" ]]; then
251     _ruby_invoke_environment $_ruby_implementation "$@"
252     fi
253    
254     unset RUBY
255     done
256    
257     [[ ${invoked} == "no" ]] && die "You need to select at least one Ruby implementation by setting RUBY_TARGETS in /etc/make.conf."
258     }
259    
260     # @FUNCTION: ruby-ng_pkg_setup
261     # @DESCRIPTION:
262     # Check whether at least one ruby target implementation is present.
263     ruby-ng_pkg_setup() {
264     # This only checks that at least one implementation is present
265     # before doing anything; by leaving the parameters empty we know
266     # it's a special case.
267     _ruby_each_implementation
268     }
269    
270     # @FUNCTION: ruby-ng_src_unpack
271     # @DESCRIPTION:
272 graaff 1.5 # Unpack the source archive.
273 graaff 1.1 ruby-ng_src_unpack() {
274     mkdir "${WORKDIR}"/all
275     pushd "${WORKDIR}"/all &>/dev/null
276    
277     # We don't support an each-unpack, it's either all or nothing!
278     if type all_ruby_unpack &>/dev/null; then
279     _ruby_invoke_environment all all_ruby_unpack
280     else
281     [[ -n ${A} ]] && unpack ${A}
282     fi
283    
284     popd &>/dev/null
285     }
286    
287     _ruby_apply_patches() {
288     for patch in "${RUBY_PATCHES[@]}"; do
289     if [ -f "${patch}" ]; then
290     epatch "${patch}"
291     elif [ -f "${FILESDIR}/${patch}" ]; then
292     epatch "${FILESDIR}/${patch}"
293     else
294     die "Cannot find patch ${patch}"
295     fi
296     done
297    
298     # This is a special case: instead of executing just in the special
299     # "all" environment, this will actually copy the effects on _all_
300     # the other environments, and is thus executed before the copy
301     type all_ruby_prepare &>/dev/null && all_ruby_prepare
302     }
303    
304     _ruby_source_copy() {
305     # Until we actually find a reason not to, we use hardlinks, this
306     # should reduce the amount of disk space that is wasted by this.
307     cp -prl all ${_ruby_implementation} \
308     || die "Unable to copy ${_ruby_implementation} environment"
309     }
310    
311     # @FUNCTION: ruby-ng_src_prepare
312     # @DESCRIPTION:
313     # Apply patches and prepare versions for each ruby target
314     # implementation. Also carry out common clean up tasks.
315     ruby-ng_src_prepare() {
316     # Way too many Ruby packages are prepared on OSX without removing
317     # the extra data forks, we do it here to avoid repeating it for
318     # almost every other ebuild.
319     find . -name '._*' -delete
320    
321     _ruby_invoke_environment all _ruby_apply_patches
322    
323 flameeyes 1.7 _PHASE="source copy" \
324     _ruby_each_implementation _ruby_source_copy
325 graaff 1.1
326     if type each_ruby_prepare &>/dev/null; then
327     _ruby_each_implementation each_ruby_prepare
328     fi
329     }
330    
331     # @FUNCTION: ruby-ng_src_configure
332     # @DESCRIPTION:
333     # Configure the package.
334     ruby-ng_src_configure() {
335     if type each_ruby_configure &>/dev/null; then
336     _ruby_each_implementation each_ruby_configure
337     fi
338    
339     type all_ruby_configure &>/dev/null && \
340     _ruby_invoke_environment all all_ruby_configure
341     }
342    
343     # @FUNCTION: ruby-ng_src_compile
344     # @DESCRIPTION:
345     # Compile the package.
346     ruby-ng_src_compile() {
347     if type each_ruby_compile &>/dev/null; then
348     _ruby_each_implementation each_ruby_compile
349     fi
350    
351     type all_ruby_compile &>/dev/null && \
352     _ruby_invoke_environment all all_ruby_compile
353     }
354    
355     # @FUNCTION: ruby-ng_src_test
356     # @DESCRIPTION:
357     # Run tests for the package.
358     ruby-ng_src_test() {
359     if type each_ruby_test &>/dev/null; then
360     _ruby_each_implementation each_ruby_test
361     fi
362    
363     type all_ruby_test &>/dev/null && \
364     _ruby_invoke_environment all all_ruby_test
365     }
366    
367     _each_ruby_check_install() {
368     local libruby_basename=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["LIBRUBY_SO"]')
369     local libruby_soname=$(scanelf -qS "/usr/$(get_libdir)/${libruby_basename}" | awk '{ print $1 }')
370 flameeyes 1.2 local sitedir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitedir"]')
371     local sitelibdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]')
372    
373     # Look for wrong files in sitedir
374     if [[ -d "${D}${sitedir}" ]]; then
375     local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}")
376     if [[ -n ${f} ]]; then
377     eerror "Found files in sitedir, outsite sitelibdir:"
378     eerror "${f}"
379     die "Misplaced files in sitedir"
380     fi
381     fi
382 graaff 1.1
383     # The current implementation lacks libruby (i.e.: jruby)
384     [[ -z ${libruby_soname} ]] && return 0
385    
386 flameeyes 1.3 scanelf -qnR "${D}${sitedir}" \
387 graaff 1.1 | fgrep -v "${libruby_soname}" \
388     > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log
389    
390     if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then
391     ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby}"
392     ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log )
393     die "Missing links to ${libruby}"
394     fi
395     }
396    
397     # @FUNCTION: ruby-ng_src_install
398     # @DESCRIPTION:
399     # Install the package for each ruby target implementation.
400     ruby-ng_src_install() {
401     if type each_ruby_install &>/dev/null; then
402     _ruby_each_implementation each_ruby_install
403     fi
404    
405     type all_ruby_install &>/dev/null && \
406     _ruby_invoke_environment all all_ruby_install
407    
408     _PHASE="check install" \
409     _ruby_each_implementation _each_ruby_check_install
410     }
411    
412     # @FUNCTION: doruby
413     # @USAGE: file [file...]
414     # @DESCRIPTION:
415     # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}.
416     doruby() {
417 flameeyes 1.4 [[ -z ${RUBY} ]] && die "\$RUBY is not set"
418 graaff 1.1 ( # don't want to pollute calling env
419 flameeyes 1.4 insinto $(${RUBY} -rrbconfig -e 'print Config::CONFIG["sitelibdir"]')
420 graaff 1.1 insopts -m 0644
421     doins "$@"
422     ) || die "failed to install $@"
423     }
424    
425     # @FUNCTION: ruby_get_libruby
426     # @RETURN: The location of libruby*.so belonging to the Ruby interpreter in ${RUBY}.
427     ruby_get_libruby() {
428     ${RUBY} -rrbconfig -e 'puts File.join(Config::CONFIG["libdir"], Config::CONFIG["LIBRUBY"])'
429     }
430    
431     # @FUNCTION: ruby_get_hdrdir
432     # @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}.
433     ruby_get_hdrdir() {
434     local rubyhdrdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["rubyhdrdir"]')
435    
436     if [[ "${rubyhdrdir}" = "nil" ]] ; then
437     rubyhdrdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["archdir"]')
438     fi
439    
440     echo "${rubyhdrdir}"
441     }

  ViewVC Help
Powered by ViewVC 1.1.20