merge.sh 2.1 KB

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