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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Sat Dec 5 11:32:19 2009 UTC (5 years ago) by flameeyes
Branch: MAIN
Changes since 1.2: +2 -2 lines
Avoid calling ruby twice since we already calculated that directory.

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

  ViewVC Help
Powered by ViewVC 1.1.20