Commit 9d468c1c authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Add ability to find unused flag with list_flags.py.

Add a new "-u" switch to list_flags.py to search for unused flags. It
checks the obvious files that should reference flags.

Change-Id: I0f9b050b2adcafd0a612bae93f2e4ef08cdf0e7e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2416851
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808477}
parent c4d9fa8d
......@@ -84,6 +84,21 @@ def resolve_owners(flags):
return new_flags
def find_unused(flags):
FLAG_FILES = [
'chrome/browser/about_flags.cc',
'ios/chrome/browser/flags/about_flags.mm',
]
flag_files_data = [open(f, 'rb').read().decode('utf-8') for f in FLAG_FILES]
unused_flags = []
for flag in flags:
# Search for the name in quotes.
needle = '"%s"' % flag['name']
if not any([needle in data for data in flag_files_data]):
unused_flags.append(flag)
return unused_flags
def print_flags(flags, verbose):
"""Prints the supplied list of flags.
......@@ -119,6 +134,7 @@ def main():
group = parser.add_mutually_exclusive_group()
group.add_argument('-n', '--never-expires', action='store_true')
group.add_argument('-e', '--expired-by', type=int)
group.add_argument('-u', '--find-unused', action='store_true')
parser.add_argument('-v', '--verbose', action='store_true')
parser.add_argument('--testonly', action='store_true')
args = parser.parse_args()
......@@ -131,6 +147,8 @@ def main():
flags = keep_expired_by(flags, args.expired_by)
if args.never_expires:
flags = keep_never_expires(flags)
if args.find_unused:
flags = find_unused(flags)
flags = resolve_owners(flags)
print_flags(flags, args.verbose)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment