Restore patch reverted on trunk instead of a branch
[official-gcc.git] / libsanitizer / merge.sh
blobdfa7bf3d196b5960c8e49da24dff47ca53bec014
1 #!/bin/bash
3 # FIXME: do we need a license (or whatever else) header here?
5 # This script merges libsanitizer sources from upstream.
7 VCS=${1:-svn}
9 get_upstream() {
10 rm -rf upstream
11 git clone https://github.com/llvm/llvm-project.git upstream
14 get_current_rev() {
15 cd upstream
16 git rev-parse HEAD
19 list_files() {
20 (cd $1; ls *.{cc,cpp,h,inc,S} 2> /dev/null)
24 change_comment_headers() {
25 for f in $(list_files $1); do
26 sed -n 3p $1/$f | grep -q 'The LLVM Compiler Infrastructure' || continue
27 changed=$(awk 'NR != 2 && NR != 3' < $1/$f)
28 echo "$changed" > $1/$f
29 done
32 # ARGUMENTS: upstream_path local_path
33 # This function merges changes from the directory upstream_path to
34 # the directory local_path.
35 merge() {
36 upstream_path=upstream/$1
37 local_path=$2
38 change_comment_headers $upstream_path
39 echo MERGE: $upstream_path
40 all=$( (list_files $upstream_path; list_files $local_path) | sort | uniq)
41 #echo $all
42 for f in $all; do
43 if [ -f $upstream_path/$f -a -f $local_path/$f ]; then
44 echo "FOUND IN BOTH :" $f
45 # diff -u $local_path/$f $upstream_path/$f
46 cp -v $upstream_path/$f $local_path
47 elif [ -f $upstream_path/$f ]; then
48 echo "FOUND IN UPSTREAM :" $f
49 cp -v $upstream_path/$f $local_path
50 $VCS add $local_path/$f
51 elif [ -f $local_path/$f ]; then
52 echo "FOUND IN LOCAL :" $f
53 $VCS rm $local_path/$f
55 done
59 fatal() {
60 echo "$1"
61 exit 1;
64 pwd | grep 'libsanitizer$' || \
65 fatal "Run this script from libsanitizer dir"
66 get_upstream
67 CUR_REV=$(get_current_rev)
68 echo Current upstream revision: $CUR_REV
69 merge include/sanitizer include/sanitizer
70 merge lib/asan asan
71 merge lib/lsan lsan
72 merge lib/tsan/rtl tsan
73 merge lib/sanitizer_common sanitizer_common
74 merge lib/interception interception
75 merge lib/ubsan ubsan
77 # Need to merge lib/builtins/assembly.h file:
78 mkdir -p builtins
79 cp -v upstream/lib/builtins/assembly.h builtins/assembly.h
81 rm -rf upstream
83 # Update the MERGE file.
84 cat << EOF > MERGE
85 $CUR_REV
87 The first line of this file holds the git revision number of the
88 last merge done from the master library sources.
89 EOF