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

Unified Diff: Source/bindings/scripts/aggregate_generated_dictionaries.py

Issue 386963003: [WIP][NotForLand] IDL dictionary support (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 5 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/bindings/scripts/aggregate_generated_dictionaries.py
diff --git a/Source/bindings/scripts/aggregate_generated_dictionaries.py b/Source/bindings/scripts/aggregate_generated_dictionaries.py
new file mode 100644
index 0000000000000000000000000000000000000000..a94c0f435272665aeec27993652a2957db77c6ea
--- /dev/null
+++ b/Source/bindings/scripts/aggregate_generated_dictionaries.py
@@ -0,0 +1,59 @@
+# 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.
+
+"""Aggregate generated dictionary impl classes.
+
+Usage:
+aggregate_generated_dictionaries.py COMPONENT_DIR INTERFACES_INFO OUTPUT_FILE
+
+COMPONENT_DIR is the name of a component, i.e., 'core' or 'modules'.
+INTERFACES_INFO is a pickle file generated by compute_interfaces_info_overall.py.
+OUTPUT_FILE is the filename of output.
+"""
+
+import cPickle as pickle
+import posixpath
+import sys
+from utilities import write_file
+
+
+COPYRIGHT = """// 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.
+"""
+
+
+def generate_path(interface_name, interface_info):
+ return posixpath.join(interface_info['relative_dir'],
+ '%s.cpp' % interface_name)
+
+
+def generate_content(generated_paths):
+ output = [COPYRIGHT,
+ '\n#define NO_IMPLICIT_ATOMICSTRING\n\n']
Nils Barth (inactive) 2014/07/18 21:52:33 How about \n in the header instead?
bashi 2014/07/22 02:33:56 Done.
+ for generated_path in sorted(generated_paths):
Nils Barth (inactive) 2014/07/18 21:52:33 generator expression (and output.extend)?
bashi 2014/07/22 02:33:56 Done.
+ output.append('#include "%s"\n' % generated_path)
+ return ''.join(output)
+
+
+def main(component_dir, interfaces_info, output_file_name):
+ generated_paths = [
+ generate_path(interface_name, interface_info)
+ for interface_name, interface_info in interfaces_info.iteritems()
+ if (interface_info['component_dir'] == component_dir and
+ interface_info['is_dictionary'])]
+ contents = generate_content(generated_paths)
+ write_file(contents, output_file_name, only_if_changed=True)
+
+
+if __name__ == '__main__':
Nils Barth (inactive) 2014/07/18 21:52:33 Should be: if __name__ == '__main__': sys.exit
bashi 2014/07/22 02:33:56 Done.
+ # FIXME: we might want to accept multiple output files.
+ if len(sys.argv) != 4:
+ raise Exception('Expected 3 arguments.')
+ component_dir = sys.argv[1]
+ interfaces_info_file_name = sys.argv[2]
+ with open(interfaces_info_file_name) as interfaces_info_file:
+ interfaces_info = pickle.load(interfaces_info_file)
+ output_file_name = sys.argv[3]
Nils Barth (inactive) 2014/07/18 21:52:33 Clearer to have all argv assignment together.
bashi 2014/07/22 02:33:56 Done.
+ sys.exit(main(component_dir, interfaces_info, output_file_name))

Powered by Google App Engine
This is Rietveld 408576698