blob: cdc5b2ee41cd18edc3675cb3648eac95db4aef67 [file] [log] [blame]
Kiyoung Kimf5a52d92024-06-28 12:52:07 +00001# Copyright (C) 2024 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import argparse
16import sys
17
18COLOR_WARNING = '\033[93m'
19COLOR_ERROR = '\033[91m'
20COLOR_NORMAL = '\033[0m'
21
22def find_unique_items(kati_installed_files, soong_installed_files, allowlist, system_module_name):
23 with open(kati_installed_files, 'r') as kati_list_file, \
24 open(soong_installed_files, 'r') as soong_list_file, \
25 open(allowlist, 'r') as allowlist_file:
26 kati_files = set(kati_list_file.read().split())
27 soong_files = set(soong_list_file.read().split())
28 allowed_files = set(filter(lambda x: len(x), map(lambda x: x.lstrip().split('#',1)[0].rstrip() , allowlist_file.read().split('\n'))))
29
30 def is_unknown_diff(filepath):
31 return not filepath in allowed_files
32
33 unique_in_kati = set(filter(is_unknown_diff, kati_files - soong_files))
34 unique_in_soong = set(filter(is_unknown_diff, soong_files - kati_files))
35
36 if unique_in_kati:
37 print(f'{COLOR_ERROR}Please add following modules into system image module {system_module_name}.{COLOR_NORMAL}')
38 print(f'{COLOR_WARNING}KATI only module(s):{COLOR_NORMAL}')
39 for item in sorted(unique_in_kati):
40 print(item)
41
42 if unique_in_soong:
43 if unique_in_kati:
44 print('')
45
46 print(f'{COLOR_ERROR}Please add following modules into build/make/target/product/base_system.mk.{COLOR_NORMAL}')
47 print(f'{COLOR_WARNING}Soong only module(s):{COLOR_NORMAL}')
48 for item in sorted(unique_in_soong):
49 print(item)
50
51 if unique_in_kati or unique_in_soong:
52 print('')
53 print(f'{COLOR_ERROR}FAILED: System image from KATI and SOONG differs from installed file list.{COLOR_NORMAL}')
54 sys.exit(1)
55
56
57if __name__ == '__main__':
58 parser = argparse.ArgumentParser()
59
60 parser.add_argument('kati_installed_file_list')
61 parser.add_argument('soong_installed_file_list')
62 parser.add_argument('allowlist')
63 parser.add_argument('system_module_name')
64 args = parser.parse_args()
65
66 find_unique_items(args.kati_installed_file_list, args.soong_installed_file_list, args.allowlist, args.system_module_name)