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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.44 - (show annotations) (download)
Sun Dec 28 10:13:18 2014 UTC (4 months, 3 weeks ago) by graaff
Branch: MAIN
CVS Tags: HEAD
Changes since 1.43: +11 -3 lines
Add test recipe for rspec:3 slot.

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

  ViewVC Help
Powered by ViewVC 1.1.20