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

Diff of /eclass/mercurial.eclass

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

Revision 1.7 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.7 2009/09/29 21:51:33 nelchael Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/mercurial.eclass,v 1.19 2012/04/03 19:16:29 nelchael Exp $
4 4
5# @ECLASS: mercurial.eclass 5# @ECLASS: mercurial.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# nelchael@gentoo.org 7# Krzysztof Pawlik <nelchael@gentoo.org>
8# Dirkjan Ochtman <djc@gentoo.org>
8# @BLURB: This eclass provides generic mercurial fetching functions 9# @BLURB: This eclass provides generic mercurial fetching functions
9# @DESCRIPTION: 10# @DESCRIPTION:
10# This eclass provides generic mercurial fetching functions. To fetch sources 11# 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# 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# you need to share single repository between several ebuilds set EHG_PROJECT to
14 15
15inherit eutils 16inherit eutils
16 17
17EXPORT_FUNCTIONS src_unpack 18EXPORT_FUNCTIONS src_unpack
18 19
19DEPEND="dev-util/mercurial" 20DEPEND="dev-vcs/mercurial"
20 21
21# @ECLASS-VARIABLE: EHG_REPO_URI 22# @ECLASS-VARIABLE: EHG_REPO_URI
22# @DESCRIPTION: 23# @DESCRIPTION:
23# Mercurial repository URI. 24# Mercurial repository URI.
24 25
25# @ECLASS-VARIABLE: EHG_REVISION 26# @ECLASS-VARIABLE: EHG_REVISION
26# @DESCRIPTION: 27# @DESCRIPTION:
27# Create working directory for specified revision, defaults to tip. 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.
28[[ -z "${EHG_REVISION}" ]] && EHG_REVISION="tip" 32[[ -z "${EHG_REVISION}" ]] && EHG_REVISION="tip"
33
34# @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"
29 38
30# @ECLASS-VARIABLE: EHG_PROJECT 39# @ECLASS-VARIABLE: EHG_PROJECT
31# @DESCRIPTION: 40# @DESCRIPTION:
32# Project name. 41# Project name.
33# 42#
34# This variable default to $PN, but can be changed to allow repository sharing 43# This variable default to $PN, but can be changed to allow repository sharing
35# between several ebuilds. 44# between several ebuilds.
36[[ -z "${EHG_PROJECT}" ]] && EHG_PROJECT="${PN}" 45[[ -z "${EHG_PROJECT}" ]] && EHG_PROJECT="${PN}"
37 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
38# @ECLASS-VARIABLE: EHG_CLONE_CMD 53# @ECLASS-VARIABLE: EHG_CLONE_CMD
39# @DESCRIPTION: 54# @DESCRIPTION:
40# Command used to perform initial repository clone. 55# Command used to perform initial repository clone.
41[[ -z "${EHG_CLONE_CMD}" ]] && EHG_CLONE_CMD="hg clone --quiet --pull --noupdate" 56[[ -z "${EHG_CLONE_CMD}" ]] && EHG_CLONE_CMD="hg clone ${EHG_QUIET_CMD_OPT} --pull --noupdate"
42 57
43# @ECLASS-VARIABLE: EHG_PULL_CMD 58# @ECLASS-VARIABLE: EHG_PULL_CMD
44# @DESCRIPTION: 59# @DESCRIPTION:
45# Command used to update repository. 60# Command used to update repository.
46[[ -z "${EHG_PULL_CMD}" ]] && EHG_PULL_CMD="hg pull --quiet" 61[[ -z "${EHG_PULL_CMD}" ]] && EHG_PULL_CMD="hg pull ${EHG_QUIET_CMD_OPT}"
47 62
48# @ECLASS-VARIABLE: EHG_OFFLINE 63# @ECLASS-VARIABLE: EHG_OFFLINE
49# @DESCRIPTION: 64# @DESCRIPTION:
50# Set this variable to a non-empty value to disable the automatic updating of 65# Set this variable to a non-empty value to disable the automatic updating of
51# a mercurial source tree. This is intended to be set outside the ebuild by 66# a mercurial source tree. This is intended to be set outside the ebuild by
52# users. 67# users.
53EHG_OFFLINE="${EHG_OFFLINE:-${ESCM_OFFLINE}}" 68EHG_OFFLINE="${EHG_OFFLINE:-${EVCS_OFFLINE}}"
54 69
55# @FUNCTION: mercurial_fetch 70# @FUNCTION: mercurial_fetch
56# @USAGE: [repository_uri] [module] 71# @USAGE: [repository_uri] [module] [sourcedir]
57# @DESCRIPTION: 72# @DESCRIPTION:
58# Clone or update repository. 73# Clone or update repository.
59# 74#
60# If not repository URI is passed it defaults to EHG_REPO_URI, if module is 75# If repository URI is not passed it defaults to EHG_REPO_URI, if module is
61# empty it defaults to basename of EHG_REPO_URI. 76# empty it defaults to basename of EHG_REPO_URI, sourcedir defaults to S.
62function mercurial_fetch { 77function mercurial_fetch {
63 debug-print-function ${FUNCNAME} ${*} 78 debug-print-function ${FUNCNAME} ${*}
64 79
65 EHG_REPO_URI=${1-${EHG_REPO_URI}} 80 EHG_REPO_URI=${1-${EHG_REPO_URI}}
66 [[ -z "${EHG_REPO_URI}" ]] && die "EHG_REPO_URI is empty" 81 [[ -z "${EHG_REPO_URI}" ]] && die "EHG_REPO_URI is empty"
67 82
68 local hg_src_dir="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/hg-src"
69 local module="${2-$(basename "${EHG_REPO_URI}")}" 83 local module="${2-$(basename "${EHG_REPO_URI}")}"
84 local sourcedir="${3-${S}}"
70 85
71 # Should be set but blank to prevent using $HOME/.hgrc 86 # Should be set but blank to prevent using $HOME/.hgrc
72 export HGRCPATH= 87 export HGRCPATH=
73 88
74 # Check ${hg_src_dir} directory: 89 # Check ${EHG_STORE_DIR} directory:
75 addwrite "$(dirname "${hg_src_dir}")" || die "addwrite failed" 90 addwrite "$(dirname "${EHG_STORE_DIR}")" || die "addwrite failed"
76 if [[ ! -d "${hg_src_dir}" ]]; then 91 if [[ ! -d "${EHG_STORE_DIR}" ]]; then
77 mkdir -p "${hg_src_dir}" || die "failed to create ${hg_src_dir}" 92 mkdir -p "${EHG_STORE_DIR}" || die "failed to create ${EHG_STORE_DIR}"
78 chmod -f g+rw "${hg_src_dir}" || \ 93 chmod -f g+rw "${EHG_STORE_DIR}" || \
79 die "failed to chown ${hg_src_dir}" 94 die "failed to chown ${EHG_STORE_DIR}"
80 fi 95 fi
81 96
82 # Create project directory: 97 # Create project directory:
83 mkdir -p "${hg_src_dir}/${EHG_PROJECT}" || \ 98 mkdir -p "${EHG_STORE_DIR}/${EHG_PROJECT}" || \
84 die "failed to create ${hg_src_dir}/${EHG_PROJECT}" 99 die "failed to create ${EHG_STORE_DIR}/${EHG_PROJECT}"
85 chmod -f g+rw "${hg_src_dir}/${EHG_PROJECT}" || \ 100 chmod -f g+rw "${EHG_STORE_DIR}/${EHG_PROJECT}" || \
86 die "failed to chwon ${EHG_PROJECT}" 101 echo "Warning: failed to chmod g+rw ${EHG_PROJECT}"
87 cd "${hg_src_dir}/${EHG_PROJECT}" || \ 102 cd "${EHG_STORE_DIR}/${EHG_PROJECT}" || \
88 die "failed to cd to ${hg_src_dir}/${EHG_PROJECT}" 103 die "failed to cd to ${EHG_STORE_DIR}/${EHG_PROJECT}"
89 104
90 # Clone/update repository: 105 # Clone/update repository:
91 if [[ ! -d "${module}" ]]; then 106 if [[ ! -d "${module}" ]]; then
92 einfo "Cloning ${EHG_REPO_URI} to ${hg_src_dir}/${EHG_PROJECT}/${module}" 107 einfo "Cloning ${EHG_REPO_URI} to ${EHG_STORE_DIR}/${EHG_PROJECT}/${module}"
93 ${EHG_CLONE_CMD} "${EHG_REPO_URI}" "${module}" || { 108 ${EHG_CLONE_CMD} "${EHG_REPO_URI}" "${module}" || {
94 rm -rf "${module}" 109 rm -rf "${module}"
95 die "failed to clone ${EHG_REPO_URI}" 110 die "failed to clone ${EHG_REPO_URI}"
96 } 111 }
97 cd "${module}" 112 cd "${module}"
98 elif [[ -z "${EHG_OFFLINE}" ]]; then 113 elif [[ -z "${EHG_OFFLINE}" ]]; then
99 einfo "Updating ${hg_src_dir}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}" 114 einfo "Updating ${EHG_STORE_DIR}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}"
100 cd "${module}" || die "failed to cd to ${module}" 115 cd "${module}" || die "failed to cd to ${module}"
101 ${EHG_PULL_CMD} || die "update failed" 116 ${EHG_PULL_CMD}
117 # mercurial-2.1: hg pull returns 1 if there are no incoming changesets
118 [[ $? -eq 0 || $? -eq 1 ]] || die "update failed"
102 fi 119 fi
103 120
104 # Checkout working copy: 121 # Checkout working copy:
105 einfo "Creating working directory in ${WORKDIR}/${module} (revision: ${EHG_REVISION})" 122 einfo "Creating working directory in ${sourcedir} (target revision: ${EHG_REVISION})"
106 hg clone \ 123 hg clone \
107 --quiet \ 124 ${EHG_QUIET_CMD_OPT} \
108 --rev="${EHG_REVISION}" \ 125 --updaterev="${EHG_REVISION}" \
109 "${hg_src_dir}/${EHG_PROJECT}/${module}" \ 126 "${EHG_STORE_DIR}/${EHG_PROJECT}/${module}" \
110 "${WORKDIR}/${module}" || die "hg clone failed" 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}"
111} 135}
112 136
113# @FUNCTION: mercurial_src_unpack 137# @FUNCTION: mercurial_src_unpack
114# @DESCRIPTION: 138# @DESCRIPTION:
115# The mercurial src_unpack function, which will be exported. 139# The mercurial src_unpack function, which will be exported.

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

  ViewVC Help
Powered by ViewVC 1.1.20