re PR tree-optimization/64454 (optimize (x%5)%5)
[official-gcc.git] / libgo / merge.sh
blobc79f7596dcaa8cbb13496223b7d25dfb218c6d9d
1 #!/bin/sh
3 # Copyright 2009 The Go Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style
5 # license that can be found in the LICENSE file.
7 # This script merges changes from the master copy of the Go library
8 # into the libgo library. This does the easy stuff; the hard stuff is
9 # left to the user.
11 # The file MERGE should hold the Mercurial revision number of the last
12 # revision which was merged into these sources. Given that, and given
13 # the current sources, we can run the usual diff3 algorithm to merge
14 # all changes into our sources.
16 set -e
18 TMPDIR=${TMPDIR:-/tmp}
20 OLDDIR=${TMPDIR}/libgo-merge-old
21 NEWDIR=${TMPDIR}/libgo-merge-new
23 if ! test -f MERGE; then
24 echo 1>&2 "merge.sh: must be run in libgo source directory"
25 exit 1
28 rev=weekly
29 case $# in
30 1) ;;
31 2) rev=$2 ;;
33 echo 1>&2 "merge.sh: Usage: merge.sh mercurial-repository [revision]"
34 exit 1
36 esac
38 repository=$1
40 old_rev=`sed 1q MERGE`
42 rm -rf ${OLDDIR}
43 git clone ${repository} ${OLDDIR}
44 (cd ${OLDDIR} && git checkout ${old_rev})
46 rm -rf ${NEWDIR}
47 git clone ${repository} ${NEWDIR}
48 (cd ${NEWDIR} && git checkout ${rev})
50 new_rev=`cd ${NEWDIR} && git log | sed 1q | sed -e 's/commit //'`
52 merge() {
53 name=$1
54 old=$2
55 new=$3
56 libgo=$4
57 if ! test -f ${new}; then
58 # The file does not exist in the new version.
59 if ! test -f ${old}; then
60 echo 1>&2 "merge.sh internal error no files $old $new"
61 exit 1
63 if ! test -f ${libgo}; then
64 # File removed in new version and libgo.
66 else
67 echo "merge.sh: ${name}: REMOVED"
68 rm -f ${libgo}
69 hg rm ${libgo}
71 elif test -f ${old}; then
72 # The file exists in the old version.
73 if ! test -f ${libgo}; then
74 echo "merge.sh: $name: skipping: exists in old and new git, but not in libgo"
75 continue
77 if cmp -s ${old} ${libgo}; then
78 # The libgo file is unchanged from the old version.
79 if cmp -s ${new} ${libgo}; then
80 # File is unchanged from old to new version.
81 continue
83 # Update file in libgo.
84 echo "merge.sh: $name: updating"
85 cp ${new} ${libgo}
86 else
87 # The libgo file has local changes.
88 set +e
89 diff3 -m -E ${libgo} ${old} ${new} > ${libgo}.tmp
90 status=$?
91 set -e
92 case $status in
94 echo "merge.sh: $name: updating"
95 mv ${libgo}.tmp ${libgo}
98 echo "merge.sh: $name: CONFLICTS"
99 mv ${libgo}.tmp ${libgo}
100 hg resolve -u ${libgo}
103 echo 1>&2 "merge.sh: $name: diff3 failure"
104 exit 1
106 esac
108 else
109 # The file does not exist in the old version.
110 if test -f ${libgo}; then
111 if ! cmp -s ${new} ${libgo}; then
112 echo 1>&2 "merge.sh: $name: IN NEW AND LIBGO BUT NOT OLD"
114 else
115 echo "merge.sh: $name: NEW"
116 dir=`dirname ${libgo}`
117 if ! test -d ${dir}; then
118 mkdir -p ${dir}
120 cp ${new} ${libgo}
121 hg add ${libgo}
126 merge_c() {
127 from=$1
128 to=$2
129 oldfile=${OLDDIR}/src/runtime/$from
130 if test -f ${oldfile}; then
131 sed -e 's/·/_/g' < ${oldfile} > ${oldfile}.tmp
132 oldfile=${oldfile}.tmp
133 newfile=${NEWDIR}/src/runtime/$from
134 sed -e 's/·/_/g' < ${newfile} > ${newfile}.tmp
135 newfile=${newfile}.tmp
136 libgofile=runtime/$to
137 merge $from ${oldfile} ${newfile} ${libgofile}
141 if test -f VERSION; then
142 if ! cmp -s ${NEWDIR}/VERSION VERSION; then
143 cp ${NEWDIR}/VERSION .
145 else
146 if test -f ${NEWDIR}/VERSION; then
147 cp ${NEWDIR}/VERSION .
151 (cd ${NEWDIR}/src && find . -name '*.go' -print) | while read f; do
152 oldfile=${OLDDIR}/src/$f
153 newfile=${NEWDIR}/src/$f
154 libgofile=go/$f
155 merge $f ${oldfile} ${newfile} ${libgofile}
156 done
158 (cd ${NEWDIR}/src && find . -name testdata -print) | while read d; do
159 oldtd=${OLDDIR}/src/$d
160 newtd=${NEWDIR}/src/$d
161 libgotd=go/$d
162 if ! test -d ${oldtd}; then
163 continue
165 (cd ${oldtd} && git ls-files .) | while read f; do
166 if test "`basename $f`" = ".gitignore"; then
167 continue
169 name=$d/$f
170 oldfile=${oldtd}/$f
171 newfile=${newtd}/$f
172 libgofile=${libgotd}/$f
173 merge ${name} ${oldfile} ${newfile} ${libgofile}
174 done
175 done
177 cmdlist="cgo go gofmt"
178 for c in $cmdlist; do
179 (cd ${NEWDIR}/src/cmd/$c && find . -name '*.go' -print) | while read f; do
180 oldfile=${OLDDIR}/src/cmd/$c/$f
181 newfile=${NEWDIR}/src/cmd/$c/$f
182 libgofile=go/cmd/$c/$f
183 merge $f ${oldfile} ${newfile} ${libgofile}
184 done
186 (cd ${NEWDIR}/src/cmd/$c && find . -name testdata -print) | while read d; do
187 oldtd=${OLDDIR}/src/cmd/$c/$d
188 newtd=${NEWDIR}/src/cmd/$c/$d
189 libgotd=go/cmd/$c/$d
190 if ! test -d ${oldtd}; then
191 continue
193 (cd ${oldtd} && git ls-files .) | while read f; do
194 if test "`basename $f`" = ".gitignore"; then
195 continue
197 name=$d/$f
198 oldfile=${oldtd}/$f
199 newfile=${newtd}/$f
200 libgofile=${libgotd}/$f
201 merge ${name} ${oldfile} ${newfile} ${libgofile}
202 done
203 done
204 done
206 runtime="chan.goc chan.h cpuprof.goc env_posix.c heapdump.c lock_futex.c lfstack.goc lock_sema.c mcache.c mcentral.c mfixalloc.c mgc0.c mgc0.h mheap.c msize.c netpoll.goc netpoll_epoll.c netpoll_kqueue.c netpoll_stub.c panic.c print.c proc.c race.h rdebug.goc runtime.c runtime.h signal_unix.c signal_unix.h malloc.h malloc.goc mprof.goc parfor.c runtime1.goc sema.goc sigqueue.goc string.goc time.goc"
207 for f in $runtime; do
208 # merge_c $f $f
209 true
210 done
212 # merge_c os_linux.c thread-linux.c
213 # merge_c mem_linux.c mem.c
215 (cd ${OLDDIR}/src && find . -name '*.go' -print) | while read f; do
216 oldfile=${OLDDIR}/src/$f
217 newfile=${NEWDIR}/src/$f
218 libgofile=go/$f
219 if test -f ${newfile}; then
220 continue
222 if ! test -f ${libgofile}; then
223 continue
225 echo "merge.sh: ${libgofile}: REMOVED"
226 rm -f ${libgofile}
227 hg rm ${libgofile}
228 done
230 (echo ${new_rev}; sed -ne '2,$p' MERGE) > MERGE.tmp
231 mv MERGE.tmp MERGE