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: | |
haraken
2014/10/09 04:24:00
When can this happen?
tasak
2014/10/10 07:52:22
I found that os.path.split('/') returns '/', None.
| |
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 def is_valid_component_dependency(component, dependency): | |
43 assert component in KNOWN_COMPONENTS | |
44 assert dependency in KNOWN_COMPONENTS | |
45 if component == 'core' and dependency == 'modules': | |
46 return False | |
47 return True | |
38 | 48 |
39 | 49 |
40 ################################################################################ | 50 ################################################################################ |
41 # Basic file reading/writing | 51 # Basic file reading/writing |
42 ################################################################################ | 52 ################################################################################ |
43 | 53 |
44 def get_file_contents(filename): | 54 def get_file_contents(filename): |
45 with open(filename) as f: | 55 with open(filename) as f: |
46 return f.read() | 56 return f.read() |
47 | 57 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 | 222 |
213 def get_put_forward_interfaces_from_idl(file_contents): | 223 def get_put_forward_interfaces_from_idl(file_contents): |
214 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' | 224 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' |
215 r'readonly\s+' | 225 r'readonly\s+' |
216 r'attribute\s+' | 226 r'attribute\s+' |
217 r'(\w+)') | 227 r'(\w+)') |
218 return sorted(set(match.group(1) | 228 return sorted(set(match.group(1) |
219 for match in re.finditer(put_forwards_pattern, | 229 for match in re.finditer(put_forwards_pattern, |
220 file_contents, | 230 file_contents, |
221 flags=re.DOTALL))) | 231 flags=re.DOTALL))) |
OLD | NEW |