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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.26 - (show annotations) (download)
Sun Aug 22 07:28:24 2010 UTC (4 years, 4 months ago) by graaff
Branch: MAIN
Changes since 1.25: +3 -1 lines
Update ruby eclass documentation.

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.25 2010/07/30 17:28:53 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 # @REQUIRED
37 # @DESCRIPTION:
38 # This variable contains a space separated list of targets (see above) a package
39 # is compatible to. It must be set before the `inherit' call. There is no
40 # default. All ebuilds are expected to set this variable.
41
42 # @ECLASS-VARIABLE: RUBY_PATCHES
43 # @DEFAULT_UNSET
44 # @DESCRIPTION:
45 # A String or Array of filenames of patches to apply to all implementations.
46
47 # @ECLASS-VARIABLE: RUBY_OPTIONAL
48 # @DESCRIPTION:
49 # Set the value to "yes" to make the dependency on a Ruby interpreter optional.
50
51 inherit eutils toolchain-funcs
52
53 EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_setup
54
55 case ${EAPI} in
56 0|1)
57 die "Unsupported EAPI=${EAPI} (too old) for ruby-ng.eclass" ;;
58 2|3) ;;
59 *)
60 die "Unknown EAPI=${EAPI} for ruby-ng.eclass"
61 esac
62
63 # @FUNCTION: ruby_implementation_depend
64 # @USAGE: target [comparator [version]]
65 # @RETURN: Package atom of a Ruby implementation to be used in dependencies.
66 # @DESCRIPTION:
67 # This function returns the formal package atom for a Ruby implementation.
68 #
69 # `target' has to be one of the valid values for USE_RUBY (see above)
70 #
71 # Set `comparator' and `version' to include a comparator (=, >=, etc.) and a
72 # version string to the returned string
73 ruby_implementation_depend() {
74 local rubypn=
75 local rubyslot=
76
77 case $1 in
78 ruby18)
79 rubypn="dev-lang/ruby"
80 rubyslot=":1.8"
81 ;;
82 ruby19)
83 rubypn="dev-lang/ruby"
84 rubyslot=":1.9"
85 ;;
86 ree18)
87 rubypn="dev-lang/ruby-enterprise"
88 rubyslot=":1.8"
89 ;;
90 jruby)
91 rubypn="dev-java/jruby"
92 rubyslot=""
93 ;;
94 *) die "$1: unknown Ruby implementation"
95 esac
96
97 echo "$2${rubypn}$3${rubyslot}"
98 }
99
100 # @FUNCTION: ruby_samelib
101 # @RETURN: use flag string with current ruby implementations
102 # @DESCRIPTION:
103 # Convenience function to output the use dependency part of a
104 # dependency. Used as a building block for ruby_add_rdepend() and
105 # ruby_add_bdepend(), but may also be useful in an ebuild to specify
106 # more complex dependencies.
107 ruby_samelib() {
108 local res=
109 for _ruby_implementation in $USE_RUBY; do
110 has -${_ruby_implementation} $@ || \
111 res="${res}ruby_targets_${_ruby_implementation}?,"
112 done
113
114 echo "[${res%,}]"
115 }
116
117 _ruby_atoms_samelib_generic() {
118 eshopts_push -o noglob
119 echo "RUBYTARGET? ("
120 for token in $*; do
121 case "$token" in
122 "||" | "(" | ")" | *"?")
123 echo "${token}" ;;
124 *])
125 echo "${token%[*}[RUBYTARGET,${token/*[}" ;;
126 *)
127 echo "${token}[RUBYTARGET]" ;;
128 esac
129 done
130 echo ")"
131 eshopts_pop
132 }
133
134 _ruby_atoms_samelib() {
135 local atoms=$(_ruby_atoms_samelib_generic "$*")
136
137 for _ruby_implementation in $USE_RUBY; do
138 echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}"
139 done
140 }
141
142 _ruby_wrap_conditions() {
143 local conditions="$1"
144 local atoms="$2"
145
146 for condition in $conditions; do
147 atoms="${condition}? ( ${atoms} )"
148 done
149
150 echo "$atoms"
151 }
152
153 # @FUNCTION: ruby_add_rdepend
154 # @USAGE: dependencies
155 # @DESCRIPTION:
156 # Adds the specified dependencies, with use condition(s) to RDEPEND,
157 # taking the current set of ruby targets into account. This makes sure
158 # that all ruby dependencies of the package are installed for the same
159 # ruby targets. Use this function for all ruby dependencies instead of
160 # setting RDEPEND yourself. The list of atoms uses the same syntax as
161 # normal dependencies.
162 #
163 # Note: runtime dependencies are also added as build-time test
164 # dependencies.
165 ruby_add_rdepend() {
166 case $# in
167 1) ;;
168 2)
169 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_rdepend for $CATEGORY/$PF"
170 ruby_add_rdepend "$(_ruby_wrap_conditions "$1" "$2")"
171 return
172 ;;
173 *)
174 die "bad number of arguments to $0"
175 ;;
176 esac
177
178 local dependency=$(_ruby_atoms_samelib "$1")
179
180 RDEPEND="${RDEPEND} $dependency"
181
182 # Add the dependency as a test-dependency since we're going to
183 # execute the code during test phase.
184 DEPEND="${DEPEND} test? ( ${dependency} )"
185 hasq test "$IUSE" || IUSE="${IUSE} test"
186 }
187
188 # @FUNCTION: ruby_add_bdepend
189 # @USAGE: dependencies
190 # @DESCRIPTION:
191 # Adds the specified dependencies, with use condition(s) to DEPEND,
192 # taking the current set of ruby targets into account. This makes sure
193 # that all ruby dependencies of the package are installed for the same
194 # ruby targets. Use this function for all ruby dependencies instead of
195 # setting DEPEND yourself. The list of atoms uses the same syntax as
196 # normal dependencies.
197 ruby_add_bdepend() {
198 case $# in
199 1) ;;
200 2)
201 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_bdepend for $CATEGORY/$PF"
202 ruby_add_bdepend "$(_ruby_wrap_conditions "$1" "$2")"
203 return
204 ;;
205 *)
206 die "bad number of arguments to $0"
207 ;;
208 esac
209
210 local dependency=$(_ruby_atoms_samelib "$1")
211
212 DEPEND="${DEPEND} $dependency"
213 RDEPEND="${RDEPEND}"
214 }
215
216 for _ruby_implementation in $USE_RUBY; do
217 IUSE="${IUSE} ruby_targets_${_ruby_implementation}"
218
219 # If you specify RUBY_OPTIONAL you also need to take care of
220 # ruby useflag and dependency.
221 if [[ ${RUBY_OPTIONAL} != "yes" ]]; then
222 DEPEND="${DEPEND} ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
223 RDEPEND="${RDEPEND} ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
224 fi
225 done
226
227 _ruby_invoke_environment() {
228 old_S=${S}
229 sub_S=${S#${WORKDIR}/}
230
231 # Special case, for the always-lovely GitHub fetches. With this,
232 # we allow the star glob to just expand to whatever directory it's
233 # called.
234 if [[ ${sub_S} = *"*" ]]; then
235 pushd "${WORKDIR}"/all &>/dev/null
236 sub_S=$(eval ls -d ${sub_S} 2>/dev/null)
237 popd &>/dev/null
238 fi
239
240 environment=$1; shift
241
242 my_WORKDIR="${WORKDIR}"/${environment}
243 S="${my_WORKDIR}"/"${sub_S}"
244
245 if [[ -d "${S}" ]]; then
246 pushd "$S" &>/dev/null
247 elif [[ -d "${my_WORKDIR}" ]]; then
248 pushd "${my_WORKDIR}" &>/dev/null
249 else
250 pushd "${WORKDIR}" &>/dev/null
251 fi
252
253 ebegin "Running ${_PHASE:-${EBUILD_PHASE}} phase for $environment"
254 "$@"
255 popd &>/dev/null
256
257 S=${old_S}
258 }
259
260 _ruby_each_implementation() {
261 local invoked=no
262 for _ruby_implementation in ${USE_RUBY}; do
263 # only proceed if it's requested
264 use ruby_targets_${_ruby_implementation} || continue
265
266 local _ruby_name=$_ruby_implementation
267
268 # Add all USE_RUBY values where the flag name diverts from the binary here
269 case $_ruby_implementation in
270 ree18)
271 _ruby_name=rubyee18
272 ;;
273 esac
274
275 RUBY=$(type -p $_ruby_name 2>/dev/null)
276 invoked=yes
277
278 if [[ -n "$1" ]]; then
279 _ruby_invoke_environment $_ruby_implementation "$@"
280 fi
281
282 unset RUBY
283 done
284
285 [[ ${invoked} == "no" ]] && die "You need to select at least one Ruby implementation by setting RUBY_TARGETS in /etc/make.conf."
286 }
287
288 # @FUNCTION: ruby-ng_pkg_setup
289 # @DESCRIPTION:
290 # Check whether at least one ruby target implementation is present.
291 ruby-ng_pkg_setup() {
292 # This only checks that at least one implementation is present
293 # before doing anything; by leaving the parameters empty we know
294 # it's a special case.
295 _ruby_each_implementation
296 }
297
298 # @FUNCTION: ruby-ng_src_unpack
299 # @DESCRIPTION:
300 # Unpack the source archive.
301 ruby-ng_src_unpack() {
302 mkdir "${WORKDIR}"/all
303 pushd "${WORKDIR}"/all &>/dev/null
304
305 # We don't support an each-unpack, it's either all or nothing!
306 if type all_ruby_unpack &>/dev/null; then
307 _ruby_invoke_environment all all_ruby_unpack
308 else
309 [[ -n ${A} ]] && unpack ${A}
310 fi
311
312 popd &>/dev/null
313 }
314
315 _ruby_apply_patches() {
316 for patch in "${RUBY_PATCHES[@]}"; do
317 if [ -f "${patch}" ]; then
318 epatch "${patch}"
319 elif [ -f "${FILESDIR}/${patch}" ]; then
320 epatch "${FILESDIR}/${patch}"
321 else
322 die "Cannot find patch ${patch}"
323 fi
324 done
325
326 # This is a special case: instead of executing just in the special
327 # "all" environment, this will actually copy the effects on _all_
328 # the other environments, and is thus executed before the copy
329 type all_ruby_prepare &>/dev/null && all_ruby_prepare
330 }
331
332 _ruby_source_copy() {
333 # Until we actually find a reason not to, we use hardlinks, this
334 # should reduce the amount of disk space that is wasted by this.
335 cp -prl all ${_ruby_implementation} \
336 || die "Unable to copy ${_ruby_implementation} environment"
337 }
338
339 # @FUNCTION: ruby-ng_src_prepare
340 # @DESCRIPTION:
341 # Apply patches and prepare versions for each ruby target
342 # implementation. Also carry out common clean up tasks.
343 ruby-ng_src_prepare() {
344 # Way too many Ruby packages are prepared on OSX without removing
345 # the extra data forks, we do it here to avoid repeating it for
346 # almost every other ebuild.
347 find . -name '._*' -delete
348
349 _ruby_invoke_environment all _ruby_apply_patches
350
351 _PHASE="source copy" \
352 _ruby_each_implementation _ruby_source_copy
353
354 if type each_ruby_prepare &>/dev/null; then
355 _ruby_each_implementation each_ruby_prepare
356 fi
357 }
358
359 # @FUNCTION: ruby-ng_src_configure
360 # @DESCRIPTION:
361 # Configure the package.
362 ruby-ng_src_configure() {
363 if type each_ruby_configure &>/dev/null; then
364 _ruby_each_implementation each_ruby_configure
365 fi
366
367 type all_ruby_configure &>/dev/null && \
368 _ruby_invoke_environment all all_ruby_configure
369 }
370
371 # @FUNCTION: ruby-ng_src_compile
372 # @DESCRIPTION:
373 # Compile the package.
374 ruby-ng_src_compile() {
375 if type each_ruby_compile &>/dev/null; then
376 _ruby_each_implementation each_ruby_compile
377 fi
378
379 type all_ruby_compile &>/dev/null && \
380 _ruby_invoke_environment all all_ruby_compile
381 }
382
383 # @FUNCTION: ruby-ng_src_test
384 # @DESCRIPTION:
385 # Run tests for the package.
386 ruby-ng_src_test() {
387 if type each_ruby_test &>/dev/null; then
388 _ruby_each_implementation each_ruby_test
389 fi
390
391 type all_ruby_test &>/dev/null && \
392 _ruby_invoke_environment all all_ruby_test
393 }
394
395 _each_ruby_check_install() {
396 local scancmd=scanelf
397 # we have a Mach-O object here
398 [[ ${CHOST} == *-darwin ]] && scancmd=scanmacho
399
400 has "${EAPI}" 2 && ! use prefix && EPREFIX=
401
402 local libruby_basename=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["LIBRUBY_SO"]')
403 local libruby_soname=$(basename $(${scancmd} -F "%S#F" -qS "${EPREFIX}/usr/$(get_libdir)/${libruby_basename}") 2>/dev/null)
404 local sitedir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitedir"]')
405 local sitelibdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]')
406
407 # Look for wrong files in sitedir
408 # if [[ -d "${D}${sitedir}" ]]; then
409 # local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}")
410 # if [[ -n ${f} ]]; then
411 # eerror "Found files in sitedir, outsite sitelibdir:"
412 # eerror "${f}"
413 # die "Misplaced files in sitedir"
414 # fi
415 # fi
416
417 # The current implementation lacks libruby (i.e.: jruby)
418 [[ -z ${libruby_soname} ]] && return 0
419
420 # Check also the gems directory, since we could be installing compiled
421 # extensions via ruby-fakegem; make sure to check only in sitelibdir, since
422 # that's what changes between two implementations (otherwise you'd get false
423 # positives now that Ruby 1.9.2 installs with the same sitedir as 1.8)
424 ${scancmd} -qnR "${D}${sitelibdir}" "${D}${sitelibdir/site_ruby/gems}" \
425 | fgrep -v "${libruby_soname}" \
426 > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log
427
428 if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then
429 ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}"
430 ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log )
431 die "Missing links to ${libruby_soname}"
432 fi
433 }
434
435 # @FUNCTION: ruby-ng_src_install
436 # @DESCRIPTION:
437 # Install the package for each ruby target implementation.
438 ruby-ng_src_install() {
439 if type each_ruby_install &>/dev/null; then
440 _ruby_each_implementation each_ruby_install
441 fi
442
443 type all_ruby_install &>/dev/null && \
444 _ruby_invoke_environment all all_ruby_install
445
446 _PHASE="check install" \
447 _ruby_each_implementation _each_ruby_check_install
448 }
449
450 # @FUNCTION: ruby_rbconfig_value
451 # @USAGE: rbconfig item
452 # @RETURN: Returns the value of the given rbconfig item of the Ruby interpreter in ${RUBY}.
453 ruby_rbconfig_value() {
454 echo $(${RUBY} -rrbconfig -e "puts Config::CONFIG['$1']")
455 }
456
457 # @FUNCTION: doruby
458 # @USAGE: file [file...]
459 # @DESCRIPTION:
460 # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}.
461 doruby() {
462 [[ -z ${RUBY} ]] && die "\$RUBY is not set"
463 has "${EAPI}" 2 && ! use prefix && EPREFIX=
464 ( # don't want to pollute calling env
465 sitelibdir=$(ruby_rbconfig_value 'sitelibdir')
466 insinto ${sitelibdir#${EPREFIX}}
467 insopts -m 0644
468 doins "$@"
469 ) || die "failed to install $@"
470 }
471
472 # @FUNCTION: ruby_get_libruby
473 # @RETURN: The location of libruby*.so belonging to the Ruby interpreter in ${RUBY}.
474 ruby_get_libruby() {
475 ${RUBY} -rrbconfig -e 'puts File.join(Config::CONFIG["libdir"], Config::CONFIG["LIBRUBY"])'
476 }
477
478 # @FUNCTION: ruby_get_hdrdir
479 # @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}.
480 ruby_get_hdrdir() {
481 local rubyhdrdir=$(ruby_rbconfig_value 'rubyhdrdir')
482
483 if [[ "${rubyhdrdir}" = "nil" ]] ; then
484 rubyhdrdir=$(ruby_rbconfig_value 'archdir')
485 fi
486
487 echo "${rubyhdrdir}"
488 }
489
490 # @FUNCTION: ruby_get_version
491 # @RETURN: The version of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
492 ruby_get_version() {
493 local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
494
495 echo $(${ruby} -e 'puts RUBY_VERSION')
496 }
497
498 # @FUNCTION: ruby_get_implementation
499 # @RETURN: The implementation of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
500 ruby_get_implementation() {
501 local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
502
503 case $(${ruby} --version) in
504 *Enterprise*)
505 echo "ree"
506 ;;
507 *jruby*)
508 echo "jruby"
509 ;;
510 *)
511 echo "mri"
512 ;;
513 esac
514 }

  ViewVC Help
Powered by ViewVC 1.1.20