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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (show annotations) (download)
Sat May 22 12:45:03 2010 UTC (4 years, 7 months ago) by flameeyes
Branch: MAIN
Changes since 1.17: +3 -1 lines
Avoid globbing while parsing the dependency string.

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

  ViewVC Help
Powered by ViewVC 1.1.20