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