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

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

Issue 345893002: Implement an infrastructure of Blink-in-JS Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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
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())

Powered by Google App Engine
This is Rietveld 408576698