/[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.11 Revision 1.40
1# Copyright 1999-2009 Gentoo Foundation 1# Copyright 1999-2011 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.11 2010/04/26 15:07:58 a3li Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/ruby-ng.eclass,v 1.40 2011/10/05 17:46:20 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# @AUTHOR:
9# Author: Diego E. Pettenò <flameeyes@gentoo.org> 9# Author: Diego E. Pettenò <flameeyes@gentoo.org>
10#
11# Author: Alex Legler <a3li@gentoo.org> 10# Author: Alex Legler <a3li@gentoo.org>
12#
13# Author: Hans de Graaff <graaff@gentoo.org> 11# Author: Hans de Graaff <graaff@gentoo.org>
14#
15# @BLURB: An eclass for installing Ruby packages with proper support for multiple Ruby slots. 12# @BLURB: An eclass for installing Ruby packages with proper support for multiple Ruby slots.
16# @DESCRIPTION: 13# @DESCRIPTION:
17# The Ruby eclass is designed to allow an easier installation of Ruby packages 14# The Ruby eclass is designed to allow an easier installation of Ruby packages
18# and their incorporation into the Gentoo Linux system. 15# and their incorporation into the Gentoo Linux system.
19# 16#
31# 28#
32# * each_ruby_configure 29# * each_ruby_configure
33# * all_ruby_configure 30# * all_ruby_configure
34 31
35# @ECLASS-VARIABLE: USE_RUBY 32# @ECLASS-VARIABLE: USE_RUBY
33# @REQUIRED
36# @DESCRIPTION: 34# @DESCRIPTION:
37# This variable contains a space separated list of targets (see above) a package 35# 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 36# is compatible to. It must be set before the `inherit' call. There is no
39# default. All ebuilds are expected to set this variable. 37# default. All ebuilds are expected to set this variable.
40 38
41# @ECLASS-VARIABLE: RUBY_PATCHES 39# @ECLASS-VARIABLE: RUBY_PATCHES
40# @DEFAULT_UNSET
42# @DESCRIPTION: 41# @DESCRIPTION:
43# A String or Array of filenames of patches to apply to all implementations. 42# A String or Array of filenames of patches to apply to all implementations.
44 43
45# @ECLASS-VARIABLE: RUBY_OPTIONAL 44# @ECLASS-VARIABLE: RUBY_OPTIONAL
46# @DESCRIPTION: 45# @DESCRIPTION:
47# Set the value to "yes" to make the dependency on a Ruby interpreter optional. 46# Set the value to "yes" to make the dependency on a Ruby interpreter
47# optional and then ruby_implementations_depend() to help populate
48# DEPEND and RDEPEND.
48 49
50# @ECLASS-VARIABLE: RUBY_S
51# @DEFAULT_UNSET
52# @DESCRIPTION:
53# If defined this variable determines the source directory name after
54# unpacking. This defaults to the name of the package. Note that this
55# variable supports a wildcard mechanism to help with github tarballs
56# that contain the commit hash as part of the directory name.
57
58# @ECLASS-VARIABLE: RUBY_QA_ALLOWED_LIBS
59# @DEFAULT_UNSET
60# @DESCRIPTION:
61# If defined this variable contains a whitelist of shared objects that
62# are allowed to exist even if they don't link to libruby. This avoids
63# the QA check that makes this mandatory. This is most likely not what
64# you are looking for if you get the related "Missing links" QA warning,
65# since the proper fix is almost always to make sure the shared object
66# is linked against libruby. There are cases were this is not the case
67# and the shared object is generic code to be used in some other way
68# (e.g. selenium's firefox driver extension). When set this argument is
69# passed to "grep -E" to remove reporting of these shared objects.
70
49inherit eutils toolchain-funcs 71inherit eutils java-utils-2 toolchain-funcs
50 72
51EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_setup 73EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_setup
52 74
53case ${EAPI} in 75case ${EAPI} in
54 0|1) 76 0|1)
55 die "Unsupported EAPI=${EAPI} (too old) for ruby-ng.eclass" ;; 77 die "Unsupported EAPI=${EAPI} (too old) for ruby-ng.eclass" ;;
56 2) ;; 78 2|3) ;;
79 4)
80 # S is no longer automatically assigned when it doesn't exist.
81 S="${WORKDIR}"
82 ;;
57 *) 83 *)
58 die "Unknown EAPI=${EAPI} for ruby-ng.eclass" 84 die "Unknown EAPI=${EAPI} for ruby-ng.eclass"
59esac 85esac
60 86
61# @FUNCTION: ruby_implementation_depend 87# @FUNCTION: ruby_implementation_depend
110 done 136 done
111 137
112 echo "[${res%,}]" 138 echo "[${res%,}]"
113} 139}
114 140
141_ruby_atoms_samelib_generic() {
142 eshopts_push -o noglob
143 echo "RUBYTARGET? ("
144 for token in $*; do
145 case "$token" in
146 "||" | "(" | ")" | *"?")
147 echo "${token}" ;;
148 *])
149 echo "${token%[*}[RUBYTARGET,${token/*[}" ;;
150 *)
151 echo "${token}[RUBYTARGET]" ;;
152 esac
153 done
154 echo ")"
155 eshopts_pop
156}
157
158# @FUNCTION: ruby_implementation_command
159# @RETURN: the path to the given ruby implementation
160# @DESCRIPTION:
161# Not all implementations have the same command basename as the
162# target; namely Ruby Enterprise 1.8 uses ree18 and rubyee18
163# respectively. This function translate between the two
115_ruby_implementation_depend() { 164ruby_implementation_command() {
116 echo "ruby_targets_${1}? ( ${2}[ruby_targets_${1}] )" 165 local _ruby_name=$1
117}
118 166
119_ruby_add_bdepend() { 167 # Add all USE_RUBY values where the flag name diverts from the binary here
120 local atom=$1 168 case $1 in
169 ree18)
170 _ruby_name=rubyee18
171 ;;
172 esac
173
174 echo $(type -p ${_ruby_name} 2>/dev/null)
175}
176
177_ruby_atoms_samelib() {
178 local atoms=$(_ruby_atoms_samelib_generic "$*")
179
180 for _ruby_implementation in $USE_RUBY; do
181 echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}"
182 done
183}
184
185_ruby_wrap_conditions() {
121 local conditions=$2 186 local conditions="$1"
187 local atoms="$2"
122 188
123 for condition in $conditions; do 189 for condition in $conditions; do
124 hasq $condition "$IUSE" || IUSE="${IUSE} $condition"
125 atom="${condition}? ( ${atom} )" 190 atoms="${condition}? ( ${atoms} )"
126 done 191 done
127 192
128 DEPEND="${DEPEND} ${atom}" 193 echo "$atoms"
129 RDEPEND="${RDEPEND}"
130}
131
132_ruby_add_rdepend() {
133 local atom=$1
134 local conditions=$2
135
136 for condition in $conditions; do
137 hasq $condition "$IUSE" || IUSE="${IUSE} $condition"
138 atom="${condition}? ( ${atom} )"
139 done
140
141 RDEPEND="${RDEPEND} ${atom}"
142 _ruby_add_bdepend "$atom" test
143} 194}
144 195
145# @FUNCTION: ruby_add_rdepend 196# @FUNCTION: ruby_add_rdepend
146# @USAGE: [conditions] atom 197# @USAGE: dependencies
147# @DESCRIPTION: 198# @DESCRIPTION:
148# Adds the specified atom(s) with optional use condition(s) to 199# Adds the specified dependencies, with use condition(s) to RDEPEND,
149# RDEPEND, taking the current set of ruby targets into account. This 200# taking the current set of ruby targets into account. This makes sure
150# makes sure that all ruby dependencies of the package are installed 201# that all ruby dependencies of the package are installed for the same
151# for the same ruby targets. Use this function for all ruby 202# ruby targets. Use this function for all ruby dependencies instead of
152# dependencies instead of setting RDEPEND yourself. Both atom and 203# setting RDEPEND yourself. The list of atoms uses the same syntax as
153# conditions can be a space-separated list of atoms or conditions. 204# normal dependencies.
205#
206# Note: runtime dependencies are also added as build-time test
207# dependencies.
154ruby_add_rdepend() { 208ruby_add_rdepend() {
155 local atoms=
156 local conditions=
157 case $# in 209 case $# in
158 1) 210 1) ;;
159 atoms=$1
160 ;;
161 2) 211 2)
162 conditions=$1 212 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_rdepend for $CATEGORY/$PF"
163 atoms=$2 213 ruby_add_rdepend "$(_ruby_wrap_conditions "$1" "$2")"
214 return
164 ;; 215 ;;
165 *) 216 *)
166 die "bad number of arguments to $0" 217 die "bad number of arguments to $0"
167 ;; 218 ;;
168 esac 219 esac
169 220
170 for atom in $atoms; do 221 local dependency=$(_ruby_atoms_samelib "$1")
171 _ruby_add_rdepend "${atom}$(ruby_samelib)" "$conditions" 222
172 done 223 RDEPEND="${RDEPEND} $dependency"
224
225 # Add the dependency as a test-dependency since we're going to
226 # execute the code during test phase.
227 DEPEND="${DEPEND} test? ( ${dependency} )"
228 has test "$IUSE" || IUSE="${IUSE} test"
173} 229}
174 230
175# @FUNCTION: ruby_add_bdepend 231# @FUNCTION: ruby_add_bdepend
176# @USAGE: [conditions] atom 232# @USAGE: dependencies
177# @DESCRIPTION: 233# @DESCRIPTION:
178# Adds the specified atom(s) with optional use condition(s) to both 234# Adds the specified dependencies, with use condition(s) to DEPEND,
179# DEPEND and RDEPEND, taking the current set of ruby targets into 235# taking the current set of ruby targets into account. This makes sure
180# account. This makes sure that all ruby dependencies of the package 236# that all ruby dependencies of the package are installed for the same
181# are installed for the same ruby targets. Use this function for all 237# ruby targets. Use this function for all ruby dependencies instead of
182# ruby dependencies instead of setting DEPEND and RDEPEND 238# setting DEPEND yourself. The list of atoms uses the same syntax as
183# yourself. Both atom and conditions can be a space-separated list of 239# normal dependencies.
184# atoms or conditions.
185ruby_add_bdepend() { 240ruby_add_bdepend() {
186 local atoms=
187 local conditions=
188 case $# in 241 case $# in
189 1) 242 1) ;;
190 atoms=$1
191 ;;
192 2) 243 2)
193 conditions=$1 244 [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_bdepend for $CATEGORY/$PF"
194 atoms=$2 245 ruby_add_bdepend "$(_ruby_wrap_conditions "$1" "$2")"
246 return
195 ;; 247 ;;
196 *) 248 *)
197 die "bad number of arguments to $0" 249 die "bad number of arguments to $0"
198 ;; 250 ;;
199 esac 251 esac
200 252
201 for atom in $atoms; do 253 local dependency=$(_ruby_atoms_samelib "$1")
202 _ruby_add_bdepend "${atom}$(ruby_samelib)" "$conditions"
203 done
204}
205 254
255 DEPEND="${DEPEND} $dependency"
256 RDEPEND="${RDEPEND}"
257}
258
259# @FUNCTION: ruby_get_use_implementations
260# @DESCRIPTION:
261# Gets an array of ruby use targets enabled by the user
262ruby_get_use_implementations() {
263 local i implementation
264 for implementation in ${USE_RUBY}; do
265 use ruby_targets_${implementation} && i+=" ${implementation}"
266 done
267 echo $i
268}
269
270# @FUNCTION: ruby_get_use_targets
271# @DESCRIPTION:
272# Gets an array of ruby use targets that the ebuild sets
273ruby_get_use_targets() {
274 local t implementation
275 for implementation in ${USE_RUBY}; do
276 t+=" ruby_targets_${implementation}"
277 done
278 echo $t
279}
280
281if [[ ${EAPI:-0} -ge 4 && ${RUBY_OPTIONAL} != "yes" ]]; then
282 REQUIRED_USE=" || ( $(ruby_get_use_targets) )"
283fi
284
285# @FUNCTION: ruby_implementations_depend
286# @RETURN: Dependencies suitable for injection into DEPEND and RDEPEND.
287# @DESCRIPTION:
288# Produces the dependency string for the various implementations of ruby
289# which the package is being built against. This should not be used when
290# RUBY_OPTIONAL is unset but must be used if RUBY_OPTIONAL=yes. Do not
291# confuse this function with ruby_implementation_depend().
292#
293# @EXAMPLE:
294# EAPI=4
295# RUBY_OPTIONAL=yes
296#
297# inherit ruby-ng
298# ...
299# DEPEND="ruby? ( $(ruby_implementations_depend) )"
300# RDEPEND="${DEPEND}"
301ruby_implementations_depend() {
302 local depend
303 for _ruby_implementation in ${USE_RUBY}; do
304 depend="${depend}${depend+ }ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
305 done
306 echo "${depend}"
307}
308
206for _ruby_implementation in $USE_RUBY; do 309for _ruby_implementation in ${USE_RUBY}; do
207 IUSE="${IUSE} ruby_targets_${_ruby_implementation}" 310 IUSE="${IUSE} ruby_targets_${_ruby_implementation}"
208
209 # If you specify RUBY_OPTIONAL you also need to take care of
210 # ruby useflag and dependency.
211 if [[ ${RUBY_OPTIONAL} != "yes" ]]; then
212 DEPEND="${DEPEND} ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
213 RDEPEND="${RDEPEND} ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
214 fi
215done 311done
312# If you specify RUBY_OPTIONAL you also need to take care of
313# ruby useflag and dependency.
314if [[ ${RUBY_OPTIONAL} != yes ]]; then
315 DEPEND="${DEPEND} $(ruby_implementations_depend)"
316 RDEPEND="${RDEPEND} $(ruby_implementations_depend)"
317fi
216 318
217_ruby_invoke_environment() { 319_ruby_invoke_environment() {
218 old_S=${S} 320 old_S=${S}
321 case ${EAPI} in
322 4)
323 if [ -z ${RUBY_S} ]; then
324 sub_S=${P}
325 else
326 sub_S=${RUBY_S}
327 fi
328 ;;
329 *)
219 sub_S=${S#${WORKDIR}} 330 sub_S=${S#${WORKDIR}/}
331 ;;
332 esac
333
334 # Special case, for the always-lovely GitHub fetches. With this,
335 # we allow the star glob to just expand to whatever directory it's
336 # called.
337 if [[ ${sub_S} = *"*"* ]]; then
338 case ${EAPI} in
339 2|3)
340 #The old method of setting S depends on undefined package
341 # manager behaviour, so encourage upgrading to EAPI=4.
342 eqawarn "Using * expansion of S is deprecated. Use EAPI and RUBY_S instead."
343 ;;
344 esac
345 pushd "${WORKDIR}"/all &>/dev/null
346 sub_S=$(eval ls -d ${sub_S} 2>/dev/null)
347 popd &>/dev/null
348 fi
220 349
221 environment=$1; shift 350 environment=$1; shift
222 351
223 my_WORKDIR="${WORKDIR}"/${environment} 352 my_WORKDIR="${WORKDIR}"/${environment}
224 S="${my_WORKDIR}"/"${sub_S}" 353 S="${my_WORKDIR}"/"${sub_S}"
242 local invoked=no 371 local invoked=no
243 for _ruby_implementation in ${USE_RUBY}; do 372 for _ruby_implementation in ${USE_RUBY}; do
244 # only proceed if it's requested 373 # only proceed if it's requested
245 use ruby_targets_${_ruby_implementation} || continue 374 use ruby_targets_${_ruby_implementation} || continue
246 375
247 local _ruby_name=$_ruby_implementation 376 RUBY=$(ruby_implementation_command ${_ruby_implementation})
248
249 # Add all USE_RUBY values where the flag name diverts from the binary here
250 case $_ruby_implementation in
251 ree18)
252 _ruby_name=rubyee18
253 ;;
254 esac
255
256 RUBY=$(type -p $_ruby_name 2>/dev/null)
257 invoked=yes 377 invoked=yes
258 378
259 if [[ -n "$1" ]]; then 379 if [[ -n "$1" ]]; then
260 _ruby_invoke_environment $_ruby_implementation "$@" 380 _ruby_invoke_environment ${_ruby_implementation} "$@"
261 fi 381 fi
262 382
263 unset RUBY 383 unset RUBY
264 done 384 done
265 385
272ruby-ng_pkg_setup() { 392ruby-ng_pkg_setup() {
273 # This only checks that at least one implementation is present 393 # This only checks that at least one implementation is present
274 # before doing anything; by leaving the parameters empty we know 394 # before doing anything; by leaving the parameters empty we know
275 # it's a special case. 395 # it's a special case.
276 _ruby_each_implementation 396 _ruby_each_implementation
397
398 use ruby_targets_jruby && java-pkg_setup-vm
277} 399}
278 400
279# @FUNCTION: ruby-ng_src_unpack 401# @FUNCTION: ruby-ng_src_unpack
280# @DESCRIPTION: 402# @DESCRIPTION:
281# Unpack the source archive. 403# Unpack the source archive.
372 type all_ruby_test &>/dev/null && \ 494 type all_ruby_test &>/dev/null && \
373 _ruby_invoke_environment all all_ruby_test 495 _ruby_invoke_environment all all_ruby_test
374} 496}
375 497
376_each_ruby_check_install() { 498_each_ruby_check_install() {
499 local scancmd=scanelf
500 # we have a Mach-O object here
501 [[ ${CHOST} == *-darwin ]] && scancmd=scanmacho
502
503 has "${EAPI}" 2 && ! use prefix && EPREFIX=
504
377 local libruby_basename=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["LIBRUBY_SO"]') 505 local libruby_basename=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["LIBRUBY_SO"]')
378 local libruby_soname=$(scanelf -qS "/usr/$(get_libdir)/${libruby_basename}" | awk '{ print $1 }') 506 local libruby_soname=$(basename $(${scancmd} -F "%S#F" -qS "${EPREFIX}/usr/$(get_libdir)/${libruby_basename}") 2>/dev/null)
379 local sitedir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitedir"]') 507 local sitedir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitedir"]')
380 local sitelibdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]') 508 local sitelibdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]')
381 509
382 # Look for wrong files in sitedir 510 # Look for wrong files in sitedir
383 if [[ -d "${D}${sitedir}" ]]; then 511 # if [[ -d "${D}${sitedir}" ]]; then
384 local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}") 512 # local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}")
385 if [[ -n ${f} ]]; then 513 # if [[ -n ${f} ]]; then
386 eerror "Found files in sitedir, outsite sitelibdir:" 514 # eerror "Found files in sitedir, outsite sitelibdir:"
387 eerror "${f}" 515 # eerror "${f}"
388 die "Misplaced files in sitedir" 516 # die "Misplaced files in sitedir"
389 fi 517 # fi
390 fi 518 # fi
391 519
392 # The current implementation lacks libruby (i.e.: jruby) 520 # The current implementation lacks libruby (i.e.: jruby)
393 [[ -z ${libruby_soname} ]] && return 0 521 [[ -z ${libruby_soname} ]] && return 0
394 522
395 scanelf -qnR "${D}${sitedir}" \ 523 # Check also the gems directory, since we could be installing compiled
524 # extensions via ruby-fakegem; make sure to check only in sitelibdir, since
525 # that's what changes between two implementations (otherwise you'd get false
526 # positives now that Ruby 1.9.2 installs with the same sitedir as 1.8)
527 ${scancmd} -qnR "${D}${sitelibdir}" "${D}${sitelibdir/site_ruby/gems}" \
396 | fgrep -v "${libruby_soname}" \ 528 | fgrep -v "${libruby_soname}" \
529 | grep -E -v "${RUBY_QA_ALLOWED_LIBS}" \
397 > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log 530 > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log
398 531
399 if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then 532 if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then
400 ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby}" 533 ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}"
401 ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ) 534 ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log )
402 die "Missing links to ${libruby}" 535 die "Missing links to ${libruby_soname}"
403 fi 536 fi
404} 537}
405 538
406# @FUNCTION: ruby-ng_src_install 539# @FUNCTION: ruby-ng_src_install
407# @DESCRIPTION: 540# @DESCRIPTION:
429# @USAGE: file [file...] 562# @USAGE: file [file...]
430# @DESCRIPTION: 563# @DESCRIPTION:
431# Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}. 564# Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}.
432doruby() { 565doruby() {
433 [[ -z ${RUBY} ]] && die "\$RUBY is not set" 566 [[ -z ${RUBY} ]] && die "\$RUBY is not set"
567 has "${EAPI}" 2 && ! use prefix && EPREFIX=
434 ( # don't want to pollute calling env 568 ( # don't want to pollute calling env
435 insinto $(ruby_rbconfig_value 'sitelibdir') 569 sitelibdir=$(ruby_rbconfig_value 'sitelibdir')
570 insinto ${sitelibdir#${EPREFIX}}
436 insopts -m 0644 571 insopts -m 0644
437 doins "$@" 572 doins "$@"
438 ) || die "failed to install $@" 573 ) || die "failed to install $@"
439} 574}
440 575

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.40

  ViewVC Help
Powered by ViewVC 1.1.20