Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Unified Diff: Source/build/scripts/make_private_script_source.py

Issue 569063002: Reland [blink-in-js] Migrate resources required for blink-in-js to grd - part 3 (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased patch Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/core/v8/PrivateScriptRunner.cpp ('k') | Source/core/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index 8064ae710121deaeadae34f7fbb517778f441e9b..19078b2eae6dab7e22257ca46c41844712ceeb35 100644
--- a/Source/build/scripts/make_private_script_source.py
+++ b/Source/build/scripts/make_private_script_source.py
@@ -9,6 +9,7 @@ Usage:
python make_private_script_source.py DESTINATION_FILE SOURCE_FILES
"""
+import optparse
import os
import re
import sys
@@ -32,34 +33,51 @@ def extract_partial_interface_name(filename):
def main():
- output_filename = sys.argv[1]
- input_filenames = sys.argv[2:]
+ parser = optparse.OptionParser()
+ parser.add_option('--for-testing', action="store_true", default=False)
+
+ options, args = parser.parse_args()
+ output_filename = args[0]
+ input_filenames = args[1:]
source_name, ext = os.path.splitext(os.path.basename(output_filename))
contents = []
- 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.append('const unsigned char kSourceOf%s[] = {\n %s\n};\n\n' % (
- class_name, ', '.join(hex_values)))
+ contents.append('#ifndef %s_h\n' % source_name)
+ contents.append('#define %s_h\n' % source_name)
+ if options.for_testing:
+ 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.append('const char kSourceOf%s[] = {\n %s\n};\n\n' % (
+ class_name, ', '.join(hex_values)))
contents.append('struct %s {' % source_name)
contents.append("""
const char* scriptClassName;
const char* className;
- const unsigned char* source;
- size_t size;
+ """)
+ if options.for_testing:
+ contents.append("""
+ const char* source;
+ size_t size;""")
+ else:
+ contents.append('const char* resourceFile;')
+ contents.append("""
};
""")
+
contents.append('struct %s k%s[] = {\n' % (source_name, source_name))
for input_filename in input_filenames:
script_class_name, ext = os.path.splitext(os.path.basename(input_filename))
class_name = extract_partial_interface_name(input_filename) or script_class_name
- contents.append(' { "%s", "%s", kSourceOf%s, sizeof(kSourceOf%s) },\n' % (script_class_name, class_name, script_class_name, script_class_name))
+ if options.for_testing:
+ contents.append(' { "%s", "%s", kSourceOf%s, sizeof(kSourceOf%s) },\n' % (script_class_name, class_name, script_class_name, script_class_name))
+ else:
+ contents.append(' { "%s", "%s", "%s.js" },\n' % (script_class_name, class_name, script_class_name))
contents.append('};\n')
-
+ contents.append('#endif // %s_h\n' % source_name)
with open(output_filename, 'w') as output_file:
output_file.write("".join(contents))
« no previous file with comments | « Source/bindings/core/v8/PrivateScriptRunner.cpp ('k') | Source/core/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698