| 1 | # Copyright 1999-2012 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.19 2012/04/03 19:16:29 nelchael Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/mercurial.eclass,v 1.20 2012/12/26 23:08:53 ottxor Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: mercurial.eclass |
5 | # @ECLASS: mercurial.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # Krzysztof Pawlik <nelchael@gentoo.org> |
7 | # Christoph Junghans <ottxor@gentoo.org> |
| 8 | # Dirkjan Ochtman <djc@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> |
| 9 | # @BLURB: This eclass provides generic mercurial fetching functions |
12 | # @BLURB: This eclass provides generic mercurial fetching functions |
| 10 | # @DESCRIPTION: |
13 | # @DESCRIPTION: |
| 11 | # This eclass provides generic mercurial fetching functions. To fetch sources |
14 | # This eclass provides generic mercurial fetching functions. To fetch sources |
| 12 | # from mercurial repository just set EHG_REPO_URI to correct repository URI. If |
15 | # from mercurial repository just set EHG_REPO_URI to correct repository URI. If |
| 13 | # you need to share single repository between several ebuilds set EHG_PROJECT to |
16 | # you need to share single repository between several ebuilds set EHG_PROJECT to |
| … | |
… | |
| 27 | # @DESCRIPTION: |
30 | # @DESCRIPTION: |
| 28 | # Create working directory for specified revision, defaults to tip. |
31 | # Create working directory for specified revision, defaults to tip. |
| 29 | # |
32 | # |
| 30 | # EHG_REVISION is passed as a value for --updaterev parameter, so it can be more |
33 | # EHG_REVISION is passed as a value for --updaterev parameter, so it can be more |
| 31 | # than just a revision, please consult `hg help revisions' for more details. |
34 | # than just a revision, please consult `hg help revisions' for more details. |
| 32 | [[ -z "${EHG_REVISION}" ]] && EHG_REVISION="tip" |
35 | : ${EHG_REVISION:="default"} |
| 33 | |
36 | |
| 34 | # @ECLASS-VARIABLE: EHG_STORE_DIR |
37 | # @ECLASS-VARIABLE: EHG_STORE_DIR |
| 35 | # @DESCRIPTION: |
38 | # @DESCRIPTION: |
| 36 | # Mercurial sources store directory. Users may override this in /etc/make.conf |
39 | # Mercurial sources store directory. Users may override this in /etc/make.conf |
| 37 | [[ -z "${EHG_STORE_DIR}" ]] && EHG_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/hg-src" |
40 | [[ -z "${EHG_STORE_DIR}" ]] && EHG_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/hg-src" |
| … | |
… | |
| 72 | # @DESCRIPTION: |
75 | # @DESCRIPTION: |
| 73 | # Clone or update repository. |
76 | # Clone or update repository. |
| 74 | # |
77 | # |
| 75 | # If repository URI is not passed it defaults to EHG_REPO_URI, if module is |
78 | # If repository URI is not passed it defaults to EHG_REPO_URI, if module is |
| 76 | # empty it defaults to basename of EHG_REPO_URI, sourcedir defaults to S. |
79 | # empty it defaults to basename of EHG_REPO_URI, sourcedir defaults to S. |
| 77 | function mercurial_fetch { |
80 | mercurial_fetch() { |
| 78 | debug-print-function ${FUNCNAME} ${*} |
81 | debug-print-function ${FUNCNAME} "${@}" |
|
|
82 | |
|
|
83 | has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX= |
| 79 | |
84 | |
| 80 | EHG_REPO_URI=${1-${EHG_REPO_URI}} |
85 | EHG_REPO_URI=${1-${EHG_REPO_URI}} |
| 81 | [[ -z "${EHG_REPO_URI}" ]] && die "EHG_REPO_URI is empty" |
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" ) |
| 82 | |
91 | |
| 83 | local module="${2-$(basename "${EHG_REPO_URI}")}" |
92 | local module="${2-$(basename "${EHG_REPO_URI}")}" |
| 84 | local sourcedir="${3-${S}}" |
93 | local sourcedir="${3-${S}}" |
| 85 | |
94 | |
| 86 | # Should be set but blank to prevent using $HOME/.hgrc |
95 | # Should be set but blank to prevent using $HOME/.hgrc |
| … | |
… | |
| 103 | die "failed to cd to ${EHG_STORE_DIR}/${EHG_PROJECT}" |
112 | die "failed to cd to ${EHG_STORE_DIR}/${EHG_PROJECT}" |
| 104 | |
113 | |
| 105 | # Clone/update repository: |
114 | # Clone/update repository: |
| 106 | if [[ ! -d "${module}" ]]; then |
115 | if [[ ! -d "${module}" ]]; then |
| 107 | einfo "Cloning ${EHG_REPO_URI} to ${EHG_STORE_DIR}/${EHG_PROJECT}/${module}" |
116 | einfo "Cloning ${EHG_REPO_URI} to ${EHG_STORE_DIR}/${EHG_PROJECT}/${module}" |
| 108 | ${EHG_CLONE_CMD} "${EHG_REPO_URI}" "${module}" || { |
117 | ${EHG_CLONE_CMD} "${cert_opt[@]}" "${EHG_REPO_URI}" "${module}" || { |
| 109 | rm -rf "${module}" |
118 | rm -rf "${module}" |
| 110 | die "failed to clone ${EHG_REPO_URI}" |
119 | die "failed to clone ${EHG_REPO_URI}" |
| 111 | } |
120 | } |
| 112 | cd "${module}" |
121 | cd "${module}" |
| 113 | elif [[ -z "${EHG_OFFLINE}" ]]; then |
122 | elif [[ -z "${EHG_OFFLINE}" ]]; then |
| 114 | einfo "Updating ${EHG_STORE_DIR}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}" |
123 | einfo "Updating ${EHG_STORE_DIR}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}" |
| 115 | cd "${module}" || die "failed to cd to ${module}" |
124 | cd "${module}" || die "failed to cd to ${module}" |
| 116 | ${EHG_PULL_CMD} |
125 | ${EHG_PULL_CMD} "${cert_opt[@]}" "${EHG_REPO_URI}" || die "update failed" |
| 117 | # mercurial-2.1: hg pull returns 1 if there are no incoming changesets |
|
|
| 118 | [[ $? -eq 0 || $? -eq 1 ]] || die "update failed" |
|
|
| 119 | fi |
126 | fi |
| 120 | |
127 | |
| 121 | # Checkout working copy: |
128 | # Checkout working copy: |
| 122 | einfo "Creating working directory in ${sourcedir} (target revision: ${EHG_REVISION})" |
129 | einfo "Creating working directory in ${sourcedir} (target revision: ${EHG_REVISION})" |
| 123 | hg clone \ |
130 | hg clone \ |
| … | |
… | |
| 129 | # id num branch |
136 | # id num branch |
| 130 | # fd6e32d61721 6276 default |
137 | # fd6e32d61721 6276 default |
| 131 | local HG_REVDATA=($(hg identify -b -i "${sourcedir}")) |
138 | local HG_REVDATA=($(hg identify -b -i "${sourcedir}")) |
| 132 | export HG_REV_ID=${HG_REVDATA[0]} |
139 | export HG_REV_ID=${HG_REVDATA[0]} |
| 133 | local HG_REV_BRANCH=${HG_REVDATA[1]} |
140 | local HG_REV_BRANCH=${HG_REVDATA[1]} |
| 134 | einfo "Work directory: ${sourcedir} global id: ${HG_REV_ID} branch: ${HG_REV_BRANCH}" |
141 | einfo "Work directory: ${sourcedir} global id: ${HG_REV_ID} (was ${EHG_REVISION} branch: ${HG_REV_BRANCH}" |
|
|
142 | } |
|
|
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 |
| 135 | } |
182 | } |
| 136 | |
183 | |
| 137 | # @FUNCTION: mercurial_src_unpack |
184 | # @FUNCTION: mercurial_src_unpack |
| 138 | # @DESCRIPTION: |
185 | # @DESCRIPTION: |
| 139 | # The mercurial src_unpack function, which will be exported. |
186 | # The mercurial src_unpack function, which will be exported. |
| 140 | function mercurial_src_unpack { |
187 | function mercurial_src_unpack { |
|
|
188 | debug-print-function ${FUNCNAME} "$@" |
|
|
189 | |
| 141 | mercurial_fetch |
190 | mercurial_fetch |
|
|
191 | mercurial_bootstrap |
| 142 | } |
192 | } |