PR target/49816
[official-gcc.git] / libgo / merge.sh
blob3696783abbe3277c496a126ba142c55dc0a10bb1
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 if test $# -ne 1; then
29 echo 1>&2 "merge.sh: Usage: merge.sh mercurial-repository"
30 exit 1
33 repository=$1
35 merge_rev=`sed 1q MERGE`
37 rm -rf ${OLDDIR}
38 hg clone -r ${merge_rev} ${repository} ${OLDDIR}
40 rm -rf ${NEWDIR}
41 hg clone ${repository} ${NEWDIR}
43 new_rev=`cd ${NEWDIR} && hg log | sed 1q | sed -e 's/.*://'`
45 merge() {
46 name=$1
47 old=$2
48 new=$3
49 libgo=$4
50 if ! test -f ${new}; then
51 # The file does not exist in the new version.
52 if ! test -f ${old}; then
53 echo 1>&2 "merge.sh internal error no files $old $new"
54 exit 1
56 if ! test -f ${libgo}; then
57 # File removed in new version and libgo.
59 else
60 echo "merge.sh: ${name}: REMOVED"
61 rm -f ${libgo}
62 hg rm ${libgo}
64 elif test -f ${old}; then
65 # The file exists in the old version.
66 if ! test -f ${libgo}; then
67 echo "merge.sh: $name: skipping: exists in old and new hg, but not in libgo"
68 continue
70 if cmp -s ${old} ${libgo}; then
71 # The libgo file is unchanged from the old version.
72 if cmp -s ${new} ${libgo}; then
73 # File is unchanged from old to new version.
74 continue
76 # Update file in libgo.
77 echo "merge.sh: $name: updating"
78 cp ${new} ${libgo}
79 else
80 # The libgo file has local changes.
81 set +e
82 diff3 -m -E ${libgo} ${old} ${new} > ${libgo}.tmp
83 status=$?
84 set -e
85 case $status in
87 echo "merge.sh: $name: updating"
88 mv ${libgo}.tmp ${libgo}
91 echo "merge.sh: $name: CONFLICTS"
92 mv ${libgo}.tmp ${libgo}
93 hg resolve -u ${libgo}
96 echo 1>&2 "merge.sh: $name: diff3 failure"
97 exit 1
99 esac
101 else
102 # The file does not exist in the old version.
103 if test -f ${libgo}; then
104 if ! cmp -s ${new} ${libgo}; then
105 echo 1>&2 "merge.sh: $name: IN NEW AND LIBGO BUT NOT OLD"
107 else
108 echo "merge.sh: $name: NEW"
109 dir=`dirname ${libgo}`
110 if ! test -d ${dir}; then
111 mkdir -p ${dir}
113 cp ${new} ${libgo}
114 hg add ${libgo}
119 (cd ${NEWDIR}/src/pkg && find . -name '*.go' -print) | while read f; do
120 if test `dirname $f` = "./syscall"; then
121 continue
123 oldfile=${OLDDIR}/src/pkg/$f
124 newfile=${NEWDIR}/src/pkg/$f
125 libgofile=go/$f
126 merge $f ${oldfile} ${newfile} ${libgofile}
127 done
129 (cd ${NEWDIR}/src/pkg && find . -name testdata -print) | while read d; do
130 oldtd=${OLDDIR}/src/pkg/$d
131 newtd=${NEWDIR}/src/pkg/$d
132 libgotd=go/$d
133 if ! test -d ${oldtd}; then
134 continue
136 (cd ${oldtd} && hg status -A .) | while read f; do
137 if test "`basename $f`" = ".hgignore"; then
138 continue
140 f=`echo $f | sed -e 's/^..//'`
141 name=$d/$f
142 oldfile=${oldtd}/$f
143 newfile=${newtd}/$f
144 libgofile=${libgotd}/$f
145 merge ${name} ${oldfile} ${newfile} ${libgofile}
146 done
147 done
149 runtime="goc2c.c mcache.c mcentral.c mfinal.c mfixalloc.c mgc0.c mheap.c msize.c malloc.h malloc.goc mprof.goc"
150 for f in $runtime; do
151 oldfile=${OLDDIR}/src/pkg/runtime/$f
152 newfile=${NEWDIR}/src/pkg/runtime/$f
153 libgofile=runtime/$f
154 merge $f ${oldfile} ${newfile} ${libgofile}
155 done
157 (cd ${OLDDIR}/src/pkg && find . -name '*.go' -print) | while read f; do
158 oldfile=${OLDDIR}/src/pkg/$f
159 newfile=${NEWDIR}/src/pkg/$f
160 libgofile=go/$f
161 if test -f ${newfile}; then
162 continue
164 if ! test -f ${libgofile}; then
165 continue
167 echo "merge.sh: ${libgofile}: REMOVED"
168 rm -f ${libgofile}
169 hg rm ${libgofile}
170 done
172 (echo ${new_rev}; sed -ne '2,$p' MERGE) > MERGE.tmp
173 mv MERGE.tmp MERGE