kde-plasma/breeze-gtk: x86 stable wrt bug #613144
[gentoo.git] / eclass / mercurial.eclass
1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: mercurial.eclass
5 # @MAINTAINER:
6 # Christoph Junghans <junghans@gentoo.org>
7 # Dirkjan Ochtman <djc@gentoo.org>
8 # @AUTHOR:
9 # Next gen author: Krzysztof Pawlik <nelchael@gentoo.org>
10 # Original author: Aron Griffis <agriffis@gentoo.org>
11 # @BLURB: This eclass provides generic mercurial fetching functions
12 # @DESCRIPTION:
13 # This eclass provides generic mercurial fetching functions. To fetch sources
14 # from mercurial repository just set EHG_REPO_URI to correct repository URI. If
15 # you need to share single repository between several ebuilds set EHG_PROJECT to
16 # project name in all of them.
17
18 inherit eutils
19
20 EXPORT_FUNCTIONS src_unpack
21
22 DEPEND="dev-vcs/mercurial"
23
24 # @ECLASS-VARIABLE: EHG_REPO_URI
25 # @DESCRIPTION:
26 # Mercurial repository URI.
27
28 # @ECLASS-VARIABLE: EHG_REVISION
29 # @DESCRIPTION:
30 # Create working directory for specified revision, defaults to default.
31 #
32 # EHG_REVISION is passed as a value for --updaterev parameter, so it can be more
33 # than just a revision, please consult `hg help revisions' for more details.
34 : ${EHG_REVISION:="default"}
35
36 # @ECLASS-VARIABLE: EHG_STORE_DIR
37 # @DESCRIPTION:
38 # Mercurial sources store directory. Users may override this in /etc/portage/make.conf
39 [[ -z "${EHG_STORE_DIR}" ]] && EHG_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/hg-src"
40
41 # @ECLASS-VARIABLE: EHG_PROJECT
42 # @DESCRIPTION:
43 # Project name.
44 #
45 # This variable default to $PN, but can be changed to allow repository sharing
46 # between several ebuilds.
47 [[ -z "${EHG_PROJECT}" ]] && EHG_PROJECT="${PN}"
48
49 # @ECLASS-VARIABLE: EGIT_CHECKOUT_DIR
50 # @DESCRIPTION:
51 # The directory to check the hg sources out to.
52 #
53 # EHG_CHECKOUT_DIR=${S}
54
55 # @ECLASS-VARIABLE: EHG_QUIET
56 # @DESCRIPTION:
57 # Suppress some extra noise from mercurial, set it to 'ON' to be quiet.
58 : ${EHG_QUIET:="OFF"}
59 [[ "${EHG_QUIET}" == "ON" ]] && EHG_QUIET_CMD_OPT="--quiet"
60
61 # @ECLASS-VARIABLE: EHG_CLONE_CMD
62 # @DESCRIPTION:
63 # Command used to perform initial repository clone.
64 [[ -z "${EHG_CLONE_CMD}" ]] && EHG_CLONE_CMD="hg clone ${EHG_QUIET_CMD_OPT} --pull --noupdate"
65
66 # @ECLASS-VARIABLE: EHG_PULL_CMD
67 # @DESCRIPTION:
68 # Command used to update repository.
69 [[ -z "${EHG_PULL_CMD}" ]] && EHG_PULL_CMD="hg pull ${EHG_QUIET_CMD_OPT}"
70
71 # @ECLASS-VARIABLE: EHG_OFFLINE
72 # @DESCRIPTION:
73 # Set this variable to a non-empty value to disable the automatic updating of
74 # a mercurial source tree. This is intended to be set outside the ebuild by
75 # users.
76 EHG_OFFLINE="${EHG_OFFLINE:-${EVCS_OFFLINE}}"
77
78 # @FUNCTION: mercurial_fetch
79 # @USAGE: [repository_uri] [module] [sourcedir]
80 # @DESCRIPTION:
81 # Clone or update repository.
82 #
83 # If repository URI is not passed it defaults to EHG_REPO_URI, if module is
84 # empty it defaults to basename of EHG_REPO_URI, sourcedir defaults to
85 # EHG_CHECKOUT_DIR, which defaults to S.
86
87 mercurial_fetch() {
88         debug-print-function ${FUNCNAME} "${@}"
89
90         has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
91
92         EHG_REPO_URI=${1-${EHG_REPO_URI}}
93         [[ -z "${EHG_REPO_URI}" ]] && die "EHG_REPO_URI is empty"
94
95         local module="${2-$(basename "${EHG_REPO_URI}")}"
96         local sourcedir="${3:-${EHG_CHECKOUT_DIR:-${S}}}"
97
98         # Should be set but blank to prevent using $HOME/.hgrc
99         export HGRCPATH=
100
101         # Check ${EHG_STORE_DIR} directory:
102         addwrite "$(dirname "${EHG_STORE_DIR}")" || die "addwrite failed"
103         if [[ ! -d "${EHG_STORE_DIR}" ]]; then
104                 mkdir -p "${EHG_STORE_DIR}" || die "failed to create ${EHG_STORE_DIR}"
105                 chmod -f g+rw "${EHG_STORE_DIR}" || \
106                         die "failed to chown ${EHG_STORE_DIR}"
107         fi
108
109         # Create project directory:
110         mkdir -p "${EHG_STORE_DIR}/${EHG_PROJECT}" || \
111                 die "failed to create ${EHG_STORE_DIR}/${EHG_PROJECT}"
112         chmod -f g+rw "${EHG_STORE_DIR}/${EHG_PROJECT}" || \
113                 echo "Warning: failed to chmod g+rw ${EHG_PROJECT}"
114         pushd "${EHG_STORE_DIR}/${EHG_PROJECT}" > /dev/null || \
115                 die "failed to cd to ${EHG_STORE_DIR}/${EHG_PROJECT}"
116
117         # Clone/update repository:
118         if [[ ! -d "${module}" ]]; then
119                 einfo "Cloning ${EHG_REPO_URI} to ${EHG_STORE_DIR}/${EHG_PROJECT}/${module}"
120                 ${EHG_CLONE_CMD} "${EHG_REPO_URI}" "${module}" || {
121                         rm -rf "${module}"
122                         die "failed to clone ${EHG_REPO_URI}"
123                 }
124         elif [[ -z "${EHG_OFFLINE}" ]]; then
125                 einfo "Updating ${EHG_STORE_DIR}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}"
126                 pushd "${module}" > /dev/null || die "failed to cd to ${module}"
127                 ${EHG_PULL_CMD} "${EHG_REPO_URI}" || die "update failed"
128                 popd > /dev/null || die
129         fi
130         popd > /dev/null || die
131
132         # Checkout working copy:
133         einfo "Creating working directory in ${sourcedir} (target revision: ${EHG_REVISION})"
134         mkdir -p "${sourcedir}" || die "failed to create ${sourcedir}"
135         hg clone \
136                 ${EHG_QUIET_CMD_OPT} \
137                 --updaterev="${EHG_REVISION}" \
138                 "${EHG_STORE_DIR}/${EHG_PROJECT}/${module}" \
139                 "${sourcedir}" || die "hg clone failed"
140         # An exact revision helps a lot for testing purposes, so have some output...
141         # id           num  branch
142         # fd6e32d61721 6276 default
143         local HG_REVDATA=($(hg identify -b -i "${sourcedir}"))
144         export HG_REV_ID=${HG_REVDATA[0]}
145         local HG_REV_BRANCH=${HG_REVDATA[1]}
146         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 }
188
189 # @FUNCTION: mercurial_src_unpack
190 # @DESCRIPTION:
191 # The mercurial src_unpack function, which will be exported.
192 function mercurial_src_unpack {
193         debug-print-function ${FUNCNAME} "$@"
194
195         mercurial_fetch
196         mercurial_bootstrap
197 }