From e596452f03d390f84d47e0bcec5250c690923e1f Mon Sep 17 00:00:00 2001 From: Daniel Norman Date: Tue, 19 Mar 2019 10:32:03 -0700 Subject: [PATCH] Validates the config lists used by the script. This validation is to help ensure that any usage of custom merge config files does not accidentally exclude any item that has been added to the default config lists. Bug: 124197349 Test: Run merge_target_files with custom merge config files. Change-Id: I34c51cb75212368146a2944d37621f311060d24d --- tools/releasetools/merge_target_files.py | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tools/releasetools/merge_target_files.py b/tools/releasetools/merge_target_files.py index 501451658f..94ae353eda 100755 --- a/tools/releasetools/merge_target_files.py +++ b/tools/releasetools/merge_target_files.py @@ -199,6 +199,38 @@ def read_config_list(config_file_path): return config_file.read().splitlines() +def validate_config_lists(system_item_list, other_item_list): + """Performs validations on the merge config lists. + + Args: + system_item_list: The list of items to extract from the partial + system target files package as is. + + other_item_list: The list of items to extract from the partial + other target files package as is. + + Returns: + False if a validation fails, otherwise true. + """ + default_combined_item_set = set(default_system_item_list) + default_combined_item_set.update(default_other_item_list) + + combined_item_set = set(system_item_list) + combined_item_set.update(other_item_list) + + # Check that the merge config lists are not missing any item specified + # by the default config lists. + difference = default_combined_item_set.difference(combined_item_set) + if difference: + logger.error('Missing merge config items: %s' % list(difference)) + logger.error('Please ensure missing items are in either the ' + 'system-item-list or other-item-list files provided to ' + 'this script.') + return False + + return True + + def process_ab_partitions_txt( system_target_files_temp_dir, other_target_files_temp_dir, @@ -671,6 +703,11 @@ def main(): else: other_item_list = default_other_item_list + if not validate_config_lists( + system_item_list=system_item_list, + other_item_list=other_item_list): + sys.exit(1) + call_func_with_temp_dir( lambda temp_dir: merge_target_files( temp_dir=temp_dir,