• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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          _notice_subdir = "$_current_toolchain/${invoker.subsystem_name}/${invoker.part_name}"
67
68          # Although static library and source set are not installed, their
69          # notice files still needs to be collected.
70          # We may collect a little more notice files than needed.
71          outputs += [
72            "${static_libraries_notice_dir}/$_notice_subdir/$module_name.a.txt",
73          ]
74        } else {
75          if (defined(module_type) && module_type == "java_library" &&
76              defined(license_file) &&
77              get_path_info(license_file, "extension") == "zip") {
78            outputs = [ "$target_out_dir/$module_name.notice.zip" ]
79          } else {
80            outputs += [ "$target_out_dir/$module_name.notice.txt" ]
81          }
82        }
83      }
84
85      args = [
86        "--module-source-dir",
87        rebase_path(module_source_dir, root_build_dir),
88        "--depfile",
89        rebase_path(depfile, root_build_dir),
90
91        # use default License for modules couldn't find license
92        "--default-license",
93        rebase_path("//build/ohos/notice/license", root_build_dir),
94      ]
95      foreach(o, outputs) {
96        args += [
97          "--output",
98          rebase_path(o, root_build_dir),
99        ]
100      }
101
102      if (defined(license_file)) {
103        _license_as_sources = true
104        if (defined(license_as_sources)) {
105          _license_as_sources = license_as_sources
106        }
107        if (_license_as_sources) {
108          inputs = [ license_file ]
109        }
110        args += [
111          "--license-file",
112          rebase_path(license_file, root_build_dir),
113        ]
114      }
115    }
116  }
117}
118