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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Tue Dec 15 16:27:46 2009 UTC (4 years, 6 months ago) by flameeyes
Branch: MAIN
Changes since 1.2: +3 -3 lines
Use the fakegem name and version vars for the source uri.

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

  ViewVC Help
Powered by ViewVC 1.1.20