/[gentoo-x86]/eclass/mercurial.eclass
Gentoo

Diff of /eclass/mercurial.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 Revision 1.19
1# Copyright 1999-2006 Gentoo Foundation 1# Copyright 1999-2012 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/mercurial.eclass,v 1.1 2006/05/20 02:43:01 agriffis Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/mercurial.eclass,v 1.19 2012/04/03 19:16:29 nelchael Exp $
4 4
5# mercurial: Fetch sources from mercurial repositories, similar to cvs.eclass. 5# @ECLASS: mercurial.eclass
6# To use this from an ebuild, set EHG_REPO_URI in your ebuild. Then either 6# @MAINTAINER:
7# leave the default src_unpack or call mercurial_src_unpack. 7# Krzysztof Pawlik <nelchael@gentoo.org>
8# Dirkjan Ochtman <djc@gentoo.org>
9# @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.
8 15
9inherit eutils 16inherit eutils
10 17
11EXPORT_FUNCTIONS src_unpack 18EXPORT_FUNCTIONS src_unpack
12 19
13DEPEND="dev-util/mercurial net-misc/rsync" 20DEPEND="dev-vcs/mercurial"
14EHG_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/hg-src"
15 21
16# This must be set by the ebuild 22# @ECLASS-VARIABLE: EHG_REPO_URI
17: ${EHG_REPO_URI:=} # repository uri 23# @DESCRIPTION:
24# Mercurial repository URI.
18 25
19# These can be set by the ebuild but are usually fine as-is 26# @ECLASS-VARIABLE: EHG_REVISION
20: ${EHG_CLONE_CMD:=hg clone} # clone cmd 27# @DESCRIPTION:
21: ${EHG_PULL_CMD:=hg pull -u} # pull cmd 28# Create working directory for specified revision, defaults to tip.
29#
30# 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[[ -z "${EHG_REVISION}" ]] && EHG_REVISION="tip"
22 33
23# should be set but blank to prevent using $HOME/.hgrc 34# @ECLASS-VARIABLE: EHG_STORE_DIR
24export HGRCPATH= 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"
25 38
39# @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# @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# @ECLASS-VARIABLE: EHG_CLONE_CMD
54# @DESCRIPTION:
55# Command used to perform initial repository clone.
56[[ -z "${EHG_CLONE_CMD}" ]] && EHG_CLONE_CMD="hg clone ${EHG_QUIET_CMD_OPT} --pull --noupdate"
57
58# @ECLASS-VARIABLE: EHG_PULL_CMD
59# @DESCRIPTION:
60# Command used to update repository.
61[[ -z "${EHG_PULL_CMD}" ]] && EHG_PULL_CMD="hg pull ${EHG_QUIET_CMD_OPT}"
62
63# @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.
68EHG_OFFLINE="${EHG_OFFLINE:-${EVCS_OFFLINE}}"
69
70# @FUNCTION: mercurial_fetch
71# @USAGE: [repository_uri] [module] [sourcedir]
72# @DESCRIPTION:
73# Clone or update repository.
74#
75# 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.
26function mercurial_fetch { 77function mercurial_fetch {
27 declare repo=${1:-$EHG_REPO_URI} proj=${2:-${PN/-hg}} 78 debug-print-function ${FUNCNAME} ${*}
28 repo=${repo%/} # remove trailing slash
29 [[ -n $repo ]] || die "EHG_REPO_URI is empty"
30 79
80 EHG_REPO_URI=${1-${EHG_REPO_URI}}
81 [[ -z "${EHG_REPO_URI}" ]] && die "EHG_REPO_URI is empty"
82
83 local module="${2-$(basename "${EHG_REPO_URI}")}"
84 local sourcedir="${3-${S}}"
85
86 # Should be set but blank to prevent using $HOME/.hgrc
87 export HGRCPATH=
88
89 # Check ${EHG_STORE_DIR} directory:
90 addwrite "$(dirname "${EHG_STORE_DIR}")" || die "addwrite failed"
31 if [[ ! -d ${EHG_STORE_DIR} ]]; then 91 if [[ ! -d "${EHG_STORE_DIR}" ]]; then
32 ebegin "create ${EHG_STORE_DIR}" 92 mkdir -p "${EHG_STORE_DIR}" || die "failed to create ${EHG_STORE_DIR}"
33 addwrite / &&
34 mkdir -p "${EHG_STORE_DIR}" &&
35 chmod -f o+rw "${EHG_STORE_DIR}" && 93 chmod -f g+rw "${EHG_STORE_DIR}" || \
36 export SANDBOX_WRITE="${SANDBOX_WRITE%:/}" 94 die "failed to chown ${EHG_STORE_DIR}"
37 eend $? || die
38 fi 95 fi
39 96
40 cd "${EHG_STORE_DIR}" || die "can't chdir to ${EHG_STORE_DIR}" 97 # Create project directory:
41 addwrite "$(pwd -P)" 98 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 echo "Warning: failed to chmod g+rw ${EHG_PROJECT}"
102 cd "${EHG_STORE_DIR}/${EHG_PROJECT}" || \
103 die "failed to cd to ${EHG_STORE_DIR}/${EHG_PROJECT}"
42 104
43 if [[ ! -d ${proj}/${repo##*/} ]]; then 105 # Clone/update repository:
44 # first check out 106 if [[ ! -d "${module}" ]]; then
45 ebegin "${EHG_CLONE_CMD} ${repo}" 107 einfo "Cloning ${EHG_REPO_URI} to ${EHG_STORE_DIR}/${EHG_PROJECT}/${module}"
46 mkdir -p "${proj}" && 108 ${EHG_CLONE_CMD} "${EHG_REPO_URI}" "${module}" || {
47 chmod -f o+rw "${proj}" && 109 rm -rf "${module}"
48 cd "${proj}" && 110 die "failed to clone ${EHG_REPO_URI}"
49 ${EHG_CLONE_CMD} "${repo}" && 111 }
50 cd "${repo##*/}" 112 cd "${module}"
51 eend $? || die 113 elif [[ -z "${EHG_OFFLINE}" ]]; then
52 else 114 einfo "Updating ${EHG_STORE_DIR}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}"
53 # update working copy 115 cd "${module}" || die "failed to cd to ${module}"
54 ebegin "${EHG_PULL_CMD} ${repo}"
55 cd "${proj}/${repo##*/}" &&
56 ${EHG_PULL_CMD} 116 ${EHG_PULL_CMD}
57 eend $? || die 117 # mercurial-2.1: hg pull returns 1 if there are no incoming changesets
118 [[ $? -eq 0 || $? -eq 1 ]] || die "update failed"
58 fi 119 fi
59 120
60 # use rsync instead of cp for --exclude 121 # Checkout working copy:
61 ebegin "rsync to ${S}" 122 einfo "Creating working directory in ${sourcedir} (target revision: ${EHG_REVISION})"
62 mkdir -p "${S}" && 123 hg clone \
63 rsync -av --delete --exclude=.hg/ . "${S}" 124 ${EHG_QUIET_CMD_OPT} \
64 eend $? || die 125 --updaterev="${EHG_REVISION}" \
126 "${EHG_STORE_DIR}/${EHG_PROJECT}/${module}" \
127 "${sourcedir}" || die "hg clone failed"
128 # An exact revision helps a lot for testing purposes, so have some output...
129 # id num branch
130 # fd6e32d61721 6276 default
131 local HG_REVDATA=($(hg identify -b -i "${sourcedir}"))
132 export HG_REV_ID=${HG_REVDATA[0]}
133 local HG_REV_BRANCH=${HG_REVDATA[1]}
134 einfo "Work directory: ${sourcedir} global id: ${HG_REV_ID} branch: ${HG_REV_BRANCH}"
65} 135}
66 136
137# @FUNCTION: mercurial_src_unpack
138# @DESCRIPTION:
139# The mercurial src_unpack function, which will be exported.
67function mercurial_src_unpack { 140function mercurial_src_unpack {
68 mercurial_fetch 141 mercurial_fetch
69} 142}

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.19

  ViewVC Help
Powered by ViewVC 1.1.20