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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations) (download)
Fri Jan 1 23:13:26 2010 UTC (4 years, 8 months ago) by flameeyes
Branch: MAIN
Changes since 1.8: +3 -2 lines
Don't error out if there is neither bin nor lib directories to install.

This is the case of the pg gem for instance.

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

  ViewVC Help
Powered by ViewVC 1.1.20