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. |
11 """ | 11 """ |
12 | 12 |
13 import os | 13 import os |
14 import re | 14 import re |
15 import subprocess | 15 import subprocess |
16 | 16 |
17 | 17 |
18 class UnusedElementsDetector(object): | 18 class UnusedElementsDetector(object): |
19 """Finds unused Polymer elements.""" | 19 """Finds unused Polymer elements.""" |
20 | 20 |
21 # Unused elements to ignore because we plan to use them soon. | 21 # Unused elements to ignore because we plan to use them soon. |
22 __WHITELIST = ( | 22 __WHITELIST = ( |
23 # Necessary for closure. | 23 # Necessary for closure. |
24 'polymer-externs', | 24 'polymer-externs', |
| 25 # TODO(tsergeant): Remove app-route from Chromium. |
| 26 'app-route', |
25 ) | 27 ) |
26 | 28 |
27 def __init__(self): | 29 def __init__(self): |
28 polymer_dir = os.path.dirname(os.path.realpath(__file__)) | 30 polymer_dir = os.path.dirname(os.path.realpath(__file__)) |
29 self.__COMPONENTS_DIR = os.path.join(polymer_dir, 'components-chromium') | 31 self.__COMPONENTS_DIR = os.path.join(polymer_dir, 'components-chromium') |
30 | 32 |
31 @staticmethod | 33 @staticmethod |
32 def __StripHtmlComments(filename): | 34 def __StripHtmlComments(filename): |
33 """Returns the contents of an HTML file with <!-- --> comments stripped. | 35 """Returns the contents of an HTML file with <!-- --> comments stripped. |
34 | 36 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 # scripts). | 151 # scripts). |
150 if re.search('/%s' % element_dir, | 152 if re.search('/%s' % element_dir, |
151 self.__StripComments( | 153 self.__StripComments( |
152 os.path.join(dirpath, filename))): | 154 os.path.join(dirpath, filename))): |
153 return True | 155 return True |
154 return False | 156 return False |
155 | 157 |
156 | 158 |
157 if __name__ == '__main__': | 159 if __name__ == '__main__': |
158 UnusedElementsDetector().Run() | 160 UnusedElementsDetector().Run() |
OLD | NEW |