OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Convert PrivateScript's sources to C++ constant strings. | 5 """Convert PrivateScript's sources to C++ constant strings. |
6 FIXME: We don't want to add more build scripts. Rewrite this script in grit. crb
ug.com/388121 | 6 FIXME: We don't want to add more build scripts. Rewrite this script in grit. crb
ug.com/388121 |
7 | 7 |
8 Usage: | 8 Usage: |
9 python make_private_script_source.py DESTINATION_FILE SOURCE_FILES | 9 python make_private_script_source.py DESTINATION_FILE SOURCE_FILES |
10 """ | 10 """ |
(...skipping 28 matching lines...) Expand all Loading... |
39 contents = [] | 39 contents = [] |
40 for input_filename in input_filenames: | 40 for input_filename in input_filenames: |
41 class_name, ext = os.path.splitext(os.path.basename(input_filename)) | 41 class_name, ext = os.path.splitext(os.path.basename(input_filename)) |
42 with open(input_filename) as input_file: | 42 with open(input_filename) as input_file: |
43 input_text = input_file.read() | 43 input_text = input_file.read() |
44 hex_values = ['0x{0:02x}'.format(ord(char)) for char in input_text] | 44 hex_values = ['0x{0:02x}'.format(ord(char)) for char in input_text] |
45 contents.append('const unsigned char kSourceOf%s[] = {\n %s\n};\n
\n' % ( | 45 contents.append('const unsigned char kSourceOf%s[] = {\n %s\n};\n
\n' % ( |
46 class_name, ', '.join(hex_values))) | 46 class_name, ', '.join(hex_values))) |
47 contents.append('struct %s {' % source_name) | 47 contents.append('struct %s {' % source_name) |
48 contents.append(""" | 48 contents.append(""" |
| 49 const char* scriptClassName; |
49 const char* className; | 50 const char* className; |
50 const char* dependencyClassName; | |
51 const unsigned char* source; | 51 const unsigned char* source; |
52 size_t size; | 52 size_t size; |
53 }; | 53 }; |
54 | 54 |
55 """) | 55 """) |
56 contents.append('struct %s k%s[] = {\n' % (source_name, source_name)) | 56 contents.append('struct %s k%s[] = {\n' % (source_name, source_name)) |
57 for input_filename in input_filenames: | 57 for input_filename in input_filenames: |
58 class_name, ext = os.path.splitext(os.path.basename(input_filename)) | 58 script_class_name, ext = os.path.splitext(os.path.basename(input_filenam
e)) |
59 dependency_class_name = extract_partial_interface_name(input_filename) o
r class_name | 59 class_name = extract_partial_interface_name(input_filename) or script_cl
ass_name |
60 contents.append(' { "%s", "%s", kSourceOf%s, sizeof(kSourceOf%s) },\n
' % (class_name, dependency_class_name, class_name, class_name)) | 60 contents.append(' { "%s", "%s", kSourceOf%s, sizeof(kSourceOf%s) },\n
' % (script_class_name, class_name, script_class_name, script_class_name)) |
61 contents.append('};\n') | 61 contents.append('};\n') |
62 | 62 |
63 with open(output_filename, 'w') as output_file: | 63 with open(output_filename, 'w') as output_file: |
64 output_file.write("".join(contents)) | 64 output_file.write("".join(contents)) |
65 | 65 |
66 | 66 |
67 if __name__ == '__main__': | 67 if __name__ == '__main__': |
68 sys.exit(main()) | 68 sys.exit(main()) |
OLD | NEW |