| 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 21 matching lines...) Expand all Loading... |
| 32 with open(filename) as f: | 32 with open(filename) as f: |
| 33 return f.read() | 33 return f.read() |
| 34 | 34 |
| 35 | 35 |
| 36 def read_file_to_list(filename): | 36 def read_file_to_list(filename): |
| 37 """Returns a list of (stripped) lines for a given filename.""" | 37 """Returns a list of (stripped) lines for a given filename.""" |
| 38 with open(filename) as f: | 38 with open(filename) as f: |
| 39 return [line.rstrip('\n') for line in f] | 39 return [line.rstrip('\n') for line in f] |
| 40 | 40 |
| 41 | 41 |
| 42 def resolve_cygpath(cygdrive_names): | |
| 43 if not cygdrive_names: | |
| 44 return [] | |
| 45 cmd = ['cygpath', '-f', '-', '-wa'] | |
| 46 process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIP
E, stderr=subprocess.STDOUT) | |
| 47 idl_file_names = [] | |
| 48 for file_name in cygdrive_names: | |
| 49 process.stdin.write('%s\n' % file_name) | |
| 50 process.stdin.flush() | |
| 51 idl_file_names.append(process.stdout.readline().rstrip()) | |
| 52 process.stdin.close() | |
| 53 process.wait() | |
| 54 return idl_file_names | |
| 55 | |
| 56 | |
| 57 def read_idl_files_list_from_file(filename): | 42 def read_idl_files_list_from_file(filename): |
| 58 """Similar to read_file_to_list, but also resolves cygpath.""" | 43 """Similar to read_file_to_list, but also resolves cygpath.""" |
| 59 with open(filename) as input_file: | 44 with open(filename) as input_file: |
| 60 file_names = sorted([os.path.realpath(line.rstrip('\n')) | 45 file_names = sorted([os.path.realpath(line.rstrip('\n')) |
| 61 for line in input_file]) | 46 for line in input_file]) |
| 62 idl_file_names = [file_name for file_name in file_names | 47 idl_file_names = [file_name for file_name in file_names |
| 63 if not file_name.startswith('/cygdrive')] | 48 if not file_name.startswith('/cygdrive')] |
| 64 cygdrive_names = [file_name for file_name in file_names | 49 cygdrive_names = [file_name for file_name in file_names |
| 65 if file_name.startswith('/cygdrive')] | 50 if file_name.startswith('/cygdrive')] |
| 66 idl_file_names.extend(resolve_cygpath(cygdrive_names)) | 51 idl_file_names.extend(resolve_cygpath(cygdrive_names)) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 return ( | 129 return ( |
| 145 [left for left, right in implements_pairs if right == interface_name], | 130 [left for left, right in implements_pairs if right == interface_name], |
| 146 [right for left, right in implements_pairs if left == interface_name]) | 131 [right for left, right in implements_pairs if left == interface_name]) |
| 147 | 132 |
| 148 | 133 |
| 149 def is_callback_interface_from_idl(file_contents): | 134 def is_callback_interface_from_idl(file_contents): |
| 150 match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents) | 135 match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents) |
| 151 return bool(match) | 136 return bool(match) |
| 152 | 137 |
| 153 | 138 |
| 154 def is_dictionary_from_idl(file_contents): | |
| 155 match = re.search(r'dictionary\s+\w+\s*{', file_contents) | |
| 156 return bool(match) | |
| 157 | |
| 158 | |
| 159 def get_parent_interface(file_contents): | 139 def get_parent_interface(file_contents): |
| 160 match = re.search(r'interface\s+' | 140 match = re.search(r'interface\s+' |
| 161 r'\w+\s*' | 141 r'\w+\s*' |
| 162 r':\s*(\w+)\s*' | 142 r':\s*(\w+)\s*' |
| 163 r'{', | 143 r'{', |
| 164 file_contents) | 144 file_contents) |
| 165 return match and match.group(1) | 145 return match and match.group(1) |
| 166 | 146 |
| 167 | 147 |
| 168 def get_interface_extended_attributes_from_idl(file_contents): | 148 def get_interface_extended_attributes_from_idl(file_contents): |
| (...skipping 30 matching lines...) Expand all Loading... |
| 199 | 179 |
| 200 def get_put_forward_interfaces_from_idl(file_contents): | 180 def get_put_forward_interfaces_from_idl(file_contents): |
| 201 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' | 181 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' |
| 202 r'readonly\s+' | 182 r'readonly\s+' |
| 203 r'attribute\s+' | 183 r'attribute\s+' |
| 204 r'(\w+)') | 184 r'(\w+)') |
| 205 return sorted(set(match.group(1) | 185 return sorted(set(match.group(1) |
| 206 for match in re.finditer(put_forwards_pattern, | 186 for match in re.finditer(put_forwards_pattern, |
| 207 file_contents, | 187 file_contents, |
| 208 flags=re.DOTALL))) | 188 flags=re.DOTALL))) |
| OLD | NEW |