Massage the output from examples for consistency with Python 2.6.
[scons.git] / bin / ae-svn-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 Subversion
12 #
13 # This script is expected to be run by the integrate_pass_notify_command
14 # and as such the baseline has already assumed the shape asked for by
15 # the change.
16 #
17 #       integrate_pass_notify_command =
18 #           "$bin/ae-svn-ci $project $change http://svn.site.com/svn/trunk --username svn_user";
19 #
20 # Alternatively, you may wish to tailor this script to the individual
21 # needs of your project.  Make it a source file, e.g. "etc/ae-svn-ci.sh"
22 # and then use the following:
23 #
24 #       integrate_pass_notify_command =
25 #           "$sh ${s etc/ae-svn-ci} $project $change http://svn.site.com/svn/trunk --username svn_user";
26 #
27
28 USAGE="Usage: $0 [-hnq] <project> <change> <url> [<co_options>]"
29
30 PRINT="echo"
31 EXECUTE="eval"
32
33 while getopts "hnq" FLAG
34 do
35     case ${FLAG} in
36     h )
37         echo "${USAGE}"
38         exit 0
39         ;;
40     n )
41         EXECUTE=":"
42         ;;
43     q )
44         PRINT=":"
45         ;;
46     * )
47         echo "$0: unknown option ${FLAG}" >&2
48         exit 1
49         ;;
50     esac
51 done
52
53 shift `expr ${OPTIND} - 1`
54
55 case $# in
56 [012])
57     echo "${USAGE}" 1>&2
58     exit 1
59     ;;
60 *)
61     project=$1
62     change=$2
63     svn_url=$3
64     shift 3
65     svn_co_flags=$*
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-svn-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 Subversion 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 Subversion where it is going to put a
113 # module, so we can always get the "cd" right?
114 #
115 ${PRINT} svn co $svn_url $module $svn_co_flags
116 ${EXECUTE} svn co $svn_url $module $svn_co_flags > 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 # Subversion 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 Subversion 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 .svn -prune -o -type d -print |
145     xargs --max-args=1 |
146     while read dir
147     do
148         if [ ! -d "$dir/.svn" ]
149         then
150             Command svn add -N "$dir"
151         fi
152     done
153 fi
154
155 #
156 # Use the Aegis meta-data to perform some commands that Subversion can't
157 # figure out for itself.  We use an inline "aer" report script to identify
158 # when a remove-create pair are actually due to a move.
159 #
160 aegis -rpt -nph -f - <<_EOF_ |
161 auto cs;
162 cs = project[project_name()].state.branch.change[change_number()];
163
164 columns({width = 1000;});
165
166 auto file, moved;
167 for (file in cs.src)
168 {
169     if (file.move != "")
170         moved[file.move] = 1;
171 }
172
173 auto action;
174 for (file in cs.src)
175 {
176     if (file.action == "remove" && file.move != "")
177         action = "move";
178     else
179         action = file.action;
180     /*
181      * Suppress printing of any files created as the result of a move.
182      * These are printed as the destination when printing the line for
183      * the file that was *removed* as a result of the move.
184      */
185     if (action != "create" || ! moved[file.file_name])
186         print(sprintf("%s %s \\"%s\\" \\"%s\\"", file.usage, action, file.file_name, file.move));
187 }
188 _EOF_
189 while read line
190 do
191     eval set -- "$line"
192     usage="$1"
193     action="$2"
194     srcfile="$3"
195     dstfile="$4"
196     case $action in
197     create)
198         Command svn add $srcfile
199         ;;
200     remove)
201         Command rm -f $srcfile
202         Command svn remove $srcfile
203         ;;
204     move)
205         Command mv $dstfile $dstfile.move
206         Command svn move $srcfile $dstfile
207         Command cp $dstfile.move $dstfile
208         Command rm -f $dstfile.move
209         ;;
210     *)
211         ;;
212     esac
213 done
214
215 #
216 # Extract the brief description.  We'd like to do this using aesub
217 # or something, like so:
218 #
219 #      message=`aesub '${version} - ${change description}'`
220 #
221 # but the expansion of ${change description} has a lame hard-coded max of
222 # 80 characters, so we have to do this by hand.  (This has the slight
223 # benefit of preserving backslashes in front of any double-quotes in
224 # the text; that will have to be handled if we go back to using aesub.)
225 #
226 description=`aegis -ca -l | sed -n 's/brief_description = "\(.*\)";$/\1/p'`
227 version=`aesub '${version}'`
228 message="$version - $description"
229
230 #
231 # Now commit all the changes.
232 #
233 Command svn commit -m \"$message\"
234
235 #
236 # All done.  Clean up and go home.
237 #
238 cd $here
239 rm -rf ${TMP}
240 exit 0