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

Contents of /eclass/mercurial.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Mon Mar 9 20:09:24 2009 UTC (5 years, 6 months ago) by nelchael
Branch: MAIN
Changes since 1.4: +89 -56 lines
Cleanup eclass, add documentation.

1 # Copyright 1999-2006 Gentoo Foundation
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 $
4
5 # @ECLASS: mercurial.eclass
6 # @MAINTAINER:
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.
14
15 inherit eutils
16
17 EXPORT_FUNCTIONS src_unpack
18
19 DEPEND="dev-util/mercurial"
20
21 # @ECLASS-VARIABLE: EHG_REPO_URI
22 # @DESCRIPTION:
23 # Mercurial repository URI.
24
25 # @ECLASS-VARIABLE: EHG_REVISION
26 # @DESCRIPTION:
27 # Create working directory for specified revision, defaults to tip.
28 [[ -z "${EHG_REVISION}" ]] && EHG_REVISION="tip"
29
30 # @ECLASS-VARIABLE: EHG_PROJECT
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}"
37
38 # @ECLASS-VARIABLE: EHG_CLONE_CMD
39 # @DESCRIPTION:
40 # Command used to perform initial repository clone.
41 [[ -z "${EHG_CLONE_CMD}" ]] && EHG_CLONE_CMD="hg clone --quiet --pull --noupdate"
42
43 # @ECLASS-VARIABLE: EHG_PULL_CMD
44 # @DESCRIPTION:
45 # Command used to update repository.
46 [[ -z "${EHG_PULL_CMD}" ]] && EHG_PULL_CMD="hg pull --quiet"
47
48 # @FUNCTION: mercurial_fetch
49 # @USAGE: [repository_uri] [module]
50 # @DESCRIPTION:
51 # Clone or update repository.
52 #
53 # If not repository URI is passed it defaults to EHG_REPO_URI, if module is
54 # empty it defaults to basename of EHG_REPO_URI.
55 function mercurial_fetch {
56 debug-print-function ${FUNCNAME} ${*}
57
58 EHG_REPO_URI=${1-${EHG_REPO_URI}}
59 [[ -z "${EHG_REPO_URI}" ]] && die "EHG_REPO_URI is empty"
60
61 local hg_src_dir="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/hg-src"
62 local module="${2-$(basename "${EHG_REPO_URI}")}"
63
64 # Should be set but blank to prevent using $HOME/.hgrc
65 export HGRCPATH=
66
67 # Check ${hg_src_dir} directory:
68 addwrite "$(dirname "${hg_src_dir}")" || die "addwrite failed"
69 if [[ ! -d "${hg_src_dir}" ]]; then
70 mkdir -p "${hg_src_dir}" || die "failed to create ${hg_src_dir}"
71 chmod -f g+rw "${hg_src_dir}" || \
72 die "failed to chown ${hg_src_dir}"
73 fi
74
75 # Create project directory:
76 mkdir -p "${hg_src_dir}/${EHG_PROJECT}" || \
77 die "failed to create ${hg_src_dir}/${EHG_PROJECT}"
78 chmod -f g+rw "${hg_src_dir}/${EHG_PROJECT}" || \
79 die "failed to chwon ${EHG_PROJECT}"
80 cd "${hg_src_dir}/${EHG_PROJECT}" || \
81 die "failed to cd to ${hg_src_dir}/${EHG_PROJECT}"
82
83 # Clone/update repository:
84 if [[ ! -d "${module}" ]]; then
85 einfo "Cloning ${EHG_REPO_URI} to ${hg_src_dir}/${EHG_PROJECT}/${module}"
86 ${EHG_CLONE_CMD} "${EHG_REPO_URI}" "${module}" || {
87 rm -rf "${module}"
88 die "failed to clone ${EHG_REPO_URI}"
89 }
90 cd "${module}"
91 else
92 einfo "Updating ${hg_src_dir}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}"
93 cd "${module}" || die "failed to cd to ${module}"
94 ${EHG_PULL_CMD} || die "update failed"
95 fi
96
97 # Checkout working copy:
98 einfo "Creating working directory in ${WORKDIR}/${module} (revision: ${EHG_REVISION})"
99 hg clone \
100 --quiet \
101 --rev="${EHG_REVISION}" \
102 "${hg_src_dir}/${EHG_PROJECT}/${module}" \
103 "${WORKDIR}/${module}" || die "hg archive failed"
104 }
105
106 # @FUNCTION: mercurial_src_unpack
107 # @DESCRIPTION:
108 # The mercurial src_unpack function, which will be exported.
109 function mercurial_src_unpack {
110 mercurial_fetch
111 }

  ViewVC Help
Powered by ViewVC 1.1.20