| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """Convert Blink-in-JS sources to C++ constant strings. |
| 6 |
| 7 Usage: |
| 8 python make_blink_in_js.py DESTINATION_FILE SOURCE_FILES |
| 9 """ |
| 10 |
| 11 import os |
| 12 import sys |
| 13 |
| 14 |
| 15 def main(): |
| 16 output_filename = sys.argv[1] |
| 17 input_filenames = sys.argv[2:] |
| 18 contents = '' |
| 19 for input_filename in input_filenames: |
| 20 class_name, ext = os.path.splitext(os.path.basename(input_filename)) |
| 21 with open(input_filename) as input_file: |
| 22 input_text = input_file.read() |
| 23 hex_values = ['0x{0:02x}'.format(ord(char)) for char in input_text] |
| 24 contents += 'const unsigned char kSourceOf%s[] = {\n %s\n};\n' %
( |
| 25 class_name, ', '.join(hex_values)) |
| 26 contents += '\nstruct BlinkInJSSources {\n const char* name;\n const u
nsigned char* source;\n size_t size;\n};\n\n' |
| 27 contents += 'struct BlinkInJSSources kBlinkInJSSources[] = {\n' |
| 28 for input_filename in input_filenames: |
| 29 class_name, ext = os.path.splitext(os.path.basename(input_filename)) |
| 30 contents += ' { "%s", kSourceOf%s, sizeof(kSourceOf%s) },\n' % (class
_name, class_name, class_name) |
| 31 contents += '};\n' |
| 32 |
| 33 with open(output_filename, 'w') as output_file: |
| 34 output_file.write(contents) |
| 35 |
| 36 |
| 37 if __name__ == '__main__': |
| 38 sys.exit(main()) |
| OLD | NEW |