Avoids bailing on non-zero exit status from commands. This will lets
[scons.git] / bin / ae-cvs-ci
1 #
2 #       aegis - project change supervisor
3 #       Copyright (C) 2004 Peter Miller;
4 #       All rights reserved.
5 #
6 #       As a specific exception to the GPL, you are allowed to copy
7 #       this source file into your own project and modify it, without
8 #       releasing your project under the GPL, unless there is some other
9 #       file or condition which would require it.
10 #
11 # MANIFEST: shell script to commit changes to CVS
12 #
13 # It is assumed that your CVSROOT and CVS_RSH environment variables have
14 # already been set appropriately.
15 #
16 # This script is expected to be run as by integrate_pass_notify_command
17 # and as such the baseline has already assumed the shape asked for by
18 # the change.
19 #
20 #       integrate_pass_notify_command =
21 #           "$bin/ae-cvs-ci $project $change";
22 #
23 # Alternatively, you may wish to tailor this script to the individual
24 # needs of your project.  Make it a source file, e.g. "etc/ae-cvs-ci.sh"
25 # and then use the following:
26 #
27 #       integrate_pass_notify_command =
28 #           "$sh ${s etc/ae-cvs-ci} $project $change";
29 #
30
31 USAGE="Usage: $0 <project> <change>"
32
33 PRINT="echo"
34 EXECUTE="eval"
35
36 while getopts "hnq" FLAG
37 do
38     case ${FLAG} in
39     h )
40         echo "${USAGE}"
41         exit 0
42         ;;
43     n )
44         EXECUTE=":"
45         ;;
46     q )
47         PRINT=":"
48         ;;
49     * )
50         echo "$0: unknown option ${FLAG}" >&2
51         exit 1
52         ;;
53     esac
54 done
55
56 shift `expr ${OPTIND} - 1`
57
58 case $# in
59 2)
60     project=$1
61     change=$2
62     ;;
63 *)
64     echo "${USAGE}" 1>&2
65     exit 1
66     ;;
67 esac
68
69 here=`pwd`
70
71 AEGIS_PROJECT=$project
72 export AEGIS_PROJECT
73 AEGIS_CHANGE=$change
74 export AEGIS_CHANGE
75
76 module=`echo $project | sed 's|[.].*||'`
77
78 baseline=`aegis -cd -bl`
79
80 if test X${TMPDIR} = X; then TMPDIR=/var/tmp; fi
81
82 TMP=${TMPDIR}/ae-cvs-ci.$$
83 mkdir ${TMP}
84 cd ${TMP}
85
86 PWD=`pwd`
87 if test X${PWD} != X${TMP}; then
88     echo "$0: ended up in ${PWD}, not ${TMP}" >&2
89     exit 1
90 fi
91
92 fail()
93 {
94     set +x
95     cd $here
96     rm -rf ${TMP}
97     echo "FAILED" 1>&2
98     exit 1
99 }
100 trap "fail" 1 2 3 15
101
102 Command()
103 {
104     ${PRINT} "$*"
105     ${EXECUTE} "$*"
106 }
107
108 #
109 # Create a new CVS work area.
110 #
111 # Note: this assumes the module is checked-out into a directory of the
112 # same name.  Is there a way to ask CVS where is is going to put a
113 # modules, so we can always get the "cd" right?
114 #
115 ${PRINT} cvs co $module
116 ${EXECUTE} cvs co $module > LOG 2>&1
117 if test $? -ne 0; then cat LOG; fail; fi
118 ${EXECUTE} cd $module
119
120 #
121 # Now we need to extract the sources from Aegis and drop them into the
122 # CVS work area.  There are two ways to do this.
123 #
124 # The first way is to use the generated tarball.
125 # This has the advantage that it has the Makefile.in file in it, and
126 # will work immediately.
127 #
128 # The second way is to use aetar, which will give exact sources, and
129 # omit all derived files.  This will *not* include the Makefile.in,
130 # and so will not be readily compilable.
131 #
132 # gunzip < $baseline/export/${project}.tar.gz | tardy -rp ${project} | tar xf -
133 aetar -send -comp-alg=gzip -o - | tar xzf -
134
135 #
136 # If any new directories have been created we will need to add them
137 # to CVS before we can add the new files which we know are in them,
138 # or they would not have been created.  Do this only if the -n option
139 # isn't used, because if it is, we won't have actually checked out the
140 # source and we'd erroneously report that all of them need to be added.
141 #
142 if test "X${EXECUTE}" != "X:"
143 then
144     find . \( -name CVS -o -name Attic \) -prune -o -type d -print |
145     xargs --max-args=1 |
146     while read dir
147     do
148         if [ ! -d "$dir/CVS" ]
149         then
150             Command cvs add "$dir"
151         fi
152     done
153 fi
154
155 #
156 # Use the Aegis meta-data to perform some CVS commands that CVS can't
157 # figure out for itself.
158 #
159 aegis -l cf -unf | sed 's| -> [0-9][0-9.]*||' |
160 while read usage action rev filename
161 do
162     if test "x$filename" = "x"
163     then
164         filename="$rev"
165     fi
166     case $action in
167     create)
168         Command cvs add $filename
169         ;;
170     remove)
171         Command rm -f $filename
172         Command cvs remove $filename
173         ;;
174     *)
175         ;;
176     esac
177 done
178
179 #
180 # Extract the brief description.  We'd like to do this using aesub
181 # or something, like so:
182 #
183 #      message=`aesub '${version} - ${change description}'`
184 #
185 # but the expansion of ${change description} has a lame hard-coded max of
186 # 80 characters, so we have to do this by hand.  (This has the slight
187 # benefit of preserving backslashes in front of any double-quotes in
188 # the text; that will have to be handled if we go back to using aesub.)
189 #
190 description=`aegis -ca -l | sed -n 's/brief_description = "\(.*\)";$/\1/p'`
191 version=`aesub '${version}'`
192 message="$version - $description"
193
194 #
195 # Now commit all the changes.
196 #
197 Command cvs -q commit -m \"$message\"
198
199 #
200 # All done.  Clean up and go home.
201 #
202 cd $here
203 rm -rf ${TMP}
204 exit 0