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

Diff of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.3 Revision 1.35
1# Copyright 1999-2004 Gentoo Foundation 1# Copyright 1999-2009 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/ruby-ng.eclass,v 1.3 2009/12/05 11:32:19 flameeyes Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/ruby-ng.eclass,v 1.35 2011/07/19 05:48:09 graaff Exp $
4# 4#
5# @ECLASS: ruby-ng.eclass 5# @ECLASS: ruby-ng.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Ruby herd <ruby@gentoo.org> 7# Ruby herd <ruby@gentoo.org>
8# 8#
31# 31#
32# * each_ruby_configure 32# * each_ruby_configure
33# * all_ruby_configure 33# * all_ruby_configure
34 34
35# @ECLASS-VARIABLE: USE_RUBY 35# @ECLASS-VARIABLE: USE_RUBY
36# @REQUIRED
36# @DESCRIPTION: 37# @DESCRIPTION:
37# This variable contains a space separated list of targets (see above) a package 38# 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# 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# default. All ebuilds are expected to set this variable.
40 41
41# @ECLASS-VARIABLE: RUBY_PATCHES 42# @ECLASS-VARIABLE: RUBY_PATCHES
43# @DEFAULT_UNSET
42# @DESCRIPTION: 44# @DESCRIPTION:
43# A String or Array of filenames of patches to apply to all implementations. 45# A String or Array of filenames of patches to apply to all implementations.
44 46
45# @ECLASS-VARIABLE: RUBY_OPTIONAL 47# @ECLASS-VARIABLE: RUBY_OPTIONAL
46# @DESCRIPTION: 48# @DESCRIPTION:
47# Set the value to "yes" to make the dependency on a Ruby interpreter optional. 49# Set the value to "yes" to make the dependency on a Ruby interpreter optional.
50
51# @ECLASS-VARIABLE: RUBY_S
52# @DEFAULT_UNSET
53# @DESCRIPTION:
54# If defined this variable determines the source directory name after
55# unpacking. This defaults to the name of the package. Note that this
56# variable supports a wildcard mechanism to help with github tarballs
57# that contain the commit hash as part of the directory name.
58
59# @ECLASS-VARIABLE: RUBY_QA_ALLOWED_LIBS
60# @DEFAULT_UNSET
61# @DESCRIPTION:
62# If defined this variable contains a whitelist of shared objects that
63# are allowed to exist even if they don't link to libruby. This avoids
64# the QA check that makes this mandatory. This is most likely not what
65# you are looking for if you get the related "Missing links" QA warning,
66# since the proper fix is almost always to make sure the shared object
67# is linked against libruby. There are cases were this is not the case
68# and the shared object is generic code to be used in some other way
69# (e.g. selenium's firefox driver extension). When set this argument is
70# passed to "grep -E" to remove reporting of these shared objects.
48 71
49inherit eutils toolchain-funcs 72inherit eutils toolchain-funcs
50 73
51EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_setup 74EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_setup
52 75
53case ${EAPI} in 76case ${EAPI} in
54 0|1) 77 0|1)
55 die "Unsupported EAPI=${EAPI} (too old) for ruby-ng.eclass" ;; 78 die "Unsupported EAPI=${EAPI} (too old) for ruby-ng.eclass" ;;
56 2) ;; 79 2|3) ;;
80 4)
81 # S is no longer automatically assigned when it doesn't exist.
82 S="${WORKDIR}"
83 ;;
57 *) 84 *)
58 die "Unknown EAPI=${EAPI} for ruby-ng.eclass" 85 die "Unknown EAPI=${EAPI} for ruby-ng.eclass"
59esac 86esac
60 87
61# @FUNCTION: ruby_implementation_depend 88# @FUNCTION: ruby_implementation_depend
110 done 137 done
111 138
112 echo "[${res%,}]" 139 echo "[${res%,}]"
113} 140}
114 141
142_ruby_atoms_samelib_generic() {
143 eshopts_push -o noglob
144 echo "RUBYTARGET? ("
145 for token in $*; do
146 case "$token" in
147 "||" | "(" | ")" | *"?")
148 echo "${token}" ;;
149 *])
150 echo "${token%[*}[RUBYTARGET,${token/*[}" ;;
151 *)
152 echo "${token}[RUBYTARGET]" ;;
153 esac
154 done
155 echo ")"
156 eshopts_pop
157}
158
159# @FUNCTION: ruby_implementation_command
160# @RETURN: the path to the given ruby implementation
161# @DESCRIPTION:
162# Not all implementations have the same command basename as the
163# target; namely Ruby Enterprise 1.8 uses ree18 and rubyee18
164# respectively. This function translate between the two
115_ruby_implementation_depend() { 165ruby_implementation_command() {
116 echo "ruby_targets_${1}? ( ${2}[ruby_targets_${1}] )" 166 local _ruby_name=$1
117}
118 167
119_ruby_add_bdepend() { 168 # Add all USE_RUBY values where the flag name diverts from the binary here
120 local atom=$1 169 case $1 in
170 ree18)
171 _ruby_name=rubyee18
172 ;;
173 esac
174
175 echo $(type -p ${_ruby_name} 2>/dev/null)
176}
177
178_ruby_atoms_samelib() {
179 local atoms=$(_ruby_atoms_samelib_generic "$*")
180
181 for _ruby_implementation in $USE_RUBY; do
182 echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}"
183 done
184}
185
186_ruby_wrap_conditions() {
121 local conditions=$2 187 local conditions="$1"
188 local atoms="$2"
122 189
123 for condition in $conditions; do 190 for condition in $conditions; do
124 atom="${condition}? ( ${atom} )" 191 atoms="${condition}? ( ${atoms} )"
125 done 192 done
126 193
127 DEPEND="${DEPEND} ${atom}" 194 echo "$atoms"
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} 195}
142 196
143# @FUNCTION: ruby_add_rdepend 197# @FUNCTION: ruby_add_rdepend
144# @USAGE: [conditions] atom 198# @USAGE: dependencies
145# @DESCRIPTION: 199# @DESCRIPTION:
146# Adds the specified atom(s) with optional use condition(s) to 200# Adds the specified dependencies, with use condition(s) to RDEPEND,
147# RDEPEND, taking the current set of ruby targets into account. This 201# taking the current set of ruby targets into account. This makes sure
148# makes sure that all ruby dependencies of the package are installed 202# that all ruby dependencies of the package are installed for the same
149# for the same ruby targets. Use this function for all ruby 203# ruby targets. Use this function for all ruby dependencies instead of
150# dependencies instead of setting RDEPEND yourself. Both atom and 204# setting RDEPEND yourself. The list of atoms uses the same syntax as
151# conditions can be a space-separated list of atoms or conditions. 205# normal dependencies.
206#
207# Note: runtime dependencies are also added as build-time test
208# dependencies.
152ruby_add_rdepend() { 209ruby_add_rdepend() {
153 local atoms=
154 local conditions=
155 case $# in 210 case $# in
156 1) 211 1) ;;
157 atoms=$1
158 ;;
159 2) 212 2)
160 conditions=$1 213 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_rdepend for $CATEGORY/$PF"
161 atoms=$2 214 ruby_add_rdepend "$(_ruby_wrap_conditions "$1" "$2")"
215 return
162 ;; 216 ;;
163 *) 217 *)
164 die "bad number of arguments to $0" 218 die "bad number of arguments to $0"
165 ;; 219 ;;
166 esac 220 esac
167 221
168 for atom in $atoms; do 222 local dependency=$(_ruby_atoms_samelib "$1")
169 _ruby_add_rdepend "${atom}$(ruby_samelib)" "$conditions" 223
170 done 224 RDEPEND="${RDEPEND} $dependency"
225
226 # Add the dependency as a test-dependency since we're going to
227 # execute the code during test phase.
228 DEPEND="${DEPEND} test? ( ${dependency} )"
229 has test "$IUSE" || IUSE="${IUSE} test"
171} 230}
172 231
173# @FUNCTION: ruby_add_bdepend 232# @FUNCTION: ruby_add_bdepend
174# @USAGE: [conditions] atom 233# @USAGE: dependencies
175# @DESCRIPTION: 234# @DESCRIPTION:
176# Adds the specified atom(s) with optional use condition(s) to both 235# Adds the specified dependencies, with use condition(s) to DEPEND,
177# DEPEND and RDEPEND, taking the current set of ruby targets into 236# taking the current set of ruby targets into account. This makes sure
178# account. This makes sure that all ruby dependencies of the package 237# that all ruby dependencies of the package are installed for the same
179# are installed for the same ruby targets. Use this function for all 238# ruby targets. Use this function for all ruby dependencies instead of
180# ruby dependencies instead of setting DEPEND and RDEPEND 239# setting DEPEND yourself. The list of atoms uses the same syntax as
181# yourself. Both atom and conditions can be a space-separated list of 240# normal dependencies.
182# atoms or conditions.
183ruby_add_bdepend() { 241ruby_add_bdepend() {
184 local atoms=
185 local conditions=
186 case $# in 242 case $# in
187 1) 243 1) ;;
188 atoms=$1
189 ;;
190 2) 244 2)
191 conditions=$1 245 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_bdepend for $CATEGORY/$PF"
192 atoms=$2 246 ruby_add_bdepend "$(_ruby_wrap_conditions "$1" "$2")"
247 return
193 ;; 248 ;;
194 *) 249 *)
195 die "bad number of arguments to $0" 250 die "bad number of arguments to $0"
196 ;; 251 ;;
197 esac 252 esac
198 253
199 for atom in $atoms; do 254 local dependency=$(_ruby_atoms_samelib "$1")
200 _ruby_add_bdepend "${atom}$(ruby_samelib)" "$conditions" 255
201 done 256 DEPEND="${DEPEND} $dependency"
257 RDEPEND="${RDEPEND}"
202} 258}
203 259
204for _ruby_implementation in $USE_RUBY; do 260for _ruby_implementation in $USE_RUBY; do
205 IUSE="${IUSE} ruby_targets_${_ruby_implementation}" 261 IUSE="${IUSE} ruby_targets_${_ruby_implementation}"
206 262
212 fi 268 fi
213done 269done
214 270
215_ruby_invoke_environment() { 271_ruby_invoke_environment() {
216 old_S=${S} 272 old_S=${S}
273 case ${EAPI} in
274 4)
275 if [ -z ${RUBY_S} ]; then
276 sub_S=${P}
277 else
278 sub_S=${RUBY_S}
279 fi
280 ;;
281 *)
217 sub_S=${S#${WORKDIR}} 282 sub_S=${S#${WORKDIR}/}
283 ;;
284 esac
285
286 # Special case, for the always-lovely GitHub fetches. With this,
287 # we allow the star glob to just expand to whatever directory it's
288 # called.
289 if [[ ${sub_S} = *"*"* ]]; then
290 case ${EAPI} in
291 2|3)
292 #The old method of setting S depends on undefined package
293 # manager behaviour, so encourage upgrading to EAPI=4.
294 eqawarn "Using * expansion of S is deprecated. Use EAPI and RUBY_S instead."
295 ;;
296 esac
297 pushd "${WORKDIR}"/all &>/dev/null
298 sub_S=$(eval ls -d ${sub_S} 2>/dev/null)
299 popd &>/dev/null
300 fi
218 301
219 environment=$1; shift 302 environment=$1; shift
220 303
221 my_WORKDIR="${WORKDIR}"/${environment} 304 my_WORKDIR="${WORKDIR}"/${environment}
222 S="${my_WORKDIR}"/"${sub_S}" 305 S="${my_WORKDIR}"/"${sub_S}"
240 local invoked=no 323 local invoked=no
241 for _ruby_implementation in ${USE_RUBY}; do 324 for _ruby_implementation in ${USE_RUBY}; do
242 # only proceed if it's requested 325 # only proceed if it's requested
243 use ruby_targets_${_ruby_implementation} || continue 326 use ruby_targets_${_ruby_implementation} || continue
244 327
245 RUBY=$(type -p $_ruby_implementation 2>/dev/null) 328 RUBY=$(ruby_implementation_command ${_ruby_implementation})
246 invoked=yes 329 invoked=yes
247 330
248 if [[ -n "$1" ]]; then 331 if [[ -n "$1" ]]; then
249 _ruby_invoke_environment $_ruby_implementation "$@" 332 _ruby_invoke_environment ${_ruby_implementation} "$@"
250 fi 333 fi
251 334
252 unset RUBY 335 unset RUBY
253 done 336 done
254 337
265 _ruby_each_implementation 348 _ruby_each_implementation
266} 349}
267 350
268# @FUNCTION: ruby-ng_src_unpack 351# @FUNCTION: ruby-ng_src_unpack
269# @DESCRIPTION: 352# @DESCRIPTION:
270# Unpack the source archive, including gems. 353# Unpack the source archive.
271ruby-ng_src_unpack() { 354ruby-ng_src_unpack() {
272 mkdir "${WORKDIR}"/all 355 mkdir "${WORKDIR}"/all
273 pushd "${WORKDIR}"/all &>/dev/null 356 pushd "${WORKDIR}"/all &>/dev/null
274 357
275 # We don't support an each-unpack, it's either all or nothing! 358 # We don't support an each-unpack, it's either all or nothing!
316 # almost every other ebuild. 399 # almost every other ebuild.
317 find . -name '._*' -delete 400 find . -name '._*' -delete
318 401
319 _ruby_invoke_environment all _ruby_apply_patches 402 _ruby_invoke_environment all _ruby_apply_patches
320 403
404 _PHASE="source copy" \
321 _ruby_each_implementation _ruby_source_copy 405 _ruby_each_implementation _ruby_source_copy
322 406
323 if type each_ruby_prepare &>/dev/null; then 407 if type each_ruby_prepare &>/dev/null; then
324 _ruby_each_implementation each_ruby_prepare 408 _ruby_each_implementation each_ruby_prepare
325 fi 409 fi
326} 410}
360 type all_ruby_test &>/dev/null && \ 444 type all_ruby_test &>/dev/null && \
361 _ruby_invoke_environment all all_ruby_test 445 _ruby_invoke_environment all all_ruby_test
362} 446}
363 447
364_each_ruby_check_install() { 448_each_ruby_check_install() {
449 local scancmd=scanelf
450 # we have a Mach-O object here
451 [[ ${CHOST} == *-darwin ]] && scancmd=scanmacho
452
453 has "${EAPI}" 2 && ! use prefix && EPREFIX=
454
365 local libruby_basename=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["LIBRUBY_SO"]') 455 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 }') 456 local libruby_soname=$(basename $(${scancmd} -F "%S#F" -qS "${EPREFIX}/usr/$(get_libdir)/${libruby_basename}") 2>/dev/null)
367 local sitedir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitedir"]') 457 local sitedir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitedir"]')
368 local sitelibdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]') 458 local sitelibdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]')
369 459
370 # Look for wrong files in sitedir 460 # Look for wrong files in sitedir
371 if [[ -d "${D}${sitedir}" ]]; then 461 # if [[ -d "${D}${sitedir}" ]]; then
372 local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}") 462 # local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}")
373 if [[ -n ${f} ]]; then 463 # if [[ -n ${f} ]]; then
374 eerror "Found files in sitedir, outsite sitelibdir:" 464 # eerror "Found files in sitedir, outsite sitelibdir:"
375 eerror "${f}" 465 # eerror "${f}"
376 die "Misplaced files in sitedir" 466 # die "Misplaced files in sitedir"
377 fi 467 # fi
378 fi 468 # fi
379 469
380 # The current implementation lacks libruby (i.e.: jruby) 470 # The current implementation lacks libruby (i.e.: jruby)
381 [[ -z ${libruby_soname} ]] && return 0 471 [[ -z ${libruby_soname} ]] && return 0
382 472
383 scanelf -qnR "${D}${sitedir}" \ 473 # Check also the gems directory, since we could be installing compiled
474 # extensions via ruby-fakegem; make sure to check only in sitelibdir, since
475 # that's what changes between two implementations (otherwise you'd get false
476 # positives now that Ruby 1.9.2 installs with the same sitedir as 1.8)
477 ${scancmd} -qnR "${D}${sitelibdir}" "${D}${sitelibdir/site_ruby/gems}" \
384 | fgrep -v "${libruby_soname}" \ 478 | fgrep -v "${libruby_soname}" \
479 | grep -E -v "${RUBY_QA_ALLOWED_LIBS}" \
385 > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log 480 > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log
386 481
387 if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then 482 if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then
388 ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby}" 483 ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}"
389 ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ) 484 ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log )
390 die "Missing links to ${libruby}" 485 die "Missing links to ${libruby_soname}"
391 fi 486 fi
392} 487}
393 488
394# @FUNCTION: ruby-ng_src_install 489# @FUNCTION: ruby-ng_src_install
395# @DESCRIPTION: 490# @DESCRIPTION:
404 499
405 _PHASE="check install" \ 500 _PHASE="check install" \
406 _ruby_each_implementation _each_ruby_check_install 501 _ruby_each_implementation _each_ruby_check_install
407} 502}
408 503
504# @FUNCTION: ruby_rbconfig_value
505# @USAGE: rbconfig item
506# @RETURN: Returns the value of the given rbconfig item of the Ruby interpreter in ${RUBY}.
507ruby_rbconfig_value() {
508 echo $(${RUBY} -rrbconfig -e "puts Config::CONFIG['$1']")
509}
510
409# @FUNCTION: doruby 511# @FUNCTION: doruby
410# @USAGE: file [file...] 512# @USAGE: file [file...]
411# @DESCRIPTION: 513# @DESCRIPTION:
412# Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}. 514# Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}.
413doruby() { 515doruby() {
516 [[ -z ${RUBY} ]] && die "\$RUBY is not set"
517 has "${EAPI}" 2 && ! use prefix && EPREFIX=
414 ( # don't want to pollute calling env 518 ( # don't want to pollute calling env
415 insinto $(${RUBY} -r rbconfig -e 'print Config::CONFIG["sitelibdir"]') 519 sitelibdir=$(ruby_rbconfig_value 'sitelibdir')
520 insinto ${sitelibdir#${EPREFIX}}
416 insopts -m 0644 521 insopts -m 0644
417 doins "$@" 522 doins "$@"
418 ) || die "failed to install $@" 523 ) || die "failed to install $@"
419} 524}
420 525
425} 530}
426 531
427# @FUNCTION: ruby_get_hdrdir 532# @FUNCTION: ruby_get_hdrdir
428# @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}. 533# @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}.
429ruby_get_hdrdir() { 534ruby_get_hdrdir() {
430 local rubyhdrdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["rubyhdrdir"]') 535 local rubyhdrdir=$(ruby_rbconfig_value 'rubyhdrdir')
431 536
432 if [[ "${rubyhdrdir}" = "nil" ]] ; then 537 if [[ "${rubyhdrdir}" = "nil" ]] ; then
433 rubyhdrdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["archdir"]') 538 rubyhdrdir=$(ruby_rbconfig_value 'archdir')
434 fi 539 fi
435 540
436 echo "${rubyhdrdir}" 541 echo "${rubyhdrdir}"
437} 542}
543
544# @FUNCTION: ruby_get_version
545# @RETURN: The version of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
546ruby_get_version() {
547 local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
548
549 echo $(${ruby} -e 'puts RUBY_VERSION')
550}
551
552# @FUNCTION: ruby_get_implementation
553# @RETURN: The implementation of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
554ruby_get_implementation() {
555 local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
556
557 case $(${ruby} --version) in
558 *Enterprise*)
559 echo "ree"
560 ;;
561 *jruby*)
562 echo "jruby"
563 ;;
564 *)
565 echo "mri"
566 ;;
567 esac
568}

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.35

  ViewVC Help
Powered by ViewVC 1.1.20