Chromium Code Reviews| Index: Source/build/scripts/make_private_script_source.py |
| diff --git a/Source/build/scripts/make_private_script_source.py b/Source/build/scripts/make_private_script_source.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1770b758270f41d7815c4c00ffb5645812e203cf |
| --- /dev/null |
| +++ b/Source/build/scripts/make_private_script_source.py |
| @@ -0,0 +1,38 @@ |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""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
|
| + |
| +Usage: |
| +python make_private_script.py DESTINATION_FILE SOURCE_FILES |
| +""" |
| + |
| +import os |
| +import sys |
| + |
| + |
| +def main(): |
| + output_filename = sys.argv[1] |
| + input_filenames = sys.argv[2:] |
| + contents = '' |
|
Nils Barth (inactive)
2014/06/23 03:14:30
FWIW, in Python generally it's preferred to build
|
| + for input_filename in input_filenames: |
| + class_name, ext = os.path.splitext(os.path.basename(input_filename)) |
| + with open(input_filename) as input_file: |
| + input_text = input_file.read() |
| + hex_values = ['0x{0:02x}'.format(ord(char)) for char in input_text] |
| + contents += 'const unsigned char kSourceOf%s[] = {\n %s\n};\n' % ( |
| + class_name, ', '.join(hex_values)) |
| + contents += '\nstruct PrivateScriptSources {\n const char* name;\n const 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
|
| + contents += 'struct PrivateScriptSources kPrivateScriptSources[] = {\n' |
| + for input_filename in input_filenames: |
| + class_name, ext = os.path.splitext(os.path.basename(input_filename)) |
| + contents += ' { "%s", kSourceOf%s, sizeof(kSourceOf%s) },\n' % (class_name, class_name, class_name) |
| + contents += '};\n' |
| + |
| + with open(output_filename, 'w') as output_file: |
| + output_file.write(contents) |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main()) |