OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 """Aggregate generated dictionary impl classes. | |
6 | |
7 Usage: | |
8 aggregate_generated_dictionaries.py COMPONENT_DIR INTERFACES_INFO OUTPUT_FILE | |
9 | |
10 COMPONENT_DIR is the name of a component, i.e., 'core' or 'modules'. | |
11 INTERFACES_INFO is a pickle file generated by compute_interfaces_info_overall.py . | |
12 OUTPUT_FILE is the filename of output. | |
13 """ | |
14 | |
15 import cPickle as pickle | |
16 import posixpath | |
17 import sys | |
18 from utilities import write_file | |
19 | |
20 | |
21 COPYRIGHT = """// Copyright 2014 The Chromium Authors. All rights reserved. | |
22 // Use of this source code is governed by a BSD-style license that can be | |
23 // found in the LICENSE file. | |
24 """ | |
25 | |
26 | |
27 def generate_path(interface_name, interface_info): | |
28 return posixpath.join(interface_info['relative_dir'], | |
29 '%s.cpp' % interface_name) | |
30 | |
31 | |
32 def generate_content(generated_paths): | |
33 output = [COPYRIGHT, | |
34 '\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.
| |
35 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.
| |
36 output.append('#include "%s"\n' % generated_path) | |
37 return ''.join(output) | |
38 | |
39 | |
40 def main(component_dir, interfaces_info, output_file_name): | |
41 generated_paths = [ | |
42 generate_path(interface_name, interface_info) | |
43 for interface_name, interface_info in interfaces_info.iteritems() | |
44 if (interface_info['component_dir'] == component_dir and | |
45 interface_info['is_dictionary'])] | |
46 contents = generate_content(generated_paths) | |
47 write_file(contents, output_file_name, only_if_changed=True) | |
48 | |
49 | |
50 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.
| |
51 # FIXME: we might want to accept multiple output files. | |
52 if len(sys.argv) != 4: | |
53 raise Exception('Expected 3 arguments.') | |
54 component_dir = sys.argv[1] | |
55 interfaces_info_file_name = sys.argv[2] | |
56 with open(interfaces_info_file_name) as interfaces_info_file: | |
57 interfaces_info = pickle.load(interfaces_info_file) | |
58 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.
| |
59 sys.exit(main(component_dir, interfaces_info, output_file_name)) | |
OLD | NEW |