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