| 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.8 2009/12/11 21:02:29 robbat2 Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/mercurial.eclass,v 1.15 2010/11/17 18:42:03 nelchael 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 | |
| 25 | # @ECLASS-VARIABLE: EHG_REVISION |
26 | # @ECLASS-VARIABLE: EHG_REVISION |
| 26 | # @DESCRIPTION: |
27 | # @DESCRIPTION: |
| 27 | # Create working directory for specified revision, defaults to tip. |
28 | # Create working directory for specified revision, defaults to tip. |
|
|
29 | # |
|
|
30 | # EHG_REVISION is passed as a value for --rev parameter, so it can be more than |
|
|
31 | # just a revision, please consult `hg help revisions' for more details. |
| 28 | [[ -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" |
| 29 | |
38 | |
| 30 | # @ECLASS-VARIABLE: EHG_PROJECT |
39 | # @ECLASS-VARIABLE: EHG_PROJECT |
| 31 | # @DESCRIPTION: |
40 | # @DESCRIPTION: |
| 32 | # Project name. |
41 | # Project name. |
| 33 | # |
42 | # |
| … | |
… | |
| 57 | # a mercurial source tree. This is intended to be set outside the ebuild by |
66 | # a mercurial source tree. This is intended to be set outside the ebuild by |
| 58 | # users. |
67 | # users. |
| 59 | EHG_OFFLINE="${EHG_OFFLINE:-${ESCM_OFFLINE}}" |
68 | EHG_OFFLINE="${EHG_OFFLINE:-${ESCM_OFFLINE}}" |
| 60 | |
69 | |
| 61 | # @FUNCTION: mercurial_fetch |
70 | # @FUNCTION: mercurial_fetch |
| 62 | # @USAGE: [repository_uri] [module] |
71 | # @USAGE: [repository_uri] [module] [sourcedir] |
| 63 | # @DESCRIPTION: |
72 | # @DESCRIPTION: |
| 64 | # Clone or update repository. |
73 | # Clone or update repository. |
| 65 | # |
74 | # |
| 66 | # If not repository URI is passed it defaults to EHG_REPO_URI, if module is |
75 | # If repository URI is not passed it defaults to EHG_REPO_URI, if module is |
| 67 | # empty it defaults to basename of EHG_REPO_URI. |
76 | # empty it defaults to basename of EHG_REPO_URI, sourcedir defaults to S. |
| 68 | function mercurial_fetch { |
77 | function mercurial_fetch { |
| 69 | debug-print-function ${FUNCNAME} ${*} |
78 | debug-print-function ${FUNCNAME} ${*} |
| 70 | |
79 | |
| 71 | EHG_REPO_URI=${1-${EHG_REPO_URI}} |
80 | EHG_REPO_URI=${1-${EHG_REPO_URI}} |
| 72 | [[ -z "${EHG_REPO_URI}" ]] && die "EHG_REPO_URI is empty" |
81 | [[ -z "${EHG_REPO_URI}" ]] && die "EHG_REPO_URI is empty" |
| 73 | |
82 | |
| 74 | local hg_src_dir="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/hg-src" |
|
|
| 75 | local module="${2-$(basename "${EHG_REPO_URI}")}" |
83 | local module="${2-$(basename "${EHG_REPO_URI}")}" |
|
|
84 | local sourcedir="${3-${S}}" |
| 76 | |
85 | |
| 77 | # Should be set but blank to prevent using $HOME/.hgrc |
86 | # Should be set but blank to prevent using $HOME/.hgrc |
| 78 | export HGRCPATH= |
87 | export HGRCPATH= |
| 79 | |
88 | |
| 80 | # Check ${hg_src_dir} directory: |
89 | # Check ${EHG_STORE_DIR} directory: |
| 81 | addwrite "$(dirname "${hg_src_dir}")" || die "addwrite failed" |
90 | addwrite "$(dirname "${EHG_STORE_DIR}")" || die "addwrite failed" |
| 82 | if [[ ! -d "${hg_src_dir}" ]]; then |
91 | if [[ ! -d "${EHG_STORE_DIR}" ]]; then |
| 83 | mkdir -p "${hg_src_dir}" || die "failed to create ${hg_src_dir}" |
92 | mkdir -p "${EHG_STORE_DIR}" || die "failed to create ${EHG_STORE_DIR}" |
| 84 | chmod -f g+rw "${hg_src_dir}" || \ |
93 | chmod -f g+rw "${EHG_STORE_DIR}" || \ |
| 85 | die "failed to chown ${hg_src_dir}" |
94 | die "failed to chown ${EHG_STORE_DIR}" |
| 86 | fi |
95 | fi |
| 87 | |
96 | |
| 88 | # Create project directory: |
97 | # Create project directory: |
| 89 | mkdir -p "${hg_src_dir}/${EHG_PROJECT}" || \ |
98 | mkdir -p "${EHG_STORE_DIR}/${EHG_PROJECT}" || \ |
| 90 | die "failed to create ${hg_src_dir}/${EHG_PROJECT}" |
99 | die "failed to create ${EHG_STORE_DIR}/${EHG_PROJECT}" |
| 91 | chmod -f g+rw "${hg_src_dir}/${EHG_PROJECT}" || \ |
100 | chmod -f g+rw "${EHG_STORE_DIR}/${EHG_PROJECT}" || \ |
| 92 | die "failed to chwon ${EHG_PROJECT}" |
101 | echo "Warning: failed to chmod g+rw ${EHG_PROJECT}" |
| 93 | cd "${hg_src_dir}/${EHG_PROJECT}" || \ |
102 | cd "${EHG_STORE_DIR}/${EHG_PROJECT}" || \ |
| 94 | die "failed to cd to ${hg_src_dir}/${EHG_PROJECT}" |
103 | die "failed to cd to ${EHG_STORE_DIR}/${EHG_PROJECT}" |
| 95 | |
104 | |
| 96 | # Clone/update repository: |
105 | # Clone/update repository: |
| 97 | if [[ ! -d "${module}" ]]; then |
106 | if [[ ! -d "${module}" ]]; then |
| 98 | einfo "Cloning ${EHG_REPO_URI} to ${hg_src_dir}/${EHG_PROJECT}/${module}" |
107 | einfo "Cloning ${EHG_REPO_URI} to ${EHG_STORE_DIR}/${EHG_PROJECT}/${module}" |
| 99 | ${EHG_CLONE_CMD} "${EHG_REPO_URI}" "${module}" || { |
108 | ${EHG_CLONE_CMD} "${EHG_REPO_URI}" "${module}" || { |
| 100 | rm -rf "${module}" |
109 | rm -rf "${module}" |
| 101 | die "failed to clone ${EHG_REPO_URI}" |
110 | die "failed to clone ${EHG_REPO_URI}" |
| 102 | } |
111 | } |
| 103 | cd "${module}" |
112 | cd "${module}" |
| 104 | elif [[ -z "${EHG_OFFLINE}" ]]; then |
113 | elif [[ -z "${EHG_OFFLINE}" ]]; then |
| 105 | einfo "Updating ${hg_src_dir}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}" |
114 | einfo "Updating ${EHG_STORE_DIR}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}" |
| 106 | cd "${module}" || die "failed to cd to ${module}" |
115 | cd "${module}" || die "failed to cd to ${module}" |
| 107 | ${EHG_PULL_CMD} || die "update failed" |
116 | ${EHG_PULL_CMD} || die "update failed" |
| 108 | fi |
117 | fi |
| 109 | |
118 | |
| 110 | # Checkout working copy: |
119 | # Checkout working copy: |
| 111 | einfo "Creating working directory in ${WORKDIR}/${module} (revision: ${EHG_REVISION})" |
120 | einfo "Creating working directory in ${sourcedir} (target revision: ${EHG_REVISION})" |
| 112 | hg clone \ |
121 | hg clone \ |
| 113 | ${EHG_QUIET_CMD_OPT} \ |
122 | ${EHG_QUIET_CMD_OPT} \ |
| 114 | --rev="${EHG_REVISION}" \ |
123 | --rev="${EHG_REVISION}" \ |
| 115 | "${hg_src_dir}/${EHG_PROJECT}/${module}" \ |
124 | "${EHG_STORE_DIR}/${EHG_PROJECT}/${module}" \ |
| 116 | "${WORKDIR}/${module}" || die "hg clone failed" |
125 | "${sourcedir}" || die "hg clone failed" |
|
|
126 | # An exact revision helps a lot for testing purposes, so have some output... |
|
|
127 | # id num branch |
|
|
128 | # fd6e32d61721 6276 default |
|
|
129 | local HG_REVDATA=($(hg identify -b -i "${sourcedir}")) |
|
|
130 | export HG_REV_ID=${HG_REVDATA[0]} |
|
|
131 | local HG_REV_BRANCH=${HG_REVDATA[1]} |
|
|
132 | einfo "Work directory: ${sourcedir} global id: ${HG_REV_ID} branch: ${HG_REV_BRANCH}" |
| 117 | } |
133 | } |
| 118 | |
134 | |
| 119 | # @FUNCTION: mercurial_src_unpack |
135 | # @FUNCTION: mercurial_src_unpack |
| 120 | # @DESCRIPTION: |
136 | # @DESCRIPTION: |
| 121 | # The mercurial src_unpack function, which will be exported. |
137 | # The mercurial src_unpack function, which will be exported. |