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

Diff of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.18 Revision 1.29
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.18 2010/05/24 07:34:14 flameeyes Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/ruby-fakegem.eclass,v 1.29 2011/04/25 08:36:51 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#
56 56
57# @ECLASS-VARIABLE: RUBY_FAKEGEM_REQUIRE_PATHS 57# @ECLASS-VARIABLE: RUBY_FAKEGEM_REQUIRE_PATHS
58# @DESCRIPTION: 58# @DESCRIPTION:
59# Extra require paths (beside lib) to add to the specification 59# Extra require paths (beside lib) to add to the specification
60# RUBY_FAKEGEM_REQUIRE_PATHS="" 60# RUBY_FAKEGEM_REQUIRE_PATHS=""
61
62# @ECLASS-VARIABLE: RUBY_FAKEGEM_GEMSPEC
63# @DESCRIPTION:
64# Filename of .gemspec file to install instead of generating a generic one.
65# RUBY_FAKEGEM_GEMSPEC=""
61 66
62RUBY_FAKEGEM_NAME="${RUBY_FAKEGEM_NAME:-${PN}}" 67RUBY_FAKEGEM_NAME="${RUBY_FAKEGEM_NAME:-${PN}}"
63RUBY_FAKEGEM_VERSION="${RUBY_FAKEGEM_VERSION:-${PV/_pre/.pre}}" 68RUBY_FAKEGEM_VERSION="${RUBY_FAKEGEM_VERSION:-${PV/_pre/.pre}}"
64RUBY_FAKEGEM_SUFFIX="${RUBY_FAKEGEM_SUFFIX:-}" 69RUBY_FAKEGEM_SUFFIX="${RUBY_FAKEGEM_SUFFIX:-}"
65 70
71if [[ ${RUBY_FAKEGEM_TASK_DOC} != "" ]]; then 76if [[ ${RUBY_FAKEGEM_TASK_DOC} != "" ]]; then
72 IUSE="$IUSE doc" 77 IUSE="$IUSE doc"
73 ruby_add_bdepend "doc? ( dev-ruby/rake )" 78 ruby_add_bdepend "doc? ( dev-ruby/rake )"
74fi 79fi
75 80
81if [[ -n ${RUBY_FAKEGEM_DOCDIR} ]]; then
82 IUSE="$IUSE doc"
83fi
84
76if [[ ${RUBY_FAKEGEM_TASK_TEST} != "" ]]; then 85if [[ ${RUBY_FAKEGEM_TASK_TEST} != "" ]]; then
77 IUSE="$IUSE test" 86 IUSE="$IUSE test"
78 ruby_add_bdepend "test? ( dev-ruby/rake )" 87 ruby_add_bdepend "test? ( dev-ruby/rake )"
79fi 88fi
80 89
81SRC_URI="mirror://rubygems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}${RUBY_FAKEGEM_SUFFIX:+-${RUBY_FAKEGEM_SUFFIX}}.gem" 90SRC_URI="mirror://rubygems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}${RUBY_FAKEGEM_SUFFIX:+-${RUBY_FAKEGEM_SUFFIX}}.gem"
82 91
92ruby_add_bdepend dev-ruby/rubygems
83ruby_add_rdepend virtual/rubygems 93ruby_add_rdepend dev-ruby/rubygems
84 94
85# @FUNCTION: ruby_fakegem_gemsdir 95# @FUNCTION: ruby_fakegem_gemsdir
86# @RETURN: Returns the gem data directory 96# @RETURN: Returns the gem data directory
87# @DESCRIPTION: 97# @DESCRIPTION:
88# This function returns the gems data directory for the ruby 98# This function returns the gems data directory for the ruby
89# implementation in question. 99# implementation in question.
90ruby_fakegem_gemsdir() { 100ruby_fakegem_gemsdir() {
91 local _gemsitedir=$(${RUBY} -r rbconfig -e 'print Config::CONFIG["sitelibdir"]' | sed -e 's:site_ruby:gems:') 101 has "${EAPI}" 2 && ! use prefix && EPREFIX=
102
103 local _gemsitedir=$(ruby_rbconfig_value 'sitelibdir')
104 _gemsitedir=${_gemsitedir//site_ruby/gems}
105 _gemsitedir=${_gemsitedir#${EPREFIX}}
92 106
93 [[ -z ${_gemsitedir} ]] && { 107 [[ -z ${_gemsitedir} ]] && {
94 eerror "Unable to find the gems dir" 108 eerror "Unable to find the gems dir"
95 die "Unable to find the gems dir" 109 die "Unable to find the gems dir"
96 } 110 }
125 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}
126 newins "$1" ${newbasename} 140 newins "$1" ${newbasename}
127 ) || die "failed $0 $@" 141 ) || die "failed $0 $@"
128} 142}
129 143
144# @FUNCTION: ruby_fakegem_install_gemspec
145# @DESCRIPTION:
146# Install a .gemspec file for this package. Either use the file indicated
147# by the RUBY_FAKEGEM_GEMSPEC variable, or generate one using
148# ruby_fakegem_genspec.
149ruby_fakegem_install_gemspec() {
150 local gemspec="${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation}
151
152 (
153 if [[ ${RUBY_FAKEGEM_GEMSPEC} != "" ]]; then
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
166 insinto $(ruby_fakegem_gemsdir)/specifications
167 newins ${gemspec} ${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}.gemspec || die "Unable to install gemspec file."
168}
169
170# @FUNCTION: ruby_fakegem_gemspec_gemspec
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.
176ruby_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.
186ruby_fakegem_metadata_gemspec() {
187 ${RUBY} -r yaml -e "puts Gem::Specification.from_yaml(File::open('$1').read).to_ruby" > $2
188}
189
130# @FUNCTION: ruby_fakegem_genspec 190# @FUNCTION: ruby_fakegem_genspec
191# @USAGE: output-gemspec
131# @DESCRIPTION: 192# @DESCRIPTION:
132# 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"
133# 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.
134# In the gemspec, the following values are set: name, version, summary, 199# In the gemspec, the following values are set: name, version, summary,
135# homepage, and require_paths=["lib"]. 200# homepage, and require_paths=["lib"].
136# 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.
137# See RUBY_FAKEGEM_REQUIRE_PATHS for setting extra require paths. 202# See RUBY_FAKEGEM_REQUIRE_PATHS for setting extra require paths.
138ruby_fakegem_genspec() { 203ruby_fakegem_genspec() {
139 (
140 local required_paths="'lib'" 204 local required_paths="'lib'"
141 for path in ${RUBY_FAKEGEM_REQUIRE_PATHS}; do 205 for path in ${RUBY_FAKEGEM_REQUIRE_PATHS}; do
142 required_paths="${required_paths}, '${path}'" 206 required_paths="${required_paths}, '${path}'"
143 done 207 done
144 208
145 # We use the _ruby_implementation variable to avoid having stray 209 # We use the _ruby_implementation variable to avoid having stray
146 # copies with different implementations; while for now we're using 210 # copies with different implementations; while for now we're using
147 # the same exact content, we might have differences in the future, 211 # the same exact content, we might have differences in the future,
148 # so better taking this into consideration. 212 # so better taking this into consideration.
149 local quoted_description=${DESCRIPTION//\"/\\\"} 213 local quoted_description=${DESCRIPTION//\"/\\\"}
150 cat - > "${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation} <<EOF 214 cat - > $1 <<EOF
151# generated by ruby-fakegem.eclass $Revision: 1.18 $ 215# generated by ruby-fakegem.eclass $Revision: 1.29 $
152Gem::Specification.new do |s| 216Gem::Specification.new do |s|
153 s.name = "${RUBY_FAKEGEM_NAME}" 217 s.name = "${RUBY_FAKEGEM_NAME}"
154 s.version = "${RUBY_FAKEGEM_VERSION}" 218 s.version = "${RUBY_FAKEGEM_VERSION}"
155 s.summary = "${quoted_description}" 219 s.summary = "${quoted_description}"
156 s.homepage = "${HOMEPAGE}" 220 s.homepage = "${HOMEPAGE}"
157 s.require_paths = [${required_paths}] 221 s.require_paths = [${required_paths}]
158end 222end
159EOF 223EOF
160
161 insinto $(ruby_fakegem_gemsdir)/specifications
162 newins "${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation} ${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}.gemspec
163 ) || die "Unable to install fake gemspec"
164} 224}
165 225
166# @FUNCTION: ruby_fakegem_binwrapper 226# @FUNCTION: ruby_fakegem_binwrapper
167# @USAGE: command [path] 227# @USAGE: command [path]
168# @DESCRIPTION: 228# @DESCRIPTION:
186 for implementation in ${USE_RUBY}; do 246 for implementation in ${USE_RUBY}; do
187 # ignore non-enabled implementations 247 # ignore non-enabled implementations
188 use ruby_targets_${implementation} || continue 248 use ruby_targets_${implementation} || continue
189 if [ -z $rubycmd ]; then 249 if [ -z $rubycmd ]; then
190 # if no other implementation was set before, set it. 250 # if no other implementation was set before, set it.
191 rubycmd="/usr/bin/${implementation}" 251 rubycmd="$(ruby_implementation_command ${implementation})"
192 else 252 else
193 # if another implementation already arrived, then make 253 # if another implementation already arrived, then make
194 # it generic and break out of the loop. This ensures 254 # it generic and break out of the loop. This ensures
195 # that we do at most two iterations. 255 # that we do at most two iterations.
196 rubycmd="/usr/bin/env ruby" 256 rubycmd="/usr/bin/env ruby"
200 260
201 cat - > "${T}"/gembin-wrapper-${gembinary} <<EOF 261 cat - > "${T}"/gembin-wrapper-${gembinary} <<EOF
202#!${rubycmd} 262#!${rubycmd}
203# This is a simplified version of the RubyGems wrapper 263# This is a simplified version of the RubyGems wrapper
204# 264#
205# Generated by ruby-fakegem.eclass $Revision: 1.18 $ 265# Generated by ruby-fakegem.eclass $Revision: 1.29 $
206 266
207require 'rubygems' 267require 'rubygems'
208 268
209load Gem::default_path[-1] + "/gems/${relativegembinary}" 269load Gem::default_path[-1] + "/gems/${relativegembinary}"
210 270
230# Unpack the source archive, including support for unpacking gems. 290# Unpack the source archive, including support for unpacking gems.
231all_ruby_unpack() { 291all_ruby_unpack() {
232 # Special support for extracting .gem files; the file need to be 292 # Special support for extracting .gem files; the file need to be
233 # extracted twice and the mtime from the archive _has_ to be 293 # extracted twice and the mtime from the archive _has_ to be
234 # ignored (it's always set to epoch 0). 294 # ignored (it's always set to epoch 0).
235 # 295 for archive in ${A}; do
236 # This only works if there is exactly one archive and that archive 296 case "${archive}" in
237 # is a .gem file! 297 *.gem)
238 if [[ $(wc -w <<< ${A}) == 1 ]] && 298 # Make sure that we're not running unpack for more than
239 [[ ${A} == *.gem ]]; then 299 # one .gem file, since we won't support that at all.
300 [[ -d "${S}" ]] && die "Unable to unpack ${archive}, ${S} exists"
301
240 ebegin "Unpacking .gem file..." 302 ebegin "Unpacking .gem file..."
241 tar -mxf ${DISTDIR}/${A} || die 303 tar -mxf ${DISTDIR}/${archive} || die
242 eend $? 304 eend $?
243 305
306 ebegin "Uncompressing metadata"
307 gunzip metadata.gz || die
308 eend $?
309
244 mkdir "${S}" 310 mkdir "${S}"
245 pushd "${S}" &>/dev/null 311 pushd "${S}" &>/dev/null
246 312
247 ebegin "Unpacking data.tar.gz" 313 ebegin "Unpacking data.tar.gz"
248 tar -mxf "${my_WORKDIR}"/data.tar.gz || die 314 tar -mxf "${my_WORKDIR}"/data.tar.gz || die
249 eend $? 315 eend $?
316
250 popd &>/dev/null 317 popd &>/dev/null
251 else 318 ;;
252 [[ -n ${A} ]] && unpack ${A} 319 *.patch.bz2)
253 fi 320 # We apply the patches with RUBY_PATCHES directly from DISTDIR,
321 # as the WORKDIR variable changes value between the global-scope
322 # and the time all_ruby_unpack/_prepare are called. Since we can
323 # simply decompress them when applying, this is much easier to
324 # deal with for us.
325 einfo "Keeping ${archive} as-is"
326 ;;
327 *)
328 unpack ${archive}
329 ;;
330 esac
331 done
254} 332}
255 333
256# @FUNCTION: all_ruby_compile 334# @FUNCTION: all_ruby_compile
257# @DESCRIPTION: 335# @DESCRIPTION:
258# Compile the package. 336# Compile the package.
279 357
280# @FUNCTION: each_fakegem_install 358# @FUNCTION: each_fakegem_install
281# @DESCRIPTION: 359# @DESCRIPTION:
282# Install the package for each ruby target. 360# Install the package for each ruby target.
283each_fakegem_install() { 361each_fakegem_install() {
284 ruby_fakegem_genspec 362 ruby_fakegem_install_gemspec
285 363
286 local _gemlibdirs="${RUBY_FAKEGEM_EXTRAINSTALL}" 364 local _gemlibdirs="${RUBY_FAKEGEM_EXTRAINSTALL}"
287 for directory in bin lib; do 365 for directory in bin lib; do
288 [[ -d ${directory} ]] && _gemlibdirs="${_gemlibdirs} ${directory}" 366 [[ -d ${directory} ]] && _gemlibdirs="${_gemlibdirs} ${directory}"
289 done 367 done
301 379
302# @FUNCTION: all_fakegem_install 380# @FUNCTION: all_fakegem_install
303# @DESCRIPTION: 381# @DESCRIPTION:
304# Install files common to all ruby targets. 382# Install files common to all ruby targets.
305all_fakegem_install() { 383all_fakegem_install() {
306 if [[ -n ${RUBY_FAKEGEM_DOCDIR} ]] && [[ ${RUBY_FAKEGEM_TASK_DOC} != "" ]] && use doc; then 384 if [[ -n ${RUBY_FAKEGEM_DOCDIR} ]] && use doc; then
307 for dir in ${RUBY_FAKEGEM_DOCDIR}; do 385 for dir in ${RUBY_FAKEGEM_DOCDIR}; do
386 [[ -d ${dir} ]] || continue
387
308 pushd ${dir} &>/dev/null 388 pushd ${dir} &>/dev/null
309 dohtml -r * || die "failed to install documentation" 389 dohtml -r * || die "failed to install documentation"
310 popd &>/dev/null 390 popd &>/dev/null
311 done 391 done
312 fi 392 fi

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.29

  ViewVC Help
Powered by ViewVC 1.1.20