/[gentoo-x86]/eclass/darcs.eclass
Gentoo

Diff of /eclass/darcs.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.10 Revision 1.11
1# Copyright 2004 Gentoo Technologies, Inc. 1# Copyright 2011 Gentoo Technologies, Inc.
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/darcs.eclass,v 1.10 2010/11/01 20:54:46 slyfox Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/darcs.eclass,v 1.11 2011/01/30 10:27:20 slyfox Exp $
4
5# @ECLASS: darcs.eclass
6# @MAINTAINER:
7# "Gentoo's Haskell Language team" <haskell@gentoo.org>
4# 8#
5# darcs eclass author: Andres Loeh <kosmikus@gentoo.org> 9# Sergei Trofimovich <slyfox@gentoo.org>
6# tla eclass author: <rphillips@gentoo.org>
7# Original Author: Jeffrey Yasskin <jyasskin@mail.utexas.edu>
8# 10#
9# Originally derived from the tla eclass, which is derived from the 11# Original Author: Jeffrey Yasskin <jyasskin@mail.utexas.edu>
10# cvs eclass. 12# @BLURB: This eclass provides functions for fetch and unpack darcs repositories
13# @DESCRIPTION:
14# This eclass provides the generic darcs fetching functions.
11# 15#
12# This eclass provides the generic darcs fetching functions. 16# Define the EDARCS_REPOSITORY variable at least.
13# to use from an ebuild, set the 'ebuild-configurable settings' below in your 17# The ${S} variable is set to ${WORKDIR}/${P}.
14# ebuild before inheriting. then either leave the default src_unpack or extend 18# @THANKS TO:
15# over darcs_src_unpack. 19# <rphillips@gentoo.org> (tla eclass author)
20# Andres Loeh <kosmikus@gentoo.org> (darcs.eclass author)
21# Alexander Vershilov <alexander.vershilov@gmail.com> (various contributions)
16 22
17# Most of the time, you will define only $EDARCS_REPOSITORY in your 23# TODO:
18# ebuild.
19 24
20# TODO: support for tags, ... 25# support for tags
21 26
22inherit eutils # eshopts_{push,pop} 27inherit eutils # eshopts_{push,pop}
23 28
24# Don't download anything other than the darcs repository 29# Don't download anything other than the darcs repository
25SRC_URI="" 30SRC_URI=""
28# this eclass will take care of that. 33# this eclass will take care of that.
29 34
30# --- begin ebuild-configurable settings 35# --- begin ebuild-configurable settings
31 36
32# darcs command to run 37# darcs command to run
33[ -z "$EDARCS_DARCS_CMD" ] && EDARCS_DARCS_CMD="darcs" 38# @ECLASS-VARIABLE: EDARCS_DARCS_CMD
39# @DESCRIPTION:
40# Path to darcs binary.
41: ${EDARCS_DARCS_CMD:=darcs}
34 42
35# darcs commands with command-specific options 43# darcs commands with command-specific options
36[ -z "$EDARCS_GET_CMD" ] && EDARCS_GET_CMD="get --partial"
37[ -z "$EDARCS_UPDATE_CMD" ] && EDARCS_UPDATE_CMD="pull"
38 44
45# @ECLASS-VARIABLE: EDARCS_GET_CMD
46# @DESCRIPTION:
47# First fetch darcs command.
48: ${EDARCS_GET_CMD:=get --partial}
49
50# @ECLASS-VARIABLE: EDARCS_UPDATE_CMD
51# @DESCRIPTION:
52# Repo update darcs command.
53: ${EDARCS_UPDATE_CMD:=pull}
54
55# @ECLASS-VARIABLE: EDARCS_OPTIONS
56# @DESCRIPTION:
39# options to pass to both the "get" and "update" commands 57# Options to pass to both the "get" and "update" commands
40[ -z "$EDARCS_OPTIONS" ] && EDARCS_OPTIONS="--set-scripts-executable" 58: ${EDARCS_OPTIONS:=--set-scripts-executable}
41 59
60# @ECLASS-VARIABLE: EDARCS_TOP_DIR
61# @DESCRIPTION:
42# Where the darcs repositories are stored/accessed 62# Where the darcs repositories are stored/accessed
43[ -z "$EDARCS_TOP_DIR" ] && EDARCS_TOP_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/darcs-src" 63: ${EDARCS_TOP_DIR:=${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/darcs-src}
44 64
65# @ECLASS-VARIABLE: EDARCS_REPOSITORY
66# @DESCRIPTION:
45# The URI to the repository. 67# The URI to the repository.
46[ -z "$EDARCS_REPOSITORY" ] && EDARCS_REPOSITORY="" 68: ${EDARCS_REPOSITORY:=}
47 69
70# @ECLASS-VARIABLE: EDARCS_OFFLINE
71# @DESCRIPTION:
72# Set this variable to a non-empty value to disable the automatic updating of
73# a darcs repository. this is intended to be set outside the darcs source
74# tree by users.
75: ${EDARCS_OFFLINE:=${ESCM_OFFLINE}}
48 76
77# @ECLASS-VARIABLE: EDARCS_CLEAN
78# @DESCRIPTION:
49# EDARCS_CLEAN: set this to something to get a clean copy when updating 79# Set this to something to get a clean copy when updating
50# (removes the working directory, then uses $EDARCS_GET_CMD to 80# (removes the working directory, then uses EDARCS_GET_CMD to
51# re-download it.) 81# re-download it.)
82: ${EDARCS_CLEAN:=}
52 83
53# --- end ebuild-configurable settings --- 84# --- end ebuild-configurable settings ---
54 85
55# add darcs to deps 86# add darcs to deps
56DEPEND="dev-vcs/darcs" 87DEPEND="dev-vcs/darcs"
57 88
89# @FUNCTION: darcs_patchcount
90# @DESCRIPTION:
91# Internal function to determine amount of patches in repository.
58darcs_patchcount() { 92darcs_patchcount() {
59 set -- $(${EDARCS_DARCS_CMD} show repo | grep "Num Patches") 93 set -- $(${EDARCS_DARCS_CMD} show repo | grep "Num Patches")
60 # handle string like: " Num Patches: 3860" 94 # handle string like: " Num Patches: 3860"
61 echo ${3} 95 echo ${3}
62} 96}
63 97
98# @FUNCTION: darcs_fetch
99# @DESCRIPTION:
64# is called from darcs_src_unpack 100# Internal function is called from darcs_src_unpack
65darcs_fetch() { 101darcs_fetch() {
66
67 # The local directory to store the repository (useful to ensure a 102 # The local directory to store the repository (useful to ensure a
68 # unique local name); relative to EDARCS_TOP_DIR 103 # unique local name); relative to EDARCS_TOP_DIR
69 [ -z "$EDARCS_LOCALREPO" ] && [ -n "$EDARCS_REPOSITORY" ] \ 104 [[ -z ${EDARCS_LOCALREPO} ]] && [[ -n ${EDARCS_REPOSITORY} ]] \
70 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \ 105 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \
71 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/} 106 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/}
72 107
73 debug-print-function $FUNCNAME $* 108 debug-print-function ${FUNCNAME} $*
74 109
75 if [ -n "$EDARCS_CLEAN" ]; then 110 if [[ -n ${EDARCS_CLEAN} ]]; then
111 addwrite "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
76 rm -rf $EDARCS_TOP_DIR/$EDARCS_LOCALREPO 112 rm -rf "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
77 fi 113 fi
78 114
79 # create the top dir if needed 115 # create the top dir if needed
80 if [ ! -d "$EDARCS_TOP_DIR" ]; then 116 if [[ ! -d ${EDARCS_TOP_DIR} ]]; then
81 # note that the addwrite statements in this block are only there to allow creating EDARCS_TOP_DIR; 117 # note that the addwrite statements in this block are only there to allow creating EDARCS_TOP_DIR;
82 # we've already allowed writing inside it 118 # we've already allowed writing inside it
83 # this is because it's simpler than trying to find out the parent path of the directory, which 119 # this is because it's simpler than trying to find out the parent path of the directory, which
84 # would need to be the real path and not a symlink for things to work (so we can't just remove 120 # would need to be the real path and not a symlink for things to work (so we can't just remove
85 # the last path element in the string) 121 # the last path element in the string)
86 debug-print "$FUNCNAME: checkout mode. creating darcs directory" 122 debug-print "${FUNCNAME}: checkout mode. creating darcs directory"
87 addwrite /foobar 123 addwrite /foobar
88 addwrite / 124 addwrite /
89 mkdir -p "$EDARCS_TOP_DIR" 125 mkdir -p "${EDARCS_TOP_DIR}"
90 export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}" 126 export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}"
91 fi 127 fi
92 128
93 # in case EDARCS_DARCS_DIR is a symlink to a dir, get the real 129 # in case EDARCS_DARCS_DIR is a symlink to a dir, get the real
94 # dir's path, otherwise addwrite() doesn't work. 130 # dir's path, otherwise addwrite() doesn't work.
95 pushd . 131 pushd .
96 cd -P "$EDARCS_TOP_DIR" > /dev/null 132 cd -P "${EDARCS_TOP_DIR}" > /dev/null
97 EDARCS_TOP_DIR="`/bin/pwd`" 133 EDARCS_TOP_DIR="`/bin/pwd`"
98 134
99 # disable the sandbox for this dir 135 # disable the sandbox for this dir
100 addwrite "$EDARCS_TOP_DIR" 136 addwrite "${EDARCS_TOP_DIR}"
101 137
102 # determine checkout or update mode and change to the right directory. 138 # determine checkout or update mode and change to the right directory.
103 if [ ! -d "$EDARCS_TOP_DIR/$EDARCS_LOCALREPO/_darcs" ]; then 139 if [[ ! -d "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}/_darcs" ]]; then
104 mode=get 140 mode=get
105 cd "$EDARCS_TOP_DIR" 141 cd "${EDARCS_TOP_DIR}"
106 else 142 else
107 mode=update 143 mode=update
108 cd "$EDARCS_TOP_DIR/$EDARCS_LOCALREPO" 144 cd "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
109 fi 145 fi
110 146
111 # commands to run 147 # commands to run
112 local cmdget="${EDARCS_DARCS_CMD} ${EDARCS_GET_CMD} ${EDARCS_OPTIONS} --repo-name=${EDARCS_LOCALREPO} ${EDARCS_REPOSITORY}" 148 local cmdget="${EDARCS_DARCS_CMD} ${EDARCS_GET_CMD} ${EDARCS_OPTIONS} --repo-name=${EDARCS_LOCALREPO} ${EDARCS_REPOSITORY}"
113 local cmdupdate="${EDARCS_DARCS_CMD} ${EDARCS_UPDATE_CMD} --all ${EDARCS_OPTIONS} ${EDARCS_REPOSITORY}" 149 local cmdupdate="${EDARCS_DARCS_CMD} ${EDARCS_UPDATE_CMD} --all ${EDARCS_OPTIONS} ${EDARCS_REPOSITORY}"
114 150
115 if [ "${mode}" == "get" ]; then 151 if [[ ${mode} == "get" ]]; then
116 einfo "Running $cmdget" 152 einfo "Running ${cmdget}"
117 eval $cmdget || die "darcs get command failed" 153 eval ${cmdget} || die "darcs get command failed"
154 elif [[ -n ${EDARCS_OFFLINE} ]] ; then
155 einfo "Offline update"
118 elif [ "${mode}" == "update" ]; then 156 elif [[ ${mode} == "update" ]]; then
119 einfo "Running $cmdupdate" 157 einfo "Running ${cmdupdate}"
120 eval $cmdupdate || die "darcs update command failed" 158 eval ${cmdupdate} || die "darcs update command failed"
121 fi 159 fi
122 160
123 export EDARCS_PATCHCOUNT=$(darcs_patchcount) 161 export EDARCS_PATCHCOUNT=$(darcs_patchcount)
124 einfo " patches in repo: ${EDARCS_PATCHCOUNT}" 162 einfo " patches in repo: ${EDARCS_PATCHCOUNT}"
125 163
126 popd 164 popd
127} 165}
128 166
129 167# @FUNCTION: darcs_src_unpack
168# @DESCRIPTION:
169# src_upack function
130darcs_src_unpack() { 170darcs_src_unpack() {
131 # The local directory to store the repository (useful to ensure a 171 # The local directory to store the repository (useful to ensure a
132 # unique local name); relative to EDARCS_TOP_DIR 172 # unique local name); relative to EDARCS_TOP_DIR
133 [ -z "$EDARCS_LOCALREPO" ] && [ -n "$EDARCS_REPOSITORY" ] \ 173 [[ -z ${EDARCS_LOCALREPO} ]] && [[ -n ${EDARCS_REPOSITORY} ]] \
134 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \ 174 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \
135 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/} 175 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/}
136 176
137 debug-print-function $FUNCNAME $* 177 debug-print-function ${FUNCNAME} $*
138 178
139 debug-print "$FUNCNAME: init: 179 debug-print "${FUNCNAME}: init:
140 EDARCS_DARCS_CMD=$EDARCS_DARCS_CMD 180 EDARCS_DARCS_CMD=${EDARCS_DARCS_CMD}
141 EDARCS_GET_CMD=$EDARCS_GET_CMD 181 EDARCS_GET_CMD=${EDARCS_GET_CMD}
142 EDARCS_UPDATE_CMD=$EDARCS_UPDATE_CMD 182 EDARCS_UPDATE_CMD=${EDARCS_UPDATE_CMD}
143 EDARCS_OPTIONS=$EDARCS_OPTIONS 183 EDARCS_OPTIONS=${EDARCS_OPTIONS}
144 EDARCS_TOP_DIR=$EDARCS_TOP_DIR 184 EDARCS_TOP_DIR=${EDARCS_TOP_DIR}
145 EDARCS_REPOSITORY=$EDARCS_REPOSITORY 185 EDARCS_REPOSITORY=${EDARCS_REPOSITORY}
146 EDARCS_LOCALREPO=$EDARCS_LOCALREPO 186 EDARCS_LOCALREPO=${EDARCS_LOCALREPO}
147 EDARCS_CLEAN=$EDARCS_CLEAN" 187 EDARCS_CLEAN=${EDARCS_CLEAN}"
148 188
149 einfo "Fetching darcs repository $EDARCS_REPOSITORY into $EDARCS_TOP_DIR..." 189 einfo "Fetching darcs repository ${EDARCS_REPOSITORY} into ${EDARCS_TOP_DIR}..."
150 darcs_fetch 190 darcs_fetch
151 191
152 einfo "Copying $EDARCS_LOCALREPO from $EDARCS_TOP_DIR..." 192 einfo "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
153 debug-print "Copying $EDARCS_LOCALREPO from $EDARCS_TOP_DIR..." 193 debug-print "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
154 194
155 # probably redundant, but best to make sure 195 # probably redundant, but best to make sure
156 # Use ${WORKDIR}/${P} rather than ${S} so user can point ${S} to something inside. 196 # Use ${WORKDIR}/${P} rather than ${S} so user can point ${S} to something inside.
157 mkdir -p "${WORKDIR}/${P}" 197 mkdir -p "${WORKDIR}/${P}"
158 198
159 eshopts_push -s dotglob # get any dotfiles too. 199 eshopts_push -s dotglob # get any dotfiles too.
160 rsync -rlpgo --exclude="_darcs/" "$EDARCS_TOP_DIR/$EDARCS_LOCALREPO"/* "${WORKDIR}/${P}" 200 rsync -rlpgo --exclude="_darcs/" "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"/* "${WORKDIR}/${P}"
161 eshopts_pop 201 eshopts_pop
162 202
163 einfo "Darcs repository contents are now in ${WORKDIR}/${P}" 203 einfo "Darcs repository contents are now in ${WORKDIR}/${P}"
164 204
165} 205}

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

  ViewVC Help
Powered by ViewVC 1.1.20