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

Diff of /eclass/mercurial.eclass

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

Revision 1.4 Revision 1.8
1# Copyright 1999-2006 Gentoo Foundation 1# Copyright 1999-2006 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.4 2009/02/22 13:01:17 nelchael Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/mercurial.eclass,v 1.8 2009/12/11 21:02:29 robbat2 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# nelchael@gentoo.org
8# @BLURB: This eclass provides generic mercurial fetching functions
9# @DESCRIPTION:
10# This eclass provides generic mercurial fetching functions. To fetch sources
11# from mercurial repository just set EHG_REPO_URI to correct repository URI. If
12# you need to share single repository between several ebuilds set EHG_PROJECT to
13# project name in all of them.
8 14
9inherit eutils 15inherit eutils
10 16
11EXPORT_FUNCTIONS src_unpack 17EXPORT_FUNCTIONS src_unpack
12 18
13DEPEND="dev-util/mercurial net-misc/rsync" 19DEPEND="dev-util/mercurial"
14EHG_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/hg-src"
15 20
16# This must be set by the ebuild 21# @ECLASS-VARIABLE: EHG_REPO_URI
17: ${EHG_REPO_URI:=} # repository uri 22# @DESCRIPTION:
23# Mercurial repository URI.
18 24
19# These can be set by the ebuild but are usually fine as-is 25# @ECLASS-VARIABLE: EHG_REVISION
20: ${EHG_PROJECT:=$PN} # dir under EHG_STORE_DIR 26# @DESCRIPTION:
21: ${EHG_CLONE_CMD:=hg clone --pull} # clone cmd 27# Create working directory for specified revision, defaults to tip.
22: ${EHG_PULL_CMD:=hg pull -u} # pull cmd 28[[ -z "${EHG_REVISION}" ]] && EHG_REVISION="tip"
23 29
24# should be set but blank to prevent using $HOME/.hgrc 30# @ECLASS-VARIABLE: EHG_PROJECT
25export HGRCPATH= 31# @DESCRIPTION:
32# Project name.
33#
34# This variable default to $PN, but can be changed to allow repository sharing
35# between several ebuilds.
36[[ -z "${EHG_PROJECT}" ]] && EHG_PROJECT="${PN}"
26 37
38# @ECLASS-VARIABLE: EHG_QUIET
39# @DESCRIPTION:
40# Suppress some extra noise from mercurial, set it to 'OFF' to be louder.
41: ${EHG_QUIET:="ON"}
42[[ "${EHG_QUIET}" == "ON" ]] && EHG_QUIET_CMD_OPT="--quiet"
43
44# @ECLASS-VARIABLE: EHG_CLONE_CMD
45# @DESCRIPTION:
46# Command used to perform initial repository clone.
47[[ -z "${EHG_CLONE_CMD}" ]] && EHG_CLONE_CMD="hg clone ${EHG_QUIET_CMD_OPT} --pull --noupdate"
48
49# @ECLASS-VARIABLE: EHG_PULL_CMD
50# @DESCRIPTION:
51# Command used to update repository.
52[[ -z "${EHG_PULL_CMD}" ]] && EHG_PULL_CMD="hg pull ${EHG_QUIET_CMD_OPT}"
53
54# @ECLASS-VARIABLE: EHG_OFFLINE
55# @DESCRIPTION:
56# Set this variable to a non-empty value to disable the automatic updating of
57# a mercurial source tree. This is intended to be set outside the ebuild by
58# users.
59EHG_OFFLINE="${EHG_OFFLINE:-${ESCM_OFFLINE}}"
60
61# @FUNCTION: mercurial_fetch
62# @USAGE: [repository_uri] [module]
63# @DESCRIPTION:
64# Clone or update repository.
65#
66# If not repository URI is passed it defaults to EHG_REPO_URI, if module is
67# empty it defaults to basename of EHG_REPO_URI.
27function mercurial_fetch { 68function mercurial_fetch {
28 declare repo=${1:-$EHG_REPO_URI} 69 debug-print-function ${FUNCNAME} ${*}
29 repo=${repo%/} # remove trailing slash
30 [[ -n $repo ]] || die "EHG_REPO_URI is empty"
31 declare module=${2:-${repo##*/}}
32 70
33 if [[ ! -d ${EHG_STORE_DIR} ]]; then 71 EHG_REPO_URI=${1-${EHG_REPO_URI}}
34 ebegin "create ${EHG_STORE_DIR}" 72 [[ -z "${EHG_REPO_URI}" ]] && die "EHG_REPO_URI is empty"
35 addwrite / && 73
36 mkdir -p "${EHG_STORE_DIR}" && 74 local hg_src_dir="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/hg-src"
37 chmod -f g+rw "${EHG_STORE_DIR}" && 75 local module="${2-$(basename "${EHG_REPO_URI}")}"
38 export SANDBOX_WRITE="${SANDBOX_WRITE%:/}" 76
39 eend $? || die 77 # Should be set but blank to prevent using $HOME/.hgrc
78 export HGRCPATH=
79
80 # Check ${hg_src_dir} directory:
81 addwrite "$(dirname "${hg_src_dir}")" || die "addwrite failed"
82 if [[ ! -d "${hg_src_dir}" ]]; then
83 mkdir -p "${hg_src_dir}" || die "failed to create ${hg_src_dir}"
84 chmod -f g+rw "${hg_src_dir}" || \
85 die "failed to chown ${hg_src_dir}"
40 fi 86 fi
41 87
42 pushd "${EHG_STORE_DIR}" >/dev/null \ 88 # Create project directory:
43 || die "can't chdir to ${EHG_STORE_DIR}" 89 mkdir -p "${hg_src_dir}/${EHG_PROJECT}" || \
44 addwrite "$(pwd -P)" 90 die "failed to create ${hg_src_dir}/${EHG_PROJECT}"
91 chmod -f g+rw "${hg_src_dir}/${EHG_PROJECT}" || \
92 die "failed to chwon ${EHG_PROJECT}"
93 cd "${hg_src_dir}/${EHG_PROJECT}" || \
94 die "failed to cd to ${hg_src_dir}/${EHG_PROJECT}"
45 95
96 # Clone/update repository:
46 if [[ ! -d ${EHG_PROJECT}/${module} ]]; then 97 if [[ ! -d "${module}" ]]; then
47 # first check out 98 einfo "Cloning ${EHG_REPO_URI} to ${hg_src_dir}/${EHG_PROJECT}/${module}"
48 ebegin "${EHG_CLONE_CMD} ${repo}"
49 mkdir -p "${EHG_PROJECT}" &&
50 chmod -f g+rw "${EHG_PROJECT}" &&
51 cd "${EHG_PROJECT}" &&
52 ${EHG_CLONE_CMD} "${repo}" "${module}" && 99 ${EHG_CLONE_CMD} "${EHG_REPO_URI}" "${module}" || {
100 rm -rf "${module}"
101 die "failed to clone ${EHG_REPO_URI}"
102 }
53 cd "${module}" 103 cd "${module}"
54 eend $? || die 104 elif [[ -z "${EHG_OFFLINE}" ]]; then
55 else 105 einfo "Updating ${hg_src_dir}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}"
56 # update working copy 106 cd "${module}" || die "failed to cd to ${module}"
57 ebegin "${EHG_PULL_CMD} ${repo}" 107 ${EHG_PULL_CMD} || die "update failed"
58 cd "${EHG_PROJECT}/${module}" &&
59 ${EHG_PULL_CMD}
60 case $? in
61 # hg pull returns status 1 when there were no changes to pull
62 1) eend 0 ;;
63 *) eend $? || die ;;
64 esac
65 fi 108 fi
66 109
67 # use rsync instead of cp for --exclude 110 # Checkout working copy:
68 ebegin "rsync to ${WORKDIR}/${module}" 111 einfo "Creating working directory in ${WORKDIR}/${module} (revision: ${EHG_REVISION})"
69 mkdir -p "${WORKDIR}/${module}" && 112 hg clone \
70 rsync -a --delete --exclude=.hg/ . "${WORKDIR}/${module}" 113 ${EHG_QUIET_CMD_OPT} \
71 eend $? || die 114 --rev="${EHG_REVISION}" \
72 115 "${hg_src_dir}/${EHG_PROJECT}/${module}" \
73 popd >/dev/null 116 "${WORKDIR}/${module}" || die "hg clone failed"
74} 117}
75 118
119# @FUNCTION: mercurial_src_unpack
120# @DESCRIPTION:
121# The mercurial src_unpack function, which will be exported.
76function mercurial_src_unpack { 122function mercurial_src_unpack {
77 mercurial_fetch 123 mercurial_fetch
78} 124}

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.20