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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (show annotations) (download)
Tue Jul 27 11:02:47 2010 UTC (4 years, 1 month ago) by flameeyes
Branch: MAIN
Changes since 1.20: +7 -3 lines
If RUBY_FAKEGEM_DOCDIR is set, the ebuild should have the doc USE flag.

1 # Copyright 1999-2009 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-fakegem.eclass,v 1.20 2010/07/21 10:43:57 flameeyes Exp $
4 #
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 # RUBY_FAKEGEM_TASK_DOC="rdoc"
35
36 # @ECLASS-VARIABLE: RUBY_FAKEGEM_TASK_TEST
37 # @DESCRIPTION:
38 # Specify the rake(1) task used for executing tests.
39 # 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
52 # @ECLASS-VARIABLE: RUBY_FAKEGEM_BINWRAP
53 # @DESCRIPTION:
54 # Binaries to wrap around (relative to the bin/ directory)
55 # RUBY_FAKEGEM_BINWRAP="*"
56
57 # @ECLASS-VARIABLE: RUBY_FAKEGEM_REQUIRE_PATHS
58 # @DESCRIPTION:
59 # Extra require paths (beside lib) to add to the specification
60 # RUBY_FAKEGEM_REQUIRE_PATHS=""
61
62 RUBY_FAKEGEM_NAME="${RUBY_FAKEGEM_NAME:-${PN}}"
63 RUBY_FAKEGEM_VERSION="${RUBY_FAKEGEM_VERSION:-${PV/_pre/.pre}}"
64 RUBY_FAKEGEM_SUFFIX="${RUBY_FAKEGEM_SUFFIX:-}"
65
66 RUBY_FAKEGEM_TASK_DOC="${RUBY_FAKEGEM_TASK_DOC-rdoc}"
67 RUBY_FAKEGEM_TASK_TEST="${RUBY_FAKEGEM_TASK_TEST-test}"
68
69 RUBY_FAKEGEM_BINWRAP="${RUBY_FAKEGEM_BINWRAP-*}"
70
71 if [[ ${RUBY_FAKEGEM_TASK_DOC} != "" ]]; then
72 IUSE="$IUSE doc"
73 ruby_add_bdepend "doc? ( dev-ruby/rake )"
74 fi
75
76 if [[ -n ${RUBY_FAKEGEM_DOCDIR} ]]; then
77 IUSE="$IUSE doc"
78 fi
79
80 if [[ ${RUBY_FAKEGEM_TASK_TEST} != "" ]]; then
81 IUSE="$IUSE test"
82 ruby_add_bdepend "test? ( dev-ruby/rake )"
83 fi
84
85 SRC_URI="mirror://rubygems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}${RUBY_FAKEGEM_SUFFIX:+-${RUBY_FAKEGEM_SUFFIX}}.gem"
86
87 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 # See RUBY_FAKEGEM_REQUIRE_PATHS for setting extra require paths.
142 ruby_fakegem_genspec() {
143 (
144 local required_paths="'lib'"
145 for path in ${RUBY_FAKEGEM_REQUIRE_PATHS}; do
146 required_paths="${required_paths}, '${path}'"
147 done
148
149 # 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 local quoted_description=${DESCRIPTION//\"/\\\"}
154 cat - > "${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation} <<EOF
155 # generated by ruby-fakegem.eclass $Revision: 1.20 $
156 Gem::Specification.new do |s|
157 s.name = "${RUBY_FAKEGEM_NAME}"
158 s.version = "${RUBY_FAKEGEM_VERSION}"
159 s.summary = "${quoted_description}"
160 s.homepage = "${HOMEPAGE}"
161 s.require_paths = [${required_paths}]
162 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 local relativegembinary=${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}/bin/${gembinary}
180 local binpath=$(dirname $newbinary)
181 [[ ${binpath} = . ]] && binpath=/usr/bin
182
183 # 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 rubycmd="/usr/bin/${implementation}"
196 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 cat - > "${T}"/gembin-wrapper-${gembinary} <<EOF
206 #!${rubycmd}
207 # This is a simplified version of the RubyGems wrapper
208 #
209 # Generated by ruby-fakegem.eclass $Revision: 1.20 $
210
211 require 'rubygems'
212
213 load Gem::default_path[-1] + "/gems/${relativegembinary}"
214
215 EOF
216
217 exeinto ${binpath:-/usr/bin}
218 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 for archive in ${A}; do
240 if [[ ${archive} == *.gem ]]; then
241 # Make sure that we're not running unoack for more than
242 # one .gem file, since we won't support that at all.
243 [[ -d "${S}" ]] && die "Unable to unpack ${archive}, ${S} exists"
244
245 ebegin "Unpacking .gem file..."
246 tar -mxf ${DISTDIR}/${archive} || die
247 eend $?
248
249 mkdir "${S}"
250 pushd "${S}" &>/dev/null
251
252 ebegin "Unpacking data.tar.gz"
253 tar -mxf "${my_WORKDIR}"/data.tar.gz || die
254 eend $?
255 popd &>/dev/null
256 else
257 unpack ${archive}
258 fi
259 done
260 }
261
262 # @FUNCTION: all_ruby_compile
263 # @DESCRIPTION:
264 # Compile the package.
265 all_ruby_compile() {
266 all_fakegem_compile
267 }
268
269 # @FUNCTION: each_fakegem_test
270 # @DESCRIPTION:
271 # Run tests for the package for each ruby target if the test task is defined.
272 each_fakegem_test() {
273 local rubyflags=
274 ${RUBY} ${rubyflags} -S rake ${RUBY_FAKEGEM_TASK_TEST} || die "tests failed"
275 }
276
277 if [[ ${RUBY_FAKEGEM_TASK_TEST} != "" ]]; then
278 # @FUNCTION: each_ruby_test
279 # @DESCRIPTION:
280 # Run the tests for this package.
281 each_ruby_test() {
282 each_fakegem_test
283 }
284 fi
285
286 # @FUNCTION: each_fakegem_install
287 # @DESCRIPTION:
288 # Install the package for each ruby target.
289 each_fakegem_install() {
290 ruby_fakegem_genspec
291
292 local _gemlibdirs="${RUBY_FAKEGEM_EXTRAINSTALL}"
293 for directory in bin lib; do
294 [[ -d ${directory} ]] && _gemlibdirs="${_gemlibdirs} ${directory}"
295 done
296
297 [[ -n ${_gemlibdirs} ]] && \
298 ruby_fakegem_doins -r ${_gemlibdirs}
299 }
300
301 # @FUNCTION: each_ruby_install
302 # @DESCRIPTION:
303 # Install the package for each target.
304 each_ruby_install() {
305 each_fakegem_install
306 }
307
308 # @FUNCTION: all_fakegem_install
309 # @DESCRIPTION:
310 # Install files common to all ruby targets.
311 all_fakegem_install() {
312 if [[ -n ${RUBY_FAKEGEM_DOCDIR} ]] && use doc; then
313 for dir in ${RUBY_FAKEGEM_DOCDIR}; do
314 [[ -d ${dir} ]] || continue
315
316 pushd ${dir} &>/dev/null
317 dohtml -r * || die "failed to install documentation"
318 popd &>/dev/null
319 done
320 fi
321
322 if [[ -n ${RUBY_FAKEGEM_EXTRADOC} ]]; then
323 dodoc ${RUBY_FAKEGEM_EXTRADOC} || die "failed to install further documentation"
324 fi
325
326 # binary wrappers; we assume that all the implementations get the
327 # same binaries, or something is wrong anyway, so...
328 if [[ -n ${RUBY_FAKEGEM_BINWRAP} ]]; then
329 local bindir=$(find "${D}" -type d -path "*/gems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}/bin" -print -quit)
330
331 if [[ -d "${bindir}" ]]; then
332 pushd "${bindir}" &>/dev/null
333 local binaries=$(eval ls ${RUBY_FAKEGEM_BINWRAP})
334 for binary in $binaries; do
335 ruby_fakegem_binwrapper $binary
336 done
337 popd &>/dev/null
338 fi
339 fi
340 }
341
342 # @FUNCTION: all_ruby_install
343 # @DESCRIPTION:
344 # Install files common to all ruby targets.
345 all_ruby_install() {
346 all_fakegem_install
347 }

  ViewVC Help
Powered by ViewVC 1.1.20