From e4c1ec94664761d546a0ae12a487e04afd400dab Mon Sep 17 00:00:00 2001 From: Wei Li Date: Wed, 18 Sep 2024 20:15:31 +0000 Subject: [PATCH] Add command line tool that generates NOTICE.xml.gz for partitions. The tool currently generates a XML file with the root element only and its content will be filled in in following CLs. Also disable the generation of NOTICE.xml.gz in make when USE_SOONG_DEFINED_SYSTEM_IMAGE is true, so the Soong module could be used without conflict. Bug: 330949782 Bug: 338342381 Test: lunch aosp_cf_x86_64_phone-trunk_staging-eng && m, and check that system/etc/NOTICE.xml.gz have all the XML elements. Test: lunch aosp_cf_x86_64_phone_soong_system-trunk_staging-eng && m, and check that system/etc/NOTICE.xml.gz has root element only. Change-Id: I82e90bd9aa3dabc605acfe8da697ab1f7e7ecf9b --- core/Makefile | 4 +- core/os_licensing.mk | 4 ++ tools/sbom/Android.bp | 14 +++++++ tools/sbom/gen_notice_xml.py | 81 ++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 tools/sbom/gen_notice_xml.py diff --git a/core/Makefile b/core/Makefile index b0392cdc8b..0bc6f1fc9e 100644 --- a/core/Makefile +++ b/core/Makefile @@ -1964,7 +1964,7 @@ target_system_dlkm_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_SYST installed_system_dlkm_notice_xml_gz := $(TARGET_OUT_SYSTEM_DLKM)/etc/NOTICE.xml.gz ALL_INSTALLED_NOTICE_FILES := \ - $(installed_notice_html_or_xml_gz) \ + $(if $(USE_SOONG_DEFINED_SYSTEM_IMAGE),,$(installed_notice_html_or_xml_gz)) \ $(installed_vendor_notice_xml_gz) \ $(installed_product_notice_xml_gz) \ $(installed_system_ext_notice_xml_gz) \ @@ -2051,7 +2051,9 @@ endif endif # PRODUCT_NOTICE_SPLIT +ifneq ($(USE_SOONG_DEFINED_SYSTEM_IMAGE),true) ALL_DEFAULT_INSTALLED_MODULES += $(installed_notice_html_or_xml_gz) +endif need_vendor_notice:=false ifeq ($(BUILDING_VENDOR_BOOT_IMAGE),true) diff --git a/core/os_licensing.mk b/core/os_licensing.mk index 1e1b7df7a9..d15a3d0715 100644 --- a/core/os_licensing.mk +++ b/core/os_licensing.mk @@ -17,13 +17,17 @@ $(eval $(call xml-notice-rule,$(target_notice_file_xml_gz),"System image",$(syst $(eval $(call text-notice-rule,$(target_notice_file_txt),"System image",$(system_notice_file_message),$(SYSTEM_NOTICE_DEPS),$(SYSTEM_NOTICE_DEPS))) +ifneq ($(USE_SOONG_DEFINED_SYSTEM_IMAGE),true) $(installed_notice_html_or_xml_gz): $(target_notice_file_xml_gz) $(copy-file-to-target) endif +endif $(call declare-1p-target,$(target_notice_file_xml_gz)) +ifneq ($(USE_SOONG_DEFINED_SYSTEM_IMAGE),true) $(call declare-1p-target,$(installed_notice_html_or_xml_gz)) endif +endif .PHONY: vendorlicense vendorlicense: $(call corresponding-license-metadata, $(VENDOR_NOTICE_DEPS)) reportmissinglicenses diff --git a/tools/sbom/Android.bp b/tools/sbom/Android.bp index 6901b06720..74b3d626f6 100644 --- a/tools/sbom/Android.bp +++ b/tools/sbom/Android.bp @@ -109,3 +109,17 @@ python_binary_host { "sbom_lib", ], } + +python_binary_host { + name: "gen_notice_xml", + srcs: [ + "gen_notice_xml.py", + ], + version: { + py3: { + embedded_launcher: true, + }, + }, + libs: [ + ], +} diff --git a/tools/sbom/gen_notice_xml.py b/tools/sbom/gen_notice_xml.py new file mode 100644 index 0000000000..eaa6e5a74d --- /dev/null +++ b/tools/sbom/gen_notice_xml.py @@ -0,0 +1,81 @@ +# !/usr/bin/env python3 +# +# 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. + +""" +Generate NOTICE.xml.gz of a partition. +Usage example: + gen_notice_xml.py --output_file out/soong/.intermediate/.../NOTICE.xml.gz \ + --metadata out/soong/compliance-metadata/aosp_cf_x86_64_phone/compliance-metadata.db \ + --partition system \ + --product_out out/target/vsoc_x86_64 \ + --soong_out out/soong +""" + +import argparse + + +FILE_HEADER = '''\ + + +''' +FILE_FOOTER = '''\ + +''' + + +def get_args(): + parser = argparse.ArgumentParser() + parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Print more information.') + parser.add_argument('-d', '--debug', action='store_true', default=True, help='Debug mode') + parser.add_argument('--output_file', required=True, help='The path of the generated NOTICE.xml.gz file.') + parser.add_argument('--partition', required=True, help='The name of partition for which the NOTICE.xml.gz is generated.') + parser.add_argument('--metadata', required=True, help='The path of compliance metadata DB file.') + parser.add_argument('--product_out', required=True, help='The path of PRODUCT_OUT, e.g. out/target/product/vsoc_x86_64.') + parser.add_argument('--soong_out', required=True, help='The path of Soong output directory, e.g. out/soong') + + return parser.parse_args() + + +def log(*info): + if args.verbose: + for i in info: + print(i) + + +def new_file_name_tag(file_metadata, package_name): + file_path = file_metadata['installed_file'].removeprefix(args.product_out) + lib = 'Android' + if package_name: + lib = package_name + return f'{file_path}\n' + + +def new_file_content_tag(): + pass + + +def main(): + global args + args = get_args() + log('Args:', vars(args)) + + with open(args.output_file, 'w', encoding="utf-8") as notice_xml_file: + notice_xml_file.write(FILE_HEADER) + notice_xml_file.write(FILE_FOOTER) + + +if __name__ == '__main__': + main()