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

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

Issue 1961883002: Generate separate files for union type containers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 # Copyright 2014 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Utility functions (file reading, simple IDL parsing by regexes) for IDL build . 5 """Utility functions (file reading, simple IDL parsing by regexes) for IDL build .
6 6
7 Design doc: http://www.chromium.org/developers/design-documents/idl-build 7 Design doc: http://www.chromium.org/developers/design-documents/idl-build
8 """ 8 """
9 9
10 import os 10 import os
11 import cPickle as pickle 11 import cPickle as pickle
12 import platform
12 import re 13 import re
13 import shlex 14 import shlex
14 import string 15 import string
15 import subprocess 16 import subprocess
16 17
17 18
18 KNOWN_COMPONENTS = frozenset(['core', 'modules']) 19 KNOWN_COMPONENTS = frozenset(['core', 'modules'])
19 KNOWN_COMPONENTS_WITH_TESTING = frozenset(['core', 'modules', 'testing']) 20 KNOWN_COMPONENTS_WITH_TESTING = frozenset(['core', 'modules', 'testing'])
20 21
21 22
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 82
82 @property 83 @property
83 def typedefs(self): 84 def typedefs(self):
84 return {} 85 return {}
85 86
86 @property 87 @property
87 def union_types(self): 88 def union_types(self):
88 return set() 89 return set()
89 90
90 @property 91 @property
91 def include_path_for_union_types(self): 92 def include_path_for_union_types(self, name):
92 return None 93 return None
93 94
94 95
95 class ComponentInfoProviderCore(ComponentInfoProvider): 96 class ComponentInfoProviderCore(ComponentInfoProvider):
96 def __init__(self, interfaces_info, component_info): 97 def __init__(self, interfaces_info, component_info):
97 super(ComponentInfoProviderCore, self).__init__() 98 super(ComponentInfoProviderCore, self).__init__()
98 self._interfaces_info = interfaces_info 99 self._interfaces_info = interfaces_info
99 self._component_info = component_info 100 self._component_info = component_info
100 101
101 @property 102 @property
102 def interfaces_info(self): 103 def interfaces_info(self):
103 return self._interfaces_info 104 return self._interfaces_info
104 105
105 @property 106 @property
106 def component_info(self): 107 def component_info(self):
107 return self._component_info 108 return self._component_info
108 109
109 @property 110 @property
110 def enumerations(self): 111 def enumerations(self):
111 return self._component_info['enumerations'] 112 return self._component_info['enumerations']
112 113
113 @property 114 @property
114 def typedefs(self): 115 def typedefs(self):
115 return self._component_info['typedefs'] 116 return self._component_info['typedefs']
116 117
117 @property 118 @property
118 def union_types(self): 119 def union_types(self):
119 return self._component_info['union_types'] 120 return self._component_info['union_types']
120 121
121 @property 122 def include_path_for_union_types(self, name):
122 def include_path_for_union_types(self): 123 return 'bindings/core/v8/%s.h' % name
123 return 'bindings/core/v8/UnionTypesCore.h'
124 124
125 @property 125 @property
126 def specifier_for_export(self): 126 def specifier_for_export(self):
127 return 'CORE_EXPORT ' 127 return 'CORE_EXPORT '
128 128
129 @property 129 @property
130 def include_path_for_export(self): 130 def include_path_for_export(self):
131 return 'core/CoreExport.h' 131 return 'core/CoreExport.h'
132 132
133 133
(...skipping 24 matching lines...) Expand all
158 typedefs = self._component_info_core['typedefs'].copy() 158 typedefs = self._component_info_core['typedefs'].copy()
159 typedefs.update(self._component_info_modules['typedefs']) 159 typedefs.update(self._component_info_modules['typedefs'])
160 return typedefs 160 return typedefs
161 161
162 @property 162 @property
163 def union_types(self): 163 def union_types(self):
164 # Remove duplicate union types from component_info_modules to avoid 164 # Remove duplicate union types from component_info_modules to avoid
165 # generating multiple container generation. 165 # generating multiple container generation.
166 return self._component_info_modules['union_types'] - self._component_inf o_core['union_types'] 166 return self._component_info_modules['union_types'] - self._component_inf o_core['union_types']
167 167
168 @property 168 def include_path_for_union_types(self, name):
169 def include_path_for_union_types(self): 169 core_union_type_names = [union_type.name for union_type
170 return 'bindings/modules/v8/UnionTypesModules.h' 170 in self._component_info_core['union_types']]
171 if name in core_union_type_names:
172 return 'bindings/core/v8/%s.h' % name
173 return 'bindings/modules/v8/%s.h' % name
171 174
172 @property 175 @property
173 def specifier_for_export(self): 176 def specifier_for_export(self):
174 return 'MODULES_EXPORT ' 177 return 'MODULES_EXPORT '
175 178
176 @property 179 @property
177 def include_path_for_export(self): 180 def include_path_for_export(self):
178 return 'modules/ModulesExport.h' 181 return 'modules/ModulesExport.h'
179 182
180 183
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 idl_file_names.extend(resolve_cygpath(cygdrive_names)) 282 idl_file_names.extend(resolve_cygpath(cygdrive_names))
280 return idl_file_names 283 return idl_file_names
281 284
282 285
283 def read_pickle_files(pickle_filenames): 286 def read_pickle_files(pickle_filenames):
284 for pickle_filename in pickle_filenames: 287 for pickle_filename in pickle_filenames:
285 with open(pickle_filename) as pickle_file: 288 with open(pickle_filename) as pickle_file:
286 yield pickle.load(pickle_file) 289 yield pickle.load(pickle_file)
287 290
288 291
289 def write_file(new_text, destination_filename, only_if_changed): 292 def write_file(new_text, destination_filename, only_if_changed):
ncarter (slow) 2016/05/13 18:59:32 Just doing the following seems to fix the problem:
290 if only_if_changed and os.path.isfile(destination_filename): 293 if only_if_changed and os.path.isfile(destination_filename):
291 with open(destination_filename) as destination_file: 294 with open(destination_filename) as destination_file:
292 if destination_file.read() == new_text: 295 if destination_file.read() == new_text:
293 return 296 return
294 destination_dirname = os.path.dirname(destination_filename) 297 destination_dirname = os.path.dirname(destination_filename)
295 if not os.path.exists(destination_dirname): 298 if not os.path.exists(destination_dirname):
296 os.makedirs(destination_dirname) 299 os.makedirs(destination_dirname)
300 # Workaround for http://crbug.com/611437
301 # TODO(bashi): Remove this hack once we resolve too-long generated file
302 # names.
303 if platform.system() == 'Windows':
304 # http://stackoverflow.com/questions/14075465
305 destination_filename = '\\\\?\\' + destination_filename
297 with open(destination_filename, 'w') as destination_file: 306 with open(destination_filename, 'w') as destination_file:
298 destination_file.write(new_text) 307 destination_file.write(new_text)
299 308
300 309
301 def write_pickle_file(pickle_filename, data, only_if_changed): 310 def write_pickle_file(pickle_filename, data, only_if_changed):
302 if only_if_changed and os.path.isfile(pickle_filename): 311 if only_if_changed and os.path.isfile(pickle_filename):
303 with open(pickle_filename) as pickle_file: 312 with open(pickle_filename) as pickle_file:
304 try: 313 try:
305 if pickle.load(pickle_file) == data: 314 if pickle.load(pickle_file) == data:
306 return 315 return
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 extended_attributes_string = match.group(1) 386 extended_attributes_string = match.group(1)
378 match = re.search(r'[^=]\bExposed\(([^)]*)\)', file_contents) 387 match = re.search(r'[^=]\bExposed\(([^)]*)\)', file_contents)
379 if not match: 388 if not match:
380 return None 389 return None
381 arguments = [] 390 arguments = []
382 for argument in map(string.strip, match.group(1).split(',')): 391 for argument in map(string.strip, match.group(1).split(',')):
383 exposed, runtime_enabled = argument.split() 392 exposed, runtime_enabled = argument.split()
384 arguments.append({'exposed': exposed, 'runtime_enabled': runtime_enabled }) 393 arguments.append({'exposed': exposed, 'runtime_enabled': runtime_enabled })
385 394
386 return arguments 395 return arguments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698