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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (hide annotations) (download)
Fri Feb 19 08:47:36 2010 UTC (4 years, 5 months ago) by flameeyes
Branch: MAIN
Changes since 1.14: +4 -3 lines
Add support for suffixes to a gem (like .java) and support for
pre-release mangling (_pre becomes .pre).

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

  ViewVC Help
Powered by ViewVC 1.1.20