xplatRegenByteCode.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/env python
  2. #-------------------------------------------------------------------------------------------------------
  3. # Copyright (C) Microsoft. All rights reserved.
  4. # Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  5. #-------------------------------------------------------------------------------------------------------
  6. # Regenerate embedded bytecode headers.
  7. # NOTEs:
  8. # 1. this script is for linux and macOS only, on windows please use RegenAllByteCode.cmd AND update_bytecode_version.ps1
  9. # 2. this script uses paths relative to the tools directory it's in so cd to it before running
  10. # 3. this script relies on forcing 64bit CC builds to produce 32bit bytecode - this could break due to future changes to CC.
  11. # If this facility breaks the CI will fail AND either this will need fixing or bytecode will need to be regenerated using
  12. # 32 bit builds on windows
  13. # 4. Run with flag '--skip-build' if the necessary versions of ChakraCore are already built to skip the compilation step
  14. # (this is useful if editing the .js files that the bytecode is produced from)
  15. # Two versions of CC and ch must be compiled for bytecode generation
  16. # ch is used to generate bytecode.
  17. # ch (NoJIT variety) is used to generate NoJIT bytecodes.
  18. import subprocess
  19. import sys
  20. import uuid
  21. # Compile ChakraCore both noJit and Jit variants
  22. def run_sub(message, commands, error):
  23. print(message)
  24. sub = subprocess.Popen(commands)
  25. sub.wait()
  26. if sub.returncode != 0:
  27. sys.exit(error)
  28. if len(sys.argv) == 1 or sys.argv[1] != '--skip-build':
  29. run_sub('Compiling ChakraCore with no Jit',
  30. ['../build.sh', '--no-jit', '--test-build', '--target-path=../out/noJit', '-j=2'],
  31. 'No Jit build failed - aborting bytecode generation')
  32. run_sub('Compiling ChakraCore with Jit',
  33. ['../build.sh', '--test-build', '--target-path=../out/Jit', '-j=2'],
  34. 'Jit build failed - aborting bytecode generation')
  35. # Regenerate the bytecode
  36. def bytecode_job(outPath, command, error):
  37. header = open(outPath, 'w')
  38. job = subprocess.Popen(command, stdout=header)
  39. job.wait()
  40. if job.returncode != 0:
  41. sys.exit(error)
  42. # INTL
  43. print('Generating INTL bytecode')
  44. bytecode_job('../lib/Runtime/Library/InJavascript/Intl.js.nojit.bc.64b.h',
  45. ['../out/noJit/test/ch', '-GenerateLibraryByteCodeHeader', '-Intl', '../lib/Runtime/Library/InJavascript/Intl.js'],
  46. 'Failed to generate INTL 64bit noJit bytecode')
  47. bytecode_job('../lib/Runtime/Library/InJavascript/Intl.js.nojit.bc.32b.h',
  48. ['../out/noJit/test/ch', '-GenerateLibraryByteCodeHeader', '-Intl', '-Force32BitByteCode','../lib/Runtime/Library/InJavascript/Intl.js'],
  49. 'Failed to generate INTL 32bit noJit bytecode')
  50. bytecode_job('../lib/Runtime/Library/InJavascript/Intl.js.bc.64b.h',
  51. ['../out/Jit/test/ch', '-GenerateLibraryByteCodeHeader', '-Intl', '../lib/Runtime/Library/InJavascript/Intl.js'],
  52. 'Failed to generate INTL 64bit bytecode')
  53. bytecode_job('../lib/Runtime/Library/InJavascript/Intl.js.bc.32b.h',
  54. ['../out/Jit/test/ch', '-GenerateLibraryByteCodeHeader', '-Intl', '-Force32BitByteCode','../lib/Runtime/Library/InJavascript/Intl.js'],
  55. 'Failed to generate INTL 32bit bytecode')
  56. # JsBuiltin
  57. print('Generating JsBuiltin Bytecode')
  58. bytecode_job('../lib/Runtime/Library/JsBuiltin/JsBuiltin.js.nojit.bc.64b.h',
  59. ['../out/noJit/test/ch', '-GenerateLibraryByteCodeHeader', '-JsBuiltIn', '-LdChakraLib', '../lib/Runtime/Library/JsBuiltin/JsBuiltin.js'],
  60. 'Failed to generate noJit 64bit JsBuiltin Bytecode')
  61. bytecode_job('../lib/Runtime/Library/JsBuiltin/JsBuiltin.js.nojit.bc.32b.h',
  62. ['../out/noJit/test/ch', '-GenerateLibraryByteCodeHeader', '-JsBuiltIn', '-LdChakraLib', '-Force32BitByteCode', '../lib/Runtime/Library/JsBuiltin/JsBuiltin.js'],
  63. 'Failed to generate noJit 32bit JsBuiltin Bytecode')
  64. bytecode_job('../lib/Runtime/Library/JsBuiltin/JsBuiltin.js.bc.64b.h',
  65. ['../out/Jit/test/ch', '-GenerateLibraryByteCodeHeader', '-JsBuiltIn', '-LdChakraLib', '../lib/Runtime/Library/JsBuiltin/JsBuiltin.js'],
  66. 'Failed to generate 64bit JsBuiltin Bytecode')
  67. bytecode_job('../lib/Runtime/Library/JsBuiltin/JsBuiltin.js.bc.32b.h',
  68. ['../out/Jit/test/ch', '-GenerateLibraryByteCodeHeader', '-JsBuiltIn', '-LdChakraLib', '-Force32BitByteCode', '../lib/Runtime/Library/JsBuiltin/JsBuiltin.js'],
  69. 'Failed to generate 32bit JsBuiltin Bytecode')
  70. # Bytecode regeneration complete - create a new GUID for it
  71. print('Generating new GUID for new bytecode')
  72. guid_header = open('../lib/Runtime/Bytecode/ByteCodeCacheReleaseFileVersion.h', 'w')
  73. guid = str(uuid.uuid4())
  74. output_str = '''//-------------------------------------------------------------------------------------------------------
  75. // Copyright (C) Microsoft. All rights reserved.
  76. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  77. //-------------------------------------------------------------------------------------------------------
  78. // NOTE: If there is a merge conflict the correct fix is to make a new GUID.
  79. // This file was generated with tools/xplatRegenByteCode.py
  80. // {%s}
  81. const GUID byteCodeCacheReleaseFileVersion =
  82. { 0x%s, 0x%s, 0x%s, {0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s } };
  83. ''' % (guid,
  84. guid[:8], guid[9:13], guid[14:18], guid[19:21], guid[21:23], guid[24:26],
  85. guid[26:28], guid[28:30], guid[30:32], guid[32:34], guid[-2:])
  86. guid_header.write(output_str)
  87. print('Bytecode successfully regenerated. Please rebuild ChakraCore to incorporate it.')