The test also runs on soong-only build. "KATI only" does not make sense and makes confusion. Replace them with PRODUCT_PACKAGES to make it clear to understand. Bug: 455671267 Test: m Change-Id: I5a2f6f9fefc0590c29269ad6d32d9d4b25f0b10c
85 lines
3.8 KiB
Python
85 lines
3.8 KiB
Python
# Copyright (C) 2024 The Android Open Source Project
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import argparse
|
|
import sys
|
|
|
|
COLOR_WARNING = '\033[93m'
|
|
COLOR_ERROR = '\033[91m'
|
|
COLOR_NORMAL = '\033[0m'
|
|
|
|
def find_unique_items(kati_installed_files, soong_installed_files, system_module_name, allowlists):
|
|
with open(kati_installed_files, 'r') as kati_list_file, \
|
|
open(soong_installed_files, 'r') as soong_list_file:
|
|
kati_files = set(kati_list_file.read().split())
|
|
soong_files = set(soong_list_file.read().split())
|
|
|
|
allowed_files = set()
|
|
for allowlist in allowlists:
|
|
with open(allowlist, 'r') as allowlist_file:
|
|
allowed_files.update(set(filter(lambda x: len(x), map(lambda x: x.lstrip().split('#',1)[0].rstrip() , allowlist_file.read().split('\n')))))
|
|
|
|
def is_unknown_diff(filepath):
|
|
return filepath not in allowed_files
|
|
|
|
def is_unnecessary_allowlist(filepath):
|
|
return filepath not in kati_files.symmetric_difference(soong_files)
|
|
|
|
unique_in_kati = set(filter(is_unknown_diff, kati_files - soong_files))
|
|
unique_in_soong = set(filter(is_unknown_diff, soong_files - kati_files))
|
|
unnecessary_allowlists = set(filter(is_unnecessary_allowlist, allowed_files))
|
|
|
|
if unique_in_kati:
|
|
print('')
|
|
print(f'{COLOR_ERROR}Missing required modules in the "{system_module_name}" module.{COLOR_NORMAL}')
|
|
print(f'To resolve this issue, please add the modules to the Android.bp file for the "{system_module_name}" to install the following files from PRODUCT_PACKAGES.')
|
|
print(f'You can find the Android.bp file using the command "gomod {system_module_name}".')
|
|
print('See build/make/tools/filelistdiff/README.md for more details.')
|
|
print(f'{COLOR_WARNING}Files from PRODUCT_PACKAGES that are missing in the Soong definition:{COLOR_NORMAL}')
|
|
for item in sorted(unique_in_kati):
|
|
print(' '+item)
|
|
|
|
if unique_in_soong:
|
|
print('')
|
|
print(f'{COLOR_ERROR}Missing packages in PRODUCT_PACKAGES.{COLOR_NORMAL}')
|
|
print(f'Please add packages into .mk files or remove them from the "{system_module_name}" module in Android.bp file.')
|
|
print(f'You can find the Android.bp file using the command "gomod {system_module_name}".')
|
|
print('See build/make/tools/filelistdiff/README.md for more details.')
|
|
print(f'{COLOR_WARNING}Files in the Soong definition that are missing from PRODUCT_PACKAGES:{COLOR_NORMAL}')
|
|
for item in sorted(unique_in_soong):
|
|
print(' '+item)
|
|
|
|
if unnecessary_allowlists:
|
|
print('')
|
|
print(f'{COLOR_ERROR}Unnecessary files in allowlist.{COLOR_NORMAL}')
|
|
print('Please remove these entries from build/make/tools/filelistdiff/allowlist')
|
|
for item in sorted(unnecessary_allowlists):
|
|
print(' '+item)
|
|
|
|
|
|
if unique_in_kati or unique_in_soong or unnecessary_allowlists:
|
|
print('')
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('kati_installed_file_list')
|
|
parser.add_argument('soong_installed_file_list')
|
|
parser.add_argument('system_module_name')
|
|
parser.add_argument('--allowlists', nargs='*', default=[])
|
|
args = parser.parse_args()
|
|
|
|
find_unique_items(args.kati_installed_file_list, args.soong_installed_file_list, args.system_module_name, args.allowlists) |