Chromium Code Reviews| 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)) |