Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 | 6 |
| 7 import re | 7 import re |
| 8 import sys | 8 import sys |
| 9 | 9 |
| 10 usage = """find_used_resources.py | 10 usage = """find_used_resources.py |
| 11 | 11 |
| 12 Prints out (to sdout) the sorted list of resource ids that are part of unknown | 12 Prints out (to sdout) the sorted list of resource ids that are part of unknown |
| 13 pragma warning in the given build log (via stdin). | 13 pragma warning in the given build log (via stdin). |
| 14 | 14 |
| 15 This script is used to find the resources that are actually compiled in Chrome | 15 This script is used to find the resources that are actually compiled in Chrome |
| 16 in order to only include the needed strings/images in Chrome PAK files. The | 16 in order to only include the needed strings/images in Chrome PAK files. The |
| 17 script parses out the list of used resource ids. These resource ids show up in | 17 script parses out the list of used resource ids. These resource ids show up in |
| 18 the build output after building Chrome with gyp variable | 18 the build output after building Chrome with gyp variable |
| 19 enable_resource_whitelist_generation set to 1. This gyp flag causes the compiler | 19 enable_resource_whitelist_generation set to 1. This gyp flag causes the compiler |
| 20 to print out a UnknownPragma message every time a resource id is used. E.g.: | 20 to print out a UnknownPragma message every time a resource id is used. E.g.: |
| 21 foo.cc:22:0: warning: ignoring #pragma IDS_FOO_BAR [-Wunknown-pragmas] | 21 foo.cc:22:0: warning: ignoring #pragma 12345 [-Wunknown-pragmas] |
|
newt (away)
2014/03/31 17:45:14
I think it would be helpful to change this message
aurimas (slooooooooow)
2014/03/31 17:54:21
Done.
| |
| 22 | 22 |
| 23 """ | 23 """ |
| 24 | 24 |
| 25 | 25 |
| 26 def GetResourceIdsInPragmaWarnings(input): | 26 def GetResourceIdsInPragmaWarnings(input): |
| 27 """Returns sorted set of resource ids that are inside unknown pragma warnings | 27 """Returns sorted set of resource ids that are inside unknown pragma warnings |
| 28 for the given input. | 28 for the given input. |
| 29 """ | 29 """ |
| 30 used_resources = set() | 30 used_resources = set() |
| 31 unknown_pragma_warning_pattern = re.compile('warning: ignoring #pragma ' | 31 unknown_pragma_warning_pattern = re.compile('warning: ignoring #pragma ' |
| 32 '(?P<resource_id>[A-Z0-9_]*) \[-Wunknown-pragmas\]') | 32 '(?P<resource_id>[0-9]*) \[-Wunknown-pragmas\]') |
| 33 for ln in input: | 33 for ln in input: |
| 34 match = unknown_pragma_warning_pattern.search(ln) | 34 match = unknown_pragma_warning_pattern.search(ln) |
| 35 if match: | 35 if match: |
| 36 resource_id = match.group('resource_id') | 36 resource_id = match.group('resource_id') |
| 37 used_resources.add(resource_id) | 37 used_resources.add(resource_id) |
| 38 return sorted(used_resources) | 38 return sorted(used_resources) |
| 39 | 39 |
| 40 def Main(): | 40 def Main(): |
| 41 if len(sys.argv) != 1: | 41 if len(sys.argv) != 1: |
| 42 sys.stderr.write(usage) | 42 sys.stderr.write(usage) |
| 43 sys.exit(1) | 43 sys.exit(1) |
| 44 else: | 44 else: |
| 45 used_resources = GetResourceIdsInPragmaWarnings(sys.stdin) | 45 used_resources = GetResourceIdsInPragmaWarnings(sys.stdin) |
| 46 for rid in used_resources: | 46 for rid in used_resources: |
| 47 sys.stdout.write(rid + '\n') | 47 sys.stdout.write(rid + '\n') |
| 48 | 48 |
| 49 if __name__ == '__main__': | 49 if __name__ == '__main__': |
| 50 Main() | 50 Main() |
| OLD | NEW |