Commit a57817c7 authored by Peter Wen's avatar Peter Wen Committed by Commit Bot

Android: Minor improvements of list_java_targets.py

Add -C as well for --output-directory to match ninja's syntax. Make it
clear in the help text that there are easier ways to permanently specify
a default output directory.

Remove some unused fields and use f-strings.

Bug: None
Change-Id: I0a9ba8329095a5c6d8c46ddb63966f31d3307754
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2315093
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Auto-Submit: Peter Wen <wnwen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791834}
parent 2f6180f7
...@@ -8,18 +8,18 @@ ...@@ -8,18 +8,18 @@
Examples: Examples:
# List GN target for bundles: # List GN target for bundles:
build/android/list_java_targets.py --output-directory out/Default \ build/android/list_java_targets.py -C out/Default --type android_app_bundle \
--type android_app_bundle --gn-labels --gn-labels
# List all android targets with types: # List all android targets with types:
build/android/list_java_targets.py --output-directory out/Default --print-types build/android/list_java_targets.py -C out/Default --print-types
# Build all apk targets: # Build all apk targets:
build/android/list_java_targets.py --output-directory out/Default \ build/android/list_java_targets.py -C out/Default --type android_apk | xargs \
--type android_apk | xargs autoninja -C out/Default autoninja -C out/Default
# Show how many of each target type exist: # Show how many of each target type exist:
build/android/list_java_targets.py --output-directory out/Default --stats build/android/list_java_targets.py -C out/Default --stats
""" """
...@@ -79,22 +79,16 @@ def _query_for_build_config_targets(output_dir): ...@@ -79,22 +79,16 @@ def _query_for_build_config_targets(output_dir):
ninja_target = line.rsplit(':', 1)[0] ninja_target = line.rsplit(':', 1)[0]
# Ignore root aliases by ensuring a : exists. # Ignore root aliases by ensuring a : exists.
if ':' in ninja_target and ninja_target.endswith(SUFFIX): if ':' in ninja_target and ninja_target.endswith(SUFFIX):
ret.append('//' + ninja_target[:-SUFFIX_LEN]) ret.append(f'//{ninja_target[:-SUFFIX_LEN]}')
return ret return ret
class _TargetEntry(object): class _TargetEntry(object):
_cached_entries = {}
def __init__(self, gn_target): def __init__(self, gn_target):
assert gn_target.startswith('//'), gn_target assert gn_target.startswith('//'), f'{gn_target} does not start with //'
if ':' not in gn_target: assert ':' in gn_target, f'Non-root {gn_target} required'
gn_target = '%s:%s' % (gn_target, os.path.basename(gn_target))
self.gn_target = gn_target self.gn_target = gn_target
self._build_config = None self._build_config = None
self._java_files = None
self._all_entries = None
self.android_test_entries = []
@property @property
def ninja_target(self): def ninja_target(self):
...@@ -125,7 +119,9 @@ class _TargetEntry(object): ...@@ -125,7 +119,9 @@ class _TargetEntry(object):
def main(): def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('--output-directory') parser.add_argument('-C',
'--output-directory',
help='If outdir is not provided, will attempt to guess.')
parser.add_argument('--gn-labels', parser.add_argument('--gn-labels',
action='store_true', action='store_true',
help='Print GN labels rather than ninja targets') help='Print GN labels rather than ninja targets')
...@@ -174,7 +170,7 @@ def main(): ...@@ -174,7 +170,7 @@ def main():
if args.stats: if args.stats:
counts = collections.Counter(e.get_type() for e in entries) counts = collections.Counter(e.get_type() for e in entries)
for entry_type, count in sorted(counts.items()): for entry_type, count in sorted(counts.items()):
print('{}: {}'.format(entry_type, count)) print(f'{entry_type}: {count}')
else: else:
for e in entries: for e in entries:
if args.gn_labels: if args.gn_labels:
...@@ -187,7 +183,7 @@ def main(): ...@@ -187,7 +183,7 @@ def main():
to_print = to_print.replace('__test_apk__apk', '').replace('__apk', '') to_print = to_print.replace('__test_apk__apk', '').replace('__apk', '')
if args.print_types: if args.print_types:
to_print = '{}: {}'.format(to_print, e.get_type()) to_print = f'{to_print}: {e.get_type()}'
print(to_print) print(to_print)
......
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