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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.17 - (show annotations) (download)
Sat May 22 12:31:03 2010 UTC (4 years, 2 months ago) by flameeyes
Branch: MAIN
Changes since 1.16: +15 -9 lines
Use a slightly different syntax for expliciting implementation-dependent dependencies.

Rather than using a single, huge USE-conditional per atom, put the dependendencies under conditional
_and_ USE-dependency. This allows for syntax like:

USE_RUBY="ruby18 ruby19"
...

ruby_add_bdepend "test? ( dev-ruby/first )"
USE_RUBY="ruby18" ruby_add_bdepend "test? ( dev-ruby/second )"
USE_RUBY="ruby19" ruby_add_bdepend "test? ( dev-ruby/third )"

1 # Copyright 1999-2009 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-ng.eclass,v 1.16 2010/05/22 12:18:07 flameeyes Exp $
4 #
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_atoms_samelib_generic() {
116 echo "RUBYTARGET? ("
117 for token in $*; do
118 case "$token" in
119 "||" | "(" | ")" | *"?")
120 echo "${token}" ;;
121 *)
122 # TODO we need to deal with merging USE-based
123 # dependencies
124 echo "${token}[RUBYTARGET]" ;;
125 esac
126 done
127 echo ")"
128 }
129
130 _ruby_atoms_samelib() {
131 local atoms=$(_ruby_atoms_samelib_generic "$*")
132
133 for _ruby_implementation in $USE_RUBY; do
134 echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}"
135 done
136 }
137
138 _ruby_wrap_conditions() {
139 local conditions="$1"
140 local atoms="$2"
141
142 for condition in $conditions; do
143 hasq $condition "$IUSE" || IUSE="${IUSE} $condition"
144 atoms="${condition}? ( ${atoms} )"
145 done
146
147 echo "$atoms"
148 }
149
150 # @FUNCTION: ruby_add_rdepend
151 # @USAGE: dependencies
152 # @DESCRIPTION:
153 # Adds the specified dependencies, with use condition(s) to RDEPEND,
154 # taking the current set of ruby targets into account. This makes sure
155 # that all ruby dependencies of the package are installed for the same
156 # ruby targets. Use this function for all ruby dependencies instead of
157 # setting RDEPEND yourself. The list of atoms uses the same syntax as
158 # normal dependencies.
159 #
160 # Note: runtime dependencies are also added as build-time test
161 # dependencies.
162 ruby_add_rdepend() {
163 case $# in
164 1) ;;
165 2)
166 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_rdepend for $CATEGORY/$PF"
167 ruby_add_rdepend "$(_ruby_wrap_conditions "$1" "$2")"
168 return
169 ;;
170 *)
171 die "bad number of arguments to $0"
172 ;;
173 esac
174
175 local dependency=$(_ruby_atoms_samelib "$1")
176
177 RDEPEND="${RDEPEND} $dependency"
178
179 # Add the dependency as a test-dependency since we're going to
180 # execute the code during test phase.
181 DEPEND="${DEPEND} $(_ruby_wrap_conditions test "${dependency}")"
182 }
183
184 # @FUNCTION: ruby_add_bdepend
185 # @USAGE: dependencies
186 # @DESCRIPTION:
187 # Adds the specified dependencies, with use condition(s) to DEPEND,
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 DEPEND yourself. The list of atoms uses the same syntax as
192 # normal dependencies.
193 ruby_add_bdepend() {
194 case $# in
195 1) ;;
196 2)
197 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_bdepend for $CATEGORY/$PF"
198 ruby_add_bdepend "$(_ruby_wrap_conditions "$1" "$2")"
199 return
200 ;;
201 *)
202 die "bad number of arguments to $0"
203 ;;
204 esac
205
206 local dependency=$(_ruby_atoms_samelib "$1")
207
208 DEPEND="${DEPEND} $dependency"
209 }
210
211 for _ruby_implementation in $USE_RUBY; do
212 IUSE="${IUSE} ruby_targets_${_ruby_implementation}"
213
214 # If you specify RUBY_OPTIONAL you also need to take care of
215 # ruby useflag and dependency.
216 if [[ ${RUBY_OPTIONAL} != "yes" ]]; then
217 DEPEND="${DEPEND} ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
218 RDEPEND="${RDEPEND} ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
219 fi
220 done
221
222 _ruby_invoke_environment() {
223 old_S=${S}
224 sub_S=${S#${WORKDIR}/}
225
226 # Special case, for the always-lovely GitHub fetches. With this,
227 # we allow the star glob to just expand to whatever directory it's
228 # called.
229 if [[ ${sub_S} = *"*" ]]; then
230 pushd "${WORKDIR}"/all &>/dev/null
231 sub_S=$(eval ls -d ${sub_S} 2>/dev/null)
232 popd &>/dev/null
233 fi
234
235 environment=$1; shift
236
237 my_WORKDIR="${WORKDIR}"/${environment}
238 S="${my_WORKDIR}"/"${sub_S}"
239
240 if [[ -d "${S}" ]]; then
241 pushd "$S" &>/dev/null
242 elif [[ -d "${my_WORKDIR}" ]]; then
243 pushd "${my_WORKDIR}" &>/dev/null
244 else
245 pushd "${WORKDIR}" &>/dev/null
246 fi
247
248 ebegin "Running ${_PHASE:-${EBUILD_PHASE}} phase for $environment"
249 "$@"
250 popd &>/dev/null
251
252 S=${old_S}
253 }
254
255 _ruby_each_implementation() {
256 local invoked=no
257 for _ruby_implementation in ${USE_RUBY}; do
258 # only proceed if it's requested
259 use ruby_targets_${_ruby_implementation} || continue
260
261 local _ruby_name=$_ruby_implementation
262
263 # Add all USE_RUBY values where the flag name diverts from the binary here
264 case $_ruby_implementation in
265 ree18)
266 _ruby_name=rubyee18
267 ;;
268 esac
269
270 RUBY=$(type -p $_ruby_name 2>/dev/null)
271 invoked=yes
272
273 if [[ -n "$1" ]]; then
274 _ruby_invoke_environment $_ruby_implementation "$@"
275 fi
276
277 unset RUBY
278 done
279
280 [[ ${invoked} == "no" ]] && die "You need to select at least one Ruby implementation by setting RUBY_TARGETS in /etc/make.conf."
281 }
282
283 # @FUNCTION: ruby-ng_pkg_setup
284 # @DESCRIPTION:
285 # Check whether at least one ruby target implementation is present.
286 ruby-ng_pkg_setup() {
287 # This only checks that at least one implementation is present
288 # before doing anything; by leaving the parameters empty we know
289 # it's a special case.
290 _ruby_each_implementation
291 }
292
293 # @FUNCTION: ruby-ng_src_unpack
294 # @DESCRIPTION:
295 # Unpack the source archive.
296 ruby-ng_src_unpack() {
297 mkdir "${WORKDIR}"/all
298 pushd "${WORKDIR}"/all &>/dev/null
299
300 # We don't support an each-unpack, it's either all or nothing!
301 if type all_ruby_unpack &>/dev/null; then
302 _ruby_invoke_environment all all_ruby_unpack
303 else
304 [[ -n ${A} ]] && unpack ${A}
305 fi
306
307 popd &>/dev/null
308 }
309
310 _ruby_apply_patches() {
311 for patch in "${RUBY_PATCHES[@]}"; do
312 if [ -f "${patch}" ]; then
313 epatch "${patch}"
314 elif [ -f "${FILESDIR}/${patch}" ]; then
315 epatch "${FILESDIR}/${patch}"
316 else
317 die "Cannot find patch ${patch}"
318 fi
319 done
320
321 # This is a special case: instead of executing just in the special
322 # "all" environment, this will actually copy the effects on _all_
323 # the other environments, and is thus executed before the copy
324 type all_ruby_prepare &>/dev/null && all_ruby_prepare
325 }
326
327 _ruby_source_copy() {
328 # Until we actually find a reason not to, we use hardlinks, this
329 # should reduce the amount of disk space that is wasted by this.
330 cp -prl all ${_ruby_implementation} \
331 || die "Unable to copy ${_ruby_implementation} environment"
332 }
333
334 # @FUNCTION: ruby-ng_src_prepare
335 # @DESCRIPTION:
336 # Apply patches and prepare versions for each ruby target
337 # implementation. Also carry out common clean up tasks.
338 ruby-ng_src_prepare() {
339 # Way too many Ruby packages are prepared on OSX without removing
340 # the extra data forks, we do it here to avoid repeating it for
341 # almost every other ebuild.
342 find . -name '._*' -delete
343
344 _ruby_invoke_environment all _ruby_apply_patches
345
346 _PHASE="source copy" \
347 _ruby_each_implementation _ruby_source_copy
348
349 if type each_ruby_prepare &>/dev/null; then
350 _ruby_each_implementation each_ruby_prepare
351 fi
352 }
353
354 # @FUNCTION: ruby-ng_src_configure
355 # @DESCRIPTION:
356 # Configure the package.
357 ruby-ng_src_configure() {
358 if type each_ruby_configure &>/dev/null; then
359 _ruby_each_implementation each_ruby_configure
360 fi
361
362 type all_ruby_configure &>/dev/null && \
363 _ruby_invoke_environment all all_ruby_configure
364 }
365
366 # @FUNCTION: ruby-ng_src_compile
367 # @DESCRIPTION:
368 # Compile the package.
369 ruby-ng_src_compile() {
370 if type each_ruby_compile &>/dev/null; then
371 _ruby_each_implementation each_ruby_compile
372 fi
373
374 type all_ruby_compile &>/dev/null && \
375 _ruby_invoke_environment all all_ruby_compile
376 }
377
378 # @FUNCTION: ruby-ng_src_test
379 # @DESCRIPTION:
380 # Run tests for the package.
381 ruby-ng_src_test() {
382 if type each_ruby_test &>/dev/null; then
383 _ruby_each_implementation each_ruby_test
384 fi
385
386 type all_ruby_test &>/dev/null && \
387 _ruby_invoke_environment all all_ruby_test
388 }
389
390 _each_ruby_check_install() {
391 local libruby_basename=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["LIBRUBY_SO"]')
392 local libruby_soname=$(scanelf -qS "/usr/$(get_libdir)/${libruby_basename}" | awk '{ print $1 }')
393 local sitedir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitedir"]')
394 local sitelibdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]')
395
396 # Look for wrong files in sitedir
397 if [[ -d "${D}${sitedir}" ]]; then
398 local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}")
399 if [[ -n ${f} ]]; then
400 eerror "Found files in sitedir, outsite sitelibdir:"
401 eerror "${f}"
402 die "Misplaced files in sitedir"
403 fi
404 fi
405
406 # The current implementation lacks libruby (i.e.: jruby)
407 [[ -z ${libruby_soname} ]] && return 0
408
409 scanelf -qnR "${D}${sitedir}" \
410 | fgrep -v "${libruby_soname}" \
411 > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log
412
413 if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then
414 ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}"
415 ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log )
416 die "Missing links to ${libruby_soname}"
417 fi
418 }
419
420 # @FUNCTION: ruby-ng_src_install
421 # @DESCRIPTION:
422 # Install the package for each ruby target implementation.
423 ruby-ng_src_install() {
424 if type each_ruby_install &>/dev/null; then
425 _ruby_each_implementation each_ruby_install
426 fi
427
428 type all_ruby_install &>/dev/null && \
429 _ruby_invoke_environment all all_ruby_install
430
431 _PHASE="check install" \
432 _ruby_each_implementation _each_ruby_check_install
433 }
434
435 # @FUNCTION: ruby_rbconfig_value
436 # @USAGE: rbconfig item
437 # @RETURN: Returns the value of the given rbconfig item of the Ruby interpreter in ${RUBY}.
438 ruby_rbconfig_value() {
439 echo $(${RUBY} -rrbconfig -e "puts Config::CONFIG['$1']")
440 }
441
442 # @FUNCTION: doruby
443 # @USAGE: file [file...]
444 # @DESCRIPTION:
445 # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}.
446 doruby() {
447 [[ -z ${RUBY} ]] && die "\$RUBY is not set"
448 ( # don't want to pollute calling env
449 insinto $(ruby_rbconfig_value 'sitelibdir')
450 insopts -m 0644
451 doins "$@"
452 ) || die "failed to install $@"
453 }
454
455 # @FUNCTION: ruby_get_libruby
456 # @RETURN: The location of libruby*.so belonging to the Ruby interpreter in ${RUBY}.
457 ruby_get_libruby() {
458 ${RUBY} -rrbconfig -e 'puts File.join(Config::CONFIG["libdir"], Config::CONFIG["LIBRUBY"])'
459 }
460
461 # @FUNCTION: ruby_get_hdrdir
462 # @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}.
463 ruby_get_hdrdir() {
464 local rubyhdrdir=$(ruby_rbconfig_value 'rubyhdrdir')
465
466 if [[ "${rubyhdrdir}" = "nil" ]] ; then
467 rubyhdrdir=$(ruby_rbconfig_value 'archdir')
468 fi
469
470 echo "${rubyhdrdir}"
471 }
472
473 # @FUNCTION: ruby_get_version
474 # @RETURN: The version of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
475 ruby_get_version() {
476 local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
477
478 echo $(${ruby} -e 'puts RUBY_VERSION')
479 }
480
481 # @FUNCTION: ruby_get_implementation
482 # @RETURN: The implementation of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
483 ruby_get_implementation() {
484 local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
485
486 case $(${ruby} --version) in
487 *Enterprise*)
488 echo "ree"
489 ;;
490 *jruby*)
491 echo "jruby"
492 ;;
493 *)
494 echo "mri"
495 ;;
496 esac
497 }

  ViewVC Help
Powered by ViewVC 1.1.20