Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: tools/resources/generate_resource_whitelist.py

Issue 2278983002: Add resource whitelisting compatibility for offical builder scripts. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2016 The Chromium Authors. All rights reserved. 2 # Copyright 2016 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 import argparse 6 import argparse
7 import os 7 import os
8 import re 8 import re
9 import sys 9 import sys
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 r'^#define (%s) _Pragma\S+ (\d+)$' % '|'.join(resource_names)) 48 r'^#define (%s) _Pragma\S+ (\d+)$' % '|'.join(resource_names))
49 with open(header, 'r') as f: 49 with open(header, 'r') as f:
50 res_ids = [ int(pattern.match(line).group(2)) 50 res_ids = [ int(pattern.match(line).group(2))
51 for line in f if pattern.match(line) ] 51 for line in f if pattern.match(line) ]
52 if len(res_ids) != len(resource_names): 52 if len(res_ids) != len(resource_names):
53 raise Exception('Find resource id failed: the result is ' + 53 raise Exception('Find resource id failed: the result is ' +
54 ', '.join(str(i) for i in res_ids)) 54 ', '.join(str(i) for i in res_ids))
55 return set(res_ids) 55 return set(res_ids)
56 56
57 57
58 # TODO(estevenson): Remove this after updating official build scripts.
59 def _GetResourceIdsInPragmaWarnings(input):
60 """Returns set of resource ids that are inside unknown pragma warnings
61 for the given input.
62 """
63 used_resources = set()
64 unknown_pragma_warning_pattern = re.compile(
65 'whitelisted_resource_(?P<resource_id>[0-9]+)')
66 for ln in input:
67 match = unknown_pragma_warning_pattern.search(ln)
68 if match:
69 resource_id = int(match.group('resource_id'))
70 used_resources.add(resource_id)
71 return used_resources
72
73
58 def main(): 74 def main():
59 parser = argparse.ArgumentParser(usage=USAGE) 75 parser = argparse.ArgumentParser(usage=USAGE)
60 parser.add_argument( 76 parser.add_argument(
61 '-i', '--input', type=argparse.FileType('r'), default=sys.stdin, 77 '-i', '--input', type=argparse.FileType('r'), default=sys.stdin,
62 help='A resource whitelist where each line contains one resource ID') 78 help='A resource whitelist where each line contains one resource ID')
63 parser.add_argument( 79 parser.add_argument(
64 '-o', '--output', type=argparse.FileType('w'), default=sys.stdout, 80 '-o', '--output', type=argparse.FileType('w'), default=sys.stdout,
65 help='The resource list path to write (default stdout)') 81 help='The resource list path to write (default stdout)')
66 parser.add_argument( 82 parser.add_argument(
67 '--out-dir', required=True, 83 '--out-dir', required=True,
68 help='The out target directory, for example out/Release') 84 help='The out target directory, for example out/Release')
85 parser.add_argument(
86 '--use-existing-resource-ids', action='store_true', default=False,
87 help='Specifies that the input file already contains resource ids')
69 88
70 args = parser.parse_args() 89 args = parser.parse_args()
71 90
72 used_resources = set() 91 used_resources = set()
73 used_resources.update([int(resource_id) for resource_id in args.input]) 92 if args.use_existing_resource_ids:
93 used_resources.update([int(resource_id) for resource_id in args.input])
94 else:
95 used_resources.update(_GetResourceIdsInPragmaWarnings(args.input))
96
74 used_resources |= _FindResourceIds( 97 used_resources |= _FindResourceIds(
75 os.path.join(args.out_dir, COMPONENTS_STRINGS_HEADER), 98 os.path.join(args.out_dir, COMPONENTS_STRINGS_HEADER),
76 ARCH_SPECIFIC_RESOURCES) 99 ARCH_SPECIFIC_RESOURCES)
77 100
78 for resource_id in sorted(used_resources): 101 for resource_id in sorted(used_resources):
79 args.output.write('%d\n' % resource_id) 102 args.output.write('%d\n' % resource_id)
80 103
81 if __name__ == '__main__': 104 if __name__ == '__main__':
82 main() 105 main()
OLDNEW
« no previous file with comments | « chrome/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698