Kiyoung Kim | 8376b32 | 2024-06-21 14:15:49 +0900 | [diff] [blame] | 1 | # 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 | |
| 15 | import argparse |
| 16 | import sys |
| 17 | |
| 18 | COLOR_WARNING = '\033[93m' |
| 19 | COLOR_ERROR = '\033[91m' |
| 20 | COLOR_NORMAL = '\033[0m' |
| 21 | |
Justin Yun | f460a63 | 2024-10-06 12:17:11 +0900 | [diff] [blame] | 22 | def find_unique_items(kati_installed_files, soong_installed_files, system_module_name, allowlists): |
Kiyoung Kim | 8376b32 | 2024-06-21 14:15:49 +0900 | [diff] [blame] | 23 | with open(kati_installed_files, 'r') as kati_list_file, \ |
Justin Yun | f460a63 | 2024-10-06 12:17:11 +0900 | [diff] [blame] | 24 | open(soong_installed_files, 'r') as soong_list_file: |
Kiyoung Kim | 8376b32 | 2024-06-21 14:15:49 +0900 | [diff] [blame] | 25 | kati_files = set(kati_list_file.read().split()) |
| 26 | soong_files = set(soong_list_file.read().split()) |
Justin Yun | f460a63 | 2024-10-06 12:17:11 +0900 | [diff] [blame] | 27 | |
| 28 | allowed_files = set() |
| 29 | for allowlist in allowlists: |
| 30 | with open(allowlist, 'r') as allowlist_file: |
| 31 | allowed_files.update(set(filter(lambda x: len(x), map(lambda x: x.lstrip().split('#',1)[0].rstrip() , allowlist_file.read().split('\n'))))) |
Kiyoung Kim | 8376b32 | 2024-06-21 14:15:49 +0900 | [diff] [blame] | 32 | |
| 33 | def is_unknown_diff(filepath): |
Cole Faust | 3967e50 | 2024-10-02 15:36:06 -0700 | [diff] [blame] | 34 | return filepath not in allowed_files |
| 35 | |
| 36 | def is_unnecessary_allowlist(filepath): |
| 37 | return filepath not in kati_files.symmetric_difference(soong_files) |
Kiyoung Kim | 8376b32 | 2024-06-21 14:15:49 +0900 | [diff] [blame] | 38 | |
| 39 | unique_in_kati = set(filter(is_unknown_diff, kati_files - soong_files)) |
| 40 | unique_in_soong = set(filter(is_unknown_diff, soong_files - kati_files)) |
Cole Faust | 3967e50 | 2024-10-02 15:36:06 -0700 | [diff] [blame] | 41 | unnecessary_allowlists = set(filter(is_unnecessary_allowlist, allowed_files)) |
Kiyoung Kim | 8376b32 | 2024-06-21 14:15:49 +0900 | [diff] [blame] | 42 | |
| 43 | if unique_in_kati: |
Justin Yun | 776e4da | 2024-09-30 20:36:34 +0900 | [diff] [blame] | 44 | print('') |
| 45 | print(f'{COLOR_ERROR}Missing required modules in {system_module_name} module.{COLOR_NORMAL}') |
| 46 | 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.') |
| 47 | print(f'You can find the correct Android.bp file using the command "gomod {system_module_name}".') |
| 48 | print(f'{COLOR_WARNING}KATI only installed file(s):{COLOR_NORMAL}') |
Kiyoung Kim | 8376b32 | 2024-06-21 14:15:49 +0900 | [diff] [blame] | 49 | for item in sorted(unique_in_kati): |
Justin Yun | 776e4da | 2024-09-30 20:36:34 +0900 | [diff] [blame] | 50 | print(' '+item) |
Kiyoung Kim | 8376b32 | 2024-06-21 14:15:49 +0900 | [diff] [blame] | 51 | |
| 52 | if unique_in_soong: |
Justin Yun | 776e4da | 2024-09-30 20:36:34 +0900 | [diff] [blame] | 53 | print('') |
| 54 | print(f'{COLOR_ERROR}Missing packages in base_system.mk.{COLOR_NORMAL}') |
| 55 | 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.') |
| 56 | print(f'{COLOR_WARNING}Soong only installed file(s):{COLOR_NORMAL}') |
Kiyoung Kim | 8376b32 | 2024-06-21 14:15:49 +0900 | [diff] [blame] | 57 | for item in sorted(unique_in_soong): |
Justin Yun | 776e4da | 2024-09-30 20:36:34 +0900 | [diff] [blame] | 58 | print(' '+item) |
Kiyoung Kim | 8376b32 | 2024-06-21 14:15:49 +0900 | [diff] [blame] | 59 | |
Cole Faust | 3967e50 | 2024-10-02 15:36:06 -0700 | [diff] [blame] | 60 | if unnecessary_allowlists: |
| 61 | print('') |
| 62 | print(f'{COLOR_ERROR}Unnecessary files in allowlist.{COLOR_NORMAL}') |
| 63 | print('Please remove these entries from build/make/tools/filelistdiff/allowlist') |
| 64 | for item in sorted(unnecessary_allowlists): |
| 65 | print(' '+item) |
| 66 | |
| 67 | |
| 68 | if unique_in_kati or unique_in_soong or unnecessary_allowlists: |
Kiyoung Kim | 8376b32 | 2024-06-21 14:15:49 +0900 | [diff] [blame] | 69 | print('') |
Kiyoung Kim | 8376b32 | 2024-06-21 14:15:49 +0900 | [diff] [blame] | 70 | sys.exit(1) |
| 71 | |
| 72 | |
| 73 | if __name__ == '__main__': |
| 74 | parser = argparse.ArgumentParser() |
| 75 | |
| 76 | parser.add_argument('kati_installed_file_list') |
| 77 | parser.add_argument('soong_installed_file_list') |
Kiyoung Kim | 8376b32 | 2024-06-21 14:15:49 +0900 | [diff] [blame] | 78 | parser.add_argument('system_module_name') |
Cole Faust | 62ac1d9 | 2024-11-07 15:22:07 -0800 | [diff] [blame] | 79 | parser.add_argument('--allowlists', nargs='*', default=[]) |
Kiyoung Kim | 8376b32 | 2024-06-21 14:15:49 +0900 | [diff] [blame] | 80 | args = parser.parse_args() |
| 81 | |
Justin Yun | f460a63 | 2024-10-06 12:17:11 +0900 | [diff] [blame] | 82 | find_unique_items(args.kati_installed_file_list, args.soong_installed_file_list, args.system_module_name, args.allowlists) |