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} 25 26declare_args() { 27 ndk_notice_txt = "$root_build_dir/NOTICE_FILES/ndk-final-notice/NOTICE.txt" 28 ndk_notice_gz = "$root_build_dir/NOTICE_FILES/ndk-final-notice/NOTICE.xml.gz" 29 sdk_notice_txt = "$root_build_dir/NOTICE_FILES/sdk-final-notice/NOTICE.txt" 30 sdk_notice_gz = "$root_build_dir/NOTICE_FILES/sdk-final-notice/NOTICE.xml.gz" 31} 32 33# Gen notice file 34# private template 35# 36template("collect_notice") { 37 assert(defined(invoker.module_source_dir), "module_source_dir is required.") 38 if (!enable_notice_collection) { 39 group(target_name) { 40 not_needed(invoker, "*") 41 } 42 } else { 43 action_with_pydeps(target_name) { 44 forward_variables_from(invoker, 45 [ 46 "module_name", 47 "module_source_dir", 48 "deps", 49 "license_file", 50 "testonly", 51 "module_type", 52 "outputs", 53 54 # Some license file are generated in gn gen. 55 # Such notices should not be used as sources. 56 "license_as_sources", 57 ]) 58 script = rebase_path("//build/ohos/notice/collect_module_notice_file.py") 59 depfile = "${target_gen_dir}/$target_name.d" 60 61 if (!defined(outputs)) { 62 outputs = [] 63 if (defined(module_type) && 64 (module_type == "static_library" || module_type == "source_set")) { 65 _current_toolchain = get_label_info(current_toolchain, "name") 66 67 # Although static library and source set are not installed, their 68 # notice files still needs to be collected. 69 # We may collect a little more notice files than needed. 70 outputs += [ "${static_libraries_notice_dir}/$_current_toolchain/$module_name.a.txt" ] 71 } else { 72 if (defined(module_type) && module_type == "java_library" && 73 defined(license_file) && 74 get_path_info(license_file, "extension") == "zip") { 75 outputs = [ "$target_out_dir/$module_name.notice.zip" ] 76 } else { 77 outputs += [ "$target_out_dir/$module_name.notice.txt" ] 78 } 79 } 80 } 81 82 args = [ 83 "--module-source-dir", 84 rebase_path(module_source_dir, root_build_dir), 85 "--depfile", 86 rebase_path(depfile, root_build_dir), 87 88 # use default License for modules couldn't find license 89 "--default-license", 90 rebase_path("//build/ohos/notice/license", root_build_dir), 91 ] 92 foreach(o, outputs) { 93 args += [ 94 "--output", 95 rebase_path(o, root_build_dir), 96 ] 97 } 98 99 if (defined(license_file)) { 100 _license_as_sources = true 101 if (defined(license_as_sources)) { 102 _license_as_sources = license_as_sources 103 } 104 if (_license_as_sources) { 105 inputs = [ license_file ] 106 } 107 args += [ 108 "--license-file", 109 rebase_path(license_file, root_build_dir), 110 ] 111 } 112 } 113 } 114} 115