1# Copyright (c) 2021 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14import("//build/config/python.gni") 15import("//build/ohos/build_var.gni") 16import("//build/ohos_var.gni") 17import("${build_configs_path}/platforms_list.gni") 18 19declare_args() { 20 sdk_notice_dir = "$root_build_dir/NOTICE_FILES/sdk" 21 sdk_notice_archive_dir = "$root_build_dir/NOTICE_FILES/sdk_archives" 22 ndk_notice_dir = "$root_build_dir/NOTICE_FILES/ndk" 23 static_libraries_notice_dir = "$root_build_dir/NOTICE_FILES/static" 24 lite_libraries_notice_dir = "$root_build_dir/NOTICE_FILES/rootfs" 25} 26 27declare_args() { 28 ndk_notice_txt = "$root_build_dir/NOTICE_FILES/ndk-final-notice/NOTICE.txt" 29 ndk_notice_gz = "$root_build_dir/NOTICE_FILES/ndk-final-notice/NOTICE.xml.gz" 30 sdk_notice_txt = "$root_build_dir/NOTICE_FILES/sdk-final-notice/NOTICE.txt" 31 sdk_notice_gz = "$root_build_dir/NOTICE_FILES/sdk-final-notice/NOTICE.xml.gz" 32} 33 34# Gen notice file 35# private template 36# 37template("collect_notice") { 38 assert(defined(invoker.module_source_dir), "module_source_dir is required.") 39 if (!enable_notice_collection) { 40 group(target_name) { 41 not_needed(invoker, "*") 42 } 43 } else { 44 action_with_pydeps(target_name) { 45 forward_variables_from(invoker, 46 [ 47 "module_name", 48 "module_source_dir", 49 "deps", 50 "license_file", 51 "testonly", 52 "module_type", 53 "outputs", 54 "source_list", 55 56 # Some license file are generated in gn gen. 57 # Such notices should not be used as sources. 58 "license_as_sources", 59 ]) 60 script = rebase_path("//build/ohos/notice/collect_module_notice_file.py") 61 depfile = "${target_gen_dir}/$target_name.d" 62 63 if (!defined(outputs)) { 64 outputs = [] 65 if (defined(module_type) && 66 (module_type == "static_library" || module_type == "source_set" || 67 module_type == "rust_library")) { 68 _current_toolchain = get_label_info(current_toolchain, "name") 69 _notice_subdir = "$_current_toolchain/${invoker.subsystem_name}/${invoker.part_name}" 70 71 # Although static library and source set are not installed, their 72 # notice files still needs to be collected. 73 # We may collect a little more notice files than needed. 74 outputs += [ 75 "${static_libraries_notice_dir}/$_notice_subdir/$module_name.a.txt", 76 ] 77 } else { 78 if (defined(module_type) && module_type == "java_library" && 79 defined(license_file) && 80 get_path_info(license_file, "extension") == "zip") { 81 outputs = [ "$target_out_dir/$module_name.notice.zip" ] 82 } else { 83 outputs += [ "$target_out_dir/$module_name.notice.txt" ] 84 } 85 } 86 } 87 88 args = [ 89 "--module-source-dir", 90 rebase_path(module_source_dir, root_build_dir), 91 "--depfile", 92 rebase_path(depfile, root_build_dir), 93 ] 94 foreach(o, outputs) { 95 args += [ 96 "--output", 97 rebase_path(o, root_build_dir), 98 ] 99 } 100 101 if (build_ohos_sdk && defined(module_name)) { 102 import("//build/ohos/sdk/sdk.gni") 103 if (defined(source_list)) { 104 foreach(s, source_list) { 105 args += [ 106 "--sources", 107 rebase_path(s, root_build_dir), 108 ] 109 } 110 } 111 args += [ 112 "--sdk-install-info-file", 113 rebase_path(generated_sdk_module_install_paths, root_out_dir), 114 "--label", 115 get_label_info(":${module_name}", "label_no_toolchain"), 116 "--sdk-notice-dir", 117 rebase_path(sdk_notice_dir, root_build_dir), 118 ] 119 } else { 120 not_needed([ "source_list" ]) 121 } 122 123 if (defined(license_file)) { 124 _license_as_sources = true 125 if (defined(license_as_sources)) { 126 _license_as_sources = license_as_sources 127 } 128 if (_license_as_sources) { 129 inputs = [ license_file ] 130 } 131 args += [ 132 "--license-file", 133 rebase_path(license_file, root_build_dir), 134 ] 135 } 136 } 137 } 138} 139