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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (show annotations) (download)
Sat Feb 13 08:45:03 2010 UTC (4 years, 7 months ago) by graaff
Branch: MAIN
Changes since 1.13: +3 -2 lines
Take into account that the description may contain double quotes and quote them to avoid generating invalid ruby code. Fixes #304723.

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.13 2010/01/24 00:00:40 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}}"
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 local quoted_description=${DESCRIPTION//\"/\\\"}
149 cat - > "${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation} <<EOF
150 Gem::Specification.new do |s|
151 s.name = "${RUBY_FAKEGEM_NAME}"
152 s.version = "${RUBY_FAKEGEM_VERSION}"
153 s.summary = "${quoted_description}"
154 s.homepage = "${HOMEPAGE}"
155 s.require_paths = [${required_paths}]
156 end
157 EOF
158
159 insinto $(ruby_fakegem_gemsdir)/specifications
160 newins "${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation} ${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}.gemspec
161 ) || die "Unable to install fake gemspec"
162 }
163
164 # @FUNCTION: ruby_fakegem_binwrapper
165 # @USAGE: command [path]
166 # @DESCRIPTION:
167 # Creates a new binary wrapper for a command installed by the RubyGem.
168 # path defaults to /usr/bin/$command
169 ruby_fakegem_binwrapper() {
170 (
171 local gembinary=$1
172 local newbinary=${2:-/usr/bin/$gembinary}
173 local relativegembinary=${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}/bin/${gembinary}
174 local binpath=$(dirname $newbinary)
175 [[ ${binpath} = . ]] && binpath=/usr/bin
176
177 cat - > "${T}"/gembin-wrapper-${gembinary} <<EOF
178 #!/usr/bin/env ruby
179 # This is a simplified version of the RubyGems wrapper
180 #
181 # Generated by ruby-fakegem.eclass
182
183 require 'rubygems'
184
185 load Gem::default_path[-1] + "/gems/${relativegembinary}"
186
187 EOF
188
189 exeinto ${binpath:-/usr/bin}
190 newexe "${T}"/gembin-wrapper-${gembinary} $(basename $newbinary)
191 ) || die "Unable to create fakegem wrapper"
192 }
193
194 # @FUNCTION: all_fakegem_compile
195 # @DESCRIPTION:
196 # Build documentation for the package if indicated by the doc USE flag
197 # and if there is a documetation task defined.
198 all_fakegem_compile() {
199 if [[ ${RUBY_FAKEGEM_TASK_DOC} != "" ]] && use doc; then
200 rake ${RUBY_FAKEGEM_TASK_DOC} || die "failed to (re)build documentation"
201 fi
202 }
203
204 # @FUNCTION: all_ruby_unpack
205 # @DESCRIPTION:
206 # Unpack the source archive, including support for unpacking gems.
207 all_ruby_unpack() {
208 # Special support for extracting .gem files; the file need to be
209 # extracted twice and the mtime from the archive _has_ to be
210 # ignored (it's always set to epoch 0).
211 #
212 # This only works if there is exactly one archive and that archive
213 # is a .gem file!
214 if [[ $(wc -w <<< ${A}) == 1 ]] &&
215 [[ ${A} == *.gem ]]; then
216 ebegin "Unpacking .gem file..."
217 tar -mxf ${DISTDIR}/${A} || die
218 eend $?
219
220 mkdir "${S}"
221 pushd "${S}" &>/dev/null
222
223 ebegin "Unpacking data.tar.gz"
224 tar -mxf "${my_WORKDIR}"/data.tar.gz || die
225 eend $?
226 popd &>/dev/null
227 else
228 [[ -n ${A} ]] && unpack ${A}
229 fi
230 }
231
232 # @FUNCTION: all_ruby_compile
233 # @DESCRIPTION:
234 # Compile the package.
235 all_ruby_compile() {
236 all_fakegem_compile
237 }
238
239 # @FUNCTION: each_fakegem_test
240 # @DESCRIPTION:
241 # Run tests for the package for each ruby target if the test task is defined.
242 each_fakegem_test() {
243 local rubyflags=
244 ${RUBY} ${rubyflags} -S rake ${RUBY_FAKEGEM_TASK_TEST} || die "tests failed"
245 }
246
247 if [[ ${RUBY_FAKEGEM_TASK_TEST} != "" ]]; then
248 # @FUNCTION: each_ruby_test
249 # @DESCRIPTION:
250 # Run the tests for this package.
251 each_ruby_test() {
252 each_fakegem_test
253 }
254 fi
255
256 # @FUNCTION: each_fakegem_install
257 # @DESCRIPTION:
258 # Install the package for each ruby target.
259 each_fakegem_install() {
260 ruby_fakegem_genspec
261
262 local _gemlibdirs="${RUBY_FAKEGEM_EXTRAINSTALL}"
263 for directory in bin lib; do
264 [[ -d ${directory} ]] && _gemlibdirs="${_gemlibdirs} ${directory}"
265 done
266
267 [[ -n ${_gemlibdirs} ]] && \
268 ruby_fakegem_doins -r ${_gemlibdirs}
269 }
270
271 # @FUNCTION: each_ruby_install
272 # @DESCRIPTION:
273 # Install the package for each target.
274 each_ruby_install() {
275 each_fakegem_install
276 }
277
278 # @FUNCTION: all_fakegem_install
279 # @DESCRIPTION:
280 # Install files common to all ruby targets.
281 all_fakegem_install() {
282 if [[ -n ${RUBY_FAKEGEM_DOCDIR} ]] && [[ ${RUBY_FAKEGEM_TASK_DOC} != "" ]] && use doc; then
283 for dir in ${RUBY_FAKEGEM_DOCDIR}; do
284 pushd ${dir} &>/dev/null
285 dohtml -r * || die "failed to install documentation"
286 popd &>/dev/null
287 done
288 fi
289
290 if [[ -n ${RUBY_FAKEGEM_EXTRADOC} ]]; then
291 dodoc ${RUBY_FAKEGEM_EXTRADOC} || die "failed to install further documentation"
292 fi
293
294 # binary wrappers; we assume that all the implementations get the
295 # same binaries, or something is wrong anyway, so...
296 if [[ -n ${RUBY_FAKEGEM_BINWRAP} ]]; then
297 local bindir=$(find "${D}" -type d -path "*/gems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}/bin" -print -quit)
298
299 if [[ -d "${bindir}" ]]; then
300 pushd "${bindir}" &>/dev/null
301 local binaries=$(eval ls ${RUBY_FAKEGEM_BINWRAP})
302 for binary in $binaries; do
303 ruby_fakegem_binwrapper $binary
304 done
305 popd &>/dev/null
306 fi
307 fi
308 }
309
310 # @FUNCTION: all_ruby_install
311 # @DESCRIPTION:
312 # Install files common to all ruby targets.
313 all_ruby_install() {
314 all_fakegem_install
315 }

  ViewVC Help
Powered by ViewVC 1.1.20