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

Unified Diff: tools/resources/find_used_resources.py

Issue 2271453003: Revert of Enable whitelist generation for official builds. (patchset #2 id:20001 of https://coderev… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2837
Patch Set: Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/grit/repack.gni ('k') | tools/resources/generate_resource_whitelist.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/resources/find_used_resources.py
diff --git a/tools/resources/generate_resource_whitelist.py b/tools/resources/find_used_resources.py
similarity index 59%
rename from tools/resources/generate_resource_whitelist.py
rename to tools/resources/find_used_resources.py
index 527ceb484158c9fcf32cb5d9dc34e7561d7471d9..0528115ead59cfadbc1d16cb2b38090e48937a7a 100755
--- a/tools/resources/generate_resource_whitelist.py
+++ b/tools/resources/find_used_resources.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-# Copyright 2016 The Chromium Authors. All rights reserved.
+# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -8,22 +8,18 @@ import os
import re
import sys
-USAGE = """generate_resource_whitelist.py [-h] [-i INPUT] [-o OUTPUT]
+USAGE = """find_used_resources.py [-h] [-i INPUT] [-o OUTPUT]
-INPUT specifies a file containing existing resource IDs that should be
-whitelisted, where each line of INPUT contains a single resource ID.
-
-Creates a resource whitelist by collecting existing resource IDs that are part
-of unknown pragma warnings and adds additional arch specfic resource IDs.
+Outputs the sorted list of resource ids that are part of unknown pragma warning
+in the given build log.
This script is used to find the resources that are actually compiled in Chrome
-in order to only include the needed strings/images in Chrome PAK files.
-These resource IDs show up in the build output after building Chrome with
-gn variable enable_resource_whitelist_generation set to true.
-This causes the compiler to print out an UnknownPragma message every time a
-resource ID is used.
-
-E.g. foo.cc:22:0: warning: ignoring #pragma whitelisted_resource_12345
+in order to only include the needed strings/images in Chrome PAK files. The
+script parses out the list of used resource ids. These resource ids show up in
+the build output after building Chrome with gyp variable
+enable_resource_whitelist_generation set to 1. This gyp flag causes the compiler
+to print out a UnknownPragma message every time a resource id is used. E.g.:
+foo.cc:22:0: warning: ignoring #pragma whitelisted_resource_12345
[-Wunknown-pragmas]
On Windows, the message is simply a message via __pragma(message(...)).
@@ -39,8 +35,7 @@ ARCH_SPECIFIC_RESOURCES = [
'IDS_VERSION_UI_32BIT',
]
-
-def _FindResourceIds(header, resource_names):
+def FindResourceIds(header, resource_names):
"""Returns the numerical resource IDs that correspond to the given resource
names, as #defined in the given header file."
"""
@@ -54,24 +49,36 @@ def _FindResourceIds(header, resource_names):
', '.join(str(i) for i in res_ids))
return set(res_ids)
-
-def main():
+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(
'-i', '--input', type=argparse.FileType('r'), default=sys.stdin,
- help='A resource whitelist where each line contains one resource ID')
+ help='The build log to read (default stdin)')
parser.add_argument(
'-o', '--output', type=argparse.FileType('w'), default=sys.stdout,
help='The resource list path to write (default stdout)')
- parser.add_argument(
- '--out-dir', required=True,
+ parser.add_argument('--out-dir', required=True,
help='The out target directory, for example out/Release')
args = parser.parse_args()
- used_resources = set()
- used_resources.update([int(resource_id) for resource_id in args.input])
- used_resources |= _FindResourceIds(
+
+ used_resources = GetResourceIdsInPragmaWarnings(args.input)
+ used_resources |= FindResourceIds(
os.path.join(args.out_dir, COMPONENTS_STRINGS_HEADER),
ARCH_SPECIFIC_RESOURCES)
@@ -79,4 +86,4 @@ def main():
args.output.write('%d\n' % resource_id)
if __name__ == '__main__':
- main()
+ Main()
« no previous file with comments | « tools/grit/repack.gni ('k') | tools/resources/generate_resource_whitelist.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698