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

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

Issue 2318933002: [Bindings] Remove aggregation of generated binding code (Closed)
Patch Set: Fix import order 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
(Empty)
1 #!/usr/bin/python
2 #
3 # Copyright (C) 2009 Google Inc. All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
8 #
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
14 # distribution.
15 # * Neither the name of Google Inc. nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
30 #
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
33 # found in the LICENSE file.
34
35 """Generate aggregate .cpp files that include multiple V8 binding .cpp files.
36
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.
39
40 Usage:
41 aggregate_generated_bindings.py --component-directory COMPONENT_DIR --input-file IDL_FILES_LIST OUTPUT_FILE1 OUTPUT_FILE2 ...
42
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
45 line doesn't exceed OS length limits.
46 OUTPUT_FILE1 etc. are filenames of output files.
47
48 Design doc: http://www.chromium.org/developers/design-documents/idl-build
49 """
50
51 import errno
52 import optparse
53 import os
54 import re
55 import sys
56
57 from utilities import (should_generate_impl_file_from_idl,
58 get_file_contents,
59 idl_filename_to_interface_name,
60 read_idl_files_list_from_file)
61
62 COPYRIGHT_TEMPLATE = """/*
63 * THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT.
64 *
65 * This file was generated by the action_derivedsourcesallinone.py script.
66 *
67 * Copyright (C) 2009 Google Inc. All rights reserved.
68 *
69 * Redistribution and use in source and binary forms, with or without
70 * modification, are permitted provided that the following conditions
71 * are met:
72 * 1. Redistributions of source code must retain the above copyright
73 * notice, this list of conditions and the following disclaimer.
74 * 2. Redistributions in binary form must reproduce the above copyright
75 * notice, this list of conditions and the following disclaimer in the
76 * documentation and/or other materials provided with the distribution.
77 *
78 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
79 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
80 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
81 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
82 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
83 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
84 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
85 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
86 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
87 * (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.
89 */
90 """
91
92
93 def extract_meta_data(file_paths):
94 """Extracts interface name from each IDL file."""
95 meta_data_list = []
96
97 for file_path in file_paths:
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
119
120 def generate_content(component_dir, aggregate_partial_interfaces, files_meta_dat a_this_partition):
121 # Add fixed content.
122 output = [COPYRIGHT_TEMPLATE,
123 '#define NO_IMPLICIT_ATOMICSTRING\n\n']
124
125 # List all includes.
126 files_meta_data_this_partition.sort()
127 suffix = 'Partial' if aggregate_partial_interfaces else ''
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
134 return ''.join(output)
135
136
137 def write_content(content, output_file_name):
138 parent_path, file_name = os.path.split(output_file_name)
139 if not os.path.exists(parent_path):
140 print 'Creating directory: %s' % parent_path
141 os.makedirs(parent_path)
142 with open(output_file_name, 'w') as f:
143 f.write(content)
144
145
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():
168 options, output_file_names = parse_options()
169 component_dir = options.component_directory
170 input_file_name = options.input_file
171 aggregate_partial_interfaces = options.partial
172 idl_file_names = read_idl_files_list_from_file(input_file_name,
173 is_gyp_format=True)
174
175 files_meta_data = extract_meta_data(idl_file_names)
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
186
187 if __name__ == '__main__':
188 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698