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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Wed Dec 16 09:51:30 2009 UTC (4 years, 9 months ago) by flameeyes
Branch: MAIN
Changes since 1.4: +3 -2 lines
Change the binary wrapper code.

Instead of using the Gem code to find the gem itself (which only
worked for gems whose library was named after the gem, and failed for
spec and other packages), ask Gem for its system path (which will be
dynamic depending on the Ruby implementation used) and affix the
hardcoded relative path of the wrapper (which we know at merge time).

Tested with rake, bluecloth, rspec, Ruby 1.8, 1.9 and JRuby.

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

  ViewVC Help
Powered by ViewVC 1.1.20