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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.25 - (hide annotations) (download)
Sat Dec 18 09:50:08 2010 UTC (3 years, 10 months ago) by graaff
Branch: MAIN
Changes since 1.24: +26 -5 lines
Depend directly on dev-ruby/rubygems again since we no longer have ruby targets providing rubygems themselves.

1 a3li 1.1 # Copyright 1999-2009 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 graaff 1.25 # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-fakegem.eclass,v 1.24 2010/09/23 06:47:01 grobian Exp $
4 a3li 1.1 #
5     # @ECLASS: ruby-fakegem.eclass
6     # @MAINTAINER:
7     # Ruby herd <ruby@gentoo.org>
8     #
9     # Author: Diego E. Pettenò <flameeyes@gentoo.org>
10     #
11     # Author: Alex Legler <a3li@gentoo.org>
12     #
13     # @BLURB: An eclass for installing Ruby packages to behave like RubyGems.
14     # @DESCRIPTION:
15     # This eclass allows to install arbitrary Ruby libraries (including Gems),
16     # providing integration into the RubyGems system even for "regular" packages.
17     #
18    
19     inherit ruby-ng
20    
21     # @ECLASS-VARIABLE: RUBY_FAKEGEM_NAME
22     # @DESCRIPTION:
23     # Sets the Gem name for the generated fake gemspec.
24     # RUBY_FAKEGEM_NAME="${PN}"
25    
26     # @ECLASS-VARIABLE: RUBY_FAKEGEM_VERSION
27     # @DESCRIPTION:
28     # Sets the Gem version for the generated fake gemspec.
29     # RUBY_FAKEGEM_VERSION="${PV}"
30    
31     # @ECLASS-VARIABLE: RUBY_FAKEGEM_TASK_DOC
32     # @DESCRIPTION:
33     # Specify the rake(1) task to run to generate documentation.
34 flameeyes 1.4 # RUBY_FAKEGEM_TASK_DOC="rdoc"
35 a3li 1.1
36     # @ECLASS-VARIABLE: RUBY_FAKEGEM_TASK_TEST
37     # @DESCRIPTION:
38     # Specify the rake(1) task used for executing tests.
39 flameeyes 1.4 # RUBY_FAKEGEM_TASK_TEST="test"
40    
41     # @ECLASS-VARIABLE: RUBY_FAKEGEM_DOCDIR
42     # @DESCRIPTION:
43     # Specify the directory under which the documentation is built;
44     # if empty no documentation will be installed automatically.
45     # RUBY_FAKEGEM_DOCDIR=""
46    
47     # @ECLASS-VARIABLE: RUBY_FAKEGEM_EXTRADOC
48     # @DESCRIPTION:
49     # Extra documentation to install (readme, changelogs, …).
50     # RUBY_FAKEGEM_EXTRADOC=""
51 a3li 1.1
52 flameeyes 1.6 # @ECLASS-VARIABLE: RUBY_FAKEGEM_BINWRAP
53     # @DESCRIPTION:
54     # Binaries to wrap around (relative to the bin/ directory)
55     # RUBY_FAKEGEM_BINWRAP="*"
56    
57 flameeyes 1.8 # @ECLASS-VARIABLE: RUBY_FAKEGEM_REQUIRE_PATHS
58     # @DESCRIPTION:
59     # Extra require paths (beside lib) to add to the specification
60 flameeyes 1.10 # RUBY_FAKEGEM_REQUIRE_PATHS=""
61 flameeyes 1.8
62 graaff 1.25 # @ECLASS-VARIABLE: RUBY_FAKEGEM_GEMSPEC
63     # @DESCRIPTION:
64     # Filename of .gemspec file to install instead of generating a generic one.
65     # RUBY_FAKEGEM_GEMSPEC=""
66    
67 a3li 1.1 RUBY_FAKEGEM_NAME="${RUBY_FAKEGEM_NAME:-${PN}}"
68 flameeyes 1.15 RUBY_FAKEGEM_VERSION="${RUBY_FAKEGEM_VERSION:-${PV/_pre/.pre}}"
69     RUBY_FAKEGEM_SUFFIX="${RUBY_FAKEGEM_SUFFIX:-}"
70 a3li 1.1
71     RUBY_FAKEGEM_TASK_DOC="${RUBY_FAKEGEM_TASK_DOC-rdoc}"
72     RUBY_FAKEGEM_TASK_TEST="${RUBY_FAKEGEM_TASK_TEST-test}"
73    
74 flameeyes 1.6 RUBY_FAKEGEM_BINWRAP="${RUBY_FAKEGEM_BINWRAP-*}"
75    
76 a3li 1.1 if [[ ${RUBY_FAKEGEM_TASK_DOC} != "" ]]; then
77     IUSE="$IUSE doc"
78 flameeyes 1.18 ruby_add_bdepend "doc? ( dev-ruby/rake )"
79 a3li 1.1 fi
80    
81 flameeyes 1.21 if [[ -n ${RUBY_FAKEGEM_DOCDIR} ]]; then
82     IUSE="$IUSE doc"
83     fi
84    
85 a3li 1.1 if [[ ${RUBY_FAKEGEM_TASK_TEST} != "" ]]; then
86     IUSE="$IUSE test"
87 flameeyes 1.18 ruby_add_bdepend "test? ( dev-ruby/rake )"
88 a3li 1.1 fi
89    
90 flameeyes 1.15 SRC_URI="mirror://rubygems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}${RUBY_FAKEGEM_SUFFIX:+-${RUBY_FAKEGEM_SUFFIX}}.gem"
91 flameeyes 1.3
92 graaff 1.25 ruby_add_rdepend dev-ruby/rubygems
93 a3li 1.1
94     # @FUNCTION: ruby_fakegem_gemsdir
95     # @RETURN: Returns the gem data directory
96     # @DESCRIPTION:
97     # This function returns the gems data directory for the ruby
98     # implementation in question.
99     ruby_fakegem_gemsdir() {
100 grobian 1.24 has "${EAPI}" 2 && ! use prefix && EPREFIX=
101    
102     local _gemsitedir=$(ruby_rbconfig_value 'sitelibdir')
103     _gemsitedir=${_gemsitedir//site_ruby/gems}
104     _gemsitedir=${_gemsitedir#${EPREFIX}}
105 a3li 1.1
106     [[ -z ${_gemsitedir} ]] && {
107     eerror "Unable to find the gems dir"
108     die "Unable to find the gems dir"
109     }
110    
111     echo "${_gemsitedir}"
112     }
113    
114     # @FUNCTION: ruby_fakegem_doins
115     # @USAGE: file [file...]
116     # @DESCRIPTION:
117     # Installs the specified file(s) into the gems directory.
118     ruby_fakegem_doins() {
119     (
120     insinto $(ruby_fakegem_gemsdir)/gems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}
121     doins "$@"
122     ) || die "failed $0 $@"
123     }
124    
125     # @FUNCTION: ruby_fakegem_newsins()
126     # @USAGE: file filename
127     # @DESCRIPTION:
128     # Installs the specified file into the gems directory using the provided filename.
129     ruby_fakegem_newins() {
130     (
131     # Since newins does not accept full paths but just basenames
132     # for the target file, we want to extend it here.
133     local newdirname=/$(dirname "$2")
134     [[ ${newdirname} == "/." ]] && newdirname=
135    
136     local newbasename=$(basename "$2")
137    
138     insinto $(ruby_fakegem_gemsdir)/gems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}${newdirname}
139     newins "$1" ${newbasename}
140     ) || die "failed $0 $@"
141     }
142    
143 graaff 1.25 # @FUNCTION: ruby_fakegem_gemspec
144     # @DESCRIPTION:
145     # Install a .gemspec file for this package. Either use the file indicated
146     # by the RUBY_FAKEGEM_GEMSPEC variable, or generate one using
147     # ruby_fakegem_genspec
148     ruby_fakegem_gemspec() {
149     if [[ ${RUBY_FAKEGEM_GEMSPEC} != "" ]]; then
150     (
151     insinto $(ruby_fakegem_gemsdir)/specifications
152     newins "${RUBY_FAKEGEM_GEMSPEC}" ${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}.gemspec
153     ) || die "Unable to install ${RUBY_FAKEGEM_GEMSPEC} gemspec"
154     else
155     ruby_fakegem_genspec
156     fi
157     }
158    
159 a3li 1.1 # @FUNCTION: ruby_fakegem_genspec
160     # @DESCRIPTION:
161     # Generates a gemspec for the package and places it into the "specifications"
162     # directory of RubyGems.
163     # In the gemspec, the following values are set: name, version, summary,
164     # homepage, and require_paths=["lib"].
165     # See RUBY_FAKEGEM_NAME and RUBY_FAKEGEM_VERSION for setting name and version.
166 flameeyes 1.8 # See RUBY_FAKEGEM_REQUIRE_PATHS for setting extra require paths.
167 a3li 1.1 ruby_fakegem_genspec() {
168     (
169 flameeyes 1.8 local required_paths="'lib'"
170     for path in ${RUBY_FAKEGEM_REQUIRE_PATHS}; do
171     required_paths="${required_paths}, '${path}'"
172     done
173    
174 a3li 1.1 # We use the _ruby_implementation variable to avoid having stray
175     # copies with different implementations; while for now we're using
176     # the same exact content, we might have differences in the future,
177     # so better taking this into consideration.
178 graaff 1.14 local quoted_description=${DESCRIPTION//\"/\\\"}
179 a3li 1.1 cat - > "${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation} <<EOF
180 graaff 1.25 # generated by ruby-fakegem.eclass $Revision: 1.24 $
181 a3li 1.1 Gem::Specification.new do |s|
182     s.name = "${RUBY_FAKEGEM_NAME}"
183     s.version = "${RUBY_FAKEGEM_VERSION}"
184 graaff 1.14 s.summary = "${quoted_description}"
185 a3li 1.1 s.homepage = "${HOMEPAGE}"
186 flameeyes 1.8 s.require_paths = [${required_paths}]
187 a3li 1.1 end
188     EOF
189    
190     insinto $(ruby_fakegem_gemsdir)/specifications
191     newins "${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation} ${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}.gemspec
192     ) || die "Unable to install fake gemspec"
193     }
194    
195     # @FUNCTION: ruby_fakegem_binwrapper
196     # @USAGE: command [path]
197     # @DESCRIPTION:
198     # Creates a new binary wrapper for a command installed by the RubyGem.
199     # path defaults to /usr/bin/$command
200     ruby_fakegem_binwrapper() {
201     (
202     local gembinary=$1
203     local newbinary=${2:-/usr/bin/$gembinary}
204 flameeyes 1.5 local relativegembinary=${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}/bin/${gembinary}
205 flameeyes 1.12 local binpath=$(dirname $newbinary)
206     [[ ${binpath} = . ]] && binpath=/usr/bin
207 a3li 1.1
208 flameeyes 1.16 # Try to find out whether the package is going to install for
209     # one or multiple implementations; if we're installing for a
210     # *single* implementation, no need to use “/usr/bin/env ruby”
211     # in the shebang, and we can actually avoid errors when
212     # calling the script by default (see for instance the
213     # JRuby-specific commands).
214     local rubycmd=
215     for implementation in ${USE_RUBY}; do
216     # ignore non-enabled implementations
217     use ruby_targets_${implementation} || continue
218     if [ -z $rubycmd ]; then
219     # if no other implementation was set before, set it.
220 flameeyes 1.23 rubycmd="$(ruby_implementation_command ${implementation})"
221 flameeyes 1.16 else
222     # if another implementation already arrived, then make
223     # it generic and break out of the loop. This ensures
224     # that we do at most two iterations.
225     rubycmd="/usr/bin/env ruby"
226     break
227     fi
228     done
229    
230 a3li 1.1 cat - > "${T}"/gembin-wrapper-${gembinary} <<EOF
231 flameeyes 1.16 #!${rubycmd}
232 a3li 1.1 # This is a simplified version of the RubyGems wrapper
233     #
234 graaff 1.25 # Generated by ruby-fakegem.eclass $Revision: 1.24 $
235 a3li 1.1
236     require 'rubygems'
237    
238 flameeyes 1.5 load Gem::default_path[-1] + "/gems/${relativegembinary}"
239 a3li 1.1
240     EOF
241    
242 flameeyes 1.12 exeinto ${binpath:-/usr/bin}
243 a3li 1.1 newexe "${T}"/gembin-wrapper-${gembinary} $(basename $newbinary)
244     ) || die "Unable to create fakegem wrapper"
245     }
246    
247     # @FUNCTION: all_fakegem_compile
248     # @DESCRIPTION:
249     # Build documentation for the package if indicated by the doc USE flag
250     # and if there is a documetation task defined.
251     all_fakegem_compile() {
252     if [[ ${RUBY_FAKEGEM_TASK_DOC} != "" ]] && use doc; then
253     rake ${RUBY_FAKEGEM_TASK_DOC} || die "failed to (re)build documentation"
254     fi
255     }
256    
257     # @FUNCTION: all_ruby_unpack
258     # @DESCRIPTION:
259     # Unpack the source archive, including support for unpacking gems.
260     all_ruby_unpack() {
261     # Special support for extracting .gem files; the file need to be
262     # extracted twice and the mtime from the archive _has_ to be
263     # ignored (it's always set to epoch 0).
264 flameeyes 1.19 for archive in ${A}; do
265 flameeyes 1.22 case "${archive}" in
266     *.gem)
267     # Make sure that we're not running unoack for more than
268     # one .gem file, since we won't support that at all.
269     [[ -d "${S}" ]] && die "Unable to unpack ${archive}, ${S} exists"
270    
271     ebegin "Unpacking .gem file..."
272     tar -mxf ${DISTDIR}/${archive} || die
273     eend $?
274    
275     mkdir "${S}"
276     pushd "${S}" &>/dev/null
277    
278     ebegin "Unpacking data.tar.gz"
279     tar -mxf "${my_WORKDIR}"/data.tar.gz || die
280     eend $?
281     popd &>/dev/null
282     ;;
283     *.patch.bz2)
284     # We apply the patches with RUBY_PATCHES directly from DISTDIR,
285     # as the WORKDIR variable changes value between the global-scope
286     # and the time all_ruby_unpack/_prepare are called. Since we can
287     # simply decompress them when applying, this is much easier to
288     # deal with for us.
289     einfo "Keeping ${archive} as-is"
290     ;;
291     *)
292     unpack ${archive}
293     ;;
294     esac
295 flameeyes 1.19 done
296 a3li 1.1 }
297    
298     # @FUNCTION: all_ruby_compile
299     # @DESCRIPTION:
300     # Compile the package.
301     all_ruby_compile() {
302     all_fakegem_compile
303     }
304    
305     # @FUNCTION: each_fakegem_test
306     # @DESCRIPTION:
307     # Run tests for the package for each ruby target if the test task is defined.
308     each_fakegem_test() {
309     local rubyflags=
310 flameeyes 1.13 ${RUBY} ${rubyflags} -S rake ${RUBY_FAKEGEM_TASK_TEST} || die "tests failed"
311 a3li 1.1 }
312    
313 flameeyes 1.13 if [[ ${RUBY_FAKEGEM_TASK_TEST} != "" ]]; then
314     # @FUNCTION: each_ruby_test
315     # @DESCRIPTION:
316     # Run the tests for this package.
317     each_ruby_test() {
318     each_fakegem_test
319     }
320     fi
321 a3li 1.1
322     # @FUNCTION: each_fakegem_install
323     # @DESCRIPTION:
324     # Install the package for each ruby target.
325     each_fakegem_install() {
326 graaff 1.25 ruby_fakegem_gemspec
327 a3li 1.1
328 flameeyes 1.11 local _gemlibdirs="${RUBY_FAKEGEM_EXTRAINSTALL}"
329     for directory in bin lib; do
330 a3li 1.1 [[ -d ${directory} ]] && _gemlibdirs="${_gemlibdirs} ${directory}"
331     done
332    
333 flameeyes 1.9 [[ -n ${_gemlibdirs} ]] && \
334     ruby_fakegem_doins -r ${_gemlibdirs}
335 a3li 1.1 }
336    
337     # @FUNCTION: each_ruby_install
338     # @DESCRIPTION:
339     # Install the package for each target.
340     each_ruby_install() {
341     each_fakegem_install
342     }
343    
344     # @FUNCTION: all_fakegem_install
345     # @DESCRIPTION:
346     # Install files common to all ruby targets.
347     all_fakegem_install() {
348 flameeyes 1.20 if [[ -n ${RUBY_FAKEGEM_DOCDIR} ]] && use doc; then
349 flameeyes 1.7 for dir in ${RUBY_FAKEGEM_DOCDIR}; do
350 flameeyes 1.20 [[ -d ${dir} ]] || continue
351    
352 flameeyes 1.11 pushd ${dir} &>/dev/null
353 flameeyes 1.7 dohtml -r * || die "failed to install documentation"
354 flameeyes 1.11 popd &>/dev/null
355 flameeyes 1.7 done
356 a3li 1.1 fi
357    
358     if [[ -n ${RUBY_FAKEGEM_EXTRADOC} ]]; then
359     dodoc ${RUBY_FAKEGEM_EXTRADOC} || die "failed to install further documentation"
360     fi
361 flameeyes 1.6
362     # binary wrappers; we assume that all the implementations get the
363     # same binaries, or something is wrong anyway, so...
364     if [[ -n ${RUBY_FAKEGEM_BINWRAP} ]]; then
365     local bindir=$(find "${D}" -type d -path "*/gems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}/bin" -print -quit)
366    
367     if [[ -d "${bindir}" ]]; then
368 flameeyes 1.11 pushd "${bindir}" &>/dev/null
369 flameeyes 1.6 local binaries=$(eval ls ${RUBY_FAKEGEM_BINWRAP})
370     for binary in $binaries; do
371     ruby_fakegem_binwrapper $binary
372     done
373 flameeyes 1.11 popd &>/dev/null
374 flameeyes 1.6 fi
375     fi
376 a3li 1.1 }
377    
378     # @FUNCTION: all_ruby_install
379     # @DESCRIPTION:
380     # Install files common to all ruby targets.
381     all_ruby_install() {
382     all_fakegem_install
383     }

  ViewVC Help
Powered by ViewVC 1.1.20