PR c++/64901
[official-gcc.git] / libgo / merge.sh
blob6b9e5bb9932751bad8efcc82af91605f63c9e5a9
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 hg clone -r ${old_rev} ${repository} ${OLDDIR}
45 rm -rf ${NEWDIR}
46 hg clone -u ${rev} ${repository} ${NEWDIR}
48 new_rev=`cd ${NEWDIR} && hg log -r ${rev} | sed 1q | sed -e 's/.*://'`
50 merge() {
51 name=$1
52 old=$2
53 new=$3
54 libgo=$4
55 if ! test -f ${new}; then
56 # The file does not exist in the new version.
57 if ! test -f ${old}; then
58 echo 1>&2 "merge.sh internal error no files $old $new"
59 exit 1
61 if ! test -f ${libgo}; then
62 # File removed in new version and libgo.
64 else
65 echo "merge.sh: ${name}: REMOVED"
66 rm -f ${libgo}
67 hg rm ${libgo}
69 elif test -f ${old}; then
70 # The file exists in the old version.
71 if ! test -f ${libgo}; then
72 echo "merge.sh: $name: skipping: exists in old and new hg, but not in libgo"
73 continue
75 if cmp -s ${old} ${libgo}; then
76 # The libgo file is unchanged from the old version.
77 if cmp -s ${new} ${libgo}; then
78 # File is unchanged from old to new version.
79 continue
81 # Update file in libgo.
82 echo "merge.sh: $name: updating"
83 cp ${new} ${libgo}
84 else
85 # The libgo file has local changes.
86 set +e
87 diff3 -m -E ${libgo} ${old} ${new} > ${libgo}.tmp
88 status=$?
89 set -e
90 case $status in
92 echo "merge.sh: $name: updating"
93 mv ${libgo}.tmp ${libgo}
96 echo "merge.sh: $name: CONFLICTS"
97 mv ${libgo}.tmp ${libgo}
98 hg resolve -u ${libgo}
101 echo 1>&2 "merge.sh: $name: diff3 failure"
102 exit 1
104 esac
106 else
107 # The file does not exist in the old version.
108 if test -f ${libgo}; then
109 if ! cmp -s ${new} ${libgo}; then
110 echo 1>&2 "merge.sh: $name: IN NEW AND LIBGO BUT NOT OLD"
112 else
113 echo "merge.sh: $name: NEW"
114 dir=`dirname ${libgo}`
115 if ! test -d ${dir}; then
116 mkdir -p ${dir}
118 cp ${new} ${libgo}
119 hg add ${libgo}
124 merge_c() {
125 from=$1
126 to=$2
127 oldfile=${OLDDIR}/src/runtime/$from
128 if test -f ${oldfile}; then
129 sed -e 's/·/_/g' < ${oldfile} > ${oldfile}.tmp
130 oldfile=${oldfile}.tmp
131 newfile=${NEWDIR}/src/runtime/$from
132 sed -e 's/·/_/g' < ${newfile} > ${newfile}.tmp
133 newfile=${newfile}.tmp
134 libgofile=runtime/$to
135 merge $from ${oldfile} ${newfile} ${libgofile}
139 if test -f VERSION; then
140 if ! cmp -s ${NEWDIR}/VERSION VERSION; then
141 cp ${NEWDIR}/VERSION .
143 else
144 if test -f ${NEWDIR}/VERSION; then
145 cp ${NEWDIR}/VERSION .
149 (cd ${NEWDIR}/src && find . -name '*.go' -print) | while read f; do
150 oldfile=${OLDDIR}/src/$f
151 newfile=${NEWDIR}/src/$f
152 libgofile=go/$f
153 merge $f ${oldfile} ${newfile} ${libgofile}
154 done
156 (cd ${NEWDIR}/src && find . -name testdata -print) | while read d; do
157 oldtd=${OLDDIR}/src/$d
158 newtd=${NEWDIR}/src/$d
159 libgotd=go/$d
160 if ! test -d ${oldtd}; then
161 continue
163 (cd ${oldtd} && hg status -A .) | while read f; do
164 if test "`basename $f`" = ".hgignore"; then
165 continue
167 f=`echo $f | sed -e 's/^..//'`
168 name=$d/$f
169 oldfile=${oldtd}/$f
170 newfile=${newtd}/$f
171 libgofile=${libgotd}/$f
172 merge ${name} ${oldfile} ${newfile} ${libgofile}
173 done
174 done
176 cmdlist="cgo go gofmt"
177 for c in $cmdlist; do
178 (cd ${NEWDIR}/src/cmd/$c && find . -name '*.go' -print) | while read f; do
179 oldfile=${OLDDIR}/src/cmd/$c/$f
180 newfile=${NEWDIR}/src/cmd/$c/$f
181 libgofile=go/cmd/$c/$f
182 merge $f ${oldfile} ${newfile} ${libgofile}
183 done
185 (cd ${NEWDIR}/src/cmd/$c && find . -name testdata -print) | while read d; do
186 oldtd=${OLDDIR}/src/cmd/$c/$d
187 newtd=${NEWDIR}/src/cmd/$c/$d
188 libgotd=go/cmd/$c/$d
189 if ! test -d ${oldtd}; then
190 continue
192 (cd ${oldtd} && hg status -A .) | while read f; do
193 if test "`basename $f`" = ".hgignore"; then
194 continue
196 f=`echo $f | sed -e 's/^..//'`
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