| 1 | # Copyright 1999-2009 Gentoo Foundation |
1 | # Copyright 1999-2009 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-fakegem.eclass,v 1.25 2010/12/18 09:50:08 graaff Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-fakegem.eclass,v 1.28 2011/03/05 06:58:00 graaff Exp $ |
| 4 | # |
4 | # |
| 5 | # @ECLASS: ruby-fakegem.eclass |
5 | # @ECLASS: ruby-fakegem.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # Ruby herd <ruby@gentoo.org> |
7 | # Ruby herd <ruby@gentoo.org> |
| 8 | # |
8 | # |
| … | |
… | |
| 87 | ruby_add_bdepend "test? ( dev-ruby/rake )" |
87 | ruby_add_bdepend "test? ( dev-ruby/rake )" |
| 88 | fi |
88 | fi |
| 89 | |
89 | |
| 90 | SRC_URI="mirror://rubygems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}${RUBY_FAKEGEM_SUFFIX:+-${RUBY_FAKEGEM_SUFFIX}}.gem" |
90 | SRC_URI="mirror://rubygems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}${RUBY_FAKEGEM_SUFFIX:+-${RUBY_FAKEGEM_SUFFIX}}.gem" |
| 91 | |
91 | |
|
|
92 | ruby_add_bdepend dev-ruby/rubygems |
| 92 | ruby_add_rdepend dev-ruby/rubygems |
93 | ruby_add_rdepend dev-ruby/rubygems |
| 93 | |
94 | |
| 94 | # @FUNCTION: ruby_fakegem_gemsdir |
95 | # @FUNCTION: ruby_fakegem_gemsdir |
| 95 | # @RETURN: Returns the gem data directory |
96 | # @RETURN: Returns the gem data directory |
| 96 | # @DESCRIPTION: |
97 | # @DESCRIPTION: |
| … | |
… | |
| 138 | insinto $(ruby_fakegem_gemsdir)/gems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}${newdirname} |
139 | insinto $(ruby_fakegem_gemsdir)/gems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}${newdirname} |
| 139 | newins "$1" ${newbasename} |
140 | newins "$1" ${newbasename} |
| 140 | ) || die "failed $0 $@" |
141 | ) || die "failed $0 $@" |
| 141 | } |
142 | } |
| 142 | |
143 | |
| 143 | # @FUNCTION: ruby_fakegem_gemspec |
144 | # @FUNCTION: ruby_fakegem_install_gemspec |
| 144 | # @DESCRIPTION: |
145 | # @DESCRIPTION: |
| 145 | # Install a .gemspec file for this package. Either use the file indicated |
146 | # Install a .gemspec file for this package. Either use the file indicated |
| 146 | # by the RUBY_FAKEGEM_GEMSPEC variable, or generate one using |
147 | # by the RUBY_FAKEGEM_GEMSPEC variable, or generate one using |
| 147 | # ruby_fakegem_genspec |
148 | # ruby_fakegem_genspec. |
| 148 | ruby_fakegem_gemspec() { |
149 | ruby_fakegem_install_gemspec() { |
|
|
150 | local gemspec="${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation} |
|
|
151 | |
|
|
152 | ( |
| 149 | if [[ ${RUBY_FAKEGEM_GEMSPEC} != "" ]]; then |
153 | if [[ ${RUBY_FAKEGEM_GEMSPEC} != "" ]]; then |
| 150 | ( |
154 | ruby_fakegem_gemspec_gemspec ${RUBY_FAKEGEM_GEMSPEC} ${gemspec} |
|
|
155 | else |
|
|
156 | local metadata="${WORKDIR}"/${_ruby_implementation}/metadata |
|
|
157 | |
|
|
158 | if [[ -e ${metadata} ]]; then |
|
|
159 | ruby_fakegem_metadata_gemspec ${metadata} ${gemspec} |
|
|
160 | else |
|
|
161 | ruby_fakegem_genspec ${gemspec} |
|
|
162 | fi |
|
|
163 | fi |
|
|
164 | ) || die "Unable to generate gemspec file." |
|
|
165 | |
| 151 | insinto $(ruby_fakegem_gemsdir)/specifications |
166 | insinto $(ruby_fakegem_gemsdir)/specifications |
| 152 | newins "${RUBY_FAKEGEM_GEMSPEC}" ${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}.gemspec |
167 | newins ${gemspec} ${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}.gemspec || die "Unable to install gemspec file." |
| 153 | ) || die "Unable to install ${RUBY_FAKEGEM_GEMSPEC} gemspec" |
168 | } |
| 154 | else |
169 | |
| 155 | ruby_fakegem_genspec |
170 | # @FUNCTION: ruby_fakegem_gemspec_gemspec |
| 156 | fi |
171 | # @USAGE: gemspec-input gemspec-output |
|
|
172 | # @DESCRIPTION: |
|
|
173 | # Generates an installable version of the specification indicated by |
|
|
174 | # RUBY_FAKEGEM_GEMSPEC. This file is eval'ed to produce a final specification |
|
|
175 | # in a way similar to packaging the gemspec file. |
|
|
176 | ruby_fakegem_gemspec_gemspec() { |
|
|
177 | ${RUBY} -e "puts eval(File::open('$1').read).to_ruby" > $2 |
|
|
178 | } |
|
|
179 | |
|
|
180 | # @FUNCTION: ruby_fakegem_metadata_gemspec |
|
|
181 | # @USAGE: gemspec-metadata gemspec-output |
|
|
182 | # @DESCRIPTION: |
|
|
183 | # Generates an installable version of the specification indicated by |
|
|
184 | # the metadata distributed by the gem itself. This is similar to how |
|
|
185 | # rubygems creates an installation from a .gem file. |
|
|
186 | ruby_fakegem_metadata_gemspec() { |
|
|
187 | ${RUBY} -r yaml -e "puts Gem::Specification.from_yaml(File::open('$1').read).to_ruby" > $2 |
| 157 | } |
188 | } |
| 158 | |
189 | |
| 159 | # @FUNCTION: ruby_fakegem_genspec |
190 | # @FUNCTION: ruby_fakegem_genspec |
|
|
191 | # @USAGE: output-gemspec |
| 160 | # @DESCRIPTION: |
192 | # @DESCRIPTION: |
| 161 | # Generates a gemspec for the package and places it into the "specifications" |
193 | # Generates a gemspec for the package and places it into the "specifications" |
| 162 | # directory of RubyGems. |
194 | # directory of RubyGems. |
|
|
195 | # If the metadata normally distributed with a gem is present then that is |
|
|
196 | # used to generate the gemspec file. |
|
|
197 | # |
|
|
198 | # As a fallback we can generate our own version. |
| 163 | # In the gemspec, the following values are set: name, version, summary, |
199 | # In the gemspec, the following values are set: name, version, summary, |
| 164 | # homepage, and require_paths=["lib"]. |
200 | # homepage, and require_paths=["lib"]. |
| 165 | # See RUBY_FAKEGEM_NAME and RUBY_FAKEGEM_VERSION for setting name and version. |
201 | # See RUBY_FAKEGEM_NAME and RUBY_FAKEGEM_VERSION for setting name and version. |
| 166 | # See RUBY_FAKEGEM_REQUIRE_PATHS for setting extra require paths. |
202 | # See RUBY_FAKEGEM_REQUIRE_PATHS for setting extra require paths. |
| 167 | ruby_fakegem_genspec() { |
203 | ruby_fakegem_genspec() { |
| 168 | ( |
|
|
| 169 | local required_paths="'lib'" |
204 | local required_paths="'lib'" |
| 170 | for path in ${RUBY_FAKEGEM_REQUIRE_PATHS}; do |
205 | for path in ${RUBY_FAKEGEM_REQUIRE_PATHS}; do |
| 171 | required_paths="${required_paths}, '${path}'" |
206 | required_paths="${required_paths}, '${path}'" |
| 172 | done |
207 | done |
| 173 | |
208 | |
| 174 | # We use the _ruby_implementation variable to avoid having stray |
209 | # We use the _ruby_implementation variable to avoid having stray |
| 175 | # copies with different implementations; while for now we're using |
210 | # copies with different implementations; while for now we're using |
| 176 | # the same exact content, we might have differences in the future, |
211 | # the same exact content, we might have differences in the future, |
| 177 | # so better taking this into consideration. |
212 | # so better taking this into consideration. |
| 178 | local quoted_description=${DESCRIPTION//\"/\\\"} |
213 | local quoted_description=${DESCRIPTION//\"/\\\"} |
| 179 | cat - > "${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation} <<EOF |
214 | cat - > $1 <<EOF |
| 180 | # generated by ruby-fakegem.eclass $Revision: 1.25 $ |
215 | # generated by ruby-fakegem.eclass $Revision: 1.28 $ |
| 181 | Gem::Specification.new do |s| |
216 | Gem::Specification.new do |s| |
| 182 | s.name = "${RUBY_FAKEGEM_NAME}" |
217 | s.name = "${RUBY_FAKEGEM_NAME}" |
| 183 | s.version = "${RUBY_FAKEGEM_VERSION}" |
218 | s.version = "${RUBY_FAKEGEM_VERSION}" |
| 184 | s.summary = "${quoted_description}" |
219 | s.summary = "${quoted_description}" |
| 185 | s.homepage = "${HOMEPAGE}" |
220 | s.homepage = "${HOMEPAGE}" |
| 186 | s.require_paths = [${required_paths}] |
221 | s.require_paths = [${required_paths}] |
| 187 | end |
222 | end |
| 188 | EOF |
223 | EOF |
| 189 | |
|
|
| 190 | insinto $(ruby_fakegem_gemsdir)/specifications |
|
|
| 191 | newins "${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation} ${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}.gemspec |
|
|
| 192 | ) || die "Unable to install fake gemspec" |
|
|
| 193 | } |
224 | } |
| 194 | |
225 | |
| 195 | # @FUNCTION: ruby_fakegem_binwrapper |
226 | # @FUNCTION: ruby_fakegem_binwrapper |
| 196 | # @USAGE: command [path] |
227 | # @USAGE: command [path] |
| 197 | # @DESCRIPTION: |
228 | # @DESCRIPTION: |
| … | |
… | |
| 229 | |
260 | |
| 230 | cat - > "${T}"/gembin-wrapper-${gembinary} <<EOF |
261 | cat - > "${T}"/gembin-wrapper-${gembinary} <<EOF |
| 231 | #!${rubycmd} |
262 | #!${rubycmd} |
| 232 | # This is a simplified version of the RubyGems wrapper |
263 | # This is a simplified version of the RubyGems wrapper |
| 233 | # |
264 | # |
| 234 | # Generated by ruby-fakegem.eclass $Revision: 1.25 $ |
265 | # Generated by ruby-fakegem.eclass $Revision: 1.28 $ |
| 235 | |
266 | |
| 236 | require 'rubygems' |
267 | require 'rubygems' |
| 237 | |
268 | |
| 238 | load Gem::default_path[-1] + "/gems/${relativegembinary}" |
269 | load Gem::default_path[-1] + "/gems/${relativegembinary}" |
| 239 | |
270 | |
| … | |
… | |
| 270 | |
301 | |
| 271 | ebegin "Unpacking .gem file..." |
302 | ebegin "Unpacking .gem file..." |
| 272 | tar -mxf ${DISTDIR}/${archive} || die |
303 | tar -mxf ${DISTDIR}/${archive} || die |
| 273 | eend $? |
304 | eend $? |
| 274 | |
305 | |
|
|
306 | ebegin "Uncompressing metadata" |
|
|
307 | gunzip metadata.gz || die |
|
|
308 | eend $? |
|
|
309 | |
| 275 | mkdir "${S}" |
310 | mkdir "${S}" |
| 276 | pushd "${S}" &>/dev/null |
311 | pushd "${S}" &>/dev/null |
| 277 | |
312 | |
| 278 | ebegin "Unpacking data.tar.gz" |
313 | ebegin "Unpacking data.tar.gz" |
| 279 | tar -mxf "${my_WORKDIR}"/data.tar.gz || die |
314 | tar -mxf "${my_WORKDIR}"/data.tar.gz || die |
| 280 | eend $? |
315 | eend $? |
|
|
316 | |
| 281 | popd &>/dev/null |
317 | popd &>/dev/null |
| 282 | ;; |
318 | ;; |
| 283 | *.patch.bz2) |
319 | *.patch.bz2) |
| 284 | # We apply the patches with RUBY_PATCHES directly from DISTDIR, |
320 | # We apply the patches with RUBY_PATCHES directly from DISTDIR, |
| 285 | # as the WORKDIR variable changes value between the global-scope |
321 | # as the WORKDIR variable changes value between the global-scope |
| … | |
… | |
| 321 | |
357 | |
| 322 | # @FUNCTION: each_fakegem_install |
358 | # @FUNCTION: each_fakegem_install |
| 323 | # @DESCRIPTION: |
359 | # @DESCRIPTION: |
| 324 | # Install the package for each ruby target. |
360 | # Install the package for each ruby target. |
| 325 | each_fakegem_install() { |
361 | each_fakegem_install() { |
| 326 | ruby_fakegem_gemspec |
362 | ruby_fakegem_install_gemspec |
| 327 | |
363 | |
| 328 | local _gemlibdirs="${RUBY_FAKEGEM_EXTRAINSTALL}" |
364 | local _gemlibdirs="${RUBY_FAKEGEM_EXTRAINSTALL}" |
| 329 | for directory in bin lib; do |
365 | for directory in bin lib; do |
| 330 | [[ -d ${directory} ]] && _gemlibdirs="${_gemlibdirs} ${directory}" |
366 | [[ -d ${directory} ]] && _gemlibdirs="${_gemlibdirs} ${directory}" |
| 331 | done |
367 | done |