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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (show annotations) (download)
Sat May 22 12:18:07 2010 UTC (4 years, 3 months ago) by flameeyes
Branch: MAIN
Changes since 1.15: +49 -59 lines
Allow for standard depend syntax in the single parameter form of ruby_add_rdepend and ruby_add_bdepend.

Make the two parameters form throw a warning for gentoo developers only (for now), and call back the
single-parameter function after wrapping. Update documentation to only suggest using the new syntax.

This allows dropping _ruby_add_rdepend and _ruby_add_bdepend convenience functions, and rather adds a
_ruby_wrap_conditions function.

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

  ViewVC Help
Powered by ViewVC 1.1.20