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 |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 def idl_filename_to_interface_name(idl_filename): | 25 def idl_filename_to_interface_name(idl_filename): |
26 # interface name is the root of the basename: InterfaceName.idl | 26 # interface name is the root of the basename: InterfaceName.idl |
27 return os.path.splitext(os.path.basename(idl_filename))[0] | 27 return os.path.splitext(os.path.basename(idl_filename))[0] |
28 | 28 |
29 | 29 |
30 def idl_filename_to_component(idl_filename): | 30 def idl_filename_to_component(idl_filename): |
31 path = os.path.dirname(os.path.realpath(idl_filename)) | 31 path = os.path.dirname(os.path.realpath(idl_filename)) |
32 while path: | 32 while path: |
33 dirname, basename = os.path.split(path) | 33 dirname, basename = os.path.split(path) |
| 34 if not basename: |
| 35 break |
34 if basename.lower() in KNOWN_COMPONENTS: | 36 if basename.lower() in KNOWN_COMPONENTS: |
35 return basename.lower() | 37 return basename.lower() |
36 path = dirname | 38 path = dirname |
37 raise 'Unknown component type for %s' % idl_filename | 39 raise Exception('Unknown component type for %s' % idl_filename) |
| 40 |
| 41 |
| 42 # See whether "component" can depend on "dependency" or not: |
| 43 # Suppose that we have interface X and Y: |
| 44 # - if X is a partial interface and Y is the original interface, |
| 45 # use is_valid_component_dependency(X, Y). |
| 46 # - if X implements Y, use is_valid_component_dependency(X, Y) |
| 47 # Suppose that X is a cpp file and Y is a header file: |
| 48 # - if X includes Y, use is_valid_component_dependency(X, Y) |
| 49 def is_valid_component_dependency(component, dependency): |
| 50 assert component in KNOWN_COMPONENTS |
| 51 assert dependency in KNOWN_COMPONENTS |
| 52 if component == 'core' and dependency == 'modules': |
| 53 return False |
| 54 return True |
38 | 55 |
39 | 56 |
40 ################################################################################ | 57 ################################################################################ |
41 # Basic file reading/writing | 58 # Basic file reading/writing |
42 ################################################################################ | 59 ################################################################################ |
43 | 60 |
44 def get_file_contents(filename): | 61 def get_file_contents(filename): |
45 with open(filename) as f: | 62 with open(filename) as f: |
46 return f.read() | 63 return f.read() |
47 | 64 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 229 |
213 def get_put_forward_interfaces_from_idl(file_contents): | 230 def get_put_forward_interfaces_from_idl(file_contents): |
214 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' | 231 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' |
215 r'readonly\s+' | 232 r'readonly\s+' |
216 r'attribute\s+' | 233 r'attribute\s+' |
217 r'(\w+)') | 234 r'(\w+)') |
218 return sorted(set(match.group(1) | 235 return sorted(set(match.group(1) |
219 for match in re.finditer(put_forwards_pattern, | 236 for match in re.finditer(put_forwards_pattern, |
220 file_contents, | 237 file_contents, |
221 flags=re.DOTALL))) | 238 flags=re.DOTALL))) |
OLD | NEW |