Adds support for optional config files to configure the merge.
Bug: 124467065 Test: Running `python merge_target_files.py` using the three new flags and observing that their contents are passed to the merge_target_files() function. Change-Id: I4de46f041f5ae8bc8be2730313ce873a952bf78e
This commit is contained in:
@@ -25,10 +25,22 @@ Usage: merge_target_files.py [args]
|
|||||||
The input target files package containing system bits. This is a zip
|
The input target files package containing system bits. This is a zip
|
||||||
archive.
|
archive.
|
||||||
|
|
||||||
|
--system-item-list system-item-list-file
|
||||||
|
The optional path to a newline-separated config file that replaces the
|
||||||
|
contents of default_system_item_list if provided.
|
||||||
|
|
||||||
|
--system-misc-info-keys system-misc-info-keys-file
|
||||||
|
The optional path to a newline-separated config file that replaces the
|
||||||
|
contents of default_system_misc_info_keys if provided.
|
||||||
|
|
||||||
--other-target-files other-target-files-zip-archive
|
--other-target-files other-target-files-zip-archive
|
||||||
The input target files package containing other bits. This is a zip
|
The input target files package containing other bits. This is a zip
|
||||||
archive.
|
archive.
|
||||||
|
|
||||||
|
--other-item-list other-item-list-file
|
||||||
|
The optional path to a newline-separated config file that replaces the
|
||||||
|
contents of default_other_item_list if provided.
|
||||||
|
|
||||||
--output-target-files output-target-files-package
|
--output-target-files output-target-files-package
|
||||||
The output merged target files package. Also a zip archive.
|
The output merged target files package. Also a zip archive.
|
||||||
"""
|
"""
|
||||||
@@ -48,16 +60,19 @@ logger = logging.getLogger(__name__)
|
|||||||
OPTIONS = common.OPTIONS
|
OPTIONS = common.OPTIONS
|
||||||
OPTIONS.verbose = True
|
OPTIONS.verbose = True
|
||||||
OPTIONS.system_target_files = None
|
OPTIONS.system_target_files = None
|
||||||
|
OPTIONS.system_item_list = None
|
||||||
|
OPTIONS.system_misc_info_keys = None
|
||||||
OPTIONS.other_target_files = None
|
OPTIONS.other_target_files = None
|
||||||
|
OPTIONS.other_item_list = None
|
||||||
OPTIONS.output_target_files = None
|
OPTIONS.output_target_files = None
|
||||||
OPTIONS.keep_tmp = False
|
OPTIONS.keep_tmp = False
|
||||||
|
|
||||||
# system_extract_as_is_item_list is a list of items to extract from the partial
|
# default_system_item_list is a list of items to extract from the partial
|
||||||
# system target files package as is, meaning these items will land in the
|
# system target files package as is, meaning these items will land in the
|
||||||
# output target files package exactly as they appear in the input partial
|
# output target files package exactly as they appear in the input partial
|
||||||
# system target files package.
|
# system target files package.
|
||||||
|
|
||||||
system_extract_as_is_item_list = [
|
default_system_item_list = [
|
||||||
'META/apkcerts.txt',
|
'META/apkcerts.txt',
|
||||||
'META/filesystem_config.txt',
|
'META/filesystem_config.txt',
|
||||||
'META/root_filesystem_config.txt',
|
'META/root_filesystem_config.txt',
|
||||||
@@ -78,10 +93,10 @@ system_extract_special_item_list = [
|
|||||||
'META/*',
|
'META/*',
|
||||||
]
|
]
|
||||||
|
|
||||||
# system_misc_info_keys is a list of keys to obtain from the system instance of
|
# default_system_misc_info_keys is a list of keys to obtain from the system instance of
|
||||||
# META/misc_info.txt. The remaining keys from the other instance.
|
# META/misc_info.txt. The remaining keys from the other instance.
|
||||||
|
|
||||||
system_misc_info_keys = [
|
default_system_misc_info_keys = [
|
||||||
'avb_system_hashtree_enable',
|
'avb_system_hashtree_enable',
|
||||||
'avb_system_add_hashtree_footer_args',
|
'avb_system_add_hashtree_footer_args',
|
||||||
'avb_system_key_path',
|
'avb_system_key_path',
|
||||||
@@ -98,12 +113,12 @@ system_misc_info_keys = [
|
|||||||
'system_size',
|
'system_size',
|
||||||
]
|
]
|
||||||
|
|
||||||
# other_extract_as_is_item_list is a list of items to extract from the partial
|
# default_other_item_list is a list of items to extract from the partial
|
||||||
# other target files package as is, meaning these items will land in the output
|
# other target files package as is, meaning these items will land in the output
|
||||||
# target files package exactly as they appear in the input partial other target
|
# target files package exactly as they appear in the input partial other target
|
||||||
# files package.
|
# files package.
|
||||||
|
|
||||||
other_extract_as_is_item_list = [
|
default_other_item_list = [
|
||||||
'META/boot_filesystem_config.txt',
|
'META/boot_filesystem_config.txt',
|
||||||
'META/otakeys.txt',
|
'META/otakeys.txt',
|
||||||
'META/releasetools.py',
|
'META/releasetools.py',
|
||||||
@@ -119,7 +134,7 @@ other_extract_as_is_item_list = [
|
|||||||
'VENDOR/*',
|
'VENDOR/*',
|
||||||
]
|
]
|
||||||
|
|
||||||
# other_extract_for_merge_item_list is a list of items to extract from the
|
# other_extract_special_item_list is a list of items to extract from the
|
||||||
# partial other target files package that need some special processing, such as
|
# partial other target files package that need some special processing, such as
|
||||||
# some sort of combination with items from the partial system target files
|
# some sort of combination with items from the partial system target files
|
||||||
# package.
|
# package.
|
||||||
@@ -172,6 +187,18 @@ def extract_items(target_files, target_files_temp_dir, extract_item_list):
|
|||||||
filtered_extract_item_list)
|
filtered_extract_item_list)
|
||||||
|
|
||||||
|
|
||||||
|
def read_config_list(config_file_path):
|
||||||
|
"""Reads a config file into a list of strings.
|
||||||
|
|
||||||
|
Expects the file to be newline-separated.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
config_file_path: The path to the config file to open and read.
|
||||||
|
"""
|
||||||
|
with open(config_file_path) as config_file:
|
||||||
|
return config_file.read().splitlines()
|
||||||
|
|
||||||
|
|
||||||
def process_ab_partitions_txt(
|
def process_ab_partitions_txt(
|
||||||
system_target_files_temp_dir,
|
system_target_files_temp_dir,
|
||||||
other_target_files_temp_dir,
|
other_target_files_temp_dir,
|
||||||
@@ -223,7 +250,8 @@ def process_ab_partitions_txt(
|
|||||||
def process_misc_info_txt(
|
def process_misc_info_txt(
|
||||||
system_target_files_temp_dir,
|
system_target_files_temp_dir,
|
||||||
other_target_files_temp_dir,
|
other_target_files_temp_dir,
|
||||||
output_target_files_temp_dir):
|
output_target_files_temp_dir,
|
||||||
|
system_misc_info_keys):
|
||||||
"""Perform special processing for META/misc_info.txt
|
"""Perform special processing for META/misc_info.txt
|
||||||
|
|
||||||
This function merges the contents of the META/misc_info.txt files from the
|
This function merges the contents of the META/misc_info.txt files from the
|
||||||
@@ -242,6 +270,9 @@ def process_misc_info_txt(
|
|||||||
output_target_files_temp_dir: The name of a directory that will be used
|
output_target_files_temp_dir: The name of a directory that will be used
|
||||||
to create the output target files package after all the special cases
|
to create the output target files package after all the special cases
|
||||||
are processed.
|
are processed.
|
||||||
|
|
||||||
|
system_misc_info_keys: A list of keys to obtain from the system instance
|
||||||
|
of META/misc_info.txt. The remaining keys from the other instance.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def read_helper(d):
|
def read_helper(d):
|
||||||
@@ -258,8 +289,7 @@ def process_misc_info_txt(
|
|||||||
read_helper(other_target_files_temp_dir))
|
read_helper(other_target_files_temp_dir))
|
||||||
|
|
||||||
# Replace certain values in merged_info_dict with values from
|
# Replace certain values in merged_info_dict with values from
|
||||||
# system_info_dict. TODO(b/124467065): This should be more flexible than
|
# system_info_dict.
|
||||||
# using the hard-coded system_misc_info_keys.
|
|
||||||
|
|
||||||
for key in system_misc_info_keys:
|
for key in system_misc_info_keys:
|
||||||
merged_info_dict[key] = system_info_dict[key]
|
merged_info_dict[key] = system_info_dict[key]
|
||||||
@@ -355,7 +385,8 @@ def process_special_cases(
|
|||||||
temp_dir,
|
temp_dir,
|
||||||
system_target_files_temp_dir,
|
system_target_files_temp_dir,
|
||||||
other_target_files_temp_dir,
|
other_target_files_temp_dir,
|
||||||
output_target_files_temp_dir):
|
output_target_files_temp_dir,
|
||||||
|
system_misc_info_keys):
|
||||||
"""Perform special-case processing for certain target files items.
|
"""Perform special-case processing for certain target files items.
|
||||||
|
|
||||||
Certain files in the output target files package require special-case
|
Certain files in the output target files package require special-case
|
||||||
@@ -374,6 +405,9 @@ def process_special_cases(
|
|||||||
output_target_files_temp_dir: The name of a directory that will be used
|
output_target_files_temp_dir: The name of a directory that will be used
|
||||||
to create the output target files package after all the special cases
|
to create the output target files package after all the special cases
|
||||||
are processed.
|
are processed.
|
||||||
|
|
||||||
|
system_misc_info_keys: A list of keys to obtain from the system instance
|
||||||
|
of META/misc_info.txt. The remaining keys from the other instance.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
process_ab_partitions_txt(
|
process_ab_partitions_txt(
|
||||||
@@ -384,7 +418,8 @@ def process_special_cases(
|
|||||||
process_misc_info_txt(
|
process_misc_info_txt(
|
||||||
system_target_files_temp_dir=system_target_files_temp_dir,
|
system_target_files_temp_dir=system_target_files_temp_dir,
|
||||||
other_target_files_temp_dir=other_target_files_temp_dir,
|
other_target_files_temp_dir=other_target_files_temp_dir,
|
||||||
output_target_files_temp_dir=output_target_files_temp_dir)
|
output_target_files_temp_dir=output_target_files_temp_dir,
|
||||||
|
system_misc_info_keys=system_misc_info_keys)
|
||||||
|
|
||||||
process_file_contexts_bin(
|
process_file_contexts_bin(
|
||||||
temp_dir=temp_dir,
|
temp_dir=temp_dir,
|
||||||
@@ -394,7 +429,10 @@ def process_special_cases(
|
|||||||
def merge_target_files(
|
def merge_target_files(
|
||||||
temp_dir,
|
temp_dir,
|
||||||
system_target_files,
|
system_target_files,
|
||||||
|
system_item_list,
|
||||||
|
system_misc_info_keys,
|
||||||
other_target_files,
|
other_target_files,
|
||||||
|
other_item_list,
|
||||||
output_target_files):
|
output_target_files):
|
||||||
"""Merge two target files packages together.
|
"""Merge two target files packages together.
|
||||||
|
|
||||||
@@ -410,13 +448,32 @@ def merge_target_files(
|
|||||||
system_target_files: The name of the zip archive containing the system
|
system_target_files: The name of the zip archive containing the system
|
||||||
partial target files package.
|
partial target files package.
|
||||||
|
|
||||||
|
system_item_list: The list of items to extract from the partial system
|
||||||
|
target files package as is, meaning these items will land in the output
|
||||||
|
target files package exactly as they appear in the input partial system
|
||||||
|
target files package.
|
||||||
|
|
||||||
|
system_misc_info_keys: The list of keys to obtain from the system instance
|
||||||
|
of META/misc_info.txt. The remaining keys from the other instance.
|
||||||
|
|
||||||
other_target_files: The name of the zip archive containing the other
|
other_target_files: The name of the zip archive containing the other
|
||||||
partial target files package.
|
partial target files package.
|
||||||
|
|
||||||
|
other_item_list: The list of items to extract from the partial other
|
||||||
|
target files package as is, meaning these items will land in the output
|
||||||
|
target files package exactly as they appear in the input partial other
|
||||||
|
target files package.
|
||||||
|
|
||||||
output_target_files: The name of the output zip archive target files
|
output_target_files: The name of the output zip archive target files
|
||||||
package created by merging system and other.
|
package created by merging system and other.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
'starting: merge system %s and other %s into output %s',
|
||||||
|
system_target_files,
|
||||||
|
other_target_files,
|
||||||
|
output_target_files)
|
||||||
|
|
||||||
# Create directory names that we'll use when we extract files from system,
|
# Create directory names that we'll use when we extract files from system,
|
||||||
# and other, and for zipping the final output.
|
# and other, and for zipping the final output.
|
||||||
|
|
||||||
@@ -431,7 +488,7 @@ def merge_target_files(
|
|||||||
extract_items(
|
extract_items(
|
||||||
target_files=system_target_files,
|
target_files=system_target_files,
|
||||||
target_files_temp_dir=output_target_files_temp_dir,
|
target_files_temp_dir=output_target_files_temp_dir,
|
||||||
extract_item_list=system_extract_as_is_item_list)
|
extract_item_list=system_item_list)
|
||||||
|
|
||||||
# Extract "as is" items from the input other partial target files package. We
|
# Extract "as is" items from the input other partial target files package. We
|
||||||
# extract them directly into the output temporary directory since the items
|
# extract them directly into the output temporary directory since the items
|
||||||
@@ -440,7 +497,7 @@ def merge_target_files(
|
|||||||
extract_items(
|
extract_items(
|
||||||
target_files=other_target_files,
|
target_files=other_target_files,
|
||||||
target_files_temp_dir=output_target_files_temp_dir,
|
target_files_temp_dir=output_target_files_temp_dir,
|
||||||
extract_item_list=other_extract_as_is_item_list)
|
extract_item_list=other_item_list)
|
||||||
|
|
||||||
# Extract "special" items from the input system partial target files package.
|
# Extract "special" items from the input system partial target files package.
|
||||||
# We extract these items to different directory since they require special
|
# We extract these items to different directory since they require special
|
||||||
@@ -469,7 +526,8 @@ def merge_target_files(
|
|||||||
temp_dir=temp_dir,
|
temp_dir=temp_dir,
|
||||||
system_target_files_temp_dir=system_target_files_temp_dir,
|
system_target_files_temp_dir=system_target_files_temp_dir,
|
||||||
other_target_files_temp_dir=other_target_files_temp_dir,
|
other_target_files_temp_dir=other_target_files_temp_dir,
|
||||||
output_target_files_temp_dir=output_target_files_temp_dir)
|
output_target_files_temp_dir=output_target_files_temp_dir,
|
||||||
|
system_misc_info_keys=system_misc_info_keys)
|
||||||
|
|
||||||
# Regenerate IMAGES in the temporary directory.
|
# Regenerate IMAGES in the temporary directory.
|
||||||
|
|
||||||
@@ -520,25 +578,15 @@ def merge_target_files(
|
|||||||
common.RunAndWait(command, verbose=True)
|
common.RunAndWait(command, verbose=True)
|
||||||
|
|
||||||
|
|
||||||
def merge_target_files_with_temp_dir(
|
def call_func_with_temp_dir(func, keep_tmp):
|
||||||
system_target_files,
|
|
||||||
other_target_files,
|
|
||||||
output_target_files,
|
|
||||||
keep_tmp):
|
|
||||||
"""Manage the creation and cleanup of the temporary directory.
|
"""Manage the creation and cleanup of the temporary directory.
|
||||||
|
|
||||||
This function wraps merge_target_files after first creating a temporary
|
This function calls the given function after first creating a temporary
|
||||||
directory. It also cleans up the temporary directory.
|
directory. It also cleans up the temporary directory.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
system_target_files: The name of the zip archive containing the system
|
func: The function to call. Should accept one parameter, the path to
|
||||||
partial target files package.
|
the temporary directory.
|
||||||
|
|
||||||
other_target_files: The name of the zip archive containing the other
|
|
||||||
partial target files package.
|
|
||||||
|
|
||||||
output_target_files: The name of the output zip archive target files
|
|
||||||
package created by merging system and other.
|
|
||||||
|
|
||||||
keep_tmp: Keep the temporary directory after processing is complete.
|
keep_tmp: Keep the temporary directory after processing is complete.
|
||||||
"""
|
"""
|
||||||
@@ -547,20 +595,10 @@ def merge_target_files_with_temp_dir(
|
|||||||
# we use when we extract items from the input target files packages, and also
|
# we use when we extract items from the input target files packages, and also
|
||||||
# a scratch directory that we use for temporary files.
|
# a scratch directory that we use for temporary files.
|
||||||
|
|
||||||
logger.info(
|
|
||||||
'starting: merge system %s and other %s into output %s',
|
|
||||||
system_target_files,
|
|
||||||
other_target_files,
|
|
||||||
output_target_files)
|
|
||||||
|
|
||||||
temp_dir = common.MakeTempDir(prefix='merge_target_files_')
|
temp_dir = common.MakeTempDir(prefix='merge_target_files_')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
merge_target_files(
|
func(temp_dir)
|
||||||
temp_dir=temp_dir,
|
|
||||||
system_target_files=system_target_files,
|
|
||||||
other_target_files=other_target_files,
|
|
||||||
output_target_files=output_target_files)
|
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
@@ -573,7 +611,7 @@ def merge_target_files_with_temp_dir(
|
|||||||
def main():
|
def main():
|
||||||
"""The main function.
|
"""The main function.
|
||||||
|
|
||||||
Process command line arguments, then call merge_target_files_with_temp_dir to
|
Process command line arguments, then call merge_target_files to
|
||||||
perform the heavy lifting.
|
perform the heavy lifting.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -582,8 +620,14 @@ def main():
|
|||||||
def option_handler(o, a):
|
def option_handler(o, a):
|
||||||
if o == '--system-target-files':
|
if o == '--system-target-files':
|
||||||
OPTIONS.system_target_files = a
|
OPTIONS.system_target_files = a
|
||||||
|
elif o == '--system-item-list':
|
||||||
|
OPTIONS.system_item_list = a
|
||||||
|
elif o == '--system-misc-info-keys':
|
||||||
|
OPTIONS.system_misc_info_keys = a
|
||||||
elif o == '--other-target-files':
|
elif o == '--other-target-files':
|
||||||
OPTIONS.other_target_files = a
|
OPTIONS.other_target_files = a
|
||||||
|
elif o == '--other-item-list':
|
||||||
|
OPTIONS.other_item_list = a
|
||||||
elif o == '--output-target-files':
|
elif o == '--output-target-files':
|
||||||
OPTIONS.output_target_files = a
|
OPTIONS.output_target_files = a
|
||||||
elif o == '--keep_tmp':
|
elif o == '--keep_tmp':
|
||||||
@@ -596,7 +640,10 @@ def main():
|
|||||||
sys.argv[1:], __doc__,
|
sys.argv[1:], __doc__,
|
||||||
extra_long_opts=[
|
extra_long_opts=[
|
||||||
'system-target-files=',
|
'system-target-files=',
|
||||||
|
'system-item-list=',
|
||||||
|
'system-misc-info-keys=',
|
||||||
'other-target-files=',
|
'other-target-files=',
|
||||||
|
'other-item-list=',
|
||||||
'output-target-files=',
|
'output-target-files=',
|
||||||
"keep_tmp",
|
"keep_tmp",
|
||||||
],
|
],
|
||||||
@@ -609,11 +656,31 @@ def main():
|
|||||||
common.Usage(__doc__)
|
common.Usage(__doc__)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
merge_target_files_with_temp_dir(
|
if OPTIONS.system_item_list:
|
||||||
system_target_files=OPTIONS.system_target_files,
|
system_item_list = read_config_list(OPTIONS.system_item_list)
|
||||||
other_target_files=OPTIONS.other_target_files,
|
else:
|
||||||
output_target_files=OPTIONS.output_target_files,
|
system_item_list = default_system_item_list
|
||||||
keep_tmp=OPTIONS.keep_tmp)
|
|
||||||
|
if OPTIONS.system_misc_info_keys:
|
||||||
|
system_misc_info_keys = read_config_list(OPTIONS.system_misc_info_keys)
|
||||||
|
else:
|
||||||
|
system_misc_info_keys = default_system_misc_info_keys
|
||||||
|
|
||||||
|
if OPTIONS.other_item_list:
|
||||||
|
other_item_list = read_config_list(OPTIONS.other_item_list)
|
||||||
|
else:
|
||||||
|
other_item_list = default_other_item_list
|
||||||
|
|
||||||
|
call_func_with_temp_dir(
|
||||||
|
lambda temp_dir: merge_target_files(
|
||||||
|
temp_dir=temp_dir,
|
||||||
|
system_target_files=OPTIONS.system_target_files,
|
||||||
|
system_item_list=system_item_list,
|
||||||
|
system_misc_info_keys=system_misc_info_keys,
|
||||||
|
other_target_files=OPTIONS.other_target_files,
|
||||||
|
other_item_list=other_item_list,
|
||||||
|
output_target_files=OPTIONS.output_target_files),
|
||||||
|
OPTIONS.keep_tmp)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Reference in New Issue
Block a user