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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (hide annotations) (download)
Mon Aug 30 22:08:24 2010 UTC (3 years, 10 months ago) by flameeyes
Branch: MAIN
Changes since 1.22: +4 -4 lines
Factor out the ree18→rubyee18 conversion and use it when generating the binwrapper (closes bug #335328).

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

  ViewVC Help
Powered by ViewVC 1.1.20