| OLD | NEW |
| 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 re | 12 import re |
| 13 import shlex |
| 13 import string | 14 import string |
| 14 import subprocess | 15 import subprocess |
| 15 | 16 |
| 16 | 17 |
| 17 KNOWN_COMPONENTS = frozenset(['core', 'modules']) | 18 KNOWN_COMPONENTS = frozenset(['core', 'modules']) |
| 18 KNOWN_COMPONENTS_WITH_TESTING = frozenset(['core', 'modules', 'testing']) | 19 KNOWN_COMPONENTS_WITH_TESTING = frozenset(['core', 'modules', 'testing']) |
| 19 | 20 |
| 20 | 21 |
| 21 def idl_filename_to_interface_name(idl_filename): | 22 def idl_filename_to_interface_name(idl_filename): |
| 22 # interface name is the root of the basename: InterfaceName.idl | 23 # interface name is the root of the basename: InterfaceName.idl |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 @property | 176 @property |
| 176 def include_path_for_export(self): | 177 def include_path_for_export(self): |
| 177 return 'modules/ModulesExport.h' | 178 return 'modules/ModulesExport.h' |
| 178 | 179 |
| 179 | 180 |
| 180 def load_interfaces_info_overall_pickle(info_dir): | 181 def load_interfaces_info_overall_pickle(info_dir): |
| 181 with open(os.path.join(info_dir, 'modules', 'InterfacesInfoOverall.pickle'))
as interface_info_file: | 182 with open(os.path.join(info_dir, 'modules', 'InterfacesInfoOverall.pickle'))
as interface_info_file: |
| 182 return pickle.load(interface_info_file) | 183 return pickle.load(interface_info_file) |
| 183 | 184 |
| 184 | 185 |
| 186 def merge_dict_recursively(target, diff): |
| 187 """Merges two dicts into one. |
| 188 |target| will be updated with |diff|. Part of |diff| may be re-used in |
| 189 |target|. |
| 190 """ |
| 191 for key, value in diff.iteritems(): |
| 192 if key not in target: |
| 193 target[key] = value |
| 194 elif type(value) == dict: |
| 195 merge_dict_recursively(target[key], value) |
| 196 elif type(value) == list: |
| 197 target[key].extend(value) |
| 198 elif type(value) == set: |
| 199 target[key].update(value) |
| 200 else: |
| 201 # Testing IDLs want to overwrite the values. Production code |
| 202 # doesn't need any overwriting. |
| 203 target[key] = value |
| 204 |
| 205 |
| 185 def create_component_info_provider_core(info_dir): | 206 def create_component_info_provider_core(info_dir): |
| 186 interfaces_info = load_interfaces_info_overall_pickle(info_dir) | 207 interfaces_info = load_interfaces_info_overall_pickle(info_dir) |
| 187 with open(os.path.join(info_dir, 'core', 'ComponentInfoCore.pickle')) as com
ponent_info_file: | 208 with open(os.path.join(info_dir, 'core', 'ComponentInfoCore.pickle')) as com
ponent_info_file: |
| 188 component_info = pickle.load(component_info_file) | 209 component_info = pickle.load(component_info_file) |
| 189 return ComponentInfoProviderCore(interfaces_info, component_info) | 210 return ComponentInfoProviderCore(interfaces_info, component_info) |
| 190 | 211 |
| 191 | 212 |
| 192 def create_component_info_provider_modules(info_dir): | 213 def create_component_info_provider_modules(info_dir): |
| 193 interfaces_info = load_interfaces_info_overall_pickle(info_dir) | 214 interfaces_info = load_interfaces_info_overall_pickle(info_dir) |
| 194 with open(os.path.join(info_dir, 'core', 'ComponentInfoCore.pickle')) as com
ponent_info_file: | 215 with open(os.path.join(info_dir, 'core', 'ComponentInfoCore.pickle')) as com
ponent_info_file: |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 idl_file_names = [] | 252 idl_file_names = [] |
| 232 for file_name in cygdrive_names: | 253 for file_name in cygdrive_names: |
| 233 process.stdin.write('%s\n' % file_name) | 254 process.stdin.write('%s\n' % file_name) |
| 234 process.stdin.flush() | 255 process.stdin.flush() |
| 235 idl_file_names.append(process.stdout.readline().rstrip()) | 256 idl_file_names.append(process.stdout.readline().rstrip()) |
| 236 process.stdin.close() | 257 process.stdin.close() |
| 237 process.wait() | 258 process.wait() |
| 238 return idl_file_names | 259 return idl_file_names |
| 239 | 260 |
| 240 | 261 |
| 241 def read_idl_files_list_from_file(filename): | 262 def read_idl_files_list_from_file(filename, is_gyp_format): |
| 242 """Similar to read_file_to_list, but also resolves cygpath.""" | 263 """Similar to read_file_to_list, but also resolves cygpath. |
| 264 |
| 265 If is_gyp_format is True, the file is treated as a newline-separated list |
| 266 with no quoting or escaping. When False, the file is interpreted as a |
| 267 Posix-style quoted and space-separated list.""" |
| 243 with open(filename) as input_file: | 268 with open(filename) as input_file: |
| 244 file_names = sorted([os.path.realpath(line.rstrip('\n')) | 269 if is_gyp_format: |
| 245 for line in input_file]) | 270 file_names = sorted([os.path.realpath(line.rstrip('\n')) |
| 271 for line in input_file]) |
| 272 else: |
| 273 file_names = sorted(shlex.split(input_file)) |
| 274 |
| 246 idl_file_names = [file_name for file_name in file_names | 275 idl_file_names = [file_name for file_name in file_names |
| 247 if not file_name.startswith('/cygdrive')] | 276 if not file_name.startswith('/cygdrive')] |
| 248 cygdrive_names = [file_name for file_name in file_names | 277 cygdrive_names = [file_name for file_name in file_names |
| 249 if file_name.startswith('/cygdrive')] | 278 if file_name.startswith('/cygdrive')] |
| 250 idl_file_names.extend(resolve_cygpath(cygdrive_names)) | 279 idl_file_names.extend(resolve_cygpath(cygdrive_names)) |
| 251 return idl_file_names | 280 return idl_file_names |
| 252 | 281 |
| 253 | 282 |
| 254 def read_pickle_files(pickle_filenames): | 283 def read_pickle_files(pickle_filenames): |
| 255 for pickle_filename in pickle_filenames: | 284 for pickle_filename in pickle_filenames: |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 extended_attributes_string = match.group(1) | 377 extended_attributes_string = match.group(1) |
| 349 match = re.search(r'[^=]\bExposed\(([^)]*)\)', file_contents) | 378 match = re.search(r'[^=]\bExposed\(([^)]*)\)', file_contents) |
| 350 if not match: | 379 if not match: |
| 351 return None | 380 return None |
| 352 arguments = [] | 381 arguments = [] |
| 353 for argument in map(string.strip, match.group(1).split(',')): | 382 for argument in map(string.strip, match.group(1).split(',')): |
| 354 exposed, runtime_enabled = argument.split() | 383 exposed, runtime_enabled = argument.split() |
| 355 arguments.append({'exposed': exposed, 'runtime_enabled': runtime_enabled
}) | 384 arguments.append({'exposed': exposed, 'runtime_enabled': runtime_enabled
}) |
| 356 | 385 |
| 357 return arguments | 386 return arguments |
| OLD | NEW |