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

Contents of /eclass/ruby-fakegem.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (hide annotations) (download)
Thu Jan 21 10:18:59 2010 UTC (4 years, 6 months ago) by flameeyes
Branch: MAIN
Changes since 1.11: +4 -2 lines
Default to installing the binary wrapper to /usr/bin, when calling
with just a basename for the wrapped tool.

Thanks to Klaus Birkelund Jensen for reporting, in bug #301621.

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

  ViewVC Help
Powered by ViewVC 1.1.20