| 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.6 2009/12/20 23:39:43 flameeyes Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/ruby-fakegem.eclass,v 1.15 2010/02/19 08:47:36 flameeyes 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 | # |
| … | |
… | |
| 52 | # @ECLASS-VARIABLE: RUBY_FAKEGEM_BINWRAP |
52 | # @ECLASS-VARIABLE: RUBY_FAKEGEM_BINWRAP |
| 53 | # @DESCRIPTION: |
53 | # @DESCRIPTION: |
| 54 | # Binaries to wrap around (relative to the bin/ directory) |
54 | # Binaries to wrap around (relative to the bin/ directory) |
| 55 | # RUBY_FAKEGEM_BINWRAP="*" |
55 | # RUBY_FAKEGEM_BINWRAP="*" |
| 56 | |
56 | |
|
|
57 | # @ECLASS-VARIABLE: RUBY_FAKEGEM_REQUIRE_PATHS |
|
|
58 | # @DESCRIPTION: |
|
|
59 | # Extra require paths (beside lib) to add to the specification |
|
|
60 | # RUBY_FAKEGEM_REQUIRE_PATHS="" |
|
|
61 | |
| 57 | RUBY_FAKEGEM_NAME="${RUBY_FAKEGEM_NAME:-${PN}}" |
62 | RUBY_FAKEGEM_NAME="${RUBY_FAKEGEM_NAME:-${PN}}" |
| 58 | RUBY_FAKEGEM_VERSION="${RUBY_FAKEGEM_VERSION:-${PV}}" |
63 | RUBY_FAKEGEM_VERSION="${RUBY_FAKEGEM_VERSION:-${PV/_pre/.pre}}" |
|
|
64 | RUBY_FAKEGEM_SUFFIX="${RUBY_FAKEGEM_SUFFIX:-}" |
| 59 | |
65 | |
| 60 | RUBY_FAKEGEM_TASK_DOC="${RUBY_FAKEGEM_TASK_DOC-rdoc}" |
66 | RUBY_FAKEGEM_TASK_DOC="${RUBY_FAKEGEM_TASK_DOC-rdoc}" |
| 61 | RUBY_FAKEGEM_TASK_TEST="${RUBY_FAKEGEM_TASK_TEST-test}" |
67 | RUBY_FAKEGEM_TASK_TEST="${RUBY_FAKEGEM_TASK_TEST-test}" |
| 62 | |
68 | |
| 63 | RUBY_FAKEGEM_BINWRAP="${RUBY_FAKEGEM_BINWRAP-*}" |
69 | RUBY_FAKEGEM_BINWRAP="${RUBY_FAKEGEM_BINWRAP-*}" |
| … | |
… | |
| 70 | if [[ ${RUBY_FAKEGEM_TASK_TEST} != "" ]]; then |
76 | if [[ ${RUBY_FAKEGEM_TASK_TEST} != "" ]]; then |
| 71 | IUSE="$IUSE test" |
77 | IUSE="$IUSE test" |
| 72 | ruby_add_bdepend test "dev-ruby/rake" |
78 | ruby_add_bdepend test "dev-ruby/rake" |
| 73 | fi |
79 | fi |
| 74 | |
80 | |
| 75 | SRC_URI="mirror://rubygems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}.gem" |
81 | SRC_URI="mirror://rubygems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}${RUBY_FAKEGEM_SUFFIX:+-${RUBY_FAKEGEM_SUFFIX}}.gem" |
| 76 | |
82 | |
| 77 | ruby_add_rdepend virtual/rubygems |
83 | ruby_add_rdepend virtual/rubygems |
| 78 | |
84 | |
| 79 | # @FUNCTION: ruby_fakegem_gemsdir |
85 | # @FUNCTION: ruby_fakegem_gemsdir |
| 80 | # @RETURN: Returns the gem data directory |
86 | # @RETURN: Returns the gem data directory |
| … | |
… | |
| 126 | # Generates a gemspec for the package and places it into the "specifications" |
132 | # Generates a gemspec for the package and places it into the "specifications" |
| 127 | # directory of RubyGems. |
133 | # directory of RubyGems. |
| 128 | # In the gemspec, the following values are set: name, version, summary, |
134 | # In the gemspec, the following values are set: name, version, summary, |
| 129 | # homepage, and require_paths=["lib"]. |
135 | # homepage, and require_paths=["lib"]. |
| 130 | # See RUBY_FAKEGEM_NAME and RUBY_FAKEGEM_VERSION for setting name and version. |
136 | # See RUBY_FAKEGEM_NAME and RUBY_FAKEGEM_VERSION for setting name and version. |
|
|
137 | # See RUBY_FAKEGEM_REQUIRE_PATHS for setting extra require paths. |
| 131 | ruby_fakegem_genspec() { |
138 | ruby_fakegem_genspec() { |
| 132 | ( |
139 | ( |
|
|
140 | local required_paths="'lib'" |
|
|
141 | for path in ${RUBY_FAKEGEM_REQUIRE_PATHS}; do |
|
|
142 | required_paths="${required_paths}, '${path}'" |
|
|
143 | done |
|
|
144 | |
| 133 | # We use the _ruby_implementation variable to avoid having stray |
145 | # We use the _ruby_implementation variable to avoid having stray |
| 134 | # copies with different implementations; while for now we're using |
146 | # copies with different implementations; while for now we're using |
| 135 | # the same exact content, we might have differences in the future, |
147 | # the same exact content, we might have differences in the future, |
| 136 | # so better taking this into consideration. |
148 | # so better taking this into consideration. |
|
|
149 | local quoted_description=${DESCRIPTION//\"/\\\"} |
| 137 | cat - > "${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation} <<EOF |
150 | cat - > "${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation} <<EOF |
| 138 | Gem::Specification.new do |s| |
151 | Gem::Specification.new do |s| |
| 139 | s.name = "${RUBY_FAKEGEM_NAME}" |
152 | s.name = "${RUBY_FAKEGEM_NAME}" |
| 140 | s.version = "${RUBY_FAKEGEM_VERSION}" |
153 | s.version = "${RUBY_FAKEGEM_VERSION}" |
| 141 | s.summary = "${DESCRIPTION}" |
154 | s.summary = "${quoted_description}" |
| 142 | s.homepage = "${HOMEPAGE}" |
155 | s.homepage = "${HOMEPAGE}" |
| 143 | s.require_paths = ["lib"] |
156 | s.require_paths = [${required_paths}] |
| 144 | end |
157 | end |
| 145 | EOF |
158 | EOF |
| 146 | |
159 | |
| 147 | insinto $(ruby_fakegem_gemsdir)/specifications |
160 | insinto $(ruby_fakegem_gemsdir)/specifications |
| 148 | newins "${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation} ${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}.gemspec |
161 | newins "${T}"/${RUBY_FAKEGEM_NAME}-${_ruby_implementation} ${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}.gemspec |
| … | |
… | |
| 157 | ruby_fakegem_binwrapper() { |
170 | ruby_fakegem_binwrapper() { |
| 158 | ( |
171 | ( |
| 159 | local gembinary=$1 |
172 | local gembinary=$1 |
| 160 | local newbinary=${2:-/usr/bin/$gembinary} |
173 | local newbinary=${2:-/usr/bin/$gembinary} |
| 161 | local relativegembinary=${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}/bin/${gembinary} |
174 | local relativegembinary=${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}/bin/${gembinary} |
|
|
175 | local binpath=$(dirname $newbinary) |
|
|
176 | [[ ${binpath} = . ]] && binpath=/usr/bin |
| 162 | |
177 | |
| 163 | cat - > "${T}"/gembin-wrapper-${gembinary} <<EOF |
178 | cat - > "${T}"/gembin-wrapper-${gembinary} <<EOF |
| 164 | #!/usr/bin/env ruby |
179 | #!/usr/bin/env ruby |
| 165 | # This is a simplified version of the RubyGems wrapper |
180 | # This is a simplified version of the RubyGems wrapper |
| 166 | # |
181 | # |
| … | |
… | |
| 170 | |
185 | |
| 171 | load Gem::default_path[-1] + "/gems/${relativegembinary}" |
186 | load Gem::default_path[-1] + "/gems/${relativegembinary}" |
| 172 | |
187 | |
| 173 | EOF |
188 | EOF |
| 174 | |
189 | |
| 175 | exeinto $(dirname $newbinary) |
190 | exeinto ${binpath:-/usr/bin} |
| 176 | newexe "${T}"/gembin-wrapper-${gembinary} $(basename $newbinary) |
191 | newexe "${T}"/gembin-wrapper-${gembinary} $(basename $newbinary) |
| 177 | ) || die "Unable to create fakegem wrapper" |
192 | ) || die "Unable to create fakegem wrapper" |
| 178 | } |
193 | } |
| 179 | |
194 | |
| 180 | # @FUNCTION: all_fakegem_compile |
195 | # @FUNCTION: all_fakegem_compile |
| … | |
… | |
| 202 | ebegin "Unpacking .gem file..." |
217 | ebegin "Unpacking .gem file..." |
| 203 | tar -mxf ${DISTDIR}/${A} || die |
218 | tar -mxf ${DISTDIR}/${A} || die |
| 204 | eend $? |
219 | eend $? |
| 205 | |
220 | |
| 206 | mkdir "${S}" |
221 | mkdir "${S}" |
| 207 | pushd "${S}" |
222 | pushd "${S}" &>/dev/null |
| 208 | |
223 | |
| 209 | ebegin "Unpacking data.tar.gz" |
224 | ebegin "Unpacking data.tar.gz" |
| 210 | tar -mxf "${my_WORKDIR}"/data.tar.gz || die |
225 | tar -mxf "${my_WORKDIR}"/data.tar.gz || die |
| 211 | eend $? |
226 | eend $? |
|
|
227 | popd &>/dev/null |
| 212 | else |
228 | else |
| 213 | [[ -n ${A} ]] && unpack ${A} |
229 | [[ -n ${A} ]] && unpack ${A} |
| 214 | fi |
230 | fi |
| 215 | } |
231 | } |
| 216 | |
232 | |
| … | |
… | |
| 224 | # @FUNCTION: each_fakegem_test |
240 | # @FUNCTION: each_fakegem_test |
| 225 | # @DESCRIPTION: |
241 | # @DESCRIPTION: |
| 226 | # Run tests for the package for each ruby target if the test task is defined. |
242 | # Run tests for the package for each ruby target if the test task is defined. |
| 227 | each_fakegem_test() { |
243 | each_fakegem_test() { |
| 228 | local rubyflags= |
244 | local rubyflags= |
| 229 | |
|
|
| 230 | if [[ ${RUBY_FAKEGEM_TASK_TEST} != "" ]]; then |
|
|
| 231 | ${RUBY} ${rubyflags} -S rake ${RUBY_FAKEGEM_TASK_TEST} || die "tests failed" |
245 | ${RUBY} ${rubyflags} -S rake ${RUBY_FAKEGEM_TASK_TEST} || die "tests failed" |
| 232 | else |
|
|
| 233 | echo "No test task defined, skipping tests." |
|
|
| 234 | fi |
|
|
| 235 | } |
246 | } |
| 236 | |
247 | |
|
|
248 | if [[ ${RUBY_FAKEGEM_TASK_TEST} != "" ]]; then |
| 237 | # @FUNCTION: each_ruby_test |
249 | # @FUNCTION: each_ruby_test |
| 238 | # @DESCRIPTION: |
250 | # @DESCRIPTION: |
| 239 | # Run the tests for this package. |
251 | # Run the tests for this package. |
| 240 | each_ruby_test() { |
252 | each_ruby_test() { |
| 241 | each_fakegem_test |
253 | each_fakegem_test |
| 242 | } |
254 | } |
|
|
255 | fi |
| 243 | |
256 | |
| 244 | # @FUNCTION: each_fakegem_install |
257 | # @FUNCTION: each_fakegem_install |
| 245 | # @DESCRIPTION: |
258 | # @DESCRIPTION: |
| 246 | # Install the package for each ruby target. |
259 | # Install the package for each ruby target. |
| 247 | each_fakegem_install() { |
260 | each_fakegem_install() { |
| 248 | ruby_fakegem_genspec |
261 | ruby_fakegem_genspec |
| 249 | |
262 | |
| 250 | local _gemlibdirs= |
263 | local _gemlibdirs="${RUBY_FAKEGEM_EXTRAINSTALL}" |
| 251 | for directory in bin lib ${RUBY_FAKEGEM_EXTRAINSTALL}; do |
264 | for directory in bin lib; do |
| 252 | [[ -d ${directory} ]] && _gemlibdirs="${_gemlibdirs} ${directory}" |
265 | [[ -d ${directory} ]] && _gemlibdirs="${_gemlibdirs} ${directory}" |
| 253 | done |
266 | done |
| 254 | |
267 | |
|
|
268 | [[ -n ${_gemlibdirs} ]] && \ |
| 255 | ruby_fakegem_doins -r ${_gemlibdirs} |
269 | ruby_fakegem_doins -r ${_gemlibdirs} |
| 256 | } |
270 | } |
| 257 | |
271 | |
| 258 | # @FUNCTION: each_ruby_install |
272 | # @FUNCTION: each_ruby_install |
| 259 | # @DESCRIPTION: |
273 | # @DESCRIPTION: |
| 260 | # Install the package for each target. |
274 | # Install the package for each target. |
| … | |
… | |
| 264 | |
278 | |
| 265 | # @FUNCTION: all_fakegem_install |
279 | # @FUNCTION: all_fakegem_install |
| 266 | # @DESCRIPTION: |
280 | # @DESCRIPTION: |
| 267 | # Install files common to all ruby targets. |
281 | # Install files common to all ruby targets. |
| 268 | all_fakegem_install() { |
282 | all_fakegem_install() { |
| 269 | if [[ -n ${RUBY_FAKEGEM_DOCDIR} ]] && use doc; then |
283 | if [[ -n ${RUBY_FAKEGEM_DOCDIR} ]] && [[ ${RUBY_FAKEGEM_TASK_DOC} != "" ]] && use doc; then |
| 270 | pushd ${RUBY_FAKEGEM_DOCDIR} |
284 | for dir in ${RUBY_FAKEGEM_DOCDIR}; do |
|
|
285 | pushd ${dir} &>/dev/null |
| 271 | dohtml -r * || die "failed to install documentation" |
286 | dohtml -r * || die "failed to install documentation" |
| 272 | popd |
287 | popd &>/dev/null |
|
|
288 | done |
| 273 | fi |
289 | fi |
| 274 | |
290 | |
| 275 | if [[ -n ${RUBY_FAKEGEM_EXTRADOC} ]]; then |
291 | if [[ -n ${RUBY_FAKEGEM_EXTRADOC} ]]; then |
| 276 | dodoc ${RUBY_FAKEGEM_EXTRADOC} || die "failed to install further documentation" |
292 | dodoc ${RUBY_FAKEGEM_EXTRADOC} || die "failed to install further documentation" |
| 277 | fi |
293 | fi |
| … | |
… | |
| 280 | # same binaries, or something is wrong anyway, so... |
296 | # same binaries, or something is wrong anyway, so... |
| 281 | if [[ -n ${RUBY_FAKEGEM_BINWRAP} ]]; then |
297 | if [[ -n ${RUBY_FAKEGEM_BINWRAP} ]]; then |
| 282 | local bindir=$(find "${D}" -type d -path "*/gems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}/bin" -print -quit) |
298 | local bindir=$(find "${D}" -type d -path "*/gems/${RUBY_FAKEGEM_NAME}-${RUBY_FAKEGEM_VERSION}/bin" -print -quit) |
| 283 | |
299 | |
| 284 | if [[ -d "${bindir}" ]]; then |
300 | if [[ -d "${bindir}" ]]; then |
| 285 | pushd "${bindir}" |
301 | pushd "${bindir}" &>/dev/null |
| 286 | local binaries=$(eval ls ${RUBY_FAKEGEM_BINWRAP}) |
302 | local binaries=$(eval ls ${RUBY_FAKEGEM_BINWRAP}) |
| 287 | for binary in $binaries; do |
303 | for binary in $binaries; do |
| 288 | ruby_fakegem_binwrapper $binary |
304 | ruby_fakegem_binwrapper $binary |
| 289 | done |
305 | done |
| 290 | popd |
306 | popd &>/dev/null |
| 291 | fi |
307 | fi |
| 292 | fi |
308 | fi |
| 293 | } |
309 | } |
| 294 | |
310 | |
| 295 | # @FUNCTION: all_ruby_install |
311 | # @FUNCTION: all_ruby_install |