| 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/bzr.eclass,v 1.9 2010/07/01 09:23:37 fauli Exp $ |
| 4 |
# |
| 5 |
# @ECLASS: bzr.eclass |
| 6 |
# @MAINTAINER: |
| 7 |
# Jorge Manuel B. S. Vicetto <jmbsvicetto@gentoo.org>, |
| 8 |
# Ulrich Mueller <ulm@gentoo.org>, |
| 9 |
# Christian Faulhammer <fauli@gentoo.org>, |
| 10 |
# Mark Lee <bzr-gentoo-overlay@lazymalevolence.com>, |
| 11 |
# and anyone who wants to help |
| 12 |
# @BLURB: This eclass provides support to use the Bazaar VCS |
| 13 |
# @DESCRIPTION: |
| 14 |
# The bzr.eclass provides support for apps using the Bazaar VCS |
| 15 |
# (distributed version control system). |
| 16 |
# The eclass was originally derived from the git eclass. |
| 17 |
# |
| 18 |
# Note: Just set EBZR_REPO_URI to the URI of the branch and the src_unpack() |
| 19 |
# of this eclass will put an export of the branch in ${WORKDIR}/${PN}. |
| 20 |
|
| 21 |
inherit eutils |
| 22 |
|
| 23 |
EBZR="bzr.eclass" |
| 24 |
|
| 25 |
case "${EAPI:-0}" in |
| 26 |
0|1) EXPORT_FUNCTIONS src_unpack ;; |
| 27 |
*) EXPORT_FUNCTIONS src_unpack src_prepare ;; |
| 28 |
esac |
| 29 |
|
| 30 |
HOMEPAGE="http://bazaar-vcs.org/" |
| 31 |
DESCRIPTION="Based on the ${EBZR} eclass" |
| 32 |
|
| 33 |
DEPEND=">=dev-vcs/bzr-1.5" |
| 34 |
|
| 35 |
# @ECLASS-VARIABLE: EBZR_STORE_DIR |
| 36 |
# @DESCRIPTION: |
| 37 |
# The directory to store all fetched Bazaar live sources. |
| 38 |
: ${EBZR_STORE_DIR:=${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/bzr-src} |
| 39 |
|
| 40 |
# @ECLASS-VARIABLE: EBZR_FETCH_CMD |
| 41 |
# @DESCRIPTION: |
| 42 |
# The Bazaar command to fetch the sources. |
| 43 |
EBZR_FETCH_CMD="bzr checkout --lightweight" |
| 44 |
|
| 45 |
# @ECLASS-VARIABLE: EBZR_UPDATE_CMD |
| 46 |
# @DESCRIPTION: |
| 47 |
# The Bazaar command to update the sources. |
| 48 |
EBZR_UPDATE_CMD="bzr update" |
| 49 |
|
| 50 |
# @ECLASS-VARIABLE: EBZR_DIFF_CMD |
| 51 |
# @DESCRIPTION: |
| 52 |
# The Bazaar command to get the diff output. |
| 53 |
EBZR_DIFF_CMD="bzr diff" |
| 54 |
|
| 55 |
# @ECLASS-VARIABLE: EBZR_EXPORT_CMD |
| 56 |
# @DESCRIPTION: |
| 57 |
# The Bazaar command to export a branch. |
| 58 |
EBZR_EXPORT_CMD="bzr export" |
| 59 |
|
| 60 |
# @ECLASS-VARIABLE: EBZR_REVNO_CMD |
| 61 |
# @DESCRIPTION: |
| 62 |
# The Bazaar command to list a revision number of the branch. |
| 63 |
EBZR_REVNO_CMD="bzr revno" |
| 64 |
|
| 65 |
# @ECLASS-VARIABLE: EBZR_OPTIONS |
| 66 |
# @DESCRIPTION: |
| 67 |
# The options passed to the fetch and update commands. |
| 68 |
EBZR_OPTIONS="${EBZR_OPTIONS:-}" |
| 69 |
|
| 70 |
# @ECLASS-VARIABLE: EBZR_REPO_URI |
| 71 |
# @DESCRIPTION: |
| 72 |
# The repository URI for the source package. |
| 73 |
# |
| 74 |
# @CODE |
| 75 |
# Supported protocols: |
| 76 |
# - http:// |
| 77 |
# - https:// |
| 78 |
# - sftp:// |
| 79 |
# - rsync:// |
| 80 |
# - lp: |
| 81 |
# @CODE |
| 82 |
# |
| 83 |
# Note: lp: seems to be an alias for https://launchpad.net |
| 84 |
EBZR_REPO_URI="${EBZR_REPO_URI:-}" |
| 85 |
|
| 86 |
# @ECLASS-VARIABLE: EBZR_BOOTSTRAP |
| 87 |
# @DESCRIPTION: |
| 88 |
# Bootstrap script or command like autogen.sh or etc. |
| 89 |
EBZR_BOOTSTRAP="${EBZR_BOOTSTRAP:-}" |
| 90 |
|
| 91 |
# @ECLASS-VARIABLE: EBZR_PATCHES |
| 92 |
# @DESCRIPTION: |
| 93 |
# bzr eclass can apply patches in bzr_bootstrap(). |
| 94 |
# You can use regular expressions in this variable like *.diff or |
| 95 |
# *.patch and the like. |
| 96 |
# NOTE: These patches will bei applied before EBZR_BOOTSTRAP is processed. |
| 97 |
# |
| 98 |
# Patches are searched both in ${PWD} and ${FILESDIR}, if not found in either |
| 99 |
# location, the installation dies. |
| 100 |
EBZR_PATCHES="${EBZR_PATCHES:-}" |
| 101 |
|
| 102 |
# @ECLASS-VARIABLE: EBZR_REVISION |
| 103 |
# @DESCRIPTION: |
| 104 |
# Revision to fetch, defaults to the latest |
| 105 |
# (see http://bazaar-vcs.org/BzrRevisionSpec or bzr help revisionspec). |
| 106 |
# If you set this to a non-empty value, then it is recommended not to |
| 107 |
# use a lightweight checkout (see also EBZR_FETCH_CMD). |
| 108 |
EBZR_REVISION="${EBZR_REVISION:-}" |
| 109 |
|
| 110 |
# @ECLASS-VARIABLE: EBZR_CACHE_DIR |
| 111 |
# @DESCRIPTION: |
| 112 |
# The directory to store the source for the package, relative to |
| 113 |
# EBZR_STORE_DIR. |
| 114 |
# |
| 115 |
# default: ${PN} |
| 116 |
EBZR_CACHE_DIR="${EBZR_CACHE_DIR:-${PN}}" |
| 117 |
|
| 118 |
# @ECLASS-VARIABLE: EBZR_OFFLINE |
| 119 |
# @DESCRIPTION: |
| 120 |
# Set this variable to a non-empty value to disable the automatic updating of |
| 121 |
# a bzr source tree. This is intended to be set outside the ebuild by users. |
| 122 |
EBZR_OFFLINE="${EBZR_OFFLINE:-${ESCM_OFFLINE}}" |
| 123 |
|
| 124 |
# @FUNCTION: bzr_initial_fetch |
| 125 |
# @DESCRIPTION: |
| 126 |
# Retrieves the source code from a repository for the first time, via |
| 127 |
# ${EBZR_FETCH_CMD}. |
| 128 |
bzr_initial_fetch() { |
| 129 |
local repository="${1}"; |
| 130 |
local branch_dir="${2}"; |
| 131 |
|
| 132 |
# fetch branch |
| 133 |
einfo "bzr fetch start -->" |
| 134 |
einfo " repository: ${repository} => ${branch_dir}" |
| 135 |
|
| 136 |
${EBZR_FETCH_CMD} ${EBZR_OPTIONS} "${repository}" "${branch_dir}" \ |
| 137 |
|| die "${EBZR}: can't branch from ${repository}." |
| 138 |
} |
| 139 |
|
| 140 |
# @FUNCTION: bzr_update |
| 141 |
# @DESCRIPTION: |
| 142 |
# Updates the source code from a repository, via ${EBZR_UPDATE_CMD}. |
| 143 |
bzr_update() { |
| 144 |
local repository="${1}"; |
| 145 |
|
| 146 |
if [[ -n "${EBZR_OFFLINE}" ]]; then |
| 147 |
einfo "skipping bzr update -->" |
| 148 |
einfo " repository: ${repository}" |
| 149 |
else |
| 150 |
# update branch |
| 151 |
einfo "bzr update start -->" |
| 152 |
einfo " repository: ${repository}" |
| 153 |
|
| 154 |
pushd "${EBZR_BRANCH_DIR}" > /dev/null |
| 155 |
${EBZR_UPDATE_CMD} ${EBZR_OPTIONS} \ |
| 156 |
|| die "${EBZR}: can't update from ${repository}." |
| 157 |
popd > /dev/null |
| 158 |
fi |
| 159 |
} |
| 160 |
|
| 161 |
# @FUNCTION: bzr_fetch |
| 162 |
# @DESCRIPTION: |
| 163 |
# Wrapper function to fetch sources from a Bazaar repository via bzr |
| 164 |
# fetch or bzr update, depending on whether there is an existing |
| 165 |
# working copy in ${EBZR_BRANCH_DIR}. |
| 166 |
bzr_fetch() { |
| 167 |
local EBZR_BRANCH_DIR |
| 168 |
|
| 169 |
# EBZR_REPO_URI is empty. |
| 170 |
[[ ${EBZR_REPO_URI} ]] || die "${EBZR}: EBZR_REPO_URI is empty." |
| 171 |
|
| 172 |
# check for the protocol or pull from a local repo. |
| 173 |
if [[ -z ${EBZR_REPO_URI%%:*} ]] ; then |
| 174 |
case ${EBZR_REPO_URI%%:*} in |
| 175 |
# lp: seems to be an alias to https://launchpad.net |
| 176 |
http|https|rsync|lp) |
| 177 |
;; |
| 178 |
sftp) |
| 179 |
if ! built_with_use --missing true dev-vcs/bzr sftp; then |
| 180 |
eerror "To fetch sources from ${EBZR_REPO_URI} you need SFTP" |
| 181 |
eerror "support in dev-vcs/bzr." |
| 182 |
die "Please, rebuild dev-vcs/bzr with the sftp USE flag enabled." |
| 183 |
fi |
| 184 |
;; |
| 185 |
*) |
| 186 |
die "${EBZR}: fetch from ${EBZR_REPO_URI%:*} is not yet implemented." |
| 187 |
;; |
| 188 |
esac |
| 189 |
fi |
| 190 |
|
| 191 |
if [[ ! -d ${EBZR_STORE_DIR} ]] ; then |
| 192 |
debug-print "${FUNCNAME}: initial branch. Creating bzr directory" |
| 193 |
local save_sandbox_write=${SANDBOX_WRITE} |
| 194 |
addwrite / |
| 195 |
mkdir -p "${EBZR_STORE_DIR}" \ |
| 196 |
|| die "${EBZR}: can't mkdir ${EBZR_STORE_DIR}." |
| 197 |
SANDBOX_WRITE=${save_sandbox_write} |
| 198 |
fi |
| 199 |
|
| 200 |
pushd "${EBZR_STORE_DIR}" > /dev/null \ |
| 201 |
|| die "${EBZR}: can't chdir to ${EBZR_STORE_DIR}" |
| 202 |
|
| 203 |
EBZR_BRANCH_DIR="${EBZR_STORE_DIR}/${EBZR_CACHE_DIR}" |
| 204 |
|
| 205 |
addwrite "${EBZR_STORE_DIR}" |
| 206 |
addwrite "${EBZR_BRANCH_DIR}" |
| 207 |
|
| 208 |
debug-print "${FUNCNAME}: EBZR_OPTIONS = ${EBZR_OPTIONS}" |
| 209 |
|
| 210 |
# Run bzr_initial_fetch() only if the branch has not been pulled |
| 211 |
# before or if the existing local copy is a full checkout (as did |
| 212 |
# an older version of bzr.eclass) |
| 213 |
if [[ ! -d ${EBZR_BRANCH_DIR} ]] ; then |
| 214 |
bzr_initial_fetch "${EBZR_REPO_URI}" "${EBZR_BRANCH_DIR}" |
| 215 |
else |
| 216 |
bzr_update "${EBZR_REPO_URI}" "${EBZR_BRANCH_DIR}" |
| 217 |
fi |
| 218 |
|
| 219 |
cd "${EBZR_BRANCH_DIR}" |
| 220 |
|
| 221 |
einfo "exporting ..." |
| 222 |
|
| 223 |
if [[ -z ${EBZR_REVISION} ]]; then |
| 224 |
rsync -rlpgo --exclude=".bzr/" . "${WORKDIR}/${P}" \ |
| 225 |
|| die "${EBZR}: export failed" |
| 226 |
else |
| 227 |
# revisions of a lightweight checkout are only available when online |
| 228 |
[[ -z ${EBZR_OFFLINE} || -d ${EBZR_BRANCH_DIR}/.bzr/repository ]] \ |
| 229 |
|| die "${EBZR}: No support for revisions when off-line" |
| 230 |
${EBZR_EXPORT_CMD} -r "${EBZR_REVISION}" "${WORKDIR}/${P}" \ |
| 231 |
|| die "${EBZR}: export failed" |
| 232 |
fi |
| 233 |
|
| 234 |
export EBZR_TREE_CRC32=$(awk '$1 == "crc32:" { print $2; exit }' \ |
| 235 |
.bzr/checkout/dirstate) |
| 236 |
|
| 237 |
popd > /dev/null |
| 238 |
} |
| 239 |
|
| 240 |
# @FUNCTION: bzr_bootstrap |
| 241 |
# @DESCRIPTION: |
| 242 |
# Apply patches in ${EBZR_PATCHES} and run ${EBZR_BOOTSTRAP} if specified. |
| 243 |
bzr_bootstrap() { |
| 244 |
local patch lpatch |
| 245 |
|
| 246 |
pushd "${S}" > /dev/null |
| 247 |
|
| 248 |
if [[ -n ${EBZR_PATCHES} ]] ; then |
| 249 |
einfo "apply patches -->" |
| 250 |
|
| 251 |
for patch in ${EBZR_PATCHES} ; do |
| 252 |
if [[ -f ${patch} ]] ; then |
| 253 |
epatch ${patch} |
| 254 |
else |
| 255 |
# This loop takes care of wildcarded patches given via |
| 256 |
# EBZR_PATCHES in an ebuild |
| 257 |
for lpatch in "${FILESDIR}"/${patch} ; do |
| 258 |
if [[ -f ${lpatch} ]] ; then |
| 259 |
epatch ${lpatch} |
| 260 |
else |
| 261 |
die "${EBZR}: ${patch} is not found" |
| 262 |
fi |
| 263 |
done |
| 264 |
fi |
| 265 |
done |
| 266 |
fi |
| 267 |
|
| 268 |
if [[ -n ${EBZR_BOOTSTRAP} ]] ; then |
| 269 |
einfo "begin bootstrap -->" |
| 270 |
|
| 271 |
if [[ -f ${EBZR_BOOTSTRAP} ]] && [[ -x ${EBZR_BOOTSTRAP} ]] ; then |
| 272 |
einfo " bootstrap with a file: ${EBZR_BOOTSTRAP}" |
| 273 |
"./${EBZR_BOOTSTRAP}" \ |
| 274 |
|| die "${EBZR}: can't execute EBZR_BOOTSTRAP." |
| 275 |
else |
| 276 |
einfo " bootstrap with commands: ${EBZR_BOOTSTRAP}" |
| 277 |
"${EBZR_BOOTSTRAP}" \ |
| 278 |
|| die "${EBZR}: can't eval EBZR_BOOTSTRAP." |
| 279 |
fi |
| 280 |
fi |
| 281 |
|
| 282 |
popd > /dev/null |
| 283 |
} |
| 284 |
|
| 285 |
# @FUNCTION: bzr_src_unpack |
| 286 |
# @DESCRIPTION: |
| 287 |
# Default src_unpack(). Includes bzr_fetch() and bootstrap(). |
| 288 |
bzr_src_unpack() { |
| 289 |
if ! [ -z ${EBZR_BRANCH} ]; then |
| 290 |
# This test will go away on 01 Jul 2010 |
| 291 |
eerror "This ebuild uses EBZR_BRANCH which is not supported anymore" |
| 292 |
eerror "by the bzr.eclass. Please report this to the ebuild's maintainer." |
| 293 |
die "EBZR_BRANCH still defined" |
| 294 |
fi |
| 295 |
bzr_fetch || die "${EBZR}: unknown problem in bzr_fetch()." |
| 296 |
case "${EAPI:-0}" in |
| 297 |
0|1) bzr_src_prepare ;; |
| 298 |
esac |
| 299 |
} |
| 300 |
|
| 301 |
# @FUNCTION: bzr_src_prepare |
| 302 |
# @DESCRIPTION: |
| 303 |
# Default src_prepare(). Executes bzr_bootstrap() for patch |
| 304 |
# application and Make file generation (if needed). |
| 305 |
bzr_src_prepare() { |
| 306 |
bzr_bootstrap || die "${EBZR}: unknown problem in bzr_bootstrap()." |
| 307 |
} |