blob: 170bc0f33364ba96b35a2e152861b62fb33e8782 [file] [log] [blame]
Kiyoung Kim8376b322024-06-21 14:15:49 +09001# 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):
Cole Faust3967e502024-10-02 15:36:06 -070031 return filepath not in allowed_files
32
33 def is_unnecessary_allowlist(filepath):
34 return filepath not in kati_files.symmetric_difference(soong_files)
Kiyoung Kim8376b322024-06-21 14:15:49 +090035
36 unique_in_kati = set(filter(is_unknown_diff, kati_files - soong_files))
37 unique_in_soong = set(filter(is_unknown_diff, soong_files - kati_files))
Cole Faust3967e502024-10-02 15:36:06 -070038 unnecessary_allowlists = set(filter(is_unnecessary_allowlist, allowed_files))
Kiyoung Kim8376b322024-06-21 14:15:49 +090039
40 if unique_in_kati:
Justin Yun776e4da2024-09-30 20:36:34 +090041 print('')
42 print(f'{COLOR_ERROR}Missing required modules in {system_module_name} module.{COLOR_NORMAL}')
43 print(f'To resolve this issue, please add the modules to the Android.bp file for the {system_module_name} to install the following KATI only installed files.')
44 print(f'You can find the correct Android.bp file using the command "gomod {system_module_name}".')
45 print(f'{COLOR_WARNING}KATI only installed file(s):{COLOR_NORMAL}')
Kiyoung Kim8376b322024-06-21 14:15:49 +090046 for item in sorted(unique_in_kati):
Justin Yun776e4da2024-09-30 20:36:34 +090047 print(' '+item)
Kiyoung Kim8376b322024-06-21 14:15:49 +090048
49 if unique_in_soong:
Justin Yun776e4da2024-09-30 20:36:34 +090050 print('')
51 print(f'{COLOR_ERROR}Missing packages in base_system.mk.{COLOR_NORMAL}')
52 print('Please add packages into build/make/target/product/base_system.mk or build/make/tools/filelistdiff/allowlist to install or skip the following Soong only installed files.')
53 print(f'{COLOR_WARNING}Soong only installed file(s):{COLOR_NORMAL}')
Kiyoung Kim8376b322024-06-21 14:15:49 +090054 for item in sorted(unique_in_soong):
Justin Yun776e4da2024-09-30 20:36:34 +090055 print(' '+item)
Kiyoung Kim8376b322024-06-21 14:15:49 +090056
Cole Faust3967e502024-10-02 15:36:06 -070057 if unnecessary_allowlists:
58 print('')
59 print(f'{COLOR_ERROR}Unnecessary files in allowlist.{COLOR_NORMAL}')
60 print('Please remove these entries from build/make/tools/filelistdiff/allowlist')
61 for item in sorted(unnecessary_allowlists):
62 print(' '+item)
63
64
65 if unique_in_kati or unique_in_soong or unnecessary_allowlists:
Kiyoung Kim8376b322024-06-21 14:15:49 +090066 print('')
Kiyoung Kim8376b322024-06-21 14:15:49 +090067 sys.exit(1)
68
69
70if __name__ == '__main__':
71 parser = argparse.ArgumentParser()
72
73 parser.add_argument('kati_installed_file_list')
74 parser.add_argument('soong_installed_file_list')
75 parser.add_argument('allowlist')
76 parser.add_argument('system_module_name')
77 args = parser.parse_args()
78
79 find_unique_items(args.kati_installed_file_list, args.soong_installed_file_list, args.allowlist, args.system_module_name)