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