| 1 |
agriffis |
1.1 |
# Copyright 1999-2006 Gentoo Foundation
|
| 2 |
|
|
# Distributed under the terms of the GNU General Public License v2
|
| 3 |
nelchael |
1.16 |
# $Header: /var/cvsroot/gentoo-x86/eclass/mercurial.eclass,v 1.15 2010/11/17 18:42:03 nelchael Exp $
|
| 4 |
agriffis |
1.1 |
|
| 5 |
nelchael |
1.5 |
# @ECLASS: mercurial.eclass
|
| 6 |
|
|
# @MAINTAINER:
|
| 7 |
nelchael |
1.12 |
# Krzysztof Pawlik <nelchael@gentoo.org>
|
| 8 |
|
|
# Dirkjan Ochtman <djc@gentoo.org>
|
| 9 |
nelchael |
1.5 |
# @BLURB: This eclass provides generic mercurial fetching functions
|
| 10 |
|
|
# @DESCRIPTION:
|
| 11 |
|
|
# This eclass provides generic mercurial fetching functions. To fetch sources
|
| 12 |
|
|
# from mercurial repository just set EHG_REPO_URI to correct repository URI. If
|
| 13 |
|
|
# you need to share single repository between several ebuilds set EHG_PROJECT to
|
| 14 |
|
|
# project name in all of them.
|
| 15 |
agriffis |
1.1 |
|
| 16 |
|
|
inherit eutils
|
| 17 |
|
|
|
| 18 |
|
|
EXPORT_FUNCTIONS src_unpack
|
| 19 |
|
|
|
| 20 |
djc |
1.11 |
DEPEND="dev-vcs/mercurial"
|
| 21 |
agriffis |
1.1 |
|
| 22 |
nelchael |
1.5 |
# @ECLASS-VARIABLE: EHG_REPO_URI
|
| 23 |
|
|
# @DESCRIPTION:
|
| 24 |
|
|
# Mercurial repository URI.
|
| 25 |
|
|
|
| 26 |
|
|
# @ECLASS-VARIABLE: EHG_REVISION
|
| 27 |
|
|
# @DESCRIPTION:
|
| 28 |
|
|
# Create working directory for specified revision, defaults to tip.
|
| 29 |
nelchael |
1.9 |
#
|
| 30 |
nelchael |
1.16 |
# EHG_REVISION is passed as a value for --updaterev parameter, so it can be more
|
| 31 |
|
|
# than just a revision, please consult `hg help revisions' for more details.
|
| 32 |
nelchael |
1.5 |
[[ -z "${EHG_REVISION}" ]] && EHG_REVISION="tip"
|
| 33 |
|
|
|
| 34 |
nelchael |
1.12 |
# @ECLASS-VARIABLE: EHG_STORE_DIR
|
| 35 |
|
|
# @DESCRIPTION:
|
| 36 |
|
|
# Mercurial sources store directory. Users may override this in /etc/make.conf
|
| 37 |
|
|
[[ -z "${EHG_STORE_DIR}" ]] && EHG_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/hg-src"
|
| 38 |
|
|
|
| 39 |
nelchael |
1.5 |
# @ECLASS-VARIABLE: EHG_PROJECT
|
| 40 |
|
|
# @DESCRIPTION:
|
| 41 |
|
|
# Project name.
|
| 42 |
|
|
#
|
| 43 |
|
|
# This variable default to $PN, but can be changed to allow repository sharing
|
| 44 |
|
|
# between several ebuilds.
|
| 45 |
|
|
[[ -z "${EHG_PROJECT}" ]] && EHG_PROJECT="${PN}"
|
| 46 |
|
|
|
| 47 |
robbat2 |
1.8 |
# @ECLASS-VARIABLE: EHG_QUIET
|
| 48 |
|
|
# @DESCRIPTION:
|
| 49 |
|
|
# Suppress some extra noise from mercurial, set it to 'OFF' to be louder.
|
| 50 |
|
|
: ${EHG_QUIET:="ON"}
|
| 51 |
|
|
[[ "${EHG_QUIET}" == "ON" ]] && EHG_QUIET_CMD_OPT="--quiet"
|
| 52 |
|
|
|
| 53 |
nelchael |
1.5 |
# @ECLASS-VARIABLE: EHG_CLONE_CMD
|
| 54 |
|
|
# @DESCRIPTION:
|
| 55 |
|
|
# Command used to perform initial repository clone.
|
| 56 |
robbat2 |
1.8 |
[[ -z "${EHG_CLONE_CMD}" ]] && EHG_CLONE_CMD="hg clone ${EHG_QUIET_CMD_OPT} --pull --noupdate"
|
| 57 |
nelchael |
1.5 |
|
| 58 |
|
|
# @ECLASS-VARIABLE: EHG_PULL_CMD
|
| 59 |
|
|
# @DESCRIPTION:
|
| 60 |
|
|
# Command used to update repository.
|
| 61 |
robbat2 |
1.8 |
[[ -z "${EHG_PULL_CMD}" ]] && EHG_PULL_CMD="hg pull ${EHG_QUIET_CMD_OPT}"
|
| 62 |
nelchael |
1.5 |
|
| 63 |
nelchael |
1.7 |
# @ECLASS-VARIABLE: EHG_OFFLINE
|
| 64 |
|
|
# @DESCRIPTION:
|
| 65 |
|
|
# Set this variable to a non-empty value to disable the automatic updating of
|
| 66 |
|
|
# a mercurial source tree. This is intended to be set outside the ebuild by
|
| 67 |
|
|
# users.
|
| 68 |
|
|
EHG_OFFLINE="${EHG_OFFLINE:-${ESCM_OFFLINE}}"
|
| 69 |
|
|
|
| 70 |
nelchael |
1.5 |
# @FUNCTION: mercurial_fetch
|
| 71 |
nelchael |
1.15 |
# @USAGE: [repository_uri] [module] [sourcedir]
|
| 72 |
nelchael |
1.5 |
# @DESCRIPTION:
|
| 73 |
|
|
# Clone or update repository.
|
| 74 |
|
|
#
|
| 75 |
nelchael |
1.15 |
# If repository URI is not passed it defaults to EHG_REPO_URI, if module is
|
| 76 |
|
|
# empty it defaults to basename of EHG_REPO_URI, sourcedir defaults to S.
|
| 77 |
nelchael |
1.5 |
function mercurial_fetch {
|
| 78 |
|
|
debug-print-function ${FUNCNAME} ${*}
|
| 79 |
agriffis |
1.1 |
|
| 80 |
nelchael |
1.5 |
EHG_REPO_URI=${1-${EHG_REPO_URI}}
|
| 81 |
|
|
[[ -z "${EHG_REPO_URI}" ]] && die "EHG_REPO_URI is empty"
|
| 82 |
agriffis |
1.1 |
|
| 83 |
nelchael |
1.5 |
local module="${2-$(basename "${EHG_REPO_URI}")}"
|
| 84 |
nelchael |
1.15 |
local sourcedir="${3-${S}}"
|
| 85 |
agriffis |
1.1 |
|
| 86 |
nelchael |
1.5 |
# Should be set but blank to prevent using $HOME/.hgrc
|
| 87 |
|
|
export HGRCPATH=
|
| 88 |
|
|
|
| 89 |
nelchael |
1.12 |
# Check ${EHG_STORE_DIR} directory:
|
| 90 |
|
|
addwrite "$(dirname "${EHG_STORE_DIR}")" || die "addwrite failed"
|
| 91 |
|
|
if [[ ! -d "${EHG_STORE_DIR}" ]]; then
|
| 92 |
|
|
mkdir -p "${EHG_STORE_DIR}" || die "failed to create ${EHG_STORE_DIR}"
|
| 93 |
|
|
chmod -f g+rw "${EHG_STORE_DIR}" || \
|
| 94 |
|
|
die "failed to chown ${EHG_STORE_DIR}"
|
| 95 |
agriffis |
1.1 |
fi
|
| 96 |
|
|
|
| 97 |
nelchael |
1.5 |
# Create project directory:
|
| 98 |
nelchael |
1.12 |
mkdir -p "${EHG_STORE_DIR}/${EHG_PROJECT}" || \
|
| 99 |
|
|
die "failed to create ${EHG_STORE_DIR}/${EHG_PROJECT}"
|
| 100 |
|
|
chmod -f g+rw "${EHG_STORE_DIR}/${EHG_PROJECT}" || \
|
| 101 |
nelchael |
1.10 |
echo "Warning: failed to chmod g+rw ${EHG_PROJECT}"
|
| 102 |
nelchael |
1.12 |
cd "${EHG_STORE_DIR}/${EHG_PROJECT}" || \
|
| 103 |
|
|
die "failed to cd to ${EHG_STORE_DIR}/${EHG_PROJECT}"
|
| 104 |
nelchael |
1.5 |
|
| 105 |
|
|
# Clone/update repository:
|
| 106 |
|
|
if [[ ! -d "${module}" ]]; then
|
| 107 |
nelchael |
1.12 |
einfo "Cloning ${EHG_REPO_URI} to ${EHG_STORE_DIR}/${EHG_PROJECT}/${module}"
|
| 108 |
nelchael |
1.5 |
${EHG_CLONE_CMD} "${EHG_REPO_URI}" "${module}" || {
|
| 109 |
|
|
rm -rf "${module}"
|
| 110 |
|
|
die "failed to clone ${EHG_REPO_URI}"
|
| 111 |
|
|
}
|
| 112 |
|
|
cd "${module}"
|
| 113 |
nelchael |
1.7 |
elif [[ -z "${EHG_OFFLINE}" ]]; then
|
| 114 |
nelchael |
1.12 |
einfo "Updating ${EHG_STORE_DIR}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}"
|
| 115 |
nelchael |
1.5 |
cd "${module}" || die "failed to cd to ${module}"
|
| 116 |
|
|
${EHG_PULL_CMD} || die "update failed"
|
| 117 |
agriffis |
1.1 |
fi
|
| 118 |
|
|
|
| 119 |
nelchael |
1.5 |
# Checkout working copy:
|
| 120 |
nelchael |
1.15 |
einfo "Creating working directory in ${sourcedir} (target revision: ${EHG_REVISION})"
|
| 121 |
nelchael |
1.5 |
hg clone \
|
| 122 |
robbat2 |
1.8 |
${EHG_QUIET_CMD_OPT} \
|
| 123 |
nelchael |
1.16 |
--updaterev="${EHG_REVISION}" \
|
| 124 |
nelchael |
1.12 |
"${EHG_STORE_DIR}/${EHG_PROJECT}/${module}" \
|
| 125 |
nelchael |
1.15 |
"${sourcedir}" || die "hg clone failed"
|
| 126 |
robbat2 |
1.13 |
# An exact revision helps a lot for testing purposes, so have some output...
|
| 127 |
|
|
# id num branch
|
| 128 |
|
|
# fd6e32d61721 6276 default
|
| 129 |
nelchael |
1.15 |
local HG_REVDATA=($(hg identify -b -i "${sourcedir}"))
|
| 130 |
nelchael |
1.14 |
export HG_REV_ID=${HG_REVDATA[0]}
|
| 131 |
robbat2 |
1.13 |
local HG_REV_BRANCH=${HG_REVDATA[1]}
|
| 132 |
nelchael |
1.15 |
einfo "Work directory: ${sourcedir} global id: ${HG_REV_ID} branch: ${HG_REV_BRANCH}"
|
| 133 |
agriffis |
1.1 |
}
|
| 134 |
|
|
|
| 135 |
nelchael |
1.5 |
# @FUNCTION: mercurial_src_unpack
|
| 136 |
|
|
# @DESCRIPTION:
|
| 137 |
|
|
# The mercurial src_unpack function, which will be exported.
|
| 138 |
agriffis |
1.1 |
function mercurial_src_unpack {
|
| 139 |
|
|
mercurial_fetch
|
| 140 |
|
|
}
|