Skip to content

Commit

Permalink
Add whitelist support for grit repack steps.
Browse files Browse the repository at this point in the history
-Adds new repack_options variables
-Updates pragma to output numeric_id instead of resource_id
-Updates find_used_resources.py to filter for numeric_id

To use the existing system you need to do following steps:
1. Remove out directory (we need to do a clean build)
2. Append " enable_resource_whitelist_generation=1" to GYP_DEFINES
3. Run gyp
4. Build your target (e.g. chrome_shell_apk) saving output to a file
   (e.g. build.txt)
5. cat build.txt | tools/resources/find_used_resources.py > whitelist.txt
6. Append " repack_options='--whitelist /path/to/whitelist.txt'"
7. Run gyp
8. Build your target again.
9. ???
10. Profit!!!

BUG=338759

Review URL: https://codereview.chromium.org/216233012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261611 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
aurimas@chromium.org committed Apr 4, 2014
1 parent 52b9477 commit e4fdab9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build/common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@
'grit_defines': ['-D', 'enable_notifications'],
}],
['enable_resource_whitelist_generation==1', {
'grit_rc_header_format': ['-h', '#define {textual_id} _Pragma("{textual_id}") {numeric_id}'],
'grit_rc_header_format': ['-h', '#define {textual_id} _Pragma("whitelisted_resource_{numeric_id}") {numeric_id}'],
}],
['enable_mdns==1 or OS=="mac"', {
'grit_defines': ['-D', 'enable_service_discovery'],
Expand Down
9 changes: 8 additions & 1 deletion build/repack_action.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{
'variables': {
'repack_path': '<(DEPTH)/tools/grit/grit/format/repack.py',
'repack_options%': [],
},
'inputs': [
'<(repack_path)',
Expand All @@ -19,5 +20,11 @@
'outputs': [
'<(pak_output)'
],
'action': ['python', '<(repack_path)', '<(pak_output)', '<@(pak_inputs)'],
'action': [
'python',
'<(repack_path)',
'<@(repack_options)',
'<(pak_output)',
'<@(pak_inputs)',
],
}
2 changes: 2 additions & 0 deletions chrome/chrome_repack_locales.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{
'variables': {
'repack_locales_path': 'tools/build/repack_locales.py',
'repack_options%': [],
'conditions': [
['branding=="Chrome"', {
'branding_flag': ['-b', 'google_chrome',],
Expand All @@ -31,6 +32,7 @@
'-s', '<(SHARED_INTERMEDIATE_DIR)',
'-x', '<(SHARED_INTERMEDIATE_DIR)/.',
'--use-ash', '<(use_ash)',
'<@(repack_options)',
'<@(pak_locales)',
],
}
8 changes: 7 additions & 1 deletion chrome/tools/build/repack_locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

USE_ASH = False

WHITELIST = None

# Extra input files.
EXTRA_INPUT_FILES = []

Expand Down Expand Up @@ -153,7 +155,7 @@ def repack_locales(locales):
inputs = []
inputs += calc_inputs(locale)
output = calc_output(locale)
data_pack.DataPack.RePack(output, inputs)
data_pack.DataPack.RePack(output, inputs, whitelist_file=WHITELIST)


def DoMain(argv):
Expand All @@ -163,6 +165,7 @@ def DoMain(argv):
global INT_DIR
global OS
global USE_ASH
global WHITELIST
global EXTRA_INPUT_FILES

parser = optparse.OptionParser("usage: %prog [options] locales")
Expand All @@ -185,6 +188,8 @@ def DoMain(argv):
help="The target OS. (e.g. mac, linux, win, etc.)")
parser.add_option("--use-ash", action="store", dest="use_ash",
help="Whether to include ash strings")
parser.add_option("--whitelist", action="store", help="Full path to the "
"whitelist used to filter output pak file resource IDs")
options, locales = parser.parse_args(argv)

if not locales:
Expand All @@ -199,6 +204,7 @@ def DoMain(argv):
EXTRA_INPUT_FILES = options.extra_input
OS = options.os
USE_ASH = options.use_ash == '1'
WHITELIST = options.whitelist

if not OS:
if sys.platform == 'darwin':
Expand Down
5 changes: 3 additions & 2 deletions tools/resources/find_used_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
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 IDS_FOO_BAR [-Wunknown-pragmas]
foo.cc:22:0: warning: ignoring #pragma whitelisted_resource_12345
[-Wunknown-pragmas]
"""

Expand All @@ -29,7 +30,7 @@ def GetResourceIdsInPragmaWarnings(input):
"""
used_resources = set()
unknown_pragma_warning_pattern = re.compile('warning: ignoring #pragma '
'(?P<resource_id>[A-Z0-9_]*) \[-Wunknown-pragmas\]')
'whitelisted_resource_(?P<resource_id>[0-9]*) \[-Wunknown-pragmas\]')
for ln in input:
match = unknown_pragma_warning_pattern.search(ln)
if match:
Expand Down

0 comments on commit e4fdab9

Please sign in to comment.