| 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.16 2010/05/22 12:18:07 flameeyes 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 | # |
| … | |
… | |
| 114 | |
114 | |
| 115 | _ruby_implementation_depend() { |
115 | _ruby_implementation_depend() { |
| 116 | echo "ruby_targets_${1}? ( ${2}[ruby_targets_${1}] )" |
116 | echo "ruby_targets_${1}? ( ${2}[ruby_targets_${1}] )" |
| 117 | } |
117 | } |
| 118 | |
118 | |
| 119 | _ruby_add_bdepend() { |
119 | _ruby_atoms_samelib() { |
| 120 | local atom=$1 |
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() { |
| 121 | local conditions=$2 |
133 | local conditions="$1" |
|
|
134 | local atoms="$2" |
| 122 | |
135 | |
| 123 | for condition in $conditions; do |
136 | for condition in $conditions; do |
|
|
137 | hasq $condition "$IUSE" || IUSE="${IUSE} $condition" |
| 124 | atom="${condition}? ( ${atom} )" |
138 | atoms="${condition}? ( ${atoms} )" |
| 125 | done |
139 | done |
| 126 | |
140 | |
| 127 | DEPEND="${DEPEND} ${atom}" |
141 | 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 | } |
142 | } |
| 142 | |
143 | |
| 143 | # @FUNCTION: ruby_add_rdepend |
144 | # @FUNCTION: ruby_add_rdepend |
| 144 | # @USAGE: [conditions] atom |
145 | # @USAGE: dependencies |
| 145 | # @DESCRIPTION: |
146 | # @DESCRIPTION: |
| 146 | # Adds the specified atom(s) with optional use condition(s) to |
147 | # Adds the specified dependencies, with use condition(s) to RDEPEND, |
| 147 | # RDEPEND, taking the current set of ruby targets into account. This |
148 | # taking the current set of ruby targets into account. This makes sure |
| 148 | # makes sure that all ruby dependencies of the package are installed |
149 | # that all ruby dependencies of the package are installed for the same |
| 149 | # for the same ruby targets. Use this function for all ruby |
150 | # ruby targets. Use this function for all ruby dependencies instead of |
| 150 | # dependencies instead of setting RDEPEND yourself. Both atom and |
151 | # setting RDEPEND yourself. The list of atoms uses the same syntax as |
| 151 | # conditions can be a space-separated list of atoms or conditions. |
152 | # normal dependencies. |
|
|
153 | # |
|
|
154 | # Note: runtime dependencies are also added as build-time test |
|
|
155 | # dependencies. |
| 152 | ruby_add_rdepend() { |
156 | ruby_add_rdepend() { |
| 153 | local atoms= |
|
|
| 154 | local conditions= |
|
|
| 155 | case $# in |
157 | case $# in |
| 156 | 1) |
158 | 1) ;; |
| 157 | atoms=$1 |
|
|
| 158 | ;; |
|
|
| 159 | 2) |
159 | 2) |
| 160 | conditions=$1 |
160 | [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_rdepend for $CATEGORY/$PF" |
| 161 | atoms=$2 |
161 | ruby_add_rdepend "$(_ruby_wrap_conditions "$1" "$2")" |
|
|
162 | return |
| 162 | ;; |
163 | ;; |
| 163 | *) |
164 | *) |
| 164 | die "bad number of arguments to $0" |
165 | die "bad number of arguments to $0" |
| 165 | ;; |
166 | ;; |
| 166 | esac |
167 | esac |
| 167 | |
168 | |
| 168 | for atom in $atoms; do |
169 | local dependency=$(_ruby_atoms_samelib "$1") |
| 169 | _ruby_add_rdepend "${atom}$(ruby_samelib)" "$conditions" |
170 | |
| 170 | done |
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}")" |
| 171 | } |
176 | } |
| 172 | |
177 | |
| 173 | # @FUNCTION: ruby_add_bdepend |
178 | # @FUNCTION: ruby_add_bdepend |
| 174 | # @USAGE: [conditions] atom |
179 | # @USAGE: dependencies |
| 175 | # @DESCRIPTION: |
180 | # @DESCRIPTION: |
| 176 | # Adds the specified atom(s) with optional use condition(s) to both |
181 | # Adds the specified dependencies, with use condition(s) to DEPEND, |
| 177 | # DEPEND and RDEPEND, taking the current set of ruby targets into |
182 | # taking the current set of ruby targets into account. This makes sure |
| 178 | # account. This makes sure that all ruby dependencies of the package |
183 | # 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 |
184 | # ruby targets. Use this function for all ruby dependencies instead of |
| 180 | # ruby dependencies instead of setting DEPEND and RDEPEND |
185 | # 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 |
186 | # normal dependencies. |
| 182 | # atoms or conditions. |
|
|
| 183 | ruby_add_bdepend() { |
187 | ruby_add_bdepend() { |
| 184 | local atoms= |
|
|
| 185 | local conditions= |
|
|
| 186 | case $# in |
188 | case $# in |
| 187 | 1) |
189 | 1) ;; |
| 188 | atoms=$1 |
|
|
| 189 | ;; |
|
|
| 190 | 2) |
190 | 2) |
| 191 | conditions=$1 |
191 | [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_bdepend for $CATEGORY/$PF" |
| 192 | atoms=$2 |
192 | ruby_add_bdepend "$(_ruby_wrap_conditions "$1" "$2")" |
|
|
193 | return |
| 193 | ;; |
194 | ;; |
| 194 | *) |
195 | *) |
| 195 | die "bad number of arguments to $0" |
196 | die "bad number of arguments to $0" |
| 196 | ;; |
197 | ;; |
| 197 | esac |
198 | esac |
| 198 | |
199 | |
| 199 | for atom in $atoms; do |
200 | local dependency=$(_ruby_atoms_samelib "$1") |
| 200 | _ruby_add_bdepend "${atom}$(ruby_samelib)" "$conditions" |
201 | |
| 201 | done |
202 | DEPEND="${DEPEND} $dependency" |
| 202 | } |
203 | } |
| 203 | |
204 | |
| 204 | for _ruby_implementation in $USE_RUBY; do |
205 | for _ruby_implementation in $USE_RUBY; do |
| 205 | IUSE="${IUSE} ruby_targets_${_ruby_implementation}" |
206 | IUSE="${IUSE} ruby_targets_${_ruby_implementation}" |
| 206 | |
207 | |
| … | |
… | |
| 212 | fi |
213 | fi |
| 213 | done |
214 | done |
| 214 | |
215 | |
| 215 | _ruby_invoke_environment() { |
216 | _ruby_invoke_environment() { |
| 216 | old_S=${S} |
217 | old_S=${S} |
| 217 | sub_S=${S#${WORKDIR}} |
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 |
| 218 | |
228 | |
| 219 | environment=$1; shift |
229 | environment=$1; shift |
| 220 | |
230 | |
| 221 | my_WORKDIR="${WORKDIR}"/${environment} |
231 | my_WORKDIR="${WORKDIR}"/${environment} |
| 222 | S="${my_WORKDIR}"/"${sub_S}" |
232 | S="${my_WORKDIR}"/"${sub_S}" |
| … | |
… | |
| 240 | local invoked=no |
250 | local invoked=no |
| 241 | for _ruby_implementation in ${USE_RUBY}; do |
251 | for _ruby_implementation in ${USE_RUBY}; do |
| 242 | # only proceed if it's requested |
252 | # only proceed if it's requested |
| 243 | use ruby_targets_${_ruby_implementation} || continue |
253 | use ruby_targets_${_ruby_implementation} || continue |
| 244 | |
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 | |
| 245 | RUBY=$(type -p $_ruby_implementation 2>/dev/null) |
264 | RUBY=$(type -p $_ruby_name 2>/dev/null) |
| 246 | invoked=yes |
265 | invoked=yes |
| 247 | |
266 | |
| 248 | if [[ -n "$1" ]]; then |
267 | if [[ -n "$1" ]]; then |
| 249 | _ruby_invoke_environment $_ruby_implementation "$@" |
268 | _ruby_invoke_environment $_ruby_implementation "$@" |
| 250 | fi |
269 | fi |
| … | |
… | |
| 265 | _ruby_each_implementation |
284 | _ruby_each_implementation |
| 266 | } |
285 | } |
| 267 | |
286 | |
| 268 | # @FUNCTION: ruby-ng_src_unpack |
287 | # @FUNCTION: ruby-ng_src_unpack |
| 269 | # @DESCRIPTION: |
288 | # @DESCRIPTION: |
| 270 | # Unpack the source archive, including gems. |
289 | # Unpack the source archive. |
| 271 | ruby-ng_src_unpack() { |
290 | ruby-ng_src_unpack() { |
| 272 | mkdir "${WORKDIR}"/all |
291 | mkdir "${WORKDIR}"/all |
| 273 | pushd "${WORKDIR}"/all &>/dev/null |
292 | pushd "${WORKDIR}"/all &>/dev/null |
| 274 | |
293 | |
| 275 | # We don't support an each-unpack, it's either all or nothing! |
294 | # We don't support an each-unpack, it's either all or nothing! |
| … | |
… | |
| 316 | # almost every other ebuild. |
335 | # almost every other ebuild. |
| 317 | find . -name '._*' -delete |
336 | find . -name '._*' -delete |
| 318 | |
337 | |
| 319 | _ruby_invoke_environment all _ruby_apply_patches |
338 | _ruby_invoke_environment all _ruby_apply_patches |
| 320 | |
339 | |
|
|
340 | _PHASE="source copy" \ |
| 321 | _ruby_each_implementation _ruby_source_copy |
341 | _ruby_each_implementation _ruby_source_copy |
| 322 | |
342 | |
| 323 | if type each_ruby_prepare &>/dev/null; then |
343 | if type each_ruby_prepare &>/dev/null; then |
| 324 | _ruby_each_implementation each_ruby_prepare |
344 | _ruby_each_implementation each_ruby_prepare |
| 325 | fi |
345 | fi |
| 326 | } |
346 | } |
| … | |
… | |
| 383 | scanelf -qnR "${D}${sitedir}" \ |
403 | scanelf -qnR "${D}${sitedir}" \ |
| 384 | | fgrep -v "${libruby_soname}" \ |
404 | | fgrep -v "${libruby_soname}" \ |
| 385 | > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log |
405 | > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log |
| 386 | |
406 | |
| 387 | if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then |
407 | if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then |
| 388 | ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby}" |
408 | ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}" |
| 389 | ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ) |
409 | ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ) |
| 390 | die "Missing links to ${libruby}" |
410 | die "Missing links to ${libruby_soname}" |
| 391 | fi |
411 | fi |
| 392 | } |
412 | } |
| 393 | |
413 | |
| 394 | # @FUNCTION: ruby-ng_src_install |
414 | # @FUNCTION: ruby-ng_src_install |
| 395 | # @DESCRIPTION: |
415 | # @DESCRIPTION: |
| … | |
… | |
| 404 | |
424 | |
| 405 | _PHASE="check install" \ |
425 | _PHASE="check install" \ |
| 406 | _ruby_each_implementation _each_ruby_check_install |
426 | _ruby_each_implementation _each_ruby_check_install |
| 407 | } |
427 | } |
| 408 | |
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 | |
| 409 | # @FUNCTION: doruby |
436 | # @FUNCTION: doruby |
| 410 | # @USAGE: file [file...] |
437 | # @USAGE: file [file...] |
| 411 | # @DESCRIPTION: |
438 | # @DESCRIPTION: |
| 412 | # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}. |
439 | # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}. |
| 413 | doruby() { |
440 | doruby() { |
|
|
441 | [[ -z ${RUBY} ]] && die "\$RUBY is not set" |
| 414 | ( # don't want to pollute calling env |
442 | ( # don't want to pollute calling env |
| 415 | insinto $(${RUBY} -r rbconfig -e 'print Config::CONFIG["sitelibdir"]') |
443 | insinto $(ruby_rbconfig_value 'sitelibdir') |
| 416 | insopts -m 0644 |
444 | insopts -m 0644 |
| 417 | doins "$@" |
445 | doins "$@" |
| 418 | ) || die "failed to install $@" |
446 | ) || die "failed to install $@" |
| 419 | } |
447 | } |
| 420 | |
448 | |
| … | |
… | |
| 425 | } |
453 | } |
| 426 | |
454 | |
| 427 | # @FUNCTION: ruby_get_hdrdir |
455 | # @FUNCTION: ruby_get_hdrdir |
| 428 | # @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}. |
456 | # @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}. |
| 429 | ruby_get_hdrdir() { |
457 | ruby_get_hdrdir() { |
| 430 | local rubyhdrdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["rubyhdrdir"]') |
458 | local rubyhdrdir=$(ruby_rbconfig_value 'rubyhdrdir') |
| 431 | |
459 | |
| 432 | if [[ "${rubyhdrdir}" = "nil" ]] ; then |
460 | if [[ "${rubyhdrdir}" = "nil" ]] ; then |
| 433 | rubyhdrdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["archdir"]') |
461 | rubyhdrdir=$(ruby_rbconfig_value 'archdir') |
| 434 | fi |
462 | fi |
| 435 | |
463 | |
| 436 | echo "${rubyhdrdir}" |
464 | echo "${rubyhdrdir}" |
| 437 | } |
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 | } |