Skip to content

Commit

Permalink
Add resource whitelisting compatibility for offical builder scripts.
Browse files Browse the repository at this point in the history
https://codereview.chromium.org/2272713004/ breaks
official builders so this CL ensures the offical build scripts work as
they used to.

BUG=640877
TBR=dpranke@chromium.org, brettw@chromium.org

Review-Url: https://codereview.chromium.org/2278983002
Cr-Commit-Position: refs/heads/master@{#414463}
  • Loading branch information
estevenson authored and Commit bot committed Aug 25, 2016
1 parent 0e41c53 commit 76a9aec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions chrome/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,7 @@ if (enable_resource_whitelist_generation) {
"-o",
rebase_path(_outfile, root_build_dir),
"--out-dir=.",
"--use-existing-resource-ids",
]
}
}
Expand Down
25 changes: 24 additions & 1 deletion tools/resources/generate_resource_whitelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<resource_id>[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(
Expand All @@ -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)
Expand Down

0 comments on commit 76a9aec

Please sign in to comment.