OLD | NEW |
1 #!/usr/bin/python2 | 1 #!/usr/bin/python2 |
2 | 2 |
3 # Copyright 2016 The Chromium Authors. All rights reserved. | 3 # Copyright 2016 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Identifies Polymer elements that downloaded but not used by Chrome. | 7 """Identifies Polymer elements that downloaded but not used by Chrome. |
8 | 8 |
9 Only finds "first-order" unused elements; re-run after removing unused elements | 9 Only finds "first-order" unused elements; re-run after removing unused elements |
10 to check if other elements have become unused. | 10 to check if other elements have become unused. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 # Ignore the element's own files. | 129 # Ignore the element's own files. |
130 if dirpath.startswith(os.path.join( | 130 if dirpath.startswith(os.path.join( |
131 self.__COMPONENTS_DIR, element_dir)): | 131 self.__COMPONENTS_DIR, element_dir)): |
132 continue | 132 continue |
133 | 133 |
134 for filename in filenames: | 134 for filename in filenames: |
135 if not filename.endswith('.html') and not filename.endswith('.js'): | 135 if not filename.endswith('.html') and not filename.endswith('.js'): |
136 continue | 136 continue |
137 | 137 |
138 # Skip generated files that may include the element source. | 138 # Skip generated files that may include the element source. |
139 if filename in ('crisper.js', 'vulcanized.html'): | 139 if filename in ('crisper.js', 'vulcanized.html', |
| 140 'app.crisper.js', 'app.vulcanized.html'): |
140 continue | 141 continue |
141 | 142 |
142 with open(os.path.join(dirpath, filename)) as f: | 143 with open(os.path.join(dirpath, filename)) as f: |
143 text = f.read() | 144 text = f.read() |
144 if not re.search('/%s/' % element_dir, text): | 145 if not re.search('/%s/' % element_dir, text): |
145 continue | 146 continue |
146 | 147 |
147 # Check the file again, ignoring comments (e.g. example imports and | 148 # Check the file again, ignoring comments (e.g. example imports and |
148 # scripts). | 149 # scripts). |
149 if re.search('/%s' % element_dir, | 150 if re.search('/%s' % element_dir, |
150 self.__StripComments( | 151 self.__StripComments( |
151 os.path.join(dirpath, filename))): | 152 os.path.join(dirpath, filename))): |
152 return True | 153 return True |
153 return False | 154 return False |
154 | 155 |
155 | 156 |
156 if __name__ == '__main__': | 157 if __name__ == '__main__': |
157 UnusedElementsDetector().Run() | 158 UnusedElementsDetector().Run() |
OLD | NEW |