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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.33 - (show annotations) (download)
Thu Jul 5 21:23:01 2012 UTC (3 years, 1 month ago) by flameeyes
Branch: MAIN
Changes since 1.32: +50 -20 lines
Add support for running rspec while respecting some common variables (TEST_VERBOSE and NOCOLOR) in ruby-ng; then use this with a new variable in ruby-fakegem.

1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-fakegem.eclass,v 1.32 2011/12/05 12:24:33 graaff Exp $
4
5 # @ECLASS: ruby-fakegem.eclass
6 # @MAINTAINER:
7 # Ruby herd <ruby@gentoo.org>
8 # @AUTHOR:
9 # Author: Diego E. Pettenò <flameeyes@gentoo.org>
10 # Author: Alex Legler <a3li@gentoo.org>
11 # @BLURB: An eclass for installing Ruby packages to behave like RubyGems.
12 # @DESCRIPTION:
13 # This eclass allows to install arbitrary Ruby libraries (including Gems),
14 # providing integration into the RubyGems system even for "regular" packages.
15
16 inherit ruby-ng
17
18 # @ECLASS-VARIABLE: RUBY_FAKEGEM_NAME
19 # @DESCRIPTION:
20 # Sets the Gem name for the generated fake gemspec.
21 # RUBY_FAKEGEM_NAME="${PN}"
22
23 # @ECLASS-VARIABLE: RUBY_FAKEGEM_VERSION
24 # @DESCRIPTION:
25 # Sets the Gem version for the generated fake gemspec.
26 # RUBY_FAKEGEM_VERSION="${PV}"
27
28 # @ECLASS-VARIABLE: RUBY_FAKEGEM_TASK_DOC
29 # @DESCRIPTION:
30 # Specify the rake(1) task to run to generate documentation.
31 # RUBY_FAKEGEM_TASK_DOC="rdoc"
32
33 # @ECLASS-VARIABLE: RUBY_FAKEGEM_RECIPE_TEST
34 # @DESCRIPTION:
35 # Specify one of the default testing function for ruby-fakegem:
36 # - rake (default; see also RUBY_FAKEGEM_TASK_TEST)
37 # - rspec (calls ruby-ng_rspec, adds dev-ruby/rspec:2 to the dependencies)
38 # - none
39 # RUBY_FAKEGEM_RECIPE_TEST="rake"
40
41 # @ECLASS-VARIABLE: RUBY_FAKEGEM_TASK_TEST
42 # @DESCRIPTION:
43 # Specify the rake(1) task used for executing tests. Only valid
44 # if RUBY_FAKEGEM_RECIPE_TEST is set to "rake" (the default).
45 # RUBY_FAKEGEM_TASK_TEST="test"
46
47 # @ECLASS-VARIABLE: RUBY_FAKEGEM_DOCDIR
48 # @DESCRIPTION:
49 # Specify the directory under which the documentation is built;
50 # if empty no documentation will be installed automatically.
51 # RUBY_FAKEGEM_DOCDIR=""
52
53 # @ECLASS-VARIABLE: RUBY_FAKEGEM_EXTRADOC
54 # @DESCRIPTION:
55 # Extra documentation to install (readme, changelogs, …).
56 # RUBY_FAKEGEM_EXTRADOC=""
57
58 # @ECLASS-VARIABLE: RUBY_FAKEGEM_BINWRAP
59 # @DESCRIPTION:
60 # Binaries to wrap around (relative to the bin/ directory)
61 # RUBY_FAKEGEM_BINWRAP="*"
62
63 # @ECLASS-VARIABLE: RUBY_FAKEGEM_REQUIRE_PATHS
64 # @DESCRIPTION:
65 # Extra require paths (beside lib) to add to the specification
66 # RUBY_FAKEGEM_REQUIRE_PATHS=""
67
68 # @ECLASS-VARIABLE: RUBY_FAKEGEM_GEMSPEC
69 # @DESCRIPTION:
70 # Filename of .gemspec file to install instead of generating a generic one.
71 # RUBY_FAKEGEM_GEMSPEC=""
72
73 # @ECLASS-VARIABLE: RUBY_FAKEGEM_EXTRAINSTALL
74 # @DESCRIPTION:
75 # List of files and directories relative to the top directory that also
76 # get installed. Some gems provide extra files such as version information,
77 # Rails generators, or data that needs to be installed as well.
78 # RUBY_FAKEGEM_EXTRAINSTALL=""
79
80 RUBY_FAKEGEM_NAME="${RUBY_FAKEGEM_NAME:-${PN}}"
81 RUBY_FAKEGEM_VERSION="${RUBY_FAKEGEM_VERSION:-${PV/_pre/.pre}}"
82 RUBY_FAKEGEM_SUFFIX="${RUBY_FAKEGEM_SUFFIX:-}"
83
84 RUBY_FAKEGEM_TASK_DOC="${RUBY_FAKEGEM_TASK_DOC-rdoc}"
85 RUBY_FAKEGEM_RECIPE_TEST="${RUBY_FAKEGEM_RECIPE_TEST-rake}"
86 RUBY_FAKEGEM_TASK_TEST="${RUBY_FAKEGEM_TASK_TEST-test}"
87
88 RUBY_FAKEGEM_BINWRAP="${RUBY_FAKEGEM_BINWRAP-*}"
89
90 if [[ ${RUBY_FAKEGEM_TASK_DOC} != "" ]]; then
91 IUSE="$IUSE doc"
92 ruby_add_bdepend "doc? ( dev-ruby/rake )"
93 fi
94
95 if [[ -n ${RUBY_FAKEGEM_DOCDIR} ]]; then
96 IUSE="$IUSE doc"
97 fi
98
99 [[ ${RUBY_FAKEGEM_TASK_TEST} == "" ]] && RUBY_FAKEGEM_RECIPE_TEST="none"
100
101 case ${RUBY_FAKEGEM_RECIPE_TEST} in
102 rake)
103 IUSE+=" test"
104 ruby_add_bdepend "test? ( dev-ruby/rake )"
105 ;;
106 rspec)
107 IUSE+=" test"
108 ruby_add_bdepend "test? ( dev-ruby/rspec:2 )"
109 ;;
110 *)
111 RUBY_FAKEGEM_RECIPE_TEST="none"
112 ;;
113 esac
114
115 SRC_URI="mirror://rubygems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}${RUBY_FAKEGEM_SUFFIX:+-${RUBY_FAKEGEM_SUFFIX}}.gem"
116
117 ruby_add_bdepend virtual/rubygems
118 ruby_add_rdepend virtual/rubygems
119
120 # @FUNCTION: ruby_fakegem_gemsdir
121 # @RETURN: Returns the gem data directory
122 # @DESCRIPTION:
123 # This function returns the gems data directory for the ruby
124 # implementation in question.
125 ruby_fakegem_gemsdir() {
126 has "${EAPI}" 2 && ! use prefix && EPREFIX=
127
128 local _gemsitedir=$(ruby_rbconfig_value 'sitelibdir')
129 _gemsitedir=${_gemsitedir//site_ruby/gems}
130 _gemsitedir=${_gemsitedir#${EPREFIX}}
131
132 [[ -z ${_gemsitedir} ]] && {
133 eerror "Unable to find the gems dir"
134 die "Unable to find the gems dir"
135 }
136
137 echo "${_gemsitedir}"
138 }
139
140 # @FUNCTION: ruby_fakegem_doins
141 # @USAGE: file [file...]
142 # @DESCRIPTION:
143 # Installs the specified file(s) into the gems directory.
144 ruby_fakegem_doins() {
145 (
146 insinto $(ruby_fakegem_gemsdir)/gems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}
147 doins "$@"
148 ) || die "failed $0 $@"
149 }
150
151 # @FUNCTION: ruby_fakegem_newsins()
152 # @USAGE: file filename
153 # @DESCRIPTION:
154 # Installs the specified file into the gems directory using the provided filename.
155 ruby_fakegem_newins() {
156 (
157 # Since newins does not accept full paths but just basenames
158 # for the target file, we want to extend it here.
159 local newdirname=/$(dirname "$2")
160 [[ ${newdirname} == "/." ]] && newdirname=
161
162 local newbasename=$(basename "$2")
163
164 insinto $(ruby_fakegem_gemsdir)/gems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}${newdirname}
165 newins "$1" ${newbasename}
166 ) || die "failed $0 $@"
167 }
168
169 # @FUNCTION: ruby_fakegem_install_gemspec
170 # @DESCRIPTION:
171 # Install a .gemspec file for this package. Either use the file indicated
172 # by the RUBY_FAKEGEM_GEMSPEC variable, or generate one using
173 # ruby_fakegem_genspec.
174 ruby_fakegem_install_gemspec() {
175 local gemspec="${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation}
176
177 (
178 if [[ ${RUBY_FAKEGEM_GEMSPEC} != "" ]]; then
179 ruby_fakegem_gemspec_gemspec ${RUBY_FAKEGEM_GEMSPEC} ${gemspec}
180 else
181 local metadata="${WORKDIR}"/${_ruby_implementation}/metadata
182
183 if [[ -e ${metadata} ]]; then
184 ruby_fakegem_metadata_gemspec ${metadata} ${gemspec}
185 else
186 ruby_fakegem_genspec ${gemspec}
187 fi
188 fi
189 ) || die "Unable to generate gemspec file."
190
191 insinto $(ruby_fakegem_gemsdir)/specifications
192 newins ${gemspec} ${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}.gemspec || die "Unable to install gemspec file."
193 }
194
195 # @FUNCTION: ruby_fakegem_gemspec_gemspec
196 # @USAGE: gemspec-input gemspec-output
197 # @DESCRIPTION:
198 # Generates an installable version of the specification indicated by
199 # RUBY_FAKEGEM_GEMSPEC. This file is eval'ed to produce a final specification
200 # in a way similar to packaging the gemspec file.
201 ruby_fakegem_gemspec_gemspec() {
202 ${RUBY} -e "puts eval(File::open('$1').read).to_ruby" > $2
203 }
204
205 # @FUNCTION: ruby_fakegem_metadata_gemspec
206 # @USAGE: gemspec-metadata gemspec-output
207 # @DESCRIPTION:
208 # Generates an installable version of the specification indicated by
209 # the metadata distributed by the gem itself. This is similar to how
210 # rubygems creates an installation from a .gem file.
211 ruby_fakegem_metadata_gemspec() {
212 ${RUBY} -r yaml -e "puts Gem::Specification.from_yaml(File::open('$1').read).to_ruby" > $2
213 }
214
215 # @FUNCTION: ruby_fakegem_genspec
216 # @USAGE: output-gemspec
217 # @DESCRIPTION:
218 # Generates a gemspec for the package and places it into the "specifications"
219 # directory of RubyGems.
220 # If the metadata normally distributed with a gem is present then that is
221 # used to generate the gemspec file.
222 #
223 # As a fallback we can generate our own version.
224 # In the gemspec, the following values are set: name, version, summary,
225 # homepage, and require_paths=["lib"].
226 # See RUBY_FAKEGEM_NAME and RUBY_FAKEGEM_VERSION for setting name and version.
227 # See RUBY_FAKEGEM_REQUIRE_PATHS for setting extra require paths.
228 ruby_fakegem_genspec() {
229 local required_paths="'lib'"
230 for path in ${RUBY_FAKEGEM_REQUIRE_PATHS}; do
231 required_paths="${required_paths}, '${path}'"
232 done
233
234 # We use the _ruby_implementation variable to avoid having stray
235 # copies with different implementations; while for now we're using
236 # the same exact content, we might have differences in the future,
237 # so better taking this into consideration.
238 local quoted_description=${DESCRIPTION//\"/\\\"}
239 cat - > $1 <<EOF
240 # generated by ruby-fakegem.eclass $Revision: 1.32 $
241 Gem::Specification.new do |s|
242 s.name = "${RUBY_FAKEGEM_NAME}"
243 s.version = "${RUBY_FAKEGEM_VERSION}"
244 s.summary = "${quoted_description}"
245 s.homepage = "${HOMEPAGE}"
246 s.require_paths = [${required_paths}]
247 end
248 EOF
249 }
250
251 # @FUNCTION: ruby_fakegem_binwrapper
252 # @USAGE: command [path]
253 # @DESCRIPTION:
254 # Creates a new binary wrapper for a command installed by the RubyGem.
255 # path defaults to /usr/bin/$command
256 ruby_fakegem_binwrapper() {
257 (
258 local gembinary=$1
259 local newbinary=${2:-/usr/bin/$gembinary}
260 local relativegembinary=${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}/bin/${gembinary}
261 local binpath=$(dirname $newbinary)
262 [[ ${binpath} = . ]] && binpath=/usr/bin
263
264 # Try to find out whether the package is going to install for
265 # one or multiple implementations; if we're installing for a
266 # *single* implementation, no need to use “/usr/bin/env ruby”
267 # in the shebang, and we can actually avoid errors when
268 # calling the script by default (see for instance the
269 # JRuby-specific commands).
270 local rubycmd=
271 for implementation in ${USE_RUBY}; do
272 # ignore non-enabled implementations
273 use ruby_targets_${implementation} || continue
274 if [ -z $rubycmd ]; then
275 # if no other implementation was set before, set it.
276 rubycmd="$(ruby_implementation_command ${implementation})"
277 else
278 # if another implementation already arrived, then make
279 # it generic and break out of the loop. This ensures
280 # that we do at most two iterations.
281 rubycmd="/usr/bin/env ruby"
282 break
283 fi
284 done
285
286 cat - > "${T}"/gembin-wrapper-${gembinary} <<EOF
287 #!${rubycmd}
288 # This is a simplified version of the RubyGems wrapper
289 #
290 # Generated by ruby-fakegem.eclass $Revision: 1.32 $
291
292 require 'rubygems'
293
294 load Gem::default_path[-1] + "/gems/${relativegembinary}"
295
296 EOF
297
298 exeinto ${binpath:-/usr/bin}
299 newexe "${T}"/gembin-wrapper-${gembinary} $(basename $newbinary)
300 ) || die "Unable to create fakegem wrapper"
301 }
302
303 # @FUNCTION: all_fakegem_compile
304 # @DESCRIPTION:
305 # Build documentation for the package if indicated by the doc USE flag
306 # and if there is a documetation task defined.
307 all_fakegem_compile() {
308 if [[ ${RUBY_FAKEGEM_TASK_DOC} != "" ]] && use doc; then
309 rake ${RUBY_FAKEGEM_TASK_DOC} || die "failed to (re)build documentation"
310 fi
311 }
312
313 # @FUNCTION: all_ruby_unpack
314 # @DESCRIPTION:
315 # Unpack the source archive, including support for unpacking gems.
316 all_ruby_unpack() {
317 # Special support for extracting .gem files; the file need to be
318 # extracted twice and the mtime from the archive _has_ to be
319 # ignored (it's always set to epoch 0).
320 for archive in ${A}; do
321 case "${archive}" in
322 *.gem)
323 # Make sure that we're not running unpack for more than
324 # one .gem file, since we won't support that at all.
325 [[ -d "${S}" ]] && die "Unable to unpack ${archive}, ${S} exists"
326
327 ebegin "Unpacking .gem file..."
328 tar -mxf ${DISTDIR}/${archive} || die
329 eend $?
330
331 ebegin "Uncompressing metadata"
332 gunzip metadata.gz || die
333 eend $?
334
335 mkdir "${S}"
336 pushd "${S}" &>/dev/null
337
338 ebegin "Unpacking data.tar.gz"
339 tar -mxf "${my_WORKDIR}"/data.tar.gz || die
340 eend $?
341
342 popd &>/dev/null
343 ;;
344 *.patch.bz2)
345 # We apply the patches with RUBY_PATCHES directly from DISTDIR,
346 # as the WORKDIR variable changes value between the global-scope
347 # and the time all_ruby_unpack/_prepare are called. Since we can
348 # simply decompress them when applying, this is much easier to
349 # deal with for us.
350 einfo "Keeping ${archive} as-is"
351 ;;
352 *)
353 unpack ${archive}
354 ;;
355 esac
356 done
357 }
358
359 # @FUNCTION: all_ruby_compile
360 # @DESCRIPTION:
361 # Compile the package.
362 all_ruby_compile() {
363 all_fakegem_compile
364 }
365
366 # @FUNCTION: each_fakegem_test
367 # @DESCRIPTION:
368 # Run tests for the package for each ruby target if the test task is defined.
369 each_fakegem_test() {
370 case ${RUBY_FAKEGEM_RECIPE_TEST} in
371 rake)
372 ${RUBY} -S rake ${RUBY_FAKEGEM_TASK_TEST} || die "tests failed"
373 ;;
374 rspec)
375 ruby-ng_rspec
376 ;;
377 none)
378 ewarn "each_fakegem_test called, but \${RUBY_FAKEGEM_RECIPE_TEST} is 'none'"
379 ;;
380 esac
381 }
382
383 if [[ ${RUBY_FAKEGEM_RECIPE_TEST} != none ]]; then
384 # @FUNCTION: each_ruby_test
385 # @DESCRIPTION:
386 # Run the tests for this package.
387 each_ruby_test() {
388 each_fakegem_test
389 }
390 fi
391
392 # @FUNCTION: each_fakegem_install
393 # @DESCRIPTION:
394 # Install the package for each ruby target.
395 each_fakegem_install() {
396 ruby_fakegem_install_gemspec
397
398 local _gemlibdirs="${RUBY_FAKEGEM_EXTRAINSTALL}"
399 for directory in bin lib; do
400 [[ -d ${directory} ]] && _gemlibdirs="${_gemlibdirs} ${directory}"
401 done
402
403 [[ -n ${_gemlibdirs} ]] && \
404 ruby_fakegem_doins -r ${_gemlibdirs}
405 }
406
407 # @FUNCTION: each_ruby_install
408 # @DESCRIPTION:
409 # Install the package for each target.
410 each_ruby_install() {
411 each_fakegem_install
412 }
413
414 # @FUNCTION: all_fakegem_install
415 # @DESCRIPTION:
416 # Install files common to all ruby targets.
417 all_fakegem_install() {
418 if [[ -n ${RUBY_FAKEGEM_DOCDIR} ]] && use doc; then
419 for dir in ${RUBY_FAKEGEM_DOCDIR}; do
420 [[ -d ${dir} ]] || continue
421
422 pushd ${dir} &>/dev/null
423 dohtml -r * || die "failed to install documentation"
424 popd &>/dev/null
425 done
426 fi
427
428 if [[ -n ${RUBY_FAKEGEM_EXTRADOC} ]]; then
429 dodoc ${RUBY_FAKEGEM_EXTRADOC} || die "failed to install further documentation"
430 fi
431
432 # binary wrappers; we assume that all the implementations get the
433 # same binaries, or something is wrong anyway, so...
434 if [[ -n ${RUBY_FAKEGEM_BINWRAP} ]]; then
435 local bindir=$(find "${D}" -type d -path "*/gems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}/bin" -print -quit)
436
437 if [[ -d "${bindir}" ]]; then
438 pushd "${bindir}" &>/dev/null
439 local binaries=$(eval ls ${RUBY_FAKEGEM_BINWRAP})
440 for binary in $binaries; do
441 ruby_fakegem_binwrapper $binary
442 done
443 popd &>/dev/null
444 fi
445 fi
446 }
447
448 # @FUNCTION: all_ruby_install
449 # @DESCRIPTION:
450 # Install files common to all ruby targets.
451 all_ruby_install() {
452 all_fakegem_install
453 }

  ViewVC Help
Powered by ViewVC 1.1.20