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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Mon Dec 14 12:32:18 2009 UTC (4 years, 4 months ago) by a3li
Branch: MAIN
Add ruby-fakegem.eclass

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

  ViewVC Help
Powered by ViewVC 1.1.20