| 1 | # Copyright 1999-2006 Gentoo Foundation |
1 | # Copyright 1999-2006 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.10 2010/01/17 12:03:48 nelchael Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/mercurial.eclass,v 1.13 2010/08/24 16:49:18 robbat2 Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: mercurial.eclass |
5 | # @ECLASS: mercurial.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # nelchael@gentoo.org |
7 | # Krzysztof Pawlik <nelchael@gentoo.org> |
|
|
8 | # Dirkjan Ochtman <djc@gentoo.org> |
| 8 | # @BLURB: This eclass provides generic mercurial fetching functions |
9 | # @BLURB: This eclass provides generic mercurial fetching functions |
| 9 | # @DESCRIPTION: |
10 | # @DESCRIPTION: |
| 10 | # This eclass provides generic mercurial fetching functions. To fetch sources |
11 | # This eclass provides generic mercurial fetching functions. To fetch sources |
| 11 | # from mercurial repository just set EHG_REPO_URI to correct repository URI. If |
12 | # from mercurial repository just set EHG_REPO_URI to correct repository URI. If |
| 12 | # you need to share single repository between several ebuilds set EHG_PROJECT to |
13 | # you need to share single repository between several ebuilds set EHG_PROJECT to |
| … | |
… | |
| 14 | |
15 | |
| 15 | inherit eutils |
16 | inherit eutils |
| 16 | |
17 | |
| 17 | EXPORT_FUNCTIONS src_unpack |
18 | EXPORT_FUNCTIONS src_unpack |
| 18 | |
19 | |
| 19 | DEPEND="dev-util/mercurial" |
20 | DEPEND="dev-vcs/mercurial" |
| 20 | |
21 | |
| 21 | # @ECLASS-VARIABLE: EHG_REPO_URI |
22 | # @ECLASS-VARIABLE: EHG_REPO_URI |
| 22 | # @DESCRIPTION: |
23 | # @DESCRIPTION: |
| 23 | # Mercurial repository URI. |
24 | # Mercurial repository URI. |
| 24 | |
25 | |
| … | |
… | |
| 27 | # Create working directory for specified revision, defaults to tip. |
28 | # Create working directory for specified revision, defaults to tip. |
| 28 | # |
29 | # |
| 29 | # EHG_REVISION is passed as a value for --rev parameter, so it can be more than |
30 | # EHG_REVISION is passed as a value for --rev parameter, so it can be more than |
| 30 | # just a revision, please consult `hg help revisions' for more details. |
31 | # just a revision, please consult `hg help revisions' for more details. |
| 31 | [[ -z "${EHG_REVISION}" ]] && EHG_REVISION="tip" |
32 | [[ -z "${EHG_REVISION}" ]] && EHG_REVISION="tip" |
|
|
33 | |
|
|
34 | # @ECLASS-VARIABLE: EHG_STORE_DIR |
|
|
35 | # @DESCRIPTION: |
|
|
36 | # 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" |
| 32 | |
38 | |
| 33 | # @ECLASS-VARIABLE: EHG_PROJECT |
39 | # @ECLASS-VARIABLE: EHG_PROJECT |
| 34 | # @DESCRIPTION: |
40 | # @DESCRIPTION: |
| 35 | # Project name. |
41 | # Project name. |
| 36 | # |
42 | # |
| … | |
… | |
| 72 | debug-print-function ${FUNCNAME} ${*} |
78 | debug-print-function ${FUNCNAME} ${*} |
| 73 | |
79 | |
| 74 | EHG_REPO_URI=${1-${EHG_REPO_URI}} |
80 | EHG_REPO_URI=${1-${EHG_REPO_URI}} |
| 75 | [[ -z "${EHG_REPO_URI}" ]] && die "EHG_REPO_URI is empty" |
81 | [[ -z "${EHG_REPO_URI}" ]] && die "EHG_REPO_URI is empty" |
| 76 | |
82 | |
| 77 | local hg_src_dir="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/hg-src" |
|
|
| 78 | local module="${2-$(basename "${EHG_REPO_URI}")}" |
83 | local module="${2-$(basename "${EHG_REPO_URI}")}" |
| 79 | |
84 | |
| 80 | # Should be set but blank to prevent using $HOME/.hgrc |
85 | # Should be set but blank to prevent using $HOME/.hgrc |
| 81 | export HGRCPATH= |
86 | export HGRCPATH= |
| 82 | |
87 | |
| 83 | # Check ${hg_src_dir} directory: |
88 | # Check ${EHG_STORE_DIR} directory: |
| 84 | addwrite "$(dirname "${hg_src_dir}")" || die "addwrite failed" |
89 | addwrite "$(dirname "${EHG_STORE_DIR}")" || die "addwrite failed" |
| 85 | if [[ ! -d "${hg_src_dir}" ]]; then |
90 | if [[ ! -d "${EHG_STORE_DIR}" ]]; then |
| 86 | mkdir -p "${hg_src_dir}" || die "failed to create ${hg_src_dir}" |
91 | mkdir -p "${EHG_STORE_DIR}" || die "failed to create ${EHG_STORE_DIR}" |
| 87 | chmod -f g+rw "${hg_src_dir}" || \ |
92 | chmod -f g+rw "${EHG_STORE_DIR}" || \ |
| 88 | die "failed to chown ${hg_src_dir}" |
93 | die "failed to chown ${EHG_STORE_DIR}" |
| 89 | fi |
94 | fi |
| 90 | |
95 | |
| 91 | # Create project directory: |
96 | # Create project directory: |
| 92 | mkdir -p "${hg_src_dir}/${EHG_PROJECT}" || \ |
97 | mkdir -p "${EHG_STORE_DIR}/${EHG_PROJECT}" || \ |
| 93 | die "failed to create ${hg_src_dir}/${EHG_PROJECT}" |
98 | die "failed to create ${EHG_STORE_DIR}/${EHG_PROJECT}" |
| 94 | chmod -f g+rw "${hg_src_dir}/${EHG_PROJECT}" || \ |
99 | chmod -f g+rw "${EHG_STORE_DIR}/${EHG_PROJECT}" || \ |
| 95 | echo "Warning: failed to chmod g+rw ${EHG_PROJECT}" |
100 | echo "Warning: failed to chmod g+rw ${EHG_PROJECT}" |
| 96 | cd "${hg_src_dir}/${EHG_PROJECT}" || \ |
101 | cd "${EHG_STORE_DIR}/${EHG_PROJECT}" || \ |
| 97 | die "failed to cd to ${hg_src_dir}/${EHG_PROJECT}" |
102 | die "failed to cd to ${EHG_STORE_DIR}/${EHG_PROJECT}" |
| 98 | |
103 | |
| 99 | # Clone/update repository: |
104 | # Clone/update repository: |
| 100 | if [[ ! -d "${module}" ]]; then |
105 | if [[ ! -d "${module}" ]]; then |
| 101 | einfo "Cloning ${EHG_REPO_URI} to ${hg_src_dir}/${EHG_PROJECT}/${module}" |
106 | einfo "Cloning ${EHG_REPO_URI} to ${EHG_STORE_DIR}/${EHG_PROJECT}/${module}" |
| 102 | ${EHG_CLONE_CMD} "${EHG_REPO_URI}" "${module}" || { |
107 | ${EHG_CLONE_CMD} "${EHG_REPO_URI}" "${module}" || { |
| 103 | rm -rf "${module}" |
108 | rm -rf "${module}" |
| 104 | die "failed to clone ${EHG_REPO_URI}" |
109 | die "failed to clone ${EHG_REPO_URI}" |
| 105 | } |
110 | } |
| 106 | cd "${module}" |
111 | cd "${module}" |
| 107 | elif [[ -z "${EHG_OFFLINE}" ]]; then |
112 | elif [[ -z "${EHG_OFFLINE}" ]]; then |
| 108 | einfo "Updating ${hg_src_dir}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}" |
113 | einfo "Updating ${EHG_STORE_DIR}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}" |
| 109 | cd "${module}" || die "failed to cd to ${module}" |
114 | cd "${module}" || die "failed to cd to ${module}" |
| 110 | ${EHG_PULL_CMD} || die "update failed" |
115 | ${EHG_PULL_CMD} || die "update failed" |
| 111 | fi |
116 | fi |
| 112 | |
117 | |
| 113 | # Checkout working copy: |
118 | # Checkout working copy: |
| 114 | einfo "Creating working directory in ${WORKDIR}/${module} (revision: ${EHG_REVISION})" |
119 | einfo "Creating working directory in ${WORKDIR}/${module} (target revision: ${EHG_REVISION})" |
| 115 | hg clone \ |
120 | hg clone \ |
| 116 | ${EHG_QUIET_CMD_OPT} \ |
121 | ${EHG_QUIET_CMD_OPT} \ |
| 117 | --rev="${EHG_REVISION}" \ |
122 | --rev="${EHG_REVISION}" \ |
| 118 | "${hg_src_dir}/${EHG_PROJECT}/${module}" \ |
123 | "${EHG_STORE_DIR}/${EHG_PROJECT}/${module}" \ |
| 119 | "${WORKDIR}/${module}" || die "hg clone failed" |
124 | "${WORKDIR}/${module}" || die "hg clone failed" |
|
|
125 | # An exact revision helps a lot for testing purposes, so have some output... |
|
|
126 | # id num branch |
|
|
127 | # fd6e32d61721 6276 default |
|
|
128 | local HG_REVDATA=($(hg identify -b -i "${WORKDIR}/${module}")) |
|
|
129 | local HG_REV_ID=${HG_REVDATA[0]} |
|
|
130 | local HG_REV_BRANCH=${HG_REVDATA[1]} |
|
|
131 | einfo "Work directory: ${WORKDIR}/${module} global id: ${HG_REV_ID} branch: ${HG_REV_BRANCH}" |
| 120 | } |
132 | } |
| 121 | |
133 | |
| 122 | # @FUNCTION: mercurial_src_unpack |
134 | # @FUNCTION: mercurial_src_unpack |
| 123 | # @DESCRIPTION: |
135 | # @DESCRIPTION: |
| 124 | # The mercurial src_unpack function, which will be exported. |
136 | # The mercurial src_unpack function, which will be exported. |