Chromium Code Reviews| 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. | |
|
Nils Barth (inactive)
2014/06/23 03:14:30
abarth@: should this be using GRIT or the like for
haraken
2014/06/23 06:01:46
That's a good point. At the moment I just added a
Nils Barth (inactive)
2014/06/23 06:21:25
Might be ok to do later, but would be better to do
| |
| 6 | |
| 7 Usage: | |
| 8 python make_private_script.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 = '' | |
|
Nils Barth (inactive)
2014/06/23 03:14:30
FWIW, in Python generally it's preferred to build
| |
| 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 PrivateScriptSources {\n const char* name;\n con st unsigned char* source;\n size_t size;\n};\n\n' | |
|
Nils Barth (inactive)
2014/06/23 03:14:30
This would be rather clearer as a multiline string
| |
| 27 contents += 'struct PrivateScriptSources kPrivateScriptSources[] = {\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 |