/src/third_party/mozjs/extract/js/src/zydis/update.sh

https://github.com/mongodb/mongo · Shell · 129 lines · 80 code · 20 blank · 29 comment · 5 complexity · 42f206c1bb85f369eb157ffcd98a7dab MD5 · raw file

  1. #!/usr/bin/env bash
  2. # Copyright 2019 Mozilla Foundation
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. # Usage: update.sh [-v version]
  17. #
  18. # The version is the github rev we want; the default is HEAD
  19. #
  20. # Script to pull a new version of zydis, assuming it looks like an
  21. # older version of zydis. (This is by no means assured.)
  22. if [ ! -d zydis -o ! -f zydis/moz.build ]; then
  23. echo "Run this script from the mozilla-central/js/src directory"
  24. exit 1
  25. fi
  26. REV="HEAD"
  27. if [ "$1" = "-v" ]; then
  28. REV=$2
  29. fi
  30. ZYDISTMP=$(pwd)/zydis_tmp
  31. ZYDISNEW=$(pwd)/zydis_new
  32. ZYDISOLD=$(pwd)/zydis_old
  33. rm -rf $ZYDISTMP $ZYDISNEW $ZYDISOLD
  34. # Get zydis
  35. echo "CLONING..."
  36. mkdir $ZYDISTMP
  37. (
  38. cd $ZYDISTMP
  39. git clone --recursive https://github.com/zyantific/zydis.git
  40. cd zydis
  41. git checkout $REV
  42. )
  43. # Copy Mozilla-created files
  44. echo "COPYING..."
  45. mkdir $ZYDISNEW
  46. cp zydis/{README.md,ZydisAPI.{cpp,h},Zy*ExportConfig.h,update.sh} $ZYDISNEW
  47. # Copy selected zydis files, and rename some
  48. echo "COPYING ZYDIS..."
  49. (
  50. cd $ZYDISNEW
  51. cp -R $ZYDISTMP/zydis/src Zydis
  52. cp -R $ZYDISTMP/zydis/include/Zydis/* Zydis
  53. cp $ZYDISTMP/zydis/LICENSE Zydis
  54. cp -R $ZYDISTMP/zydis/dependencies/zycore/src/ Zycore
  55. cp -R $ZYDISTMP/zydis/dependencies/zycore/include/Zycore/* Zycore
  56. cp $ZYDISTMP/zydis/dependencies/zycore/LICENSE Zycore
  57. rm -f Zycore/API/{Synchronization*,Terminal*,Thread*}
  58. mv Zydis/String.c Zydis/ZydisString.c
  59. mv Zycore/String.c Zycore/ZycoreString.c
  60. ( cd $ZYDISTMP/zydis ; git log -n 1 | grep '^commit' | awk '{ print $2 }' ) > imported-revision.txt
  61. )
  62. # Rewrite include paths to be Firefox-canonical and reflect new
  63. # locations of files.
  64. echo "REWRITING..."
  65. (
  66. cd $ZYDISNEW
  67. for fn in $(find . -name '*.h' -o -name '*.c'); do
  68. cat $fn | gawk '
  69. { if (match($0, /( *# *include +)<(Zy.*ExportConfig.h|Zy(dis|core).*\.h)>/, res)) {
  70. print res[1] "\"zydis/" res[2] "\""
  71. next
  72. } else if (match($0, /( *# *include +)<(Generated\/.*\.inc)>/, res)) {
  73. print res[1] "\"zydis/Zydis/" res[2] "\""
  74. next
  75. }
  76. print $0 }' > $fn.bak
  77. mv $fn.bak $fn
  78. done
  79. )
  80. # Generate moz.build from the sources
  81. echo "GENERATING MOZ.BUILD..."
  82. (
  83. cd $ZYDISNEW
  84. (
  85. cat <<EOF
  86. # This file was generated by update.sh
  87. FINAL_LIBRARY = 'js'
  88. # Includes should be relative to parent path
  89. LOCAL_INCLUDES += [
  90. '!..',
  91. '..'
  92. ]
  93. include('../js-config.mozbuild')
  94. include('../js-cxxflags.mozbuild')
  95. if CONFIG['JS_CODEGEN_X64'] or CONFIG['JS_CODEGEN_X86']:
  96. SOURCES += [
  97. EOF
  98. for fn in $(find . -name '*.c' -o -name '*.cpp' | ( LC_ALL=C sort --ignore-case ) | sed 's/\.\///'); do
  99. echo " '$fn',"
  100. done
  101. cat <<EOF
  102. ]
  103. EOF
  104. ) > moz.build
  105. )
  106. echo "CLEANING UP..."
  107. mv zydis $ZYDISOLD
  108. mv $ZYDISNEW zydis
  109. rm -rf $ZYDISTMP