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

Side by Side Diff: third_party/WebKit/Source/bindings/scripts/aggregate_generated_bindings.py

Issue 2248363002: [Bindings] Add option parser in aggregate_generated_bindings.py (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright (C) 2009 Google Inc. All rights reserved. 3 # Copyright (C) 2009 Google Inc. All rights reserved.
4 # 4 #
5 # Redistribution and use in source and binary forms, with or without 5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are 6 # modification, are permitted provided that the following conditions are
7 # met: 7 # met:
8 # 8 #
9 # * Redistributions of source code must retain the above copyright 9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer. 10 # notice, this list of conditions and the following disclaimer.
(...skipping 20 matching lines...) Expand all
31 # Copyright (c) 2009 The Chromium Authors. All rights reserved. 31 # Copyright (c) 2009 The Chromium Authors. All rights reserved.
32 # Use of this source code is governed by a BSD-style license that can be 32 # Use of this source code is governed by a BSD-style license that can be
33 # found in the LICENSE file. 33 # found in the LICENSE file.
34 34
35 """Generate aggregate .cpp files that include multiple V8 binding .cpp files. 35 """Generate aggregate .cpp files that include multiple V8 binding .cpp files.
36 36
37 This can be a single output file, to preserve symbol space; or multiple output 37 This can be a single output file, to preserve symbol space; or multiple output
38 files, to reduce maximum compilation unit size and allow parallel compilation. 38 files, to reduce maximum compilation unit size and allow parallel compilation.
39 39
40 Usage: 40 Usage:
41 aggregate_generated_bindings.py COMPONENT_DIR IDL_FILES_LIST -- OUTPUT_FILE1 OUT PUT_FILE2 ... 41 aggregate_generated_bindings.py --component-directory COMPONENT_DIR --input-file IDL_FILES_LIST OUTPUT_FILE1 OUTPUT_FILE2 ...
42 42
43 COMPONENT_DIR is the relative directory of a component, e.g., 'core', 'modules'. 43 COMPONENT_DIR is the relative directory of a component, e.g., 'core', 'modules'.
44 IDL_FILES_LIST is a text file containing the IDL file paths, so the command 44 IDL_FILES_LIST is a text file containing the IDL file paths, so the command
45 line doesn't exceed OS length limits. 45 line doesn't exceed OS length limits.
46 OUTPUT_FILE1 etc. are filenames of output files. 46 OUTPUT_FILE1 etc. are filenames of output files.
47 47
48 Design doc: http://www.chromium.org/developers/design-documents/idl-build 48 Design doc: http://www.chromium.org/developers/design-documents/idl-build
49 """ 49 """
50 50
51 import errno 51 import errno
52 import optparse
52 import os 53 import os
53 import re 54 import re
54 import sys 55 import sys
55 56
56 from utilities import should_generate_impl_file_from_idl, get_file_contents, idl _filename_to_component, idl_filename_to_interface_name, read_idl_files_list_from _file 57 from utilities import should_generate_impl_file_from_idl, get_file_contents, idl _filename_to_component, idl_filename_to_interface_name, read_idl_files_list_from _file
57 58
58 COPYRIGHT_TEMPLATE = """/* 59 COPYRIGHT_TEMPLATE = """/*
59 * THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT. 60 * THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT.
60 * 61 *
61 * This file was generated by the action_derivedsourcesallinone.py script. 62 * This file was generated by the action_derivedsourcesallinone.py script.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 135
135 def write_content(content, output_file_name): 136 def write_content(content, output_file_name):
136 parent_path, file_name = os.path.split(output_file_name) 137 parent_path, file_name = os.path.split(output_file_name)
137 if not os.path.exists(parent_path): 138 if not os.path.exists(parent_path):
138 print 'Creating directory: %s' % parent_path 139 print 'Creating directory: %s' % parent_path
139 os.makedirs(parent_path) 140 os.makedirs(parent_path)
140 with open(output_file_name, 'w') as f: 141 with open(output_file_name, 'w') as f:
141 f.write(content) 142 f.write(content)
142 143
143 144
144 def main(args): 145 def parse_options():
145 if len(args) <= 4: 146 parser = optparse.OptionParser()
146 raise Exception('Expected at least 5 arguments.') 147 parser.add_option('--component-directory')
147 component_dir = args[1] 148 parser.add_option('--input-file',
148 input_file_name = args[2] 149 help='A file name which lists up target IDL file names.',
149 in_out_break_index = args.index('--') 150 type='string')
150 output_file_names = args[in_out_break_index + 1:] 151
152 options, output_file_names = parser.parse_args()
153 if len(output_file_names) == 0:
154 raise Exception('Expected at least one output file name(s).')
155 if not options.input_file:
156 raise Exception('No input file is specified.')
157
158 return options, output_file_names
159
160
161 def main():
162 options, output_file_names = parse_options()
163 component_dir = options.component_directory
164 input_file_name = options.input_file
151 165
152 idl_file_names = read_idl_files_list_from_file(input_file_name, 166 idl_file_names = read_idl_files_list_from_file(input_file_name,
153 is_gyp_format=True) 167 is_gyp_format=True)
154 components = set([idl_filename_to_component(filename) 168 components = set([idl_filename_to_component(filename)
155 for filename in idl_file_names]) 169 for filename in idl_file_names])
156 if len(components) != 1: 170 if len(components) != 1:
157 raise Exception('Cannot aggregate generated codes in different component s') 171 raise Exception('Cannot aggregate generated codes in different component s')
158 aggregate_partial_interfaces = component_dir not in components 172 aggregate_partial_interfaces = component_dir not in components
159 173
160 files_meta_data = extract_meta_data(idl_file_names) 174 files_meta_data = extract_meta_data(idl_file_names)
161 total_partitions = len(output_file_names) 175 total_partitions = len(output_file_names)
162 for partition, file_name in enumerate(output_file_names): 176 for partition, file_name in enumerate(output_file_names):
163 files_meta_data_this_partition = [ 177 files_meta_data_this_partition = [
164 meta_data for meta_data in files_meta_data 178 meta_data for meta_data in files_meta_data
165 if hash(meta_data['name']) % total_partitions == partition] 179 if hash(meta_data['name']) % total_partitions == partition]
166 file_contents = generate_content(component_dir, 180 file_contents = generate_content(component_dir,
167 aggregate_partial_interfaces, 181 aggregate_partial_interfaces,
168 files_meta_data_this_partition) 182 files_meta_data_this_partition)
169 write_content(file_contents, file_name) 183 write_content(file_contents, file_name)
170 184
171 185
172 if __name__ == '__main__': 186 if __name__ == '__main__':
173 sys.exit(main(sys.argv)) 187 sys.exit(main())
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/modules/v8/generated.gyp ('k') | third_party/WebKit/Source/bindings/scripts/scripts.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698