Skip to content

Commit

Permalink
[SuperSize] Refactor: Add and use apk.CreateMetadata().
Browse files Browse the repository at this point in the history
This CL adds CreateMetadata() to apk.py, to match the one in native.py,
thus simplifying the caller archive._CreateMetadata(). Soon we'll add
code to the new function (to store Dex section sizes).

Bug: 881319
Change-Id: Ib6edf1dd78c1a39b5fa39e0225211399622155d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4117629
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Commit-Queue: Samuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1085133}
  • Loading branch information
samuelhuang authored and Chromium LUCI CQ committed Dec 19, 2022
1 parent 1c7fa97 commit 326f09b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
18 changes: 18 additions & 0 deletions tools/binary_size/libsupersize/apk.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ def FindSourceForPath(self, path):
return ''


def CreateMetadata(apk_spec, include_file_details, shorten_path):
"""Returns metadata for the given apk_spec."""
logging.debug('Constructing APK metadata')
apk_metadata = {}
if include_file_details:
apk_metadata[models.METADATA_APK_SIZE] = os.path.getsize(apk_spec.apk_path)
if apk_spec.mapping_path:
apk_metadata[models.METADATA_PROGUARD_MAPPING_FILENAME] = shorten_path(
apk_spec.mapping_path)
if apk_spec.minimal_apks_path:
apk_metadata[models.METADATA_APK_FILENAME] = shorten_path(
apk_spec.minimal_apks_path)
apk_metadata[models.METADATA_APK_SPLIT_NAME] = apk_spec.split_name
else:
apk_metadata[models.METADATA_APK_FILENAME] = shorten_path(apk_spec.apk_path)
return apk_metadata


def CreateApkOtherSymbols(apk_spec):
"""Creates symbols for resources / assets within the apk.
Expand Down
16 changes: 5 additions & 11 deletions tools/binary_size/libsupersize/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,11 @@ def _CreateMetadata(container_spec, elf_info):
shorten_path = os.path.basename

if apk_spec:
if not container_spec.native_spec:
metadata[models.METADATA_APK_SIZE] = os.path.getsize(apk_spec.apk_path)
if apk_spec.mapping_path:
metadata[models.METADATA_PROGUARD_MAPPING_FILENAME] = shorten_path(
apk_spec.mapping_path)
if apk_spec.minimal_apks_path:
metadata[models.METADATA_APK_FILENAME] = shorten_path(
apk_spec.minimal_apks_path)
metadata[models.METADATA_APK_SPLIT_NAME] = apk_spec.split_name
else:
metadata[models.METADATA_APK_FILENAME] = shorten_path(apk_spec.apk_path)
apk_metadata = apk.CreateMetadata(apk_spec=apk_spec,
include_file_details=not native_spec,
shorten_path=shorten_path)
assert not (metadata.keys() & apk_metadata.keys())
metadata.update(apk_metadata)

if native_spec:
native_metadata = native.CreateMetadata(native_spec=native_spec,
Expand Down

0 comments on commit 326f09b

Please sign in to comment.