releasetools: common.LoadInfoDict() takes a bool parameter for repacking.
It used to accept a non-None input_dir to indicate the need to
re-generate images (called from add_img_to_target_files.py). During that
flow, both of the two parameters redundantly refer to the same input
dir. This CL replaces the second parameter with a bool value instead.
Test: `python -m unittest test_common`
Test: `m dist` with aosp_taimen-userdebug
Test: `zip -d aosp_taimen-target_files-eng.zip IMAGES/\* &&
add_img_to_target_files.py -a aosp_taimen-target_files-eng.zip`
Change-Id: I0a5a164366acb116407f94bb350872a3a0b207d1
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 227d701..8d51df6 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -149,9 +149,41 @@
pass
-def LoadInfoDict(input_file, input_dir=None):
- """Read and parse the META/misc_info.txt key/value pairs from the
- input target files and return a dict."""
+def LoadInfoDict(input_file, repacking=False):
+ """Loads the key/value pairs from the given input target_files.
+
+ It reads `META/misc_info.txt` file in the target_files input, does sanity
+ checks and returns the parsed key/value pairs for to the given build. It's
+ usually called early when working on input target_files files, e.g. when
+ generating OTAs, or signing builds. Note that the function may be called
+ against an old target_files file (i.e. from past dessert releases). So the
+ property parsing needs to be backward compatible.
+
+ In a `META/misc_info.txt`, a few properties are stored as links to the files
+ in the PRODUCT_OUT directory. It works fine with the build system. However,
+ they are no longer available when (re)generating images from target_files zip.
+ When `repacking` is True, redirect these properties to the actual files in the
+ unzipped directory.
+
+ Args:
+ input_file: The input target_files file, which could be an open
+ zipfile.ZipFile instance, or a str for the dir that contains the files
+ unzipped from a target_files file.
+ repacking: Whether it's trying repack an target_files file after loading the
+ info dict (default: False). If so, it will rewrite a few loaded
+ properties (e.g. selinux_fc, root_dir) to point to the actual files in
+ target_files file. When doing repacking, `input_file` must be a dir.
+
+ Returns:
+ A dict that contains the parsed key/value pairs.
+
+ Raises:
+ AssertionError: On invalid input arguments.
+ ValueError: On malformed input values.
+ """
+ if repacking:
+ assert isinstance(input_file, str), \
+ "input_file must be a path str when doing repacking"
def read_helper(fn):
if isinstance(input_file, zipfile.ZipFile):
@@ -168,36 +200,33 @@
try:
d = LoadDictionaryFromLines(read_helper("META/misc_info.txt").split("\n"))
except KeyError:
- raise ValueError("can't find META/misc_info.txt in input target-files")
+ raise ValueError("Failed to find META/misc_info.txt in input target-files")
- assert "recovery_api_version" in d
- assert "fstab_version" in d
+ if "recovery_api_version" not in d:
+ raise ValueError("Failed to find 'recovery_api_version'")
+ if "fstab_version" not in d:
+ raise ValueError("Failed to find 'fstab_version'")
- # A few properties are stored as links to the files in the out/ directory.
- # It works fine with the build system. However, they are no longer available
- # when (re)generating from target_files zip. If input_dir is not None, we
- # are doing repacking. Redirect those properties to the actual files in the
- # unzipped directory.
- if input_dir is not None:
- # We carry a copy of file_contexts.bin under META/. If not available,
- # search BOOT/RAMDISK/. Note that sometimes we may need a different file
- # to build images than the one running on device, in that case, we must
- # have the one for image generation copied to META/.
+ if repacking:
+ # We carry a copy of file_contexts.bin under META/. If not available, search
+ # BOOT/RAMDISK/. Note that sometimes we may need a different file to build
+ # images than the one running on device, in that case, we must have the one
+ # for image generation copied to META/.
fc_basename = os.path.basename(d.get("selinux_fc", "file_contexts"))
- fc_config = os.path.join(input_dir, "META", fc_basename)
+ fc_config = os.path.join(input_file, "META", fc_basename)
assert os.path.exists(fc_config)
d["selinux_fc"] = fc_config
# Similarly we need to redirect "root_dir", and "root_fs_config".
- d["root_dir"] = os.path.join(input_dir, "ROOT")
+ d["root_dir"] = os.path.join(input_file, "ROOT")
d["root_fs_config"] = os.path.join(
- input_dir, "META", "root_filesystem_config.txt")
+ input_file, "META", "root_filesystem_config.txt")
# Redirect {system,vendor}_base_fs_file.
if "system_base_fs_file" in d:
basename = os.path.basename(d["system_base_fs_file"])
- system_base_fs_file = os.path.join(input_dir, "META", basename)
+ system_base_fs_file = os.path.join(input_file, "META", basename)
if os.path.exists(system_base_fs_file):
d["system_base_fs_file"] = system_base_fs_file
else:
@@ -207,7 +236,7 @@
if "vendor_base_fs_file" in d:
basename = os.path.basename(d["vendor_base_fs_file"])
- vendor_base_fs_file = os.path.join(input_dir, "META", basename)
+ vendor_base_fs_file = os.path.join(input_file, "META", basename)
if os.path.exists(vendor_base_fs_file):
d["vendor_base_fs_file"] = vendor_base_fs_file
else: