Merge "Create EXTRA_INSTALL_ZIPS variable" into main

This commit is contained in:
Cole Faust
2024-05-10 00:11:16 +00:00
committed by Gerrit Code Review
3 changed files with 49 additions and 1 deletions

View File

@@ -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())

View File

@@ -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"],
}

View File

@@ -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()