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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.34 - (show annotations) (download)
Mon Aug 13 22:21:26 2012 UTC (23 months, 2 weeks ago) by flameeyes
Branch: MAIN
Changes since 1.33: +15 -3 lines
Add support for cucumber as a test recipe. This allows abstracting some of the work needed to skip it over on JRuby.

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

  ViewVC Help
Powered by ViewVC 1.1.20