15f9996aaSopenharmony_ci# Copyright (c) 2021 Huawei Device Co., Ltd.
25f9996aaSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
35f9996aaSopenharmony_ci# you may not use this file except in compliance with the License.
45f9996aaSopenharmony_ci# You may obtain a copy of the License at
55f9996aaSopenharmony_ci#
65f9996aaSopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
75f9996aaSopenharmony_ci#
85f9996aaSopenharmony_ci# Unless required by applicable law or agreed to in writing, software
95f9996aaSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
105f9996aaSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
115f9996aaSopenharmony_ci# See the License for the specific language governing permissions and
125f9996aaSopenharmony_ci# limitations under the License.
135f9996aaSopenharmony_ci
145f9996aaSopenharmony_ciimport("//build/config/python.gni")
155f9996aaSopenharmony_ciimport("//build/ohos/build_var.gni")
165f9996aaSopenharmony_ciimport("//build/ohos_var.gni")
175f9996aaSopenharmony_ciimport("${build_configs_path}/platforms_list.gni")
185f9996aaSopenharmony_ci
195f9996aaSopenharmony_cideclare_args() {
205f9996aaSopenharmony_ci  sdk_notice_dir = "$root_build_dir/NOTICE_FILES/sdk"
215f9996aaSopenharmony_ci  sdk_notice_archive_dir = "$root_build_dir/NOTICE_FILES/sdk_archives"
225f9996aaSopenharmony_ci  ndk_notice_dir = "$root_build_dir/NOTICE_FILES/ndk"
235f9996aaSopenharmony_ci  static_libraries_notice_dir = "$root_build_dir/NOTICE_FILES/static"
245f9996aaSopenharmony_ci}
255f9996aaSopenharmony_ci
265f9996aaSopenharmony_cideclare_args() {
275f9996aaSopenharmony_ci  ndk_notice_txt = "$root_build_dir/NOTICE_FILES/ndk-final-notice/NOTICE.txt"
285f9996aaSopenharmony_ci  ndk_notice_gz = "$root_build_dir/NOTICE_FILES/ndk-final-notice/NOTICE.xml.gz"
295f9996aaSopenharmony_ci  sdk_notice_txt = "$root_build_dir/NOTICE_FILES/sdk-final-notice/NOTICE.txt"
305f9996aaSopenharmony_ci  sdk_notice_gz = "$root_build_dir/NOTICE_FILES/sdk-final-notice/NOTICE.xml.gz"
315f9996aaSopenharmony_ci}
325f9996aaSopenharmony_ci
335f9996aaSopenharmony_ci# Gen notice file
345f9996aaSopenharmony_ci# private template
355f9996aaSopenharmony_ci#
365f9996aaSopenharmony_citemplate("collect_notice") {
375f9996aaSopenharmony_ci  assert(defined(invoker.module_source_dir), "module_source_dir is required.")
385f9996aaSopenharmony_ci  if (!enable_notice_collection) {
395f9996aaSopenharmony_ci    group(target_name) {
405f9996aaSopenharmony_ci      not_needed(invoker, "*")
415f9996aaSopenharmony_ci    }
425f9996aaSopenharmony_ci  } else {
435f9996aaSopenharmony_ci    action_with_pydeps(target_name) {
445f9996aaSopenharmony_ci      forward_variables_from(invoker,
455f9996aaSopenharmony_ci                             [
465f9996aaSopenharmony_ci                               "module_name",
475f9996aaSopenharmony_ci                               "module_source_dir",
485f9996aaSopenharmony_ci                               "deps",
495f9996aaSopenharmony_ci                               "license_file",
505f9996aaSopenharmony_ci                               "testonly",
515f9996aaSopenharmony_ci                               "module_type",
525f9996aaSopenharmony_ci                               "outputs",
535f9996aaSopenharmony_ci                               "source_list",
545f9996aaSopenharmony_ci
555f9996aaSopenharmony_ci                               # Some license file are generated in gn gen.
565f9996aaSopenharmony_ci                               # Such notices should not be used as sources.
575f9996aaSopenharmony_ci                               "license_as_sources",
585f9996aaSopenharmony_ci                             ])
595f9996aaSopenharmony_ci      script = rebase_path("//build/ohos/notice/collect_module_notice_file.py")
605f9996aaSopenharmony_ci      depfile = "${target_gen_dir}/$target_name.d"
615f9996aaSopenharmony_ci
625f9996aaSopenharmony_ci      if (!defined(outputs)) {
635f9996aaSopenharmony_ci        outputs = []
645f9996aaSopenharmony_ci        if (defined(module_type) &&
655f9996aaSopenharmony_ci            (module_type == "static_library" || module_type == "source_set" ||
665f9996aaSopenharmony_ci             module_type == "rust_library")) {
675f9996aaSopenharmony_ci          _current_toolchain = get_label_info(current_toolchain, "name")
685f9996aaSopenharmony_ci          _notice_subdir = "$_current_toolchain/${invoker.subsystem_name}/${invoker.part_name}"
695f9996aaSopenharmony_ci
705f9996aaSopenharmony_ci          # Although static library and source set are not installed, their
715f9996aaSopenharmony_ci          # notice files still needs to be collected.
725f9996aaSopenharmony_ci          # We may collect a little more notice files than needed.
735f9996aaSopenharmony_ci          outputs += [
745f9996aaSopenharmony_ci            "${static_libraries_notice_dir}/$_notice_subdir/$module_name.a.txt",
755f9996aaSopenharmony_ci          ]
765f9996aaSopenharmony_ci        } else {
775f9996aaSopenharmony_ci          if (defined(module_type) && module_type == "java_library" &&
785f9996aaSopenharmony_ci              defined(license_file) &&
795f9996aaSopenharmony_ci              get_path_info(license_file, "extension") == "zip") {
805f9996aaSopenharmony_ci            outputs = [ "$target_out_dir/$module_name.notice.zip" ]
815f9996aaSopenharmony_ci          } else {
825f9996aaSopenharmony_ci            outputs += [ "$target_out_dir/$module_name.notice.txt" ]
835f9996aaSopenharmony_ci          }
845f9996aaSopenharmony_ci        }
855f9996aaSopenharmony_ci      }
865f9996aaSopenharmony_ci
875f9996aaSopenharmony_ci      args = [
885f9996aaSopenharmony_ci        "--module-source-dir",
895f9996aaSopenharmony_ci        rebase_path(module_source_dir, root_build_dir),
905f9996aaSopenharmony_ci        "--depfile",
915f9996aaSopenharmony_ci        rebase_path(depfile, root_build_dir),
925f9996aaSopenharmony_ci      ]
935f9996aaSopenharmony_ci      foreach(o, outputs) {
945f9996aaSopenharmony_ci        args += [
955f9996aaSopenharmony_ci          "--output",
965f9996aaSopenharmony_ci          rebase_path(o, root_build_dir),
975f9996aaSopenharmony_ci        ]
985f9996aaSopenharmony_ci      }
995f9996aaSopenharmony_ci
1005f9996aaSopenharmony_ci      if (build_ohos_sdk && defined(module_name)) {
1015f9996aaSopenharmony_ci        import("//build/ohos/sdk/sdk.gni")
1025f9996aaSopenharmony_ci        if (defined(source_list)) {
1035f9996aaSopenharmony_ci          foreach(s, source_list) {
1045f9996aaSopenharmony_ci            args += [
1055f9996aaSopenharmony_ci              "--sources",
1065f9996aaSopenharmony_ci              rebase_path(s, root_build_dir),
1075f9996aaSopenharmony_ci            ]
1085f9996aaSopenharmony_ci          }
1095f9996aaSopenharmony_ci        }
1105f9996aaSopenharmony_ci        args += [
1115f9996aaSopenharmony_ci          "--sdk-install-info-file",
1125f9996aaSopenharmony_ci          rebase_path(generated_sdk_module_install_paths, root_out_dir),
1135f9996aaSopenharmony_ci          "--label",
1145f9996aaSopenharmony_ci          get_label_info(":${module_name}", "label_no_toolchain"),
1155f9996aaSopenharmony_ci          "--sdk-notice-dir",
1165f9996aaSopenharmony_ci          rebase_path(sdk_notice_dir, root_build_dir),
1175f9996aaSopenharmony_ci        ]
1185f9996aaSopenharmony_ci      } else {
1195f9996aaSopenharmony_ci        not_needed([ "source_list" ])
1205f9996aaSopenharmony_ci      }
1215f9996aaSopenharmony_ci
1225f9996aaSopenharmony_ci      if (defined(license_file)) {
1235f9996aaSopenharmony_ci        _license_as_sources = true
1245f9996aaSopenharmony_ci        if (defined(license_as_sources)) {
1255f9996aaSopenharmony_ci          _license_as_sources = license_as_sources
1265f9996aaSopenharmony_ci        }
1275f9996aaSopenharmony_ci        if (_license_as_sources) {
1285f9996aaSopenharmony_ci          inputs = [ license_file ]
1295f9996aaSopenharmony_ci        }
1305f9996aaSopenharmony_ci        args += [
1315f9996aaSopenharmony_ci          "--license-file",
1325f9996aaSopenharmony_ci          rebase_path(license_file, root_build_dir),
1335f9996aaSopenharmony_ci        ]
1345f9996aaSopenharmony_ci      }
1355f9996aaSopenharmony_ci    }
1365f9996aaSopenharmony_ci  }
1375f9996aaSopenharmony_ci}
138