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

Contents of /eclass/cvs.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (show annotations) (download)
Fri Nov 1 10:54:42 2002 UTC (11 years, 11 months ago) by danarmak
Branch: MAIN
Changes since 1.22: +52 -5 lines
new funcitonality: non-anonymous cvs access via :ext: and ssh/rsh, courtesy of phoenix. set ECVS_ANON=no and ECVS_USER=foo, ECVS_PASS=bar to activate.

1 # Copyright 1999-2000 Gentoo Technologies, Inc.
2 # Distributed under the terms of the GNU General Public License v2
3 # Author Dan Armak <danarmak@gentoo.org>
4 # $Header: /home/cvsroot/gentoo-x86/eclass/cvs.eclass,v 1.22 2002/10/25 19:55:52 vapier Exp $
5 # This eclass provides the generic cvs fetching functions.
6
7 ECLASS=cvs
8 INHERITED="$INHERITED $ECLASS"
9
10 # You shouldn't change these settings yourself! The ebuild/eclass inheriting this eclass
11 # will take care of that. If you want to set the global KDE cvs ebuilds' settings,
12 # see the comments in kde-source.eclass.
13
14 # --- begin ebuild-configurable settings
15
16 # cvs command to run. you can set fex. "cvs -t" for extensive debug information
17 # on the cvs onnection. the default of "cvs -q -f -z4" means to be quiet, to disregard
18 # the ~/.cvsrc config file and to use maximum compression.
19 [ -z "$ECVS_CVS_COMMAND" ] && ECVS_CVS_COMMAND="cvs -q -f -z4"
20
21 # cvs options given after the command (i.e. cvs update foo)
22 # don't remove -dP or things won't work
23 [ -z "$ECVS_CVS_OPTIONS" ] && ECVS_CVS_OPTIONS="-dP"
24
25 # set this for the module/subdir to be fetched non-recursively
26 #[ -n "$ECVS_LOCAL" ] && ECVS_CVS_OPTIONS="$ECVS_CVS_OPTIONS -l"
27
28 # Where the cvs modules are stored/accessed
29 [ -z "$ECVS_TOP_DIR" ] && ECVS_TOP_DIR="${DISTDIR}/cvs-src"
30
31 # Name of cvs server, set to "offline" to disable fetching
32 # (i.e. to assume module is checked out already and don't update it).
33 # Format is server:/dir e.g. "anoncvs.kde.org:/home/kde". remove the other
34 # parts of the full CVSROOT (which looks like
35 # ":pserver:anonymous@anoncvs.kde.org:/home/kde"); these are added from
36 # other settings
37 [ -z "$ECVS_SERVER" ] && ECVS_SERVER="offline"
38
39 # Anonymous cvs login?
40 # if 'yes' uses :pserver: with empty password, if 'no' uses :ext: with $ECVS_PASS, other values not allowed
41 [ -z "$ECVS_ANON" ] && ECVS_ANON="yes"
42
43 # Username to use
44 [ -z "$ECVS_USER" ] && ECVS_USER="anonymous"
45
46 # Password to use if anonymous login is off
47 [ -z "$ECVS_PASS" ] && ECVS_PASS=""
48
49 # Module to be fetched, must be set explicitly -
50 # I don't like the former ="$PN" default setting
51 [ -z "$ECVS_MODULE" ] && debug-print "$ECLASS: error: ECVS_MODULE not set, cannot continue"
52
53 # Branch/tag to use, default is HEAD
54 # uncomment the following line to enable the reset-branch-to-HEAD behaviour
55 [ -z "$ECVS_BRANCH" ] && ECVS_BRANCH="HEAD"
56
57 # Subdirectory in module to be fetched, default is not defined = whole module
58 # DO NOT set default to "", if it's defined at all code will break!
59 # don't uncomment following line!
60 #[ -z "$ECVS_SUBDIR" ] && ECVS_SUBDIR=""
61
62 # --- end ebuild-configurable settings ---
63
64 # add cvs to deps
65 DEPEND="$DEPEND dev-util/cvs dev-python/pexpect"
66
67 # since we now longer have src_fetch as a redefinable ebuild function,
68 # we are forced to call this function from cvs_src_unpack
69 cvs_fetch() {
70
71 debug-print-function $FUNCNAME $*
72
73 debug-print "$FUNCNAME: init:
74 ECVS_CVS_COMMAND=$ECVS_CVS_COMMAND
75 ECVS_CVS_OPTIONS=$ECVS_CVS_OPTIONS
76 ECVS_TOP_DIR=$ECVS_TOP_DIR
77 ECVS_SERVER=$ECVS_SERVER
78 ECVS_ANON=$ECVS_ANON
79 ECVS_USER=$ECVS_USER
80 ECVS_PASS=$ECVS_PASS
81 ECS_MODULE=$ECVS_MODULE
82 ECVS_SUBDIR=$ECVS_SUBDIR
83 ECVS_LOCAL=$ECVS_LOCAL
84 DIR=$DIR"
85
86 # a shorthand
87 DIR="${ECVS_TOP_DIR}/${ECVS_MODULE}/${ECVS_SUBDIR}"
88 debug-print "$FUNCNAME: now DIR=$DIR"
89
90 if [ "$ECVS_SERVER" == "offline" ]; then
91 # we're not required to fetch anything, the module already exists and shouldn't be updated
92 if [ -d "$DIR" ]; then
93 debug-print "$FUNCNAME: offline mode, exiting"
94 return 0
95 else
96 einfo "ERROR: Offline mode specified, but module/subdir not found. Aborting."
97 debug-print "$FUNCNAME: offline mode specified but module/subdir not found, exiting with error"
98 return 1
99 fi
100 fi
101
102 # create target directory as needed
103 if [ ! -d "$DIR" ]; then
104 debug-print "$FUNCNAME: creating cvs directory $DIR"
105 #export SANDBOX_WRITE="$SANDBOX_WRITE:/foobar:/"
106 addwrite /foobar
107 addwrite /
108 mkdir -p /$DIR
109 export SANDBOX_WRITE=${SANDBOX_WRITE//:\/foobar:\/}
110 fi
111
112 # in case ECVS_TOP_DIR is a symlink to a dir, get the real dir's path,
113 # otherwise addwrite() doesn't work.
114 cd -P $ECVS_TOP_DIR > /dev/null
115 ECVS_TOP_DIR="`/bin/pwd`"
116 DIR="${ECVS_TOP_DIR}/${ECVS_MODULE}/${ECVS_SUBDIR}"
117 cd $OLDPWD
118
119 debug-print "$FUNCNAME: now DIR=$DIR"
120
121 # disable the sandbox for this dir
122 # not just $DIR because we want to create moduletopdir/CVS too
123 addwrite $ECVS_TOP_DIR/$ECVS_MODULE
124
125 # add option for local (non-recursive) fetching
126 [ -n "$ECVS_LOCAL" ] && ECVS_CVS_OPTIONS="$ECVS_CVS_OPTIONS -l"
127
128 # prepare a cvspass file just for this session so that cvs thinks we're logged
129 # in at the cvs server. we don't want to mess with ~/.cvspass.
130 echo ":pserver:${ECVS_SERVER} A" > ${T}/cvspass
131 export CVS_PASSFILE="${T}/cvspass"
132 #export CVSROOT=:pserver:${ECVS_USER}@${ECVS_SERVER}
133
134 # Note: cvs update and checkout commands are unified.
135 # we make sure a CVS/ dir exists in our module subdir with the right
136 # Root and Repository entries in it and cvs update.
137
138 [ "${ECVS_ANON}" == "yes" ] && \
139 newserver=":pserver:${ECVS_USER}@${ECVS_SERVER}" || \
140 newserver=":ext:${ECVS_USER}@${ECVS_SERVER}"
141
142
143 # CVS/Repository files can't (I think) contain two concatenated slashes
144 if [ -n "$ECVS_SUBDIR" ]; then
145 repository="${ECVS_MODULE}/${ECVS_SUBDIR}"
146 else
147 repository="${ECVS_MODULE}"
148 fi
149
150 debug-print "$FUNCNAME: Root<-$newserver, Repository<-$repository"
151 debug-print "$FUNCNAME: entering directory $DIR"
152 cd /$DIR
153
154 if [ ! -d "CVS" ]; then
155 # create a new CVS/ directory (checkout)
156 debug-print "$FUNCNAME: creating new cvs directory"
157
158 mkdir CVS
159 echo $newserver > CVS/Root
160 echo $repository > CVS/Repository
161 touch CVS/Entries
162
163 # if we're checking out a subdirectory only, create a CVS/ dir
164 # in the module's top dir so that the user (and we) can cvs update
165 # from there to get the full module.
166 if [ ! -d "$ECVS_TOP_DIR/$ECVS_MODULE/CVS" ]; then
167 debug-print "$FUNCNAME: Copying CVS/ directory to module top-level dir"
168 cp -r CVS $ECVS_TOP_DIR/$ECVS_MODULE/
169 echo $ECVS_MODULE > $ECVS_TOP_DIR/$ECVS_MODULE/CVS/Repository
170 fi
171
172 else
173 #update existing module
174 debug-print "$FUNCNAME: updating existing module/subdir"
175
176 # Switch servers if needed
177 # cvs keeps the server info in the CVS/Root file in every checked-out dir;
178 # we can fix those files to point to the new server
179 oldserver="`cat CVS/Root`"
180 if [ "$newserver" != "$oldserver" ]; then
181
182 einfo "Changing CVS server from $oldserver to $newserver:"
183 debug-print "$FUNCNAME: Changing CVS server from $oldserver to $newserver:"
184
185 einfo "Searching for CVS dirs..."
186 cvsdirs="`find . -iname CVS -print`"
187 debug-print "$FUNCNAME: CVS dirs found:"
188 debug-print "$cvsdirs"
189
190 einfo "Modifying CVS dirs..."
191 for x in $cvsdirs; do
192 debug-print "In $x"
193 echo $newserver > $x/Root
194 done
195
196 fi
197
198 fi
199
200 # cvs auto-switches branches, how nice
201 # warning: if we do it this way we get multiple -rX options - harmless i think
202 [ -n "$ECVS_BRANCH" ] && ECVS_CVS_OPTIONS="$ECVS_CVS_OPTIONS -r$ECVS_BRANCH"
203
204 # finally run the cvs update command
205 debug-print "$FUNCNAME: is in dir `/bin/pwd`"
206 debug-print "$FUNCNAME: running $ECVS_CVS_COMMAND update $ECVS_CVS_OPTIONS with $ECVS_SERVER for module $ECVS_MODULE subdir $ECVS_SUBDIR"
207 einfo "Running $ECVS_CVS_COMMAND update $ECVS_CVS_OPTIONS with $ECVS_SERVER for $ECVS_MODULE/$ECVS_SUBDIR..."
208
209 if [ "${ECVS_ANON}" == "no" ]; then
210
211 debug-print "$FUNCNAME: starting non-anonymous cvs login..."
212 # CVS Login - written in python :: the right way ;)
213 # Tilman Klar, <phoenix@gentoo.org>
214
215 export CVS_RSH="/usr/bin/ssh"
216
217 ############################## inline-python #####################################
218 /usr/bin/env python << EndOfFile
219
220 import pexpect,os
221
222 mypasswd = "${ECVS_PASS}"
223 mytimeout = 10
224
225 mycommand = "${ECVS_CVS_COMMAND} update ${ECVS_CVS_OPTIONS}"
226 child = pexpect.spawn(mycommand)
227
228 index = child.expect(['continue connecting','word:'], mytimeout)
229 if index == 0:
230 child.sendline('yes')
231 ## Added server to ~/.ssh/known_hosts
232 child.expect('word:', mytimeout)
233 else:
234 ## Server already is in ~/.ssh/known_hosts
235 pass
236
237 child.sendline(mypasswd)
238 child.expect(pexpect.EOF)
239
240 EndOfFile
241 ########################### End of inline-python ##################################
242 else
243 debug-print "$FUNCNAME: using anonymous cvs login"
244 $ECVS_CVS_COMMAND update $ECVS_CVS_OPTIONS || die "died running cvs update"
245 fi
246
247
248
249 }
250
251 cvs_src_unpack() {
252
253 debug-print-function $FUNCNAME $*
254 cvs_fetch || die "died running cvs_fetch"
255
256 einfo "Copying $ECVS_MODULE/$ECVS_SUBDIR from $ECVS_TOP_DIR..."
257 debug-print "Copying module $ECVS_MODULE subdir $ECVS_SUBDIR local_mode=$ECVS_LOCAL from $ECVS_TOP_DIR..."
258
259 # probably redundant, but best to make sure
260 mkdir -p $WORKDIR/$ECVS_MODULE/$ECVS_SUBDIR
261
262 if [ -n "$ECVS_SUBDIR" ]; then
263 if [ -n "$ECVS_LOCAL" ]; then
264 cp -f $ECVS_TOP_DIR/$ECVS_MODULE/$ECVS_SUBDIR/* $WORKDIR/$ECVS_MODULE/$ECVS_SUBDIR
265 else
266 cp -Rf $ECVS_TOP_DIR/$ECVS_MODULE/$ECVS_SUBDIR $WORKDIR/$ECVS_MODULE/$ECVS_SUBDIR/..
267 fi
268 else
269 if [ -n "$ECVS_LOCAL" ]; then
270 cp -f $ECVS_TOP_DIR/$ECVS_MODULE/* $WORKDIR/$ECVS_MODULE
271 else
272 cp -Rf $ECVS_TOP_DIR/$ECVS_MODULE $WORKDIR
273 fi
274 fi
275
276 # if the directory is empty, remove it; empty directories cannot exist in cvs.
277 # this happens when fex. kde-source requests module/doc/subdir which doesn't exist.
278 # still create the empty directory in workdir though.
279 if [ "`ls -A $DIR`" == "CVS" ]; then
280 debug-print "$FUNCNAME: removing cvs-empty directory $ECVS_MODULE/$ECVS_SUBDIR"
281 rm -rf $DIR
282 fi
283
284 # implement some of base_src_unpack's functionality;
285 # note however that base.eclass may not have been inherited!
286 if [ -n "$PATCHES" ]; then
287 debug-print "$FUNCNAME: PATCHES=$PATCHES, S=$S, autopatching"
288 cd $S
289 for x in $PATCHES; do
290 debug-print "patching from $x"
291 patch -p0 < $x
292 done
293 # make sure we don't try to apply patches more than once, since
294 # cvs_src_unpack is usually called several times from e.g. kde-source_src_unpack
295 export PATCHES=""
296 fi
297
298 }
299
300 EXPORT_FUNCTIONS src_unpack

  ViewVC Help
Powered by ViewVC 1.1.20