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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.37 - (show annotations) (download)
Sun Aug 19 07:45:02 2012 UTC (20 months ago) by graaff
Branch: MAIN
Changes since 1.36: +11 -4 lines
Make sure to use UTF-8 encoding when reading YAML files with ruby19. Patch and bug report by Shunsuke Shimizu in bug 431276.

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

  ViewVC Help
Powered by ViewVC 1.1.20