resource_sizes.py: Support multiple .arsc files.
resources.arsc normalization expects a single .arsc file, so use the resource packaged APK instead. This requires the output directory to be set (if not, normalization is skipped). Bug: 764827 Change-Id: Ic17d5350eb07f48f490bde78f0cd8c664f178e82 Reviewed-on: https://chromium-review.googlesource.com/667721 Commit-Queue: Eric Stevenson <estevenson@chromium.org> Reviewed-by: Andrew Grieve <agrieve@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#502347} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 0cd4fc80316b8c17edd3bd770e6d0aa561d00293
This commit is contained in:
Родитель
d396bd0578
Коммит
5c25e8bf65
|
@ -250,13 +250,24 @@ def _NormalizeLanguagePaks(translations, normalized_apk_size, factor):
|
|||
return normalized_apk_size
|
||||
|
||||
|
||||
def _NormalizeResourcesArsc(apk_path, num_translations):
|
||||
def _NormalizeResourcesArsc(apk_path, num_arsc_files, num_translations,
|
||||
out_dir):
|
||||
"""Estimates the expected overhead of untranslated strings in resources.arsc.
|
||||
|
||||
See http://crbug.com/677966 for why this is necessary.
|
||||
"""
|
||||
aapt_output = _RunAaptDumpResources(apk_path)
|
||||
# If there are multiple .arsc files, use the resource packaged APK instead.
|
||||
if num_arsc_files > 1:
|
||||
if not out_dir:
|
||||
print 'Skipping resources.arsc normalization (output directory required)'
|
||||
return 0
|
||||
ap_name = os.path.basename(apk_path).replace('.apk', '.intermediate.ap_')
|
||||
ap_path = os.path.join(out_dir, 'gen/arsc/apks', ap_name)
|
||||
if not os.path.exists(ap_path):
|
||||
raise Exception('Missing expected file: %s, try rebuilding.' % ap_path)
|
||||
apk_path = ap_path
|
||||
|
||||
aapt_output = _RunAaptDumpResources(apk_path)
|
||||
# en-rUS is in the default config and may be cluttered with non-translatable
|
||||
# strings, so en-rGB is a better baseline for finding missing translations.
|
||||
en_strings = _CreateResourceIdValueMap(aapt_output, 'en-rGB')
|
||||
|
@ -338,7 +349,7 @@ class _FileGroup(object):
|
|||
return self.ComputeExtractedSize() + self.ComputeZippedSize()
|
||||
|
||||
|
||||
def PrintApkAnalysis(apk_filename, tool_prefix, chartjson=None):
|
||||
def PrintApkAnalysis(apk_filename, tool_prefix, out_dir, chartjson=None):
|
||||
"""Analyse APK to determine size contributions of different file classes."""
|
||||
file_groups = []
|
||||
|
||||
|
@ -505,8 +516,8 @@ def PrintApkAnalysis(apk_filename, tool_prefix, chartjson=None):
|
|||
# WebView (which supports more locales), but these should mostly be empty
|
||||
# so ignore them here.
|
||||
num_arsc_translations = num_translations
|
||||
normalized_apk_size += int(
|
||||
_NormalizeResourcesArsc(apk_filename, num_arsc_translations))
|
||||
normalized_apk_size += int(_NormalizeResourcesArsc(
|
||||
apk_filename, arsc.GetNumEntries(), num_arsc_translations, out_dir))
|
||||
|
||||
perf_tests_results_helper.ReportPerfResult(chartjson,
|
||||
apk_basename + '_Specifics',
|
||||
|
@ -835,7 +846,7 @@ def main():
|
|||
argparser.error(
|
||||
'--dump-static-initializers requires --chromium-output-directory')
|
||||
|
||||
PrintApkAnalysis(args.apk, tool_prefix, chartjson=chartjson)
|
||||
PrintApkAnalysis(args.apk, tool_prefix, out_dir, chartjson=chartjson)
|
||||
_PrintDexAnalysis(args.apk, chartjson=chartjson)
|
||||
|
||||
si_count = AnalyzeStaticInitializers(
|
||||
|
|
|
@ -1633,11 +1633,15 @@ if (enable_java_templates) {
|
|||
assert(_version_code != -1) # Mark as used.
|
||||
assert(_version_name != "") # Mark as used.
|
||||
|
||||
_base_apk_path = _base_path + ".apk_intermediates"
|
||||
|
||||
_resource_packaged_apk_path = _base_apk_path + ".ap_"
|
||||
_base_resource_packaged_apk_path =
|
||||
get_path_info("$root_gen_dir/arsc/" +
|
||||
rebase_path(_final_apk_path, root_build_dir),
|
||||
"dir") + "/" + get_path_info(_final_apk_path, "name")
|
||||
_resource_packaged_apk_path = _base_resource_packaged_apk_path + ".ap_"
|
||||
_incremental_resource_packaged_apk_path =
|
||||
_base_apk_path + "_incremental.ap_"
|
||||
_base_resource_packaged_apk_path + "_incremental.ap_"
|
||||
|
||||
_base_apk_path = _base_path + ".apk_intermediates"
|
||||
_packaged_apk_path = _base_apk_path + ".unfinished.apk"
|
||||
_incremental_packaged_apk_path =
|
||||
_base_apk_path + "_incremental.unfinished.apk"
|
||||
|
@ -1678,7 +1682,9 @@ if (enable_java_templates) {
|
|||
_package_resources_target = "${_package_resources_target}__intermediate"
|
||||
_post_processed_resource_packaged_apk_path = _resource_packaged_apk_path
|
||||
_resource_packaged_apk_path =
|
||||
"${_resource_packaged_apk_path}__intermediate.ap_"
|
||||
get_path_info(_resource_packaged_apk_path, "dir") + "/" +
|
||||
get_path_info(_resource_packaged_apk_path, "name") +
|
||||
".intermediate.ap_"
|
||||
}
|
||||
|
||||
action(_package_resources_target) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче