Commit b132568a authored by Samuel Huang's avatar Samuel Huang Committed by Commit Bot

[SuperSize] Simplify SuperSize-archive start-up logic.

For SuperSize in general:
* Improve abstraction for Run(), which exists for modes
    {archive, html_report, start_server, console, diff, save_diff}:
  Change the |parser| param to a callback |on_config_error()|, since
  |parser| is used exclusively for |parser.error()|.

For archive.py:
* _RunInternal(): Move logic to assign |knobs| member variables based on
  |args| into SectionSizeKnobs.modifyWithArgs().
  * Not using __init__() since SectionSizeKnobs is used in test, which
    does not have |args|.
* Inject "deduced arguments" into |args| via setattr(), to reduce
  function param footprint. List of deduced arguments:
  * extracted_minimal_apk_path: Was passed as function param.
    * Cannot just replace |apk_file|: It's written into metadata.
  * any_path_within_output_directory: Was deduced as |any_path| from
    {apk_file, minimal_apks_file, elf_file, map_file}.
  * is_bundle: Was deduced by the presence of |minimal_apks_file|, and
    passed as function param.
* Simplify _DeduceMainPaths() by extracting _DeduceNativeInfo().
  * Use |knobs.analyze_native| instead of |args.java_only| as the
    decision variable, to be more precise.

Change-Id: Iffccd6b3072d95372eacb7091fe80cc172495334
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2121742
Commit-Queue: Samuel Huang <huangs@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753626}
parent 8ecc5619
This diff is collapsed.
......@@ -480,10 +480,10 @@ def AddArguments(parser):
'Disassemble().')
def Run(args, parser):
def Run(args, on_config_error):
for path in args.inputs:
if not path.endswith('.size'):
parser.error('All inputs must end with ".size"')
on_config_error('All inputs must end with ".size"')
size_infos = [archive.LoadAndPostProcessSizeInfo(p) for p in args.inputs]
output_directory_finder = path_util.OutputDirectoryFinder(
......
......@@ -266,13 +266,13 @@ def AddArguments(parser):
help='Diffs the input_file against an older .size file')
def Run(args, parser):
def Run(args, on_config_error):
if not args.input_size_file.endswith('.size'):
parser.error('Input must end with ".size"')
on_config_error('Input must end with ".size"')
if args.diff_with and not args.diff_with.endswith('.size'):
parser.error('Diff input must end with ".size"')
on_config_error('Diff input must end with ".size"')
if not args.output_report_file.endswith('.ndjson'):
parser.error('Output must end with ".ndjson"')
on_config_error('Output must end with ".ndjson"')
size_info = archive.LoadAndPostProcessSizeInfo(args.input_size_file)
if args.diff_with:
......
......@@ -44,7 +44,7 @@ class _DiffAction(object):
parser.add_argument('--all', action='store_true', help='Verbose diff')
@staticmethod
def Run(args, parser):
def Run(args, on_config_error):
args.output_directory = None
args.tool_prefix = None
args.inputs = [args.before, args.after]
......@@ -60,7 +60,7 @@ class _DiffAction(object):
' print("Full diff:")',
'Print(d, verbose=%s)' % bool(args.all),
])
console.Run(args, parser)
console.Run(args, on_config_error)
class _SaveDiffAction(object):
......@@ -74,13 +74,13 @@ class _SaveDiffAction(object):
help='Write generated data to the specified .sizediff file.')
@staticmethod
def Run(args, parser):
def Run(args, on_config_error):
if not args.before.endswith('.size'):
parser.error('Before input must end with ".size"')
on_config_error('Before input must end with ".size"')
if not args.after.endswith('.size'):
parser.error('After input must end with ".size"')
on_config_error('After input must end with ".size"')
if not args.output_file.endswith('.sizediff'):
parser.error('Output must end with ".sizediff"')
on_config_error('Output must end with ".sizediff"')
before_size_info = archive.LoadAndPostProcessSizeInfo(args.before)
after_size_info = archive.LoadAndPostProcessSizeInfo(args.after)
......@@ -130,7 +130,10 @@ def main():
if logging.getLogger().isEnabledFor(logging.DEBUG):
atexit.register(_LogPeakRamUsage)
args.func(args, parser)
def on_config_error(*args):
parser.error(*args)
args.func(args, on_config_error)
if __name__ == '__main__':
......
......@@ -64,7 +64,7 @@ class OutputDirectoryFinder(_PathFinder):
parent_dir = os.path.dirname(abs_path)
if parent_dir == abs_path:
break
abs_path = abs_path = parent_dir
abs_path = parent_dir
# See if CWD=output directory.
if os.path.exists('build.ninja'):
......
......@@ -44,7 +44,8 @@ def AddArguments(parser):
help='Address for the HTTP server')
def Run(args, _parser):
# pylint: disable=unused-argument
def Run(args, on_config_error):
logging.info('Starting server')
server_addr = (args.address, args.port)
......
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