blob: eaa6e5a74dc02713cc15c93e139b6f5e0d6f3c71 [file] [log] [blame]
Wei Li486c6272024-09-19 17:55:10 +00001# !/usr/bin/env python3
2#
3# Copyright (C) 2024 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""
18Generate NOTICE.xml.gz of a partition.
19Usage example:
20 gen_notice_xml.py --output_file out/soong/.intermediate/.../NOTICE.xml.gz \
21 --metadata out/soong/compliance-metadata/aosp_cf_x86_64_phone/compliance-metadata.db \
22 --partition system \
23 --product_out out/target/vsoc_x86_64 \
24 --soong_out out/soong
25"""
26
27import argparse
28
29
30FILE_HEADER = '''\
31<?xml version="1.0" encoding="utf-8"?>
32<licenses>
33'''
34FILE_FOOTER = '''\
35</licenses>
36'''
37
38
39def get_args():
40 parser = argparse.ArgumentParser()
41 parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Print more information.')
42 parser.add_argument('-d', '--debug', action='store_true', default=True, help='Debug mode')
43 parser.add_argument('--output_file', required=True, help='The path of the generated NOTICE.xml.gz file.')
44 parser.add_argument('--partition', required=True, help='The name of partition for which the NOTICE.xml.gz is generated.')
45 parser.add_argument('--metadata', required=True, help='The path of compliance metadata DB file.')
46 parser.add_argument('--product_out', required=True, help='The path of PRODUCT_OUT, e.g. out/target/product/vsoc_x86_64.')
47 parser.add_argument('--soong_out', required=True, help='The path of Soong output directory, e.g. out/soong')
48
49 return parser.parse_args()
50
51
52def log(*info):
53 if args.verbose:
54 for i in info:
55 print(i)
56
57
58def new_file_name_tag(file_metadata, package_name):
59 file_path = file_metadata['installed_file'].removeprefix(args.product_out)
60 lib = 'Android'
61 if package_name:
62 lib = package_name
63 return f'<file-name contentId="" lib="{lib}">{file_path}</file-name>\n'
64
65
66def new_file_content_tag():
67 pass
68
69
70def main():
71 global args
72 args = get_args()
73 log('Args:', vars(args))
74
75 with open(args.output_file, 'w', encoding="utf-8") as notice_xml_file:
76 notice_xml_file.write(FILE_HEADER)
77 notice_xml_file.write(FILE_FOOTER)
78
79
80if __name__ == '__main__':
81 main()