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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 for pickle_filename in pickle_filenames: | 42 for pickle_filename in pickle_filenames: |
43 with open(pickle_filename) as pickle_file: | 43 with open(pickle_filename) as pickle_file: |
44 yield pickle.load(pickle_file) | 44 yield pickle.load(pickle_file) |
45 | 45 |
46 | 46 |
47 def write_file(new_text, destination_filename, only_if_changed): | 47 def write_file(new_text, destination_filename, only_if_changed): |
48 if only_if_changed and os.path.isfile(destination_filename): | 48 if only_if_changed and os.path.isfile(destination_filename): |
49 with open(destination_filename) as destination_file: | 49 with open(destination_filename) as destination_file: |
50 if destination_file.read() == new_text: | 50 if destination_file.read() == new_text: |
51 return | 51 return |
| 52 destination_dirname = os.path.dirname(destination_filename) |
| 53 if not os.path.exists(destination_dirname): |
| 54 os.makedirs(destination_dirname) |
52 with open(destination_filename, 'w') as destination_file: | 55 with open(destination_filename, 'w') as destination_file: |
53 destination_file.write(new_text) | 56 destination_file.write(new_text) |
54 | 57 |
55 | 58 |
56 def write_pickle_file(pickle_filename, data, only_if_changed): | 59 def write_pickle_file(pickle_filename, data, only_if_changed): |
57 if only_if_changed and os.path.isfile(pickle_filename): | 60 if only_if_changed and os.path.isfile(pickle_filename): |
58 with open(pickle_filename) as pickle_file: | 61 with open(pickle_filename) as pickle_file: |
59 try: | 62 try: |
60 if pickle.load(pickle_file) == data: | 63 if pickle.load(pickle_file) == data: |
61 return | 64 return |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 return ( | 115 return ( |
113 [left for left, right in implements_pairs if right == interface_name], | 116 [left for left, right in implements_pairs if right == interface_name], |
114 [right for left, right in implements_pairs if left == interface_name]) | 117 [right for left, right in implements_pairs if left == interface_name]) |
115 | 118 |
116 | 119 |
117 def is_callback_interface_from_idl(file_contents): | 120 def is_callback_interface_from_idl(file_contents): |
118 match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents) | 121 match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents) |
119 return bool(match) | 122 return bool(match) |
120 | 123 |
121 | 124 |
| 125 def is_dictionary_from_idl(file_contents): |
| 126 match = re.search(r'dictionary\s+\w+\s*{', file_contents) |
| 127 return bool(match) |
| 128 |
| 129 |
122 def get_parent_interface(file_contents): | 130 def get_parent_interface(file_contents): |
123 match = re.search(r'interface\s+' | 131 match = re.search(r'interface\s+' |
124 r'\w+\s*' | 132 r'\w+\s*' |
125 r':\s*(\w+)\s*' | 133 r':\s*(\w+)\s*' |
126 r'{', | 134 r'{', |
127 file_contents) | 135 file_contents) |
128 return match and match.group(1) | 136 return match and match.group(1) |
129 | 137 |
130 | 138 |
131 def get_interface_extended_attributes_from_idl(file_contents): | 139 def get_interface_extended_attributes_from_idl(file_contents): |
(...skipping 30 matching lines...) Expand all Loading... |
162 | 170 |
163 def get_put_forward_interfaces_from_idl(file_contents): | 171 def get_put_forward_interfaces_from_idl(file_contents): |
164 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' | 172 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' |
165 r'readonly\s+' | 173 r'readonly\s+' |
166 r'attribute\s+' | 174 r'attribute\s+' |
167 r'(\w+)') | 175 r'(\w+)') |
168 return sorted(set(match.group(1) | 176 return sorted(set(match.group(1) |
169 for match in re.finditer(put_forwards_pattern, | 177 for match in re.finditer(put_forwards_pattern, |
170 file_contents, | 178 file_contents, |
171 flags=re.DOTALL))) | 179 flags=re.DOTALL))) |
OLD | NEW |