re PR lto/61886 (LTO breaks fread with _FORTIFY_SOURCE=2)
[platform/upstream/gcc.git] / libgo / merge.sh
1 #!/bin/sh
2
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.
6
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.
10
11 # The file MERGE should hold the Git 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.
15
16 set -e
17
18 TMPDIR=${TMPDIR:-/tmp}
19
20 OLDDIR=${TMPDIR}/libgo-merge-old
21 NEWDIR=${TMPDIR}/libgo-merge-new
22
23 if ! test -f MERGE; then
24   echo 1>&2 "merge.sh: must be run in libgo source directory"
25   exit 1
26 fi
27
28 rev=weekly
29 case $# in
30 1) ;;
31 2) rev=$2 ;;
32 *)
33   echo 1>&2 "merge.sh: Usage: merge.sh git-repository [revision]"
34   exit 1
35   ;;
36 esac
37
38 repository=$1
39
40 old_rev=`sed 1q MERGE`
41
42 rm -rf ${OLDDIR}
43 git clone ${repository} ${OLDDIR}
44 (cd ${OLDDIR} && git checkout ${old_rev})
45
46 rm -rf ${NEWDIR}
47 git clone ${repository} ${NEWDIR}
48 (cd ${NEWDIR} && git checkout ${rev})
49
50 new_rev=`cd ${NEWDIR} && git log | sed 1q | sed -e 's/commit //'`
51
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
62     fi
63     if ! test -f ${libgo}; then
64       # File removed in new version and libgo.
65       :;
66     else
67       echo "merge.sh: ${name}: REMOVED"
68       rm -f ${libgo}
69       git rm ${libgo}
70     fi
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
76     fi
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
82       fi
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
93       0)
94         echo "merge.sh: $name: updating"
95         mv ${libgo}.tmp ${libgo}
96         ;;
97       1)
98         echo "merge.sh: $name: CONFLICTS"
99         mv ${libgo}.tmp ${libgo}
100         ;;
101       *)
102         echo 1>&2 "merge.sh: $name: diff3 failure"
103         exit 1
104         ;;
105       esac
106     fi
107   else
108     # The file does not exist in the old version.
109     if test -f ${libgo}; then
110       if ! cmp -s ${new} ${libgo}; then
111         echo 1>&2 "merge.sh: $name: IN NEW AND LIBGO BUT NOT OLD"
112       fi
113     else
114       echo "merge.sh: $name: NEW"
115       dir=`dirname ${libgo}`
116       if ! test -d ${dir}; then
117         mkdir -p ${dir}
118       fi
119       cp ${new} ${libgo}
120       git add ${libgo}
121     fi
122   fi
123 }
124
125 merge_c() {
126   from=$1
127   to=$2
128   oldfile=${OLDDIR}/src/runtime/$from
129   if test -f ${oldfile}; then
130     sed -e 's/·/_/g' < ${oldfile} > ${oldfile}.tmp
131     oldfile=${oldfile}.tmp
132     newfile=${NEWDIR}/src/runtime/$from
133     sed -e 's/·/_/g' < ${newfile} > ${newfile}.tmp
134     newfile=${newfile}.tmp
135     libgofile=runtime/$to
136     merge $from ${oldfile} ${newfile} ${libgofile}
137   fi
138 }
139
140 if test -f VERSION; then
141   if ! cmp -s ${NEWDIR}/VERSION VERSION; then
142     cp ${NEWDIR}/VERSION .
143   fi
144 else
145   if test -f ${NEWDIR}/VERSION; then
146     cp ${NEWDIR}/VERSION .
147   fi
148 fi
149
150 (cd ${NEWDIR}/src && find . -name '*.go' -print) | while read f; do
151   oldfile=${OLDDIR}/src/$f
152   newfile=${NEWDIR}/src/$f
153   libgofile=go/$f
154   merge $f ${oldfile} ${newfile} ${libgofile}
155 done
156
157 (cd ${NEWDIR}/src && find . -name testdata -print) | while read d; do
158   oldtd=${OLDDIR}/src/$d
159   newtd=${NEWDIR}/src/$d
160   libgotd=go/$d
161   if ! test -d ${oldtd}; then
162     continue
163   fi
164   (cd ${oldtd} && git ls-files .) | while read f; do
165     if test "`basename $f`" = ".gitignore"; then
166       continue
167     fi
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
175
176 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"
177 for f in $runtime; do
178   # merge_c $f $f
179   true
180 done
181
182 # merge_c os_linux.c thread-linux.c
183 # merge_c mem_linux.c mem.c
184
185 (cd ${OLDDIR}/src && find . -name '*.go' -print) | while read f; do
186   oldfile=${OLDDIR}/src/$f
187   newfile=${NEWDIR}/src/$f
188   libgofile=go/$f
189   if test -f ${newfile}; then
190     continue
191   fi
192   if ! test -f ${libgofile}; then
193     continue
194   fi
195   echo "merge.sh: ${libgofile}: REMOVED"
196   rm -f ${libgofile}
197   git rm ${libgofile}
198 done
199
200 (echo ${new_rev}; sed -ne '2,$p' MERGE) > MERGE.tmp
201 mv MERGE.tmp MERGE