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

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

Issue 2325973002: Remove aggregation of generated binding code. (Closed)
Patch Set: Fix build Created 4 years, 3 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 14 matching lines...) Expand all
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 # 30 #
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 """Generates a .cpp file that includes all V8 binding .cpp files for interfaces.
36 36
37 This can be a single output file, to preserve symbol space; or multiple output 37 It is expected to preserve symbol space, and to be acceptable to make static
38 files, to reduce maximum compilation unit size and allow parallel compilation. 38 build on Windows.
39 39
40 Usage: 40 Usage:
41 aggregate_generated_bindings.py --component-directory COMPONENT_DIR --input-file IDL_FILES_LIST OUTPUT_FILE1 OUTPUT_FILE2 ... 41 $ aggregate_generated_bindings.py --component COMPONENT IDL_FILES_LIST OUTPUT_F ILE
42 42
43 COMPONENT_DIR is the relative directory of a component, e.g., 'core', 'modules'. 43 COMPONENT 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
45 line doesn't exceed OS length limits. 45 OUTPUT_FILE is the filename of output file.
46 OUTPUT_FILE1 etc. are filenames of output files.
47 46
48 Design doc: http://www.chromium.org/developers/design-documents/idl-build 47 Design doc: http://www.chromium.org/developers/design-documents/idl-build
49 """ 48 """
50 49
51 import errno 50 import errno
52 import optparse 51 import optparse
53 import os 52 import os
54 import re 53 import re
55 import sys 54 import sys
56 55 from utilities import idl_filename_to_interface_name
57 from utilities import (should_generate_impl_file_from_idl, 56 from utilities import read_idl_files_list_from_file
58 get_file_contents,
59 idl_filename_to_interface_name,
60 read_idl_files_list_from_file)
61 57
62 COPYRIGHT_TEMPLATE = """/* 58 COPYRIGHT_TEMPLATE = """/*
63 * THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT. 59 * THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT.
64 * 60 *
65 * This file was generated by the action_derivedsourcesallinone.py script. 61 * This file was generated by the action_derivedsourcesallinone.py script.
66 * 62 *
67 * Copyright (C) 2009 Google Inc. All rights reserved. 63 * Copyright (C) 2009 Google Inc. All rights reserved.
68 * 64 *
69 * Redistribution and use in source and binary forms, with or without 65 * Redistribution and use in source and binary forms, with or without
70 * modification, are permitted provided that the following conditions 66 * modification, are permitted provided that the following conditions
(...skipping 11 matching lines...) Expand all
82 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 78 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
83 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 79 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
84 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 80 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
85 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 81 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
86 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 82 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
87 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 83 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
88 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 84 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
89 */ 85 */
90 """ 86 """
91 87
88 def parse_options():
89 parser = optparse.OptionParser()
90 parser.add_option('--component')
92 91
93 def extract_meta_data(file_paths): 92 options, args = parser.parse_args()
94 """Extracts interface name from each IDL file.""" 93 if len(args) < 2:
95 meta_data_list = [] 94 raise Exception('Expected 2 filenames; one is for input, and the other i s for output.')
96 95
97 for file_path in file_paths: 96 return options, args
98 if not file_path.endswith('.idl'):
99 print 'WARNING: non-IDL file passed: "%s"' % file_path
100 continue
101 if not os.path.exists(file_path):
102 print 'WARNING: file not found: "%s"' % file_path
103 continue
104
105 idl_file_contents = get_file_contents(file_path)
106 if not should_generate_impl_file_from_idl(idl_file_contents):
107 continue
108
109 # Extract interface name from file name
110 interface_name = idl_filename_to_interface_name(file_path)
111
112 meta_data = {
113 'name': interface_name,
114 }
115 meta_data_list.append(meta_data)
116
117 return meta_data_list
118 97
119 98
120 def generate_content(component_dir, aggregate_partial_interfaces, files_meta_dat a_this_partition): 99 def generate_content(component, interface_names):
121 # Add fixed content. 100 # Add fixed content.
122 output = [COPYRIGHT_TEMPLATE, 101 output = [COPYRIGHT_TEMPLATE,
123 '#define NO_IMPLICIT_ATOMICSTRING\n\n'] 102 '#define NO_IMPLICIT_ATOMICSTRING\n\n']
124 103
125 # List all includes. 104 interface_names.sort()
126 files_meta_data_this_partition.sort() 105 output.extend('#include "bindings/%s/v8/V8%s.cpp"\n' % (component, interface )
127 suffix = 'Partial' if aggregate_partial_interfaces else '' 106 for interface in interface_names)
128 for meta_data in files_meta_data_this_partition:
129 cpp_filename = 'V8%s%s.cpp' % (meta_data['name'], suffix)
130
131 output.append('#include "bindings/%s/v8/%s"\n' %
132 (component_dir, cpp_filename))
133 107
134 return ''.join(output) 108 return ''.join(output)
135 109
136 110
137 def write_content(content, output_file_name): 111 def write_content(content, output_file_name):
138 parent_path, file_name = os.path.split(output_file_name) 112 parent_path, file_name = os.path.split(output_file_name)
139 if not os.path.exists(parent_path): 113 if not os.path.exists(parent_path):
140 print 'Creating directory: %s' % parent_path 114 print 'Creating directory: %s' % parent_path
141 os.makedirs(parent_path) 115 os.makedirs(parent_path)
142 with open(output_file_name, 'w') as f: 116 with open(output_file_name, 'w') as f:
143 f.write(content) 117 f.write(content)
144 118
145 119
146 def parse_options():
147 parser = optparse.OptionParser()
148 parser.add_option('--component-directory')
149 parser.add_option('--input-file',
150 help='A file name which lists up target IDL file names.',
151 type='string')
152 parser.add_option('--partial',
153 help='To parse partial IDLs, add this option.',
154 action='store_true',
155 dest='partial',
156 default=False)
157
158 options, output_file_names = parser.parse_args()
159 if len(output_file_names) == 0:
160 raise Exception('Expected at least one output file name(s).')
161 if not options.input_file:
162 raise Exception('No input file is specified.')
163
164 return options, output_file_names
165
166
167 def main(): 120 def main():
168 options, output_file_names = parse_options() 121 options, filenames = parse_options()
169 component_dir = options.component_directory 122 component = options.component
170 input_file_name = options.input_file 123 idl_filenames = read_idl_files_list_from_file(filenames[0],
171 aggregate_partial_interfaces = options.partial 124 is_gyp_format=False)
172 idl_file_names = read_idl_files_list_from_file(input_file_name, 125 interface_names = [idl_filename_to_interface_name(file_path)
173 is_gyp_format=True) 126 for file_path in idl_filenames]
174 127 file_contents = generate_content(component, interface_names)
175 files_meta_data = extract_meta_data(idl_file_names) 128 write_content(file_contents, filenames[1])
176 total_partitions = len(output_file_names)
177 for partition, file_name in enumerate(output_file_names):
178 files_meta_data_this_partition = [
179 meta_data for meta_data in files_meta_data
180 if hash(meta_data['name']) % total_partitions == partition]
181 file_contents = generate_content(component_dir,
182 aggregate_partial_interfaces,
183 files_meta_data_this_partition)
184 write_content(file_contents, file_name)
185 129
186 130
187 if __name__ == '__main__': 131 if __name__ == '__main__':
188 sys.exit(main()) 132 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698