/[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.11
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.1 2006/05/20 02:43:01 agriffis Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/mercurial.eclass,v 1.11 2010/03/06 12:24:05 djc 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-vcs/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_CLONE_CMD:=hg clone} # clone cmd 26# @DESCRIPTION:
21: ${EHG_PULL_CMD:=hg pull -u} # pull cmd 27# Create working directory for specified revision, defaults to tip.
28#
29# EHG_REVISION is passed as a value for --rev parameter, so it can be more than
30# just a revision, please consult `hg help revisions' for more details.
31[[ -z "${EHG_REVISION}" ]] && EHG_REVISION="tip"
22 32
23# should be set but blank to prevent using $HOME/.hgrc 33# @ECLASS-VARIABLE: EHG_PROJECT
24export HGRCPATH= 34# @DESCRIPTION:
35# Project name.
36#
37# This variable default to $PN, but can be changed to allow repository sharing
38# between several ebuilds.
39[[ -z "${EHG_PROJECT}" ]] && EHG_PROJECT="${PN}"
25 40
41# @ECLASS-VARIABLE: EHG_QUIET
42# @DESCRIPTION:
43# Suppress some extra noise from mercurial, set it to 'OFF' to be louder.
44: ${EHG_QUIET:="ON"}
45[[ "${EHG_QUIET}" == "ON" ]] && EHG_QUIET_CMD_OPT="--quiet"
46
47# @ECLASS-VARIABLE: EHG_CLONE_CMD
48# @DESCRIPTION:
49# Command used to perform initial repository clone.
50[[ -z "${EHG_CLONE_CMD}" ]] && EHG_CLONE_CMD="hg clone ${EHG_QUIET_CMD_OPT} --pull --noupdate"
51
52# @ECLASS-VARIABLE: EHG_PULL_CMD
53# @DESCRIPTION:
54# Command used to update repository.
55[[ -z "${EHG_PULL_CMD}" ]] && EHG_PULL_CMD="hg pull ${EHG_QUIET_CMD_OPT}"
56
57# @ECLASS-VARIABLE: EHG_OFFLINE
58# @DESCRIPTION:
59# Set this variable to a non-empty value to disable the automatic updating of
60# a mercurial source tree. This is intended to be set outside the ebuild by
61# users.
62EHG_OFFLINE="${EHG_OFFLINE:-${ESCM_OFFLINE}}"
63
64# @FUNCTION: mercurial_fetch
65# @USAGE: [repository_uri] [module]
66# @DESCRIPTION:
67# Clone or update repository.
68#
69# If not repository URI is passed it defaults to EHG_REPO_URI, if module is
70# empty it defaults to basename of EHG_REPO_URI.
26function mercurial_fetch { 71function mercurial_fetch {
27 declare repo=${1:-$EHG_REPO_URI} proj=${2:-${PN/-hg}} 72 debug-print-function ${FUNCNAME} ${*}
28 repo=${repo%/} # remove trailing slash
29 [[ -n $repo ]] || die "EHG_REPO_URI is empty"
30 73
31 if [[ ! -d ${EHG_STORE_DIR} ]]; then 74 EHG_REPO_URI=${1-${EHG_REPO_URI}}
32 ebegin "create ${EHG_STORE_DIR}" 75 [[ -z "${EHG_REPO_URI}" ]] && die "EHG_REPO_URI is empty"
33 addwrite / && 76
34 mkdir -p "${EHG_STORE_DIR}" && 77 local hg_src_dir="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/hg-src"
35 chmod -f o+rw "${EHG_STORE_DIR}" && 78 local module="${2-$(basename "${EHG_REPO_URI}")}"
36 export SANDBOX_WRITE="${SANDBOX_WRITE%:/}" 79
37 eend $? || die 80 # Should be set but blank to prevent using $HOME/.hgrc
81 export HGRCPATH=
82
83 # Check ${hg_src_dir} directory:
84 addwrite "$(dirname "${hg_src_dir}")" || die "addwrite failed"
85 if [[ ! -d "${hg_src_dir}" ]]; then
86 mkdir -p "${hg_src_dir}" || die "failed to create ${hg_src_dir}"
87 chmod -f g+rw "${hg_src_dir}" || \
88 die "failed to chown ${hg_src_dir}"
38 fi 89 fi
39 90
40 cd "${EHG_STORE_DIR}" || die "can't chdir to ${EHG_STORE_DIR}" 91 # Create project directory:
41 addwrite "$(pwd -P)" 92 mkdir -p "${hg_src_dir}/${EHG_PROJECT}" || \
93 die "failed to create ${hg_src_dir}/${EHG_PROJECT}"
94 chmod -f g+rw "${hg_src_dir}/${EHG_PROJECT}" || \
95 echo "Warning: failed to chmod g+rw ${EHG_PROJECT}"
96 cd "${hg_src_dir}/${EHG_PROJECT}" || \
97 die "failed to cd to ${hg_src_dir}/${EHG_PROJECT}"
42 98
43 if [[ ! -d ${proj}/${repo##*/} ]]; then 99 # Clone/update repository:
44 # first check out 100 if [[ ! -d "${module}" ]]; then
45 ebegin "${EHG_CLONE_CMD} ${repo}" 101 einfo "Cloning ${EHG_REPO_URI} to ${hg_src_dir}/${EHG_PROJECT}/${module}"
46 mkdir -p "${proj}" && 102 ${EHG_CLONE_CMD} "${EHG_REPO_URI}" "${module}" || {
47 chmod -f o+rw "${proj}" && 103 rm -rf "${module}"
48 cd "${proj}" && 104 die "failed to clone ${EHG_REPO_URI}"
49 ${EHG_CLONE_CMD} "${repo}" && 105 }
50 cd "${repo##*/}" 106 cd "${module}"
51 eend $? || die 107 elif [[ -z "${EHG_OFFLINE}" ]]; then
52 else 108 einfo "Updating ${hg_src_dir}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}"
53 # update working copy 109 cd "${module}" || die "failed to cd to ${module}"
54 ebegin "${EHG_PULL_CMD} ${repo}" 110 ${EHG_PULL_CMD} || die "update failed"
55 cd "${proj}/${repo##*/}" &&
56 ${EHG_PULL_CMD}
57 eend $? || die
58 fi 111 fi
59 112
60 # use rsync instead of cp for --exclude 113 # Checkout working copy:
61 ebegin "rsync to ${S}" 114 einfo "Creating working directory in ${WORKDIR}/${module} (revision: ${EHG_REVISION})"
62 mkdir -p "${S}" && 115 hg clone \
63 rsync -av --delete --exclude=.hg/ . "${S}" 116 ${EHG_QUIET_CMD_OPT} \
64 eend $? || die 117 --rev="${EHG_REVISION}" \
118 "${hg_src_dir}/${EHG_PROJECT}/${module}" \
119 "${WORKDIR}/${module}" || die "hg clone failed"
65} 120}
66 121
122# @FUNCTION: mercurial_src_unpack
123# @DESCRIPTION:
124# The mercurial src_unpack function, which will be exported.
67function mercurial_src_unpack { 125function mercurial_src_unpack {
68 mercurial_fetch 126 mercurial_fetch
69} 127}

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

  ViewVC Help
Powered by ViewVC 1.1.20