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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.34 - (hide annotations) (download)
Mon Aug 13 22:21:26 2012 UTC (2 years, 2 months 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 flameeyes 1.33 # Copyright 1999-2012 Gentoo Foundation
2 a3li 1.1 # Distributed under the terms of the GNU General Public License v2
3 flameeyes 1.34 # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-fakegem.eclass,v 1.33 2012/07/05 21:23:01 flameeyes Exp $
4 vapier 1.30
5 a3li 1.1 # @ECLASS: ruby-fakegem.eclass
6     # @MAINTAINER:
7     # Ruby herd <ruby@gentoo.org>
8 vapier 1.30 # @AUTHOR:
9 a3li 1.1 # 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 flameeyes 1.4 # RUBY_FAKEGEM_TASK_DOC="rdoc"
32 a3li 1.1
33 flameeyes 1.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 flameeyes 1.34 # - cucumber (calls ruby-ng_cucumber, adds dev-util/cucumber to the
39     # dependencies; does not work on JRuby).
40 flameeyes 1.33 # - none
41     # RUBY_FAKEGEM_RECIPE_TEST="rake"
42    
43 a3li 1.1 # @ECLASS-VARIABLE: RUBY_FAKEGEM_TASK_TEST
44     # @DESCRIPTION:
45 flameeyes 1.33 # Specify the rake(1) task used for executing tests. Only valid
46     # if RUBY_FAKEGEM_RECIPE_TEST is set to "rake" (the default).
47 flameeyes 1.4 # 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 a3li 1.1
60 flameeyes 1.6 # @ECLASS-VARIABLE: RUBY_FAKEGEM_BINWRAP
61     # @DESCRIPTION:
62     # Binaries to wrap around (relative to the bin/ directory)
63     # RUBY_FAKEGEM_BINWRAP="*"
64    
65 flameeyes 1.8 # @ECLASS-VARIABLE: RUBY_FAKEGEM_REQUIRE_PATHS
66     # @DESCRIPTION:
67     # Extra require paths (beside lib) to add to the specification
68 flameeyes 1.10 # RUBY_FAKEGEM_REQUIRE_PATHS=""
69 flameeyes 1.8
70 graaff 1.27 # @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 graaff 1.32 # @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 a3li 1.1 RUBY_FAKEGEM_NAME="${RUBY_FAKEGEM_NAME:-${PN}}"
83 flameeyes 1.15 RUBY_FAKEGEM_VERSION="${RUBY_FAKEGEM_VERSION:-${PV/_pre/.pre}}"
84     RUBY_FAKEGEM_SUFFIX="${RUBY_FAKEGEM_SUFFIX:-}"
85 a3li 1.1
86     RUBY_FAKEGEM_TASK_DOC="${RUBY_FAKEGEM_TASK_DOC-rdoc}"
87 flameeyes 1.33 RUBY_FAKEGEM_RECIPE_TEST="${RUBY_FAKEGEM_RECIPE_TEST-rake}"
88 a3li 1.1 RUBY_FAKEGEM_TASK_TEST="${RUBY_FAKEGEM_TASK_TEST-test}"
89    
90 flameeyes 1.6 RUBY_FAKEGEM_BINWRAP="${RUBY_FAKEGEM_BINWRAP-*}"
91    
92 a3li 1.1 if [[ ${RUBY_FAKEGEM_TASK_DOC} != "" ]]; then
93     IUSE="$IUSE doc"
94 flameeyes 1.18 ruby_add_bdepend "doc? ( dev-ruby/rake )"
95 a3li 1.1 fi
96    
97 flameeyes 1.21 if [[ -n ${RUBY_FAKEGEM_DOCDIR} ]]; then
98     IUSE="$IUSE doc"
99     fi
100    
101 flameeyes 1.33 [[ ${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 flameeyes 1.34 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 flameeyes 1.33 *)
120     RUBY_FAKEGEM_RECIPE_TEST="none"
121     ;;
122     esac
123 a3li 1.1
124 flameeyes 1.15 SRC_URI="mirror://rubygems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}${RUBY_FAKEGEM_SUFFIX:+-${RUBY_FAKEGEM_SUFFIX}}.gem"
125 flameeyes 1.3
126 graaff 1.31 ruby_add_bdepend virtual/rubygems
127     ruby_add_rdepend virtual/rubygems
128 a3li 1.1
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 grobian 1.24 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 a3li 1.1
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 graaff 1.27 # @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 graaff 1.28 ) || die "Unable to generate gemspec file."
199 graaff 1.27
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 a3li 1.1 # @FUNCTION: ruby_fakegem_genspec
225 graaff 1.27 # @USAGE: output-gemspec
226 a3li 1.1 # @DESCRIPTION:
227     # Generates a gemspec for the package and places it into the "specifications"
228     # directory of RubyGems.
229 graaff 1.27 # 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 a3li 1.1 # 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 flameeyes 1.8 # See RUBY_FAKEGEM_REQUIRE_PATHS for setting extra require paths.
237 a3li 1.1 ruby_fakegem_genspec() {
238 graaff 1.27 local required_paths="'lib'"
239     for path in ${RUBY_FAKEGEM_REQUIRE_PATHS}; do
240     required_paths="${required_paths}, '${path}'"
241     done
242 flameeyes 1.8
243 graaff 1.27 # 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 flameeyes 1.34 # generated by ruby-fakegem.eclass $Revision: 1.33 $
250 a3li 1.1 Gem::Specification.new do |s|
251     s.name = "${RUBY_FAKEGEM_NAME}"
252     s.version = "${RUBY_FAKEGEM_VERSION}"
253 graaff 1.14 s.summary = "${quoted_description}"
254 a3li 1.1 s.homepage = "${HOMEPAGE}"
255 flameeyes 1.8 s.require_paths = [${required_paths}]
256 a3li 1.1 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 flameeyes 1.5 local relativegembinary=${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}/bin/${gembinary}
270 flameeyes 1.12 local binpath=$(dirname $newbinary)
271     [[ ${binpath} = . ]] && binpath=/usr/bin
272 a3li 1.1
273 flameeyes 1.16 # 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 flameeyes 1.23 rubycmd="$(ruby_implementation_command ${implementation})"
286 flameeyes 1.16 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 a3li 1.1 cat - > "${T}"/gembin-wrapper-${gembinary} <<EOF
296 flameeyes 1.16 #!${rubycmd}
297 a3li 1.1 # This is a simplified version of the RubyGems wrapper
298     #
299 flameeyes 1.34 # Generated by ruby-fakegem.eclass $Revision: 1.33 $
300 a3li 1.1
301     require 'rubygems'
302    
303 flameeyes 1.5 load Gem::default_path[-1] + "/gems/${relativegembinary}"
304 a3li 1.1
305     EOF
306    
307 flameeyes 1.12 exeinto ${binpath:-/usr/bin}
308 a3li 1.1 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 flameeyes 1.19 for archive in ${A}; do
330 flameeyes 1.22 case "${archive}" in
331     *.gem)
332 graaff 1.29 # Make sure that we're not running unpack for more than
333 flameeyes 1.22 # 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 graaff 1.27 ebegin "Uncompressing metadata"
341     gunzip metadata.gz || die
342     eend $?
343    
344 flameeyes 1.22 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 graaff 1.27
351 flameeyes 1.22 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 flameeyes 1.19 done
366 a3li 1.1 }
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 flameeyes 1.33 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 flameeyes 1.34 cucumber)
387     ruby-ng_cucumber
388     ;;
389 flameeyes 1.33 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 flameeyes 1.13 fi
403 a3li 1.1
404     # @FUNCTION: each_fakegem_install
405     # @DESCRIPTION:
406     # Install the package for each ruby target.
407     each_fakegem_install() {
408 graaff 1.27 ruby_fakegem_install_gemspec
409 a3li 1.1
410 flameeyes 1.11 local _gemlibdirs="${RUBY_FAKEGEM_EXTRAINSTALL}"
411     for directory in bin lib; do
412 a3li 1.1 [[ -d ${directory} ]] && _gemlibdirs="${_gemlibdirs} ${directory}"
413     done
414    
415 flameeyes 1.9 [[ -n ${_gemlibdirs} ]] && \
416     ruby_fakegem_doins -r ${_gemlibdirs}
417 a3li 1.1 }
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 flameeyes 1.20 if [[ -n ${RUBY_FAKEGEM_DOCDIR} ]] && use doc; then
431 flameeyes 1.7 for dir in ${RUBY_FAKEGEM_DOCDIR}; do
432 flameeyes 1.20 [[ -d ${dir} ]] || continue
433    
434 flameeyes 1.11 pushd ${dir} &>/dev/null
435 flameeyes 1.7 dohtml -r * || die "failed to install documentation"
436 flameeyes 1.11 popd &>/dev/null
437 flameeyes 1.7 done
438 a3li 1.1 fi
439    
440     if [[ -n ${RUBY_FAKEGEM_EXTRADOC} ]]; then
441     dodoc ${RUBY_FAKEGEM_EXTRADOC} || die "failed to install further documentation"
442     fi
443 flameeyes 1.6
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 flameeyes 1.11 pushd "${bindir}" &>/dev/null
451 flameeyes 1.6 local binaries=$(eval ls ${RUBY_FAKEGEM_BINWRAP})
452     for binary in $binaries; do
453     ruby_fakegem_binwrapper $binary
454     done
455 flameeyes 1.11 popd &>/dev/null
456 flameeyes 1.6 fi
457     fi
458 a3li 1.1 }
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