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

Contents of /eclass/mercurial.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.24 - (hide annotations) (download)
Fri Jul 25 23:18:34 2014 UTC (4 months ago) by ottxor
Branch: MAIN
CVS Tags: HEAD
Changes since 1.23: +16 -11 lines
Added EHG_CHECKOUT_DIR to override checkout destination

1 ottxor 1.24 # Copyright 1999-2014 Gentoo Foundation
2 agriffis 1.1 # Distributed under the terms of the GNU General Public License v2
3 ottxor 1.24 # $Header: /var/cvsroot/gentoo-x86/eclass/mercurial.eclass,v 1.23 2013/11/04 22:05:31 floppym Exp $
4 agriffis 1.1
5 nelchael 1.5 # @ECLASS: mercurial.eclass
6     # @MAINTAINER:
7 ottxor 1.20 # Christoph Junghans <ottxor@gentoo.org>
8 nelchael 1.12 # Dirkjan Ochtman <djc@gentoo.org>
9 ottxor 1.20 # @AUTHOR:
10     # Next gen author: Krzysztof Pawlik <nelchael@gentoo.org>
11     # Original author: Aron Griffis <agriffis@gentoo.org>
12 nelchael 1.5 # @BLURB: This eclass provides generic mercurial fetching functions
13     # @DESCRIPTION:
14     # This eclass provides generic mercurial fetching functions. To fetch sources
15     # from mercurial repository just set EHG_REPO_URI to correct repository URI. If
16     # you need to share single repository between several ebuilds set EHG_PROJECT to
17     # project name in all of them.
18 agriffis 1.1
19     inherit eutils
20    
21     EXPORT_FUNCTIONS src_unpack
22    
23 djc 1.11 DEPEND="dev-vcs/mercurial"
24 agriffis 1.1
25 nelchael 1.5 # @ECLASS-VARIABLE: EHG_REPO_URI
26     # @DESCRIPTION:
27     # Mercurial repository URI.
28    
29     # @ECLASS-VARIABLE: EHG_REVISION
30     # @DESCRIPTION:
31 ottxor 1.24 # Create working directory for specified revision, defaults to default.
32 nelchael 1.9 #
33 nelchael 1.16 # EHG_REVISION is passed as a value for --updaterev parameter, so it can be more
34     # than just a revision, please consult `hg help revisions' for more details.
35 ottxor 1.20 : ${EHG_REVISION:="default"}
36 nelchael 1.5
37 nelchael 1.12 # @ECLASS-VARIABLE: EHG_STORE_DIR
38     # @DESCRIPTION:
39 zmedico 1.22 # Mercurial sources store directory. Users may override this in /etc/portage/make.conf
40 nelchael 1.12 [[ -z "${EHG_STORE_DIR}" ]] && EHG_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/hg-src"
41    
42 nelchael 1.5 # @ECLASS-VARIABLE: EHG_PROJECT
43     # @DESCRIPTION:
44     # Project name.
45     #
46     # This variable default to $PN, but can be changed to allow repository sharing
47     # between several ebuilds.
48     [[ -z "${EHG_PROJECT}" ]] && EHG_PROJECT="${PN}"
49    
50 ottxor 1.24 # @ECLASS-VARIABLE: EGIT_CHECKOUT_DIR
51     # @DESCRIPTION:
52     # The directory to check the hg sources out to.
53     #
54     # EHG_CHECKOUT_DIR=${S}
55    
56 robbat2 1.8 # @ECLASS-VARIABLE: EHG_QUIET
57     # @DESCRIPTION:
58 ottxor 1.21 # Suppress some extra noise from mercurial, set it to 'ON' to be quiet.
59     : ${EHG_QUIET:="OFF"}
60 robbat2 1.8 [[ "${EHG_QUIET}" == "ON" ]] && EHG_QUIET_CMD_OPT="--quiet"
61    
62 nelchael 1.5 # @ECLASS-VARIABLE: EHG_CLONE_CMD
63     # @DESCRIPTION:
64     # Command used to perform initial repository clone.
65 robbat2 1.8 [[ -z "${EHG_CLONE_CMD}" ]] && EHG_CLONE_CMD="hg clone ${EHG_QUIET_CMD_OPT} --pull --noupdate"
66 nelchael 1.5
67     # @ECLASS-VARIABLE: EHG_PULL_CMD
68     # @DESCRIPTION:
69     # Command used to update repository.
70 robbat2 1.8 [[ -z "${EHG_PULL_CMD}" ]] && EHG_PULL_CMD="hg pull ${EHG_QUIET_CMD_OPT}"
71 nelchael 1.5
72 nelchael 1.7 # @ECLASS-VARIABLE: EHG_OFFLINE
73     # @DESCRIPTION:
74     # Set this variable to a non-empty value to disable the automatic updating of
75     # a mercurial source tree. This is intended to be set outside the ebuild by
76     # users.
77 nelchael 1.19 EHG_OFFLINE="${EHG_OFFLINE:-${EVCS_OFFLINE}}"
78 nelchael 1.7
79 nelchael 1.5 # @FUNCTION: mercurial_fetch
80 nelchael 1.15 # @USAGE: [repository_uri] [module] [sourcedir]
81 nelchael 1.5 # @DESCRIPTION:
82     # Clone or update repository.
83     #
84 nelchael 1.15 # If repository URI is not passed it defaults to EHG_REPO_URI, if module is
85 ottxor 1.24 # empty it defaults to basename of EHG_REPO_URI, sourcedir defaults to
86     # EHG_CHECKOUT_DIR, which defaults to S.
87    
88 ottxor 1.20 mercurial_fetch() {
89     debug-print-function ${FUNCNAME} "${@}"
90    
91     has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
92 agriffis 1.1
93 nelchael 1.5 EHG_REPO_URI=${1-${EHG_REPO_URI}}
94     [[ -z "${EHG_REPO_URI}" ]] && die "EHG_REPO_URI is empty"
95 agriffis 1.1
96 nelchael 1.5 local module="${2-$(basename "${EHG_REPO_URI}")}"
97 ottxor 1.24 local sourcedir="${3:-${EHG_CHECKOUT_DIR:-${S}}}"
98 agriffis 1.1
99 nelchael 1.5 # Should be set but blank to prevent using $HOME/.hgrc
100     export HGRCPATH=
101    
102 nelchael 1.12 # Check ${EHG_STORE_DIR} directory:
103     addwrite "$(dirname "${EHG_STORE_DIR}")" || die "addwrite failed"
104     if [[ ! -d "${EHG_STORE_DIR}" ]]; then
105     mkdir -p "${EHG_STORE_DIR}" || die "failed to create ${EHG_STORE_DIR}"
106     chmod -f g+rw "${EHG_STORE_DIR}" || \
107     die "failed to chown ${EHG_STORE_DIR}"
108 agriffis 1.1 fi
109    
110 nelchael 1.5 # Create project directory:
111 nelchael 1.12 mkdir -p "${EHG_STORE_DIR}/${EHG_PROJECT}" || \
112     die "failed to create ${EHG_STORE_DIR}/${EHG_PROJECT}"
113     chmod -f g+rw "${EHG_STORE_DIR}/${EHG_PROJECT}" || \
114 nelchael 1.10 echo "Warning: failed to chmod g+rw ${EHG_PROJECT}"
115 nelchael 1.12 cd "${EHG_STORE_DIR}/${EHG_PROJECT}" || \
116     die "failed to cd to ${EHG_STORE_DIR}/${EHG_PROJECT}"
117 nelchael 1.5
118     # Clone/update repository:
119     if [[ ! -d "${module}" ]]; then
120 nelchael 1.12 einfo "Cloning ${EHG_REPO_URI} to ${EHG_STORE_DIR}/${EHG_PROJECT}/${module}"
121 ottxor 1.24 ${EHG_CLONE_CMD} "${EHG_REPO_URI}" "${module}" || {
122 nelchael 1.5 rm -rf "${module}"
123     die "failed to clone ${EHG_REPO_URI}"
124     }
125     cd "${module}"
126 nelchael 1.7 elif [[ -z "${EHG_OFFLINE}" ]]; then
127 nelchael 1.12 einfo "Updating ${EHG_STORE_DIR}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}"
128 nelchael 1.5 cd "${module}" || die "failed to cd to ${module}"
129 ottxor 1.24 ${EHG_PULL_CMD} "${EHG_REPO_URI}" || die "update failed"
130 agriffis 1.1 fi
131    
132 nelchael 1.5 # Checkout working copy:
133 nelchael 1.15 einfo "Creating working directory in ${sourcedir} (target revision: ${EHG_REVISION})"
134 ottxor 1.24 mkdir -p "${sourcedir}" || die "failed to create ${sourcedir}"
135 nelchael 1.5 hg clone \
136 robbat2 1.8 ${EHG_QUIET_CMD_OPT} \
137 nelchael 1.16 --updaterev="${EHG_REVISION}" \
138 nelchael 1.12 "${EHG_STORE_DIR}/${EHG_PROJECT}/${module}" \
139 nelchael 1.15 "${sourcedir}" || die "hg clone failed"
140 robbat2 1.13 # An exact revision helps a lot for testing purposes, so have some output...
141     # id num branch
142     # fd6e32d61721 6276 default
143 nelchael 1.15 local HG_REVDATA=($(hg identify -b -i "${sourcedir}"))
144 nelchael 1.14 export HG_REV_ID=${HG_REVDATA[0]}
145 robbat2 1.13 local HG_REV_BRANCH=${HG_REVDATA[1]}
146 ottxor 1.20 einfo "Work directory: ${sourcedir} global id: ${HG_REV_ID} (was ${EHG_REVISION} branch: ${HG_REV_BRANCH}"
147     }
148    
149     # @FUNCTION: mercurial_bootstrap
150     # @INTERNAL
151     # @DESCRIPTION:
152     # Internal function that runs bootstrap command on unpacked source.
153     mercurial_bootstrap() {
154     debug-print-function ${FUNCNAME} "$@"
155    
156     # @ECLASS-VARIABLE: EHG_BOOTSTRAP
157     # @DESCRIPTION:
158     # Command to be executed after checkout and clone of the specified
159     # repository.
160     if [[ ${EHG_BOOTSTRAP} ]]; then
161     pushd "${S}" > /dev/null
162     einfo "Starting bootstrap"
163    
164     if [[ -f ${EHG_BOOTSTRAP} ]]; then
165     # we have file in the repo which we should execute
166     debug-print "${FUNCNAME}: bootstraping with file \"${EHG_BOOTSTRAP}\""
167    
168     if [[ -x ${EHG_BOOTSTRAP} ]]; then
169     eval "./${EHG_BOOTSTRAP}" \
170     || die "${FUNCNAME}: bootstrap script failed"
171     else
172     eerror "\"${EHG_BOOTSTRAP}\" is not executable."
173     eerror "Report upstream, or bug ebuild maintainer to remove bootstrap command."
174     die "\"${EHG_BOOTSTRAP}\" is not executable"
175     fi
176     else
177     # we execute some system command
178     debug-print "${FUNCNAME}: bootstraping with commands \"${EHG_BOOTSTRAP}\""
179    
180     eval "${EHG_BOOTSTRAP}" \
181     || die "${FUNCNAME}: bootstrap commands failed"
182     fi
183    
184     einfo "Bootstrap finished"
185     popd > /dev/null
186     fi
187 agriffis 1.1 }
188    
189 nelchael 1.5 # @FUNCTION: mercurial_src_unpack
190     # @DESCRIPTION:
191     # The mercurial src_unpack function, which will be exported.
192 agriffis 1.1 function mercurial_src_unpack {
193 ottxor 1.20 debug-print-function ${FUNCNAME} "$@"
194    
195 agriffis 1.1 mercurial_fetch
196 ottxor 1.20 mercurial_bootstrap
197 agriffis 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.20