diff --git a/chrome/BUILD.gn b/chrome/BUILD.gn index 1db8721f0d9a00..73f827c8c0e054 100644 --- a/chrome/BUILD.gn +++ b/chrome/BUILD.gn @@ -1702,6 +1702,7 @@ if (enable_resource_whitelist_generation) { "-o", rebase_path(_outfile, root_build_dir), "--out-dir=.", + "--use-existing-resource-ids", ] } } diff --git a/tools/resources/generate_resource_whitelist.py b/tools/resources/generate_resource_whitelist.py index 527ceb484158c9..c4431d687aed95 100755 --- a/tools/resources/generate_resource_whitelist.py +++ b/tools/resources/generate_resource_whitelist.py @@ -55,6 +55,22 @@ def _FindResourceIds(header, resource_names): return set(res_ids) +# TODO(estevenson): Remove this after updating official build scripts. +def _GetResourceIdsInPragmaWarnings(input): + """Returns set of resource ids that are inside unknown pragma warnings + for the given input. + """ + used_resources = set() + unknown_pragma_warning_pattern = re.compile( + 'whitelisted_resource_(?P[0-9]+)') + for ln in input: + match = unknown_pragma_warning_pattern.search(ln) + if match: + resource_id = int(match.group('resource_id')) + used_resources.add(resource_id) + return used_resources + + def main(): parser = argparse.ArgumentParser(usage=USAGE) parser.add_argument( @@ -66,11 +82,18 @@ def main(): parser.add_argument( '--out-dir', required=True, help='The out target directory, for example out/Release') + parser.add_argument( + '--use-existing-resource-ids', action='store_true', default=False, + help='Specifies that the input file already contains resource ids') args = parser.parse_args() used_resources = set() - used_resources.update([int(resource_id) for resource_id in args.input]) + if args.use_existing_resource_ids: + used_resources.update([int(resource_id) for resource_id in args.input]) + else: + used_resources.update(_GetResourceIdsInPragmaWarnings(args.input)) + used_resources |= _FindResourceIds( os.path.join(args.out_dir, COMPONENTS_STRINGS_HEADER), ARCH_SPECIFIC_RESOURCES)