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