| 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.1 2006/05/20 02:43:01 agriffis Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/mercurial.eclass,v 1.20 2012/12/26 23:08:53 ottxor Exp $ |
| 4 | |
4 | |
| 5 | # mercurial: Fetch sources from mercurial repositories, similar to cvs.eclass. |
5 | # @ECLASS: mercurial.eclass |
| 6 | # To use this from an ebuild, set EHG_REPO_URI in your ebuild. Then either |
6 | # @MAINTAINER: |
| 7 | # leave the default src_unpack or call mercurial_src_unpack. |
7 | # Christoph Junghans <ottxor@gentoo.org> |
|
|
8 | # Dirkjan Ochtman <djc@gentoo.org> |
|
|
9 | # @AUTHOR: |
|
|
10 | # Next gen author: Krzysztof Pawlik <nelchael@gentoo.org> |
|
|
11 | # Original author: Aron Griffis <agriffis@gentoo.org> |
|
|
12 | # @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. |
| 8 | |
18 | |
| 9 | inherit eutils |
19 | inherit eutils |
| 10 | |
20 | |
| 11 | EXPORT_FUNCTIONS src_unpack |
21 | EXPORT_FUNCTIONS src_unpack |
| 12 | |
22 | |
| 13 | DEPEND="dev-util/mercurial net-misc/rsync" |
23 | DEPEND="dev-vcs/mercurial" |
| 14 | EHG_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/hg-src" |
|
|
| 15 | |
24 | |
| 16 | # This must be set by the ebuild |
25 | # @ECLASS-VARIABLE: EHG_REPO_URI |
| 17 | : ${EHG_REPO_URI:=} # repository uri |
26 | # @DESCRIPTION: |
|
|
27 | # Mercurial repository URI. |
| 18 | |
28 | |
| 19 | # These can be set by the ebuild but are usually fine as-is |
29 | # @ECLASS-VARIABLE: EHG_REVISION |
| 20 | : ${EHG_CLONE_CMD:=hg clone} # clone cmd |
30 | # @DESCRIPTION: |
| 21 | : ${EHG_PULL_CMD:=hg pull -u} # pull cmd |
31 | # Create working directory for specified revision, defaults to tip. |
|
|
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"} |
| 22 | |
36 | |
| 23 | # should be set but blank to prevent using $HOME/.hgrc |
37 | # @ECLASS-VARIABLE: EHG_STORE_DIR |
| 24 | export HGRCPATH= |
38 | # @DESCRIPTION: |
|
|
39 | # Mercurial sources store directory. Users may override this in /etc/make.conf |
|
|
40 | [[ -z "${EHG_STORE_DIR}" ]] && EHG_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/hg-src" |
| 25 | |
41 | |
| 26 | function mercurial_fetch { |
42 | # @ECLASS-VARIABLE: EHG_PROJECT |
| 27 | declare repo=${1:-$EHG_REPO_URI} proj=${2:-${PN/-hg}} |
43 | # @DESCRIPTION: |
| 28 | repo=${repo%/} # remove trailing slash |
44 | # Project name. |
| 29 | [[ -n $repo ]] || die "EHG_REPO_URI is empty" |
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}" |
| 30 | |
49 | |
|
|
50 | # @ECLASS-VARIABLE: EHG_QUIET |
|
|
51 | # @DESCRIPTION: |
|
|
52 | # Suppress some extra noise from mercurial, set it to 'OFF' to be louder. |
|
|
53 | : ${EHG_QUIET:="ON"} |
|
|
54 | [[ "${EHG_QUIET}" == "ON" ]] && EHG_QUIET_CMD_OPT="--quiet" |
|
|
55 | |
|
|
56 | # @ECLASS-VARIABLE: EHG_CLONE_CMD |
|
|
57 | # @DESCRIPTION: |
|
|
58 | # Command used to perform initial repository clone. |
|
|
59 | [[ -z "${EHG_CLONE_CMD}" ]] && EHG_CLONE_CMD="hg clone ${EHG_QUIET_CMD_OPT} --pull --noupdate" |
|
|
60 | |
|
|
61 | # @ECLASS-VARIABLE: EHG_PULL_CMD |
|
|
62 | # @DESCRIPTION: |
|
|
63 | # Command used to update repository. |
|
|
64 | [[ -z "${EHG_PULL_CMD}" ]] && EHG_PULL_CMD="hg pull ${EHG_QUIET_CMD_OPT}" |
|
|
65 | |
|
|
66 | # @ECLASS-VARIABLE: EHG_OFFLINE |
|
|
67 | # @DESCRIPTION: |
|
|
68 | # Set this variable to a non-empty value to disable the automatic updating of |
|
|
69 | # a mercurial source tree. This is intended to be set outside the ebuild by |
|
|
70 | # users. |
|
|
71 | EHG_OFFLINE="${EHG_OFFLINE:-${EVCS_OFFLINE}}" |
|
|
72 | |
|
|
73 | # @FUNCTION: mercurial_fetch |
|
|
74 | # @USAGE: [repository_uri] [module] [sourcedir] |
|
|
75 | # @DESCRIPTION: |
|
|
76 | # Clone or update repository. |
|
|
77 | # |
|
|
78 | # If repository URI is not passed it defaults to EHG_REPO_URI, if module is |
|
|
79 | # empty it defaults to basename of EHG_REPO_URI, sourcedir defaults to S. |
|
|
80 | mercurial_fetch() { |
|
|
81 | debug-print-function ${FUNCNAME} "${@}" |
|
|
82 | |
|
|
83 | has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX= |
|
|
84 | |
|
|
85 | EHG_REPO_URI=${1-${EHG_REPO_URI}} |
|
|
86 | [[ -z "${EHG_REPO_URI}" ]] && die "EHG_REPO_URI is empty" |
|
|
87 | |
|
|
88 | local cert_opt= |
|
|
89 | [[ -f ${EPREFIX}/etc/ssl/certs/ca-certificates.crt ]] && \ |
|
|
90 | cert_opt=( --config "web.cacerts=${EPREFIX}/etc/ssl/certs/ca-certificates.crt" ) |
|
|
91 | |
|
|
92 | local module="${2-$(basename "${EHG_REPO_URI}")}" |
|
|
93 | local sourcedir="${3-${S}}" |
|
|
94 | |
|
|
95 | # Should be set but blank to prevent using $HOME/.hgrc |
|
|
96 | export HGRCPATH= |
|
|
97 | |
|
|
98 | # Check ${EHG_STORE_DIR} directory: |
|
|
99 | addwrite "$(dirname "${EHG_STORE_DIR}")" || die "addwrite failed" |
| 31 | if [[ ! -d ${EHG_STORE_DIR} ]]; then |
100 | if [[ ! -d "${EHG_STORE_DIR}" ]]; then |
| 32 | ebegin "create ${EHG_STORE_DIR}" |
101 | mkdir -p "${EHG_STORE_DIR}" || die "failed to create ${EHG_STORE_DIR}" |
| 33 | addwrite / && |
|
|
| 34 | mkdir -p "${EHG_STORE_DIR}" && |
|
|
| 35 | chmod -f o+rw "${EHG_STORE_DIR}" && |
102 | chmod -f g+rw "${EHG_STORE_DIR}" || \ |
| 36 | export SANDBOX_WRITE="${SANDBOX_WRITE%:/}" |
103 | die "failed to chown ${EHG_STORE_DIR}" |
| 37 | eend $? || die |
|
|
| 38 | fi |
104 | fi |
| 39 | |
105 | |
| 40 | cd "${EHG_STORE_DIR}" || die "can't chdir to ${EHG_STORE_DIR}" |
106 | # Create project directory: |
| 41 | addwrite "$(pwd -P)" |
107 | mkdir -p "${EHG_STORE_DIR}/${EHG_PROJECT}" || \ |
|
|
108 | die "failed to create ${EHG_STORE_DIR}/${EHG_PROJECT}" |
|
|
109 | chmod -f g+rw "${EHG_STORE_DIR}/${EHG_PROJECT}" || \ |
|
|
110 | echo "Warning: failed to chmod g+rw ${EHG_PROJECT}" |
|
|
111 | cd "${EHG_STORE_DIR}/${EHG_PROJECT}" || \ |
|
|
112 | die "failed to cd to ${EHG_STORE_DIR}/${EHG_PROJECT}" |
| 42 | |
113 | |
| 43 | if [[ ! -d ${proj}/${repo##*/} ]]; then |
114 | # Clone/update repository: |
| 44 | # first check out |
115 | if [[ ! -d "${module}" ]]; then |
| 45 | ebegin "${EHG_CLONE_CMD} ${repo}" |
116 | einfo "Cloning ${EHG_REPO_URI} to ${EHG_STORE_DIR}/${EHG_PROJECT}/${module}" |
| 46 | mkdir -p "${proj}" && |
117 | ${EHG_CLONE_CMD} "${cert_opt[@]}" "${EHG_REPO_URI}" "${module}" || { |
| 47 | chmod -f o+rw "${proj}" && |
118 | rm -rf "${module}" |
| 48 | cd "${proj}" && |
119 | die "failed to clone ${EHG_REPO_URI}" |
| 49 | ${EHG_CLONE_CMD} "${repo}" && |
120 | } |
| 50 | cd "${repo##*/}" |
121 | cd "${module}" |
| 51 | eend $? || die |
122 | elif [[ -z "${EHG_OFFLINE}" ]]; then |
| 52 | else |
123 | einfo "Updating ${EHG_STORE_DIR}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}" |
| 53 | # update working copy |
124 | cd "${module}" || die "failed to cd to ${module}" |
| 54 | ebegin "${EHG_PULL_CMD} ${repo}" |
125 | ${EHG_PULL_CMD} "${cert_opt[@]}" "${EHG_REPO_URI}" || die "update failed" |
| 55 | cd "${proj}/${repo##*/}" && |
|
|
| 56 | ${EHG_PULL_CMD} |
|
|
| 57 | eend $? || die |
|
|
| 58 | fi |
126 | fi |
| 59 | |
127 | |
| 60 | # use rsync instead of cp for --exclude |
128 | # Checkout working copy: |
| 61 | ebegin "rsync to ${S}" |
129 | einfo "Creating working directory in ${sourcedir} (target revision: ${EHG_REVISION})" |
| 62 | mkdir -p "${S}" && |
130 | hg clone \ |
| 63 | rsync -av --delete --exclude=.hg/ . "${S}" |
131 | ${EHG_QUIET_CMD_OPT} \ |
| 64 | eend $? || die |
132 | --updaterev="${EHG_REVISION}" \ |
|
|
133 | "${EHG_STORE_DIR}/${EHG_PROJECT}/${module}" \ |
|
|
134 | "${sourcedir}" || die "hg clone failed" |
|
|
135 | # An exact revision helps a lot for testing purposes, so have some output... |
|
|
136 | # id num branch |
|
|
137 | # fd6e32d61721 6276 default |
|
|
138 | local HG_REVDATA=($(hg identify -b -i "${sourcedir}")) |
|
|
139 | export HG_REV_ID=${HG_REVDATA[0]} |
|
|
140 | local HG_REV_BRANCH=${HG_REVDATA[1]} |
|
|
141 | einfo "Work directory: ${sourcedir} global id: ${HG_REV_ID} (was ${EHG_REVISION} branch: ${HG_REV_BRANCH}" |
| 65 | } |
142 | } |
| 66 | |
143 | |
|
|
144 | # @FUNCTION: mercurial_bootstrap |
|
|
145 | # @INTERNAL |
|
|
146 | # @DESCRIPTION: |
|
|
147 | # Internal function that runs bootstrap command on unpacked source. |
|
|
148 | mercurial_bootstrap() { |
|
|
149 | debug-print-function ${FUNCNAME} "$@" |
|
|
150 | |
|
|
151 | # @ECLASS-VARIABLE: EHG_BOOTSTRAP |
|
|
152 | # @DESCRIPTION: |
|
|
153 | # Command to be executed after checkout and clone of the specified |
|
|
154 | # repository. |
|
|
155 | if [[ ${EHG_BOOTSTRAP} ]]; then |
|
|
156 | pushd "${S}" > /dev/null |
|
|
157 | einfo "Starting bootstrap" |
|
|
158 | |
|
|
159 | if [[ -f ${EHG_BOOTSTRAP} ]]; then |
|
|
160 | # we have file in the repo which we should execute |
|
|
161 | debug-print "${FUNCNAME}: bootstraping with file \"${EHG_BOOTSTRAP}\"" |
|
|
162 | |
|
|
163 | if [[ -x ${EHG_BOOTSTRAP} ]]; then |
|
|
164 | eval "./${EHG_BOOTSTRAP}" \ |
|
|
165 | || die "${FUNCNAME}: bootstrap script failed" |
|
|
166 | else |
|
|
167 | eerror "\"${EHG_BOOTSTRAP}\" is not executable." |
|
|
168 | eerror "Report upstream, or bug ebuild maintainer to remove bootstrap command." |
|
|
169 | die "\"${EHG_BOOTSTRAP}\" is not executable" |
|
|
170 | fi |
|
|
171 | else |
|
|
172 | # we execute some system command |
|
|
173 | debug-print "${FUNCNAME}: bootstraping with commands \"${EHG_BOOTSTRAP}\"" |
|
|
174 | |
|
|
175 | eval "${EHG_BOOTSTRAP}" \ |
|
|
176 | || die "${FUNCNAME}: bootstrap commands failed" |
|
|
177 | fi |
|
|
178 | |
|
|
179 | einfo "Bootstrap finished" |
|
|
180 | popd > /dev/null |
|
|
181 | fi |
|
|
182 | } |
|
|
183 | |
|
|
184 | # @FUNCTION: mercurial_src_unpack |
|
|
185 | # @DESCRIPTION: |
|
|
186 | # The mercurial src_unpack function, which will be exported. |
| 67 | function mercurial_src_unpack { |
187 | function mercurial_src_unpack { |
|
|
188 | debug-print-function ${FUNCNAME} "$@" |
|
|
189 | |
| 68 | mercurial_fetch |
190 | mercurial_fetch |
|
|
191 | mercurial_bootstrap |
| 69 | } |
192 | } |