• 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/ebpf.gni")
16import("//build/ohos_var.gni")
17
18template("ohos_part") {
19  assert(defined(invoker.subsystem_name), "module_list is required.")
20  assert(defined(invoker.module_list), "module_list is required.")
21
22  part_label = get_label_info(":${target_name}", "label_with_toolchain")
23  _deps = []
24  foreach(module_label, invoker.module_list) {
25    _deps += [ get_label_info(module_label, "label_with_toolchain") ]
26  }
27
28  # add sdk dep
29  parts_targets_info_file =
30      "${root_build_dir}/build_configs/required_parts_targets_list.json"
31
32  parts_targets_info = read_file(parts_targets_info_file, "json")
33  foreach(part_info, parts_targets_info) {
34    if (part_info.part == part_label) {
35      if (defined(part_info.inner_kits)) {
36        _deps += [ part_info.inner_kits ]
37      }
38    }
39  }
40
41  part_name = target_name
42  if (defined(invoker.origin_name)) {
43    origin_part_name = invoker.origin_name
44  } else {
45    origin_part_name = part_name
46  }
47  if (defined(invoker.variant)) {
48    variant_name = invoker.variant
49  } else {
50    variant_name = "phone"
51  }
52
53  part_modules_info_file = "${target_gen_dir}/${part_name}_modules.json"
54  generated_file("${part_name}_info") {
55    outputs = [ part_modules_info_file ]
56    data_keys = [ "install_modules" ]
57    output_conversion = "json"
58
59    part_install_info = {
60      part_label = part_label
61      part_name = part_name
62      origin_part_name = origin_part_name
63      variant_name = variant_name
64      subsystem_name = invoker.subsystem_name
65      part_info_file =
66          rebase_path(get_label_info(part_label, "target_out_dir"),
67                      root_build_dir) + "/${part_name}_install_modules.json"
68      toolchain_label = get_label_info(part_label, "toolchain")
69      build_out_dir = rebase_path(root_out_dir, root_build_dir)
70    }
71
72    part_host_info = {
73      part_label = part_label
74      part_name = part_name
75      origin_part_name = origin_part_name
76      variant_name = variant_name
77      subsystem_name = invoker.subsystem_name
78
79      # generated by generate_part_info.py
80      part_info_file =
81          rebase_path(get_label_info(part_label, "target_out_dir"),
82                      root_build_dir) + "/${part_name}_host_modules.json"
83      toolchain_label = get_label_info(part_label, "toolchain")
84      build_out_dir = rebase_path(root_out_dir, root_build_dir)
85    }
86    metadata = {
87      part_installed_info = [ part_install_info ]
88      part_host_info = [ part_host_info ]
89    }
90    deps = _deps
91  }
92
93  # ebpf
94  if (ebpf_enable) {
95    if (defined(invoker.ebpf_testcase)) {
96      collect_ebpf_testcase("${part_name}_ebpf_testcase") {
97        ebpf_testcase = invoker.ebpf_testcase
98      }
99      _deps += [ ":${part_name}_ebpf_testcase" ]
100    }
101  }
102
103  part_install_modules_file =
104      "${target_out_dir}/${part_name}_install_modules.json"
105  part_dep_modules_file = "${target_out_dir}/${part_name}_dep_modules.json"
106  part_sdk_modules_info_file =
107      "${target_gen_dir}/${part_name}_sdk_install_modules.json"
108  part_host_modules_file = "${target_out_dir}/${part_name}_host_modules.json"
109  action_with_pydeps(target_name) {
110    deps = [ ":${part_name}_info" ]
111    script = "//build/ohos/generate_part_info.py"
112    sources = [ part_modules_info_file ]
113    outputs = [
114      part_install_modules_file,
115      part_dep_modules_file,
116    ]
117    args = [
118      "--part-name",
119      part_name,
120      "--origin-part-name",
121      origin_part_name,
122      "--input-file",
123      rebase_path(part_modules_info_file, root_build_dir),
124      "--sdk-modules-info-file",
125      rebase_path(part_sdk_modules_info_file, root_build_dir),
126      "--output-install-file",
127      rebase_path(part_install_modules_file, root_build_dir),
128      "--output-deps-file",
129      rebase_path(part_dep_modules_file, root_build_dir),
130      "--output-host-file",
131      rebase_path(part_host_modules_file, root_build_dir),
132      "--current-toolchain",
133      "${current_toolchain}",
134      "--host-toolchain",
135      "${host_toolchain}",
136    ]
137  }
138}
139