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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Sun Dec 20 23:39:43 2009 UTC (4 years, 8 months ago) by flameeyes
Branch: MAIN
Changes since 1.5: +23 -1 lines
Add a RAKE_FAKEGEM_BINWRAP variable.

This way to just add command wrapping we won't be needing to define a function.
This also defaults, the same as original rubygems, to all the binaries installed, but it can be tweaked.

1 a3li 1.1 # Copyright 1999-2009 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 flameeyes 1.6 # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-fakegem.eclass,v 1.5 2009/12/16 09:51:30 flameeyes 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 a3li 1.1 RUBY_FAKEGEM_NAME="${RUBY_FAKEGEM_NAME:-${PN}}"
58     RUBY_FAKEGEM_VERSION="${RUBY_FAKEGEM_VERSION:-${PV}}"
59    
60     RUBY_FAKEGEM_TASK_DOC="${RUBY_FAKEGEM_TASK_DOC-rdoc}"
61     RUBY_FAKEGEM_TASK_TEST="${RUBY_FAKEGEM_TASK_TEST-test}"
62    
63 flameeyes 1.6 RUBY_FAKEGEM_BINWRAP="${RUBY_FAKEGEM_BINWRAP-*}"
64    
65 a3li 1.1 if [[ ${RUBY_FAKEGEM_TASK_DOC} != "" ]]; then
66     IUSE="$IUSE doc"
67     ruby_add_bdepend doc "dev-ruby/rake"
68     fi
69    
70     if [[ ${RUBY_FAKEGEM_TASK_TEST} != "" ]]; then
71     IUSE="$IUSE test"
72     ruby_add_bdepend test "dev-ruby/rake"
73     fi
74    
75 flameeyes 1.3 SRC_URI="mirror://rubygems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}.gem"
76    
77 a3li 1.1 ruby_add_rdepend virtual/rubygems
78    
79     # @FUNCTION: ruby_fakegem_gemsdir
80     # @RETURN: Returns the gem data directory
81     # @DESCRIPTION:
82     # This function returns the gems data directory for the ruby
83     # implementation in question.
84     ruby_fakegem_gemsdir() {
85     local _gemsitedir=$(${RUBY} -r rbconfig -e 'print Config::CONFIG["sitelibdir"]' | sed -e 's:site_ruby:gems:')
86    
87     [[ -z ${_gemsitedir} ]] && {
88     eerror "Unable to find the gems dir"
89     die "Unable to find the gems dir"
90     }
91    
92     echo "${_gemsitedir}"
93     }
94    
95     # @FUNCTION: ruby_fakegem_doins
96     # @USAGE: file [file...]
97     # @DESCRIPTION:
98     # Installs the specified file(s) into the gems directory.
99     ruby_fakegem_doins() {
100     (
101     insinto $(ruby_fakegem_gemsdir)/gems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}
102     doins "$@"
103     ) || die "failed $0 $@"
104     }
105    
106     # @FUNCTION: ruby_fakegem_newsins()
107     # @USAGE: file filename
108     # @DESCRIPTION:
109     # Installs the specified file into the gems directory using the provided filename.
110     ruby_fakegem_newins() {
111     (
112     # Since newins does not accept full paths but just basenames
113     # for the target file, we want to extend it here.
114     local newdirname=/$(dirname "$2")
115     [[ ${newdirname} == "/." ]] && newdirname=
116    
117     local newbasename=$(basename "$2")
118    
119     insinto $(ruby_fakegem_gemsdir)/gems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}${newdirname}
120     newins "$1" ${newbasename}
121     ) || die "failed $0 $@"
122     }
123    
124     # @FUNCTION: ruby_fakegem_genspec
125     # @DESCRIPTION:
126     # Generates a gemspec for the package and places it into the "specifications"
127     # directory of RubyGems.
128     # In the gemspec, the following values are set: name, version, summary,
129     # homepage, and require_paths=["lib"].
130     # See RUBY_FAKEGEM_NAME and RUBY_FAKEGEM_VERSION for setting name and version.
131     ruby_fakegem_genspec() {
132     (
133     # We use the _ruby_implementation variable to avoid having stray
134     # copies with different implementations; while for now we're using
135     # the same exact content, we might have differences in the future,
136     # so better taking this into consideration.
137     cat - > "${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation} <<EOF
138     Gem::Specification.new do |s|
139     s.name = "${RUBY_FAKEGEM_NAME}"
140     s.version = "${RUBY_FAKEGEM_VERSION}"
141     s.summary = "${DESCRIPTION}"
142     s.homepage = "${HOMEPAGE}"
143     s.require_paths = ["lib"]
144     end
145     EOF
146    
147     insinto $(ruby_fakegem_gemsdir)/specifications
148     newins "${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation} ${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}.gemspec
149     ) || die "Unable to install fake gemspec"
150     }
151    
152     # @FUNCTION: ruby_fakegem_binwrapper
153     # @USAGE: command [path]
154     # @DESCRIPTION:
155     # Creates a new binary wrapper for a command installed by the RubyGem.
156     # path defaults to /usr/bin/$command
157     ruby_fakegem_binwrapper() {
158     (
159     local gembinary=$1
160     local newbinary=${2:-/usr/bin/$gembinary}
161 flameeyes 1.5 local relativegembinary=${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}/bin/${gembinary}
162 a3li 1.1
163     cat - > "${T}"/gembin-wrapper-${gembinary} <<EOF
164     #!/usr/bin/env ruby
165     # This is a simplified version of the RubyGems wrapper
166     #
167     # Generated by ruby-fakegem.eclass
168    
169     require 'rubygems'
170    
171 flameeyes 1.5 load Gem::default_path[-1] + "/gems/${relativegembinary}"
172 a3li 1.1
173     EOF
174    
175     exeinto $(dirname $newbinary)
176     newexe "${T}"/gembin-wrapper-${gembinary} $(basename $newbinary)
177     ) || die "Unable to create fakegem wrapper"
178     }
179    
180     # @FUNCTION: all_fakegem_compile
181     # @DESCRIPTION:
182     # Build documentation for the package if indicated by the doc USE flag
183     # and if there is a documetation task defined.
184     all_fakegem_compile() {
185     if [[ ${RUBY_FAKEGEM_TASK_DOC} != "" ]] && use doc; then
186     rake ${RUBY_FAKEGEM_TASK_DOC} || die "failed to (re)build documentation"
187     fi
188     }
189    
190     # @FUNCTION: all_ruby_unpack
191     # @DESCRIPTION:
192     # Unpack the source archive, including support for unpacking gems.
193     all_ruby_unpack() {
194     # Special support for extracting .gem files; the file need to be
195     # extracted twice and the mtime from the archive _has_ to be
196     # ignored (it's always set to epoch 0).
197     #
198     # This only works if there is exactly one archive and that archive
199     # is a .gem file!
200     if [[ $(wc -w <<< ${A}) == 1 ]] &&
201     [[ ${A} == *.gem ]]; then
202     ebegin "Unpacking .gem file..."
203     tar -mxf ${DISTDIR}/${A} || die
204     eend $?
205    
206     mkdir "${S}"
207     pushd "${S}"
208    
209     ebegin "Unpacking data.tar.gz"
210     tar -mxf "${my_WORKDIR}"/data.tar.gz || die
211     eend $?
212     else
213     [[ -n ${A} ]] && unpack ${A}
214     fi
215     }
216    
217     # @FUNCTION: all_ruby_compile
218     # @DESCRIPTION:
219     # Compile the package.
220     all_ruby_compile() {
221     all_fakegem_compile
222     }
223    
224     # @FUNCTION: each_fakegem_test
225     # @DESCRIPTION:
226     # Run tests for the package for each ruby target if the test task is defined.
227     each_fakegem_test() {
228     local rubyflags=
229    
230     if [[ ${RUBY_FAKEGEM_TASK_TEST} != "" ]]; then
231     ${RUBY} ${rubyflags} -S rake ${RUBY_FAKEGEM_TASK_TEST} || die "tests failed"
232     else
233     echo "No test task defined, skipping tests."
234     fi
235     }
236    
237     # @FUNCTION: each_ruby_test
238     # @DESCRIPTION:
239     # Run the tests for this package.
240     each_ruby_test() {
241     each_fakegem_test
242     }
243    
244     # @FUNCTION: each_fakegem_install
245     # @DESCRIPTION:
246     # Install the package for each ruby target.
247     each_fakegem_install() {
248     ruby_fakegem_genspec
249    
250     local _gemlibdirs=
251     for directory in bin lib ${RUBY_FAKEGEM_EXTRAINSTALL}; do
252     [[ -d ${directory} ]] && _gemlibdirs="${_gemlibdirs} ${directory}"
253     done
254    
255     ruby_fakegem_doins -r ${_gemlibdirs}
256     }
257    
258     # @FUNCTION: each_ruby_install
259     # @DESCRIPTION:
260     # Install the package for each target.
261     each_ruby_install() {
262     each_fakegem_install
263     }
264    
265     # @FUNCTION: all_fakegem_install
266     # @DESCRIPTION:
267     # Install files common to all ruby targets.
268     all_fakegem_install() {
269     if [[ -n ${RUBY_FAKEGEM_DOCDIR} ]] && use doc; then
270     pushd ${RUBY_FAKEGEM_DOCDIR}
271     dohtml -r * || die "failed to install documentation"
272     popd
273     fi
274    
275     if [[ -n ${RUBY_FAKEGEM_EXTRADOC} ]]; then
276     dodoc ${RUBY_FAKEGEM_EXTRADOC} || die "failed to install further documentation"
277     fi
278 flameeyes 1.6
279     # binary wrappers; we assume that all the implementations get the
280     # same binaries, or something is wrong anyway, so...
281     if [[ -n ${RUBY_FAKEGEM_BINWRAP} ]]; then
282     local bindir=$(find "${D}" -type d -path "*/gems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}/bin" -print -quit)
283    
284     if [[ -d "${bindir}" ]]; then
285     pushd "${bindir}"
286     local binaries=$(eval ls ${RUBY_FAKEGEM_BINWRAP})
287     for binary in $binaries; do
288     ruby_fakegem_binwrapper $binary
289     done
290     popd
291     fi
292     fi
293 a3li 1.1 }
294    
295     # @FUNCTION: all_ruby_install
296     # @DESCRIPTION:
297     # Install files common to all ruby targets.
298     all_ruby_install() {
299     all_fakegem_install
300     }

  ViewVC Help
Powered by ViewVC 1.1.20