From 99bec751976251ccb709d02946cebcd02d5e29c1 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Thu, 9 May 2024 11:07:20 -0700 Subject: [PATCH] Create EXTRA_INSTALL_ZIPS variable Make needs to know about the "extra" zip files that are extracted to the staging directories so that it can track all the installed files correctly. Also add a utility tool for listing the contents of relevant zips. Bug: 337869220 Test: m droid and checked the contents of file_list.txt when adding an android_app_set locally Change-Id: Idc5dd785b03c05f7972c66620d4e6359892b3863 --- android/makevars.go | 5 +++- scripts/Android.bp | 6 ++++ scripts/extra_install_zips_file_list.py | 39 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100755 scripts/extra_install_zips_file_list.py diff --git a/android/makevars.go b/android/makevars.go index e73645fdc..b6bc14e8f 100644 --- a/android/makevars.go +++ b/android/makevars.go @@ -473,7 +473,7 @@ func (s *makeVarsSingleton) writeInstalls(installs, symlinks, katiVintfManifestI # Values written by Soong to generate install rules that can be amended by Kati. - +EXTRA_INSTALL_ZIPS := `) preserveSymlinksFlag := "-d" @@ -507,9 +507,12 @@ func (s *makeVarsSingleton) writeInstalls(installs, symlinks, katiVintfManifestI if extraFiles := install.extraFiles; extraFiles != nil { fmt.Fprintf(buf, "\t( unzip -qDD -d '%s' '%s' 2>&1 | grep -v \"zipfile is empty\"; exit $${PIPESTATUS[0]} ) || \\\n", extraFiles.dir.String(), extraFiles.zip.String()) fmt.Fprintf(buf, "\t ( code=$$?; if [ $$code -ne 0 -a $$code -ne 1 ]; then exit $$code; fi )\n") + fmt.Fprintf(buf, "EXTRA_INSTALL_ZIPS += %s:%s\n", extraFiles.dir.String(), extraFiles.zip.String()) } + fmt.Fprintln(buf) } + fmt.Fprintf(buf, ".KATI_READONLY := EXTRA_INSTALL_ZIPS\n") for _, symlink := range symlinks { fmt.Fprintf(buf, "%s:", symlink.to.String()) diff --git a/scripts/Android.bp b/scripts/Android.bp index 790fbe0c1..80cd93579 100644 --- a/scripts/Android.bp +++ b/scripts/Android.bp @@ -296,3 +296,9 @@ python_binary_host { main: "buildinfo.py", srcs: ["buildinfo.py"], } + +python_binary_host { + name: "extra_install_zips_file_list", + main: "extra_install_zips_file_list.py", + srcs: ["extra_install_zips_file_list.py"], +} diff --git a/scripts/extra_install_zips_file_list.py b/scripts/extra_install_zips_file_list.py new file mode 100755 index 000000000..8ea2a4bf0 --- /dev/null +++ b/scripts/extra_install_zips_file_list.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +import argparse +import os +import sys +import zipfile +from typing import List + +def list_files_in_zip(zipfile_path: str) -> List[str]: + with zipfile.ZipFile(zipfile_path, 'r') as zf: + return zf.namelist() + +def main(): + parser = argparse.ArgumentParser( + description='Lists paths to all files inside an EXTRA_INSTALL_ZIPS zip file relative to a partition staging directory. ' + 'This script is just a helper because its difficult to implement this logic in make code.' + ) + parser.add_argument('staging_dir', + help='Path to the partition staging directory') + parser.add_argument('extra_install_zips', nargs='*', + help='The value of EXTRA_INSTALL_ZIPS from make. It should be a list of extraction_dir:zip_file pairs.') + args = parser.parse_args() + + staging_dir = args.staging_dir.removesuffix('/') + '/' + + for zip_pair in args.extra_install_zips: + d, z = zip_pair.split(':') + d = d.removesuffix('/') + '/' + + if d.startswith(staging_dir): + d = os.path.relpath(d, staging_dir) + if d == '.': + d = '' + for f in list_files_in_zip(z): + print(os.path.join(d, f)) + + +if __name__ == "__main__": + main()