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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.26 - (hide annotations) (download)
Sat Dec 18 09:57:24 2010 UTC (3 years, 8 months ago) by graaff
Branch: MAIN
Changes since 1.25: +1 -22 lines
Revert mistaken commit of new gemspec-related code, but keep new dependency on dev-ruby/rubygems instead of virtual.

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

  ViewVC Help
Powered by ViewVC 1.1.20