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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.39 - (show annotations) (download)
Sat Jun 1 13:18:45 2013 UTC (15 months, 2 weeks ago) by graaff
Branch: MAIN
Changes since 1.38: +4 -4 lines
Quote DISTDIR.

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

  ViewVC Help
Powered by ViewVC 1.1.20