Lines 2-78
Link Here
|
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.4 2009/02/22 13:01:17 nelchael Exp $ |
3 |
# $Header: /var/cvsroot/gentoo-x86/eclass/mercurial.eclass,v 1.4 2009/02/22 13:01:17 nelchael 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 |
# nelchael@gentoo.org |
|
|
8 |
# @BLURB: This eclass provides generic mercurial fetching functions |
9 |
# @DESCRIPTION: |
10 |
# 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 |
# you need to share single repository between several ebuilds set EHG_PROJECT to |
13 |
# project name in all of them. |
8 |
|
14 |
|
9 |
inherit eutils |
15 |
inherit eutils |
10 |
|
16 |
|
11 |
EXPORT_FUNCTIONS src_unpack |
17 |
EXPORT_FUNCTIONS src_unpack |
12 |
|
18 |
|
13 |
DEPEND="dev-util/mercurial net-misc/rsync" |
19 |
DEPEND="dev-util/mercurial" |
14 |
EHG_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/hg-src" |
|
|
15 |
|
20 |
|
16 |
# This must be set by the ebuild |
21 |
# @ECLASS-VARIABLE: EHG_REPO_URI |
17 |
: ${EHG_REPO_URI:=} # repository uri |
22 |
# @DESCRIPTION: |
|
|
23 |
# Mercurial repository URI. |
24 |
|
25 |
# @ECLASS-VARIABLE: EHG_REVISION |
26 |
# @DESCRIPTION: |
27 |
# Create working directory for specified revision, defaults to tip. |
28 |
[[ -z "${EHG_REVISION}" ]] && EHG_REVISION="tip" |
29 |
|
30 |
# @ECLASS-VARIABLE: EHG_PROJECT |
31 |
# @DESCRIPTION: |
32 |
# Project name. |
33 |
# |
34 |
# This variable default to $PN, but can be changed to allow repository sharing |
35 |
# between several ebuilds. |
36 |
[[ -z "${EHG_PROJECT}" ]] && EHG_PROJECT="${PN}" |
37 |
|
38 |
# @ECLASS-VARIABLE: EHG_CLONE_CMD |
39 |
# @DESCRIPTION: |
40 |
# Command used to perform initial repository clone. |
41 |
[[ -z "${EHG_CLONE_CMD}" ]] && EHG_CLONE_CMD="hg clone --quiet --pull --noupdate" |
42 |
|
43 |
# @ECLASS-VARIABLE: EHG_PULL_CMD |
44 |
# @DESCRIPTION: |
45 |
# Command used to update repository. |
46 |
[[ -z "${EHG_PULL_CMD}" ]] && EHG_PULL_CMD="hg pull --quiet" |
47 |
|
48 |
# @FUNCTION: mercurial_fetch |
49 |
# @USAGE: [repository_uri] [module] |
50 |
# @DESCRIPTION: |
51 |
# Clone or update repository. |
52 |
# |
53 |
# If not repository URI is passed it defaults to EHG_REPO_URI, if module is |
54 |
# empty it defaults to basename of EHG_REPO_URI. |
55 |
function mercurial_fetch { |
56 |
debug-print-function ${FUNCNAME} ${*} |
18 |
|
57 |
|
19 |
# These can be set by the ebuild but are usually fine as-is |
58 |
EHG_REPO_URI=${1-${EHG_REPO_URI}} |
20 |
: ${EHG_PROJECT:=$PN} # dir under EHG_STORE_DIR |
59 |
[[ -z "${EHG_REPO_URI}" ]] && die "EHG_REPO_URI is empty" |
21 |
: ${EHG_CLONE_CMD:=hg clone --pull} # clone cmd |
|
|
22 |
: ${EHG_PULL_CMD:=hg pull -u} # pull cmd |
23 |
|
60 |
|
24 |
# should be set but blank to prevent using $HOME/.hgrc |
61 |
local hg_src_dir="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/hg-src" |
25 |
export HGRCPATH= |
62 |
local module="${2-$(basename "${EHG_REPO_URI}")}" |
26 |
|
63 |
|
27 |
function mercurial_fetch { |
64 |
# Should be set but blank to prevent using $HOME/.hgrc |
28 |
declare repo=${1:-$EHG_REPO_URI} |
65 |
export HGRCPATH= |
29 |
repo=${repo%/} # remove trailing slash |
66 |
|
30 |
[[ -n $repo ]] || die "EHG_REPO_URI is empty" |
67 |
# Check ${hg_src_dir} directory: |
31 |
declare module=${2:-${repo##*/}} |
68 |
addwrite "$(dirname "${hg_src_dir}")" || die "addwrite failed" |
32 |
|
69 |
if [[ ! -d "${hg_src_dir}" ]]; then |
33 |
if [[ ! -d ${EHG_STORE_DIR} ]]; then |
70 |
mkdir -p "${hg_src_dir}" || die "failed to create ${hg_src_dir}" |
34 |
ebegin "create ${EHG_STORE_DIR}" |
71 |
chmod -f g+rw "${hg_src_dir}" || \ |
35 |
addwrite / && |
72 |
die "failed to chown ${hg_src_dir}" |
36 |
mkdir -p "${EHG_STORE_DIR}" && |
|
|
37 |
chmod -f g+rw "${EHG_STORE_DIR}" && |
38 |
export SANDBOX_WRITE="${SANDBOX_WRITE%:/}" |
39 |
eend $? || die |
40 |
fi |
73 |
fi |
41 |
|
74 |
|
42 |
pushd "${EHG_STORE_DIR}" >/dev/null \ |
75 |
# Create project directory: |
43 |
|| die "can't chdir to ${EHG_STORE_DIR}" |
76 |
mkdir -p "${hg_src_dir}/${EHG_PROJECT}" || \ |
44 |
addwrite "$(pwd -P)" |
77 |
die "failed to create ${hg_src_dir}/${EHG_PROJECT}" |
45 |
|
78 |
chmod -f g+rw "${hg_src_dir}/${EHG_PROJECT}" || \ |
46 |
if [[ ! -d ${EHG_PROJECT}/${module} ]]; then |
79 |
die "failed to chwon ${EHG_PROJECT}" |
47 |
# first check out |
80 |
cd "${hg_src_dir}/${EHG_PROJECT}" || \ |
48 |
ebegin "${EHG_CLONE_CMD} ${repo}" |
81 |
die "failed to cd to ${hg_src_dir}/${EHG_PROJECT}" |
49 |
mkdir -p "${EHG_PROJECT}" && |
82 |
|
50 |
chmod -f g+rw "${EHG_PROJECT}" && |
83 |
# Clone/update repository: |
51 |
cd "${EHG_PROJECT}" && |
84 |
if [[ ! -d "${module}" ]]; then |
52 |
${EHG_CLONE_CMD} "${repo}" "${module}" && |
85 |
einfo "Cloning ${EHG_REPO_URI} to ${hg_src_dir}/${EHG_PROJECT}/${module}" |
53 |
cd "${module}" |
86 |
${EHG_CLONE_CMD} "${EHG_REPO_URI}" "${module}" || { |
54 |
eend $? || die |
87 |
rm -rf "${module}" |
|
|
88 |
die "failed to clone ${EHG_REPO_URI}" |
89 |
} |
90 |
cd "${module}" |
55 |
else |
91 |
else |
56 |
# update working copy |
92 |
einfo "Updating ${hg_src_dir}/${EHG_PROJECT}/${module} from ${EHG_REPO_URI}" |
57 |
ebegin "${EHG_PULL_CMD} ${repo}" |
93 |
cd "${module}" || die "failed to cd to ${module}" |
58 |
cd "${EHG_PROJECT}/${module}" && |
94 |
${EHG_PULL_CMD} || die "update failed" |
59 |
${EHG_PULL_CMD} |
|
|
60 |
case $? in |
61 |
# hg pull returns status 1 when there were no changes to pull |
62 |
1) eend 0 ;; |
63 |
*) eend $? || die ;; |
64 |
esac |
65 |
fi |
95 |
fi |
66 |
|
96 |
|
67 |
# use rsync instead of cp for --exclude |
97 |
# Checkout working copy: |
68 |
ebegin "rsync to ${WORKDIR}/${module}" |
98 |
einfo "Creating working directory in ${WORKDIR}/${module} (revision: ${EHG_REVISION})" |
69 |
mkdir -p "${WORKDIR}/${module}" && |
99 |
hg clone \ |
70 |
rsync -a --delete --exclude=.hg/ . "${WORKDIR}/${module}" |
100 |
--quiet \ |
71 |
eend $? || die |
101 |
--rev="${EHG_REVISION}" \ |
72 |
|
102 |
"${hg_src_dir}/${EHG_PROJECT}/${module}" \ |
73 |
popd >/dev/null |
103 |
"${WORKDIR}/${module}" || die "hg archive failed" |
74 |
} |
104 |
} |
75 |
|
105 |
|
|
|
106 |
# @FUNCTION: mercurial_src_unpack |
107 |
# @DESCRIPTION: |
108 |
# The mercurial src_unpack function, which will be exported. |
76 |
function mercurial_src_unpack { |
109 |
function mercurial_src_unpack { |
77 |
mercurial_fetch |
110 |
mercurial_fetch |
78 |
} |
111 |
} |