| 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 PrivateScript's sources to C++ constant strings. |
| 6 FIXME: Move this script to grit. |
| 7 |
| 8 Usage: |
| 9 python make_private_script.py DESTINATION_FILE SOURCE_FILES |
| 10 """ |
| 11 |
| 12 import os |
| 13 import sys |
| 14 |
| 15 |
| 16 def main(): |
| 17 output_filename = sys.argv[1] |
| 18 input_filenames = sys.argv[2:] |
| 19 contents = [] |
| 20 for input_filename in input_filenames: |
| 21 class_name, ext = os.path.splitext(os.path.basename(input_filename)) |
| 22 with open(input_filename) as input_file: |
| 23 input_text = input_file.read() |
| 24 hex_values = ['0x{0:02x}'.format(ord(char)) for char in input_text] |
| 25 contents.append('const unsigned char kSourceOf%s[] = {\n %s\n};\n
' % ( |
| 26 class_name, ', '.join(hex_values))) |
| 27 contents.append(""" |
| 28 struct PrivateScriptSources { |
| 29 const char* name; |
| 30 const unsigned char* source; |
| 31 size_t size; |
| 32 }; |
| 33 |
| 34 """) |
| 35 contents.append('struct PrivateScriptSources kPrivateScriptSources[] = {\n') |
| 36 for input_filename in input_filenames: |
| 37 class_name, ext = os.path.splitext(os.path.basename(input_filename)) |
| 38 contents.append(' { "%s", kSourceOf%s, sizeof(kSourceOf%s) },\n' % (c
lass_name, class_name, class_name)) |
| 39 contents.append('};\n') |
| 40 |
| 41 with open(output_filename, 'w') as output_file: |
| 42 output_file.write("".join(contents)) |
| 43 |
| 44 |
| 45 if __name__ == '__main__': |
| 46 sys.exit(main()) |
| OLD | NEW |