[iOS] Load packed resources when running ios_chrome_unittests
[chromium-blink-merge.git] / tools / resources / find_used_resources.py
blob9fc99ae9887c2ca8219eb31556c04b70c40601b1
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
6 import argparse
7 import re
8 import sys
10 USAGE = """find_used_resources.py [-h] [-i INPUT] [-o OUTPUT]
12 Outputs the sorted list of resource ids that are part of unknown pragma warning
13 in the given build log.
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
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
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.:
21 foo.cc:22:0: warning: ignoring #pragma whitelisted_resource_12345
22 [-Wunknown-pragmas]
24 On Windows, the message is simply a message via __pragma(message(...)).
26 """
29 def GetResourceIdsInPragmaWarnings(input):
30 """Returns sorted set of resource ids that are inside unknown pragma warnings
31 for the given input.
32 """
33 used_resources = set()
34 unknown_pragma_warning_pattern = re.compile(
35 'whitelisted_resource_(?P<resource_id>[0-9]+)')
36 for ln in input:
37 match = unknown_pragma_warning_pattern.search(ln)
38 if match:
39 resource_id = int(match.group('resource_id'))
40 used_resources.add(resource_id)
41 return sorted(used_resources)
43 def Main():
44 parser = argparse.ArgumentParser(usage=USAGE)
45 parser.add_argument(
46 '-i', '--input', type=argparse.FileType('r'), default=sys.stdin,
47 help='The build log to read (default stdin)')
48 parser.add_argument(
49 '-o', '--output', type=argparse.FileType('w'), default=sys.stdout,
50 help='The resource list path to write (default stdout)')
51 args = parser.parse_args()
54 used_resources = GetResourceIdsInPragmaWarnings(args.input)
55 for resource_id in used_resources:
56 args.output.write('%d\n' % resource_id)
58 if __name__ == '__main__':
59 Main()