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

Contents of /eclass/cvs.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (hide annotations) (download)
Fri Nov 1 10:54:42 2002 UTC (12 years, 1 month 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 danarmak 1.1 # Copyright 1999-2000 Gentoo Technologies, Inc.
2 vapier 1.22 # Distributed under the terms of the GNU General Public License v2
3 danarmak 1.1 # Author Dan Armak <danarmak@gentoo.org>
4 danarmak 1.23 # $Header: /home/cvsroot/gentoo-x86/eclass/cvs.eclass,v 1.22 2002/10/25 19:55:52 vapier Exp $
5 danarmak 1.1 # 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 danarmak 1.8 [ -z "$ECVS_CVS_COMMAND" ] && ECVS_CVS_COMMAND="cvs -q -f -z4"
20 danarmak 1.1
21 danarmak 1.7 # 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 danarmak 1.1 # Where the cvs modules are stored/accessed
29 danarmak 1.14 [ -z "$ECVS_TOP_DIR" ] && ECVS_TOP_DIR="${DISTDIR}/cvs-src"
30 danarmak 1.1
31 danarmak 1.9 # Name of cvs server, set to "offline" to disable fetching
32 danarmak 1.1 # (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 danarmak 1.9 [ -z "$ECVS_SERVER" ] && ECVS_SERVER="offline"
38 danarmak 1.1
39 danarmak 1.23 # 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 danarmak 1.1 # Username to use
44     [ -z "$ECVS_USER" ] && ECVS_USER="anonymous"
45    
46 danarmak 1.23 # Password to use if anonymous login is off
47 danarmak 1.1 [ -z "$ECVS_PASS" ] && ECVS_PASS=""
48    
49     # Module to be fetched, must be set explicitly -
50 danarmak 1.12 # I don't like the former ="$PN" default setting
51     [ -z "$ECVS_MODULE" ] && debug-print "$ECLASS: error: ECVS_MODULE not set, cannot continue"
52 danarmak 1.1
53 danarmak 1.14 # 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 danarmak 1.6 # 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 danarmak 1.18 #[ -z "$ECVS_SUBDIR" ] && ECVS_SUBDIR=""
61 danarmak 1.1
62     # --- end ebuild-configurable settings ---
63    
64 danarmak 1.6 # add cvs to deps
65 danarmak 1.23 DEPEND="$DEPEND dev-util/cvs dev-python/pexpect"
66 danarmak 1.1
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 danarmak 1.6 debug-print "$FUNCNAME: init:
74     ECVS_CVS_COMMAND=$ECVS_CVS_COMMAND
75 danarmak 1.7 ECVS_CVS_OPTIONS=$ECVS_CVS_OPTIONS
76 danarmak 1.6 ECVS_TOP_DIR=$ECVS_TOP_DIR
77     ECVS_SERVER=$ECVS_SERVER
78 danarmak 1.23 ECVS_ANON=$ECVS_ANON
79 danarmak 1.6 ECVS_USER=$ECVS_USER
80     ECVS_PASS=$ECVS_PASS
81     ECS_MODULE=$ECVS_MODULE
82 danarmak 1.18 ECVS_SUBDIR=$ECVS_SUBDIR
83 danarmak 1.7 ECVS_LOCAL=$ECVS_LOCAL
84 danarmak 1.6 DIR=$DIR"
85 danarmak 1.14
86 danarmak 1.6 # a shorthand
87 danarmak 1.17 DIR="${ECVS_TOP_DIR}/${ECVS_MODULE}/${ECVS_SUBDIR}"
88 danarmak 1.18 debug-print "$FUNCNAME: now DIR=$DIR"
89 danarmak 1.7
90 danarmak 1.9 if [ "$ECVS_SERVER" == "offline" ]; then
91 danarmak 1.1 # we're not required to fetch anything, the module already exists and shouldn't be updated
92 danarmak 1.21 if [ -d "$DIR" ]; then
93 danarmak 1.1 debug-print "$FUNCNAME: offline mode, exiting"
94     return 0
95 danarmak 1.21 else
96 danarmak 1.6 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 danarmak 1.1 return 1
99 danarmak 1.21 fi
100 danarmak 1.1 fi
101 danarmak 1.18
102 danarmak 1.17 # 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 danarmak 1.1
112 danarmak 1.17 # 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 danarmak 1.18 DIR="${ECVS_TOP_DIR}/${ECVS_MODULE}/${ECVS_SUBDIR}"
117 danarmak 1.17 cd $OLDPWD
118    
119 danarmak 1.18 debug-print "$FUNCNAME: now DIR=$DIR"
120    
121 danarmak 1.6 # 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 danarmak 1.17
125     # add option for local (non-recursive) fetching
126     [ -n "$ECVS_LOCAL" ] && ECVS_CVS_OPTIONS="$ECVS_CVS_OPTIONS -l"
127 danarmak 1.6
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 danarmak 1.21
134 danarmak 1.6 # 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 danarmak 1.23 [ "${ECVS_ANON}" == "yes" ] && \
139     newserver=":pserver:${ECVS_USER}@${ECVS_SERVER}" || \
140     newserver=":ext:${ECVS_USER}@${ECVS_SERVER}"
141    
142 danarmak 1.6
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 danarmak 1.18 debug-print "$FUNCNAME: entering directory $DIR"
152 danarmak 1.17 cd /$DIR
153    
154 danarmak 1.18 if [ ! -d "CVS" ]; then
155 danarmak 1.6 # 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 danarmak 1.1 # Switch servers if needed
177 danarmak 1.6 # cvs keeps the server info in the CVS/Root file in every checked-out dir;
178 danarmak 1.1 # 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 danarmak 1.6 fi
199 danarmak 1.14
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 danarmak 1.1
204 danarmak 1.6 # finally run the cvs update command
205 danarmak 1.18 debug-print "$FUNCNAME: is in dir `/bin/pwd`"
206 danarmak 1.7 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 danarmak 1.23
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 danarmak 1.1
249     }
250    
251     cvs_src_unpack() {
252    
253 danarmak 1.21 debug-print-function $FUNCNAME $*
254 danarmak 1.1 cvs_fetch || die "died running cvs_fetch"
255    
256 danarmak 1.21 einfo "Copying $ECVS_MODULE/$ECVS_SUBDIR from $ECVS_TOP_DIR..."
257 danarmak 1.19 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 danarmak 1.7
262     if [ -n "$ECVS_SUBDIR" ]; then
263 danarmak 1.21 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 danarmak 1.7 else
269 danarmak 1.21 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 danarmak 1.7 fi
275 danarmak 1.10
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 danarmak 1.21 # 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 danarmak 1.1
298     }
299    
300     EXPORT_FUNCTIONS src_unpack

  ViewVC Help
Powered by ViewVC 1.1.20