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

Contents of /eclass/ruby-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Fri Dec 25 18:01:34 2009 UTC (4 years, 8 months ago) by flameeyes
Branch: MAIN
Changes since 1.6: +3 -2 lines
Properly report the source copy phase.

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.6 2009/12/14 12:25:47 a3li 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_implementation_depend() {
116 echo "ruby_targets_${1}? ( ${2}[ruby_targets_${1}] )"
117 }
118
119 _ruby_add_bdepend() {
120 local atom=$1
121 local conditions=$2
122
123 for condition in $conditions; do
124 atom="${condition}? ( ${atom} )"
125 done
126
127 DEPEND="${DEPEND} ${atom}"
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
143 # @FUNCTION: ruby_add_rdepend
144 # @USAGE: [conditions] atom
145 # @DESCRIPTION:
146 # Adds the specified atom(s) with optional use condition(s) to
147 # RDEPEND, taking the current set of ruby targets into account. This
148 # makes sure that all ruby dependencies of the package are installed
149 # for the same ruby targets. Use this function for all ruby
150 # dependencies instead of setting RDEPEND yourself. Both atom and
151 # conditions can be a space-separated list of atoms or conditions.
152 ruby_add_rdepend() {
153 local atoms=
154 local conditions=
155 case $# in
156 1)
157 atoms=$1
158 ;;
159 2)
160 conditions=$1
161 atoms=$2
162 ;;
163 *)
164 die "bad number of arguments to $0"
165 ;;
166 esac
167
168 for atom in $atoms; do
169 _ruby_add_rdepend "${atom}$(ruby_samelib)" "$conditions"
170 done
171 }
172
173 # @FUNCTION: ruby_add_bdepend
174 # @USAGE: [conditions] atom
175 # @DESCRIPTION:
176 # Adds the specified atom(s) with optional use condition(s) to both
177 # DEPEND and RDEPEND, taking the current set of ruby targets into
178 # account. This makes sure that all ruby dependencies of the package
179 # are installed for the same ruby targets. Use this function for all
180 # ruby dependencies instead of setting DEPEND and RDEPEND
181 # yourself. Both atom and conditions can be a space-separated list of
182 # atoms or conditions.
183 ruby_add_bdepend() {
184 local atoms=
185 local conditions=
186 case $# in
187 1)
188 atoms=$1
189 ;;
190 2)
191 conditions=$1
192 atoms=$2
193 ;;
194 *)
195 die "bad number of arguments to $0"
196 ;;
197 esac
198
199 for atom in $atoms; do
200 _ruby_add_bdepend "${atom}$(ruby_samelib)" "$conditions"
201 done
202 }
203
204 for _ruby_implementation in $USE_RUBY; do
205 IUSE="${IUSE} ruby_targets_${_ruby_implementation}"
206
207 # If you specify RUBY_OPTIONAL you also need to take care of
208 # ruby useflag and dependency.
209 if [[ ${RUBY_OPTIONAL} != "yes" ]]; then
210 DEPEND="${DEPEND} ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
211 RDEPEND="${RDEPEND} ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
212 fi
213 done
214
215 _ruby_invoke_environment() {
216 old_S=${S}
217 sub_S=${S#${WORKDIR}}
218
219 environment=$1; shift
220
221 my_WORKDIR="${WORKDIR}"/${environment}
222 S="${my_WORKDIR}"/"${sub_S}"
223
224 if [[ -d "${S}" ]]; then
225 pushd "$S" &>/dev/null
226 elif [[ -d "${my_WORKDIR}" ]]; then
227 pushd "${my_WORKDIR}" &>/dev/null
228 else
229 pushd "${WORKDIR}" &>/dev/null
230 fi
231
232 ebegin "Running ${_PHASE:-${EBUILD_PHASE}} phase for $environment"
233 "$@"
234 popd &>/dev/null
235
236 S=${old_S}
237 }
238
239 _ruby_each_implementation() {
240 local invoked=no
241 for _ruby_implementation in ${USE_RUBY}; do
242 # only proceed if it's requested
243 use ruby_targets_${_ruby_implementation} || continue
244
245 RUBY=$(type -p $_ruby_implementation 2>/dev/null)
246 invoked=yes
247
248 if [[ -n "$1" ]]; then
249 _ruby_invoke_environment $_ruby_implementation "$@"
250 fi
251
252 unset RUBY
253 done
254
255 [[ ${invoked} == "no" ]] && die "You need to select at least one Ruby implementation by setting RUBY_TARGETS in /etc/make.conf."
256 }
257
258 # @FUNCTION: ruby-ng_pkg_setup
259 # @DESCRIPTION:
260 # Check whether at least one ruby target implementation is present.
261 ruby-ng_pkg_setup() {
262 # This only checks that at least one implementation is present
263 # before doing anything; by leaving the parameters empty we know
264 # it's a special case.
265 _ruby_each_implementation
266 }
267
268 # @FUNCTION: ruby-ng_src_unpack
269 # @DESCRIPTION:
270 # Unpack the source archive.
271 ruby-ng_src_unpack() {
272 mkdir "${WORKDIR}"/all
273 pushd "${WORKDIR}"/all &>/dev/null
274
275 # We don't support an each-unpack, it's either all or nothing!
276 if type all_ruby_unpack &>/dev/null; then
277 _ruby_invoke_environment all all_ruby_unpack
278 else
279 [[ -n ${A} ]] && unpack ${A}
280 fi
281
282 popd &>/dev/null
283 }
284
285 _ruby_apply_patches() {
286 for patch in "${RUBY_PATCHES[@]}"; do
287 if [ -f "${patch}" ]; then
288 epatch "${patch}"
289 elif [ -f "${FILESDIR}/${patch}" ]; then
290 epatch "${FILESDIR}/${patch}"
291 else
292 die "Cannot find patch ${patch}"
293 fi
294 done
295
296 # This is a special case: instead of executing just in the special
297 # "all" environment, this will actually copy the effects on _all_
298 # the other environments, and is thus executed before the copy
299 type all_ruby_prepare &>/dev/null && all_ruby_prepare
300 }
301
302 _ruby_source_copy() {
303 # Until we actually find a reason not to, we use hardlinks, this
304 # should reduce the amount of disk space that is wasted by this.
305 cp -prl all ${_ruby_implementation} \
306 || die "Unable to copy ${_ruby_implementation} environment"
307 }
308
309 # @FUNCTION: ruby-ng_src_prepare
310 # @DESCRIPTION:
311 # Apply patches and prepare versions for each ruby target
312 # implementation. Also carry out common clean up tasks.
313 ruby-ng_src_prepare() {
314 # Way too many Ruby packages are prepared on OSX without removing
315 # the extra data forks, we do it here to avoid repeating it for
316 # almost every other ebuild.
317 find . -name '._*' -delete
318
319 _ruby_invoke_environment all _ruby_apply_patches
320
321 _PHASE="source copy" \
322 _ruby_each_implementation _ruby_source_copy
323
324 if type each_ruby_prepare &>/dev/null; then
325 _ruby_each_implementation each_ruby_prepare
326 fi
327 }
328
329 # @FUNCTION: ruby-ng_src_configure
330 # @DESCRIPTION:
331 # Configure the package.
332 ruby-ng_src_configure() {
333 if type each_ruby_configure &>/dev/null; then
334 _ruby_each_implementation each_ruby_configure
335 fi
336
337 type all_ruby_configure &>/dev/null && \
338 _ruby_invoke_environment all all_ruby_configure
339 }
340
341 # @FUNCTION: ruby-ng_src_compile
342 # @DESCRIPTION:
343 # Compile the package.
344 ruby-ng_src_compile() {
345 if type each_ruby_compile &>/dev/null; then
346 _ruby_each_implementation each_ruby_compile
347 fi
348
349 type all_ruby_compile &>/dev/null && \
350 _ruby_invoke_environment all all_ruby_compile
351 }
352
353 # @FUNCTION: ruby-ng_src_test
354 # @DESCRIPTION:
355 # Run tests for the package.
356 ruby-ng_src_test() {
357 if type each_ruby_test &>/dev/null; then
358 _ruby_each_implementation each_ruby_test
359 fi
360
361 type all_ruby_test &>/dev/null && \
362 _ruby_invoke_environment all all_ruby_test
363 }
364
365 _each_ruby_check_install() {
366 local libruby_basename=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["LIBRUBY_SO"]')
367 local libruby_soname=$(scanelf -qS "/usr/$(get_libdir)/${libruby_basename}" | awk '{ print $1 }')
368 local sitedir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitedir"]')
369 local sitelibdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]')
370
371 # Look for wrong files in sitedir
372 if [[ -d "${D}${sitedir}" ]]; then
373 local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}")
374 if [[ -n ${f} ]]; then
375 eerror "Found files in sitedir, outsite sitelibdir:"
376 eerror "${f}"
377 die "Misplaced files in sitedir"
378 fi
379 fi
380
381 # The current implementation lacks libruby (i.e.: jruby)
382 [[ -z ${libruby_soname} ]] && return 0
383
384 scanelf -qnR "${D}${sitedir}" \
385 | fgrep -v "${libruby_soname}" \
386 > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log
387
388 if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then
389 ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby}"
390 ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log )
391 die "Missing links to ${libruby}"
392 fi
393 }
394
395 # @FUNCTION: ruby-ng_src_install
396 # @DESCRIPTION:
397 # Install the package for each ruby target implementation.
398 ruby-ng_src_install() {
399 if type each_ruby_install &>/dev/null; then
400 _ruby_each_implementation each_ruby_install
401 fi
402
403 type all_ruby_install &>/dev/null && \
404 _ruby_invoke_environment all all_ruby_install
405
406 _PHASE="check install" \
407 _ruby_each_implementation _each_ruby_check_install
408 }
409
410 # @FUNCTION: doruby
411 # @USAGE: file [file...]
412 # @DESCRIPTION:
413 # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}.
414 doruby() {
415 [[ -z ${RUBY} ]] && die "\$RUBY is not set"
416 ( # don't want to pollute calling env
417 insinto $(${RUBY} -rrbconfig -e 'print Config::CONFIG["sitelibdir"]')
418 insopts -m 0644
419 doins "$@"
420 ) || die "failed to install $@"
421 }
422
423 # @FUNCTION: ruby_get_libruby
424 # @RETURN: The location of libruby*.so belonging to the Ruby interpreter in ${RUBY}.
425 ruby_get_libruby() {
426 ${RUBY} -rrbconfig -e 'puts File.join(Config::CONFIG["libdir"], Config::CONFIG["LIBRUBY"])'
427 }
428
429 # @FUNCTION: ruby_get_hdrdir
430 # @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}.
431 ruby_get_hdrdir() {
432 local rubyhdrdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["rubyhdrdir"]')
433
434 if [[ "${rubyhdrdir}" = "nil" ]] ; then
435 rubyhdrdir=$(${RUBY} -rrbconfig -e 'puts Config::CONFIG["archdir"]')
436 fi
437
438 echo "${rubyhdrdir}"
439 }

  ViewVC Help
Powered by ViewVC 1.1.20