1#!/usr/bin/env python3 2# Copyright (C) 2021 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import argparse 17import sys 18from resource_utils import get_all_resources, get_resources_from_single_file, Resource 19 20if sys.version_info[0] != 3: 21 print("Must use python 3") 22 sys.exit(1) 23 24""" 25Script used to verify the 'overlayable.xml' file. 26""" 27def main(): 28 parser = argparse.ArgumentParser(description='Verify overlayable.xml.') 29 optional_args = parser.add_argument_group('optional arguments') 30 optional_args.add_argument('-e', '--excludeFiles', nargs='*', help='File paths (absolute or relative to cwd) that should be excluded when generating overlayable.xml') 31 required_args = parser.add_argument_group('required arguments') 32 required_args.add_argument('-r', '--resourcePath', help='Path to resource directory (absolute or relative to cwd)', required=True) 33 required_args.add_argument('-o', '--overlayableFilePath', help='Filepath to overlayable.xml (absolute or relative to cwd).', required=True) 34 args = parser.parse_args() 35 36 resources = get_all_resources(args.resourcePath, args.excludeFiles) 37 old_mapping = get_resources_from_single_file(args.overlayableFilePath) 38 compare_resources(old_mapping, resources, args.overlayableFilePath) 39 40def compare_resources(old_mapping, new_mapping, res_public_file): 41 removed = old_mapping.difference(new_mapping) 42 added = new_mapping.difference(old_mapping) 43 if len(removed) > 0: 44 print('Resources removed:\n' + '\n'.join(map(lambda x: str(x), removed))) 45 if len(added) > 0: 46 print('Resources added:\n' + '\n'.join(map(lambda x: str(x), added))) 47 if len(added) + len(removed) > 0: 48 print("Some resource have been modified. If this is intentional please " + 49 "run 'python3 generate-overlayable.py' again and submit the new %s" % res_public_file) 50 print("Some projects may include $PROJECT_TOP/tools/generate-overlayable.sh which calls " + 51 "the above command with the appropriate command line arguments") 52 sys.exit(1) 53 54if __name__ == '__main__': 55 main() 56