• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2023 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/components/ets_frontend/es2abc_config.gni")
15import("//build/config/python.gni")
16import("//build/ohos/notice/notice.gni")
17import("//build/templates/common/collect_target.gni")
18import("//build/templates/metadata/module_info.gni")
19
20# Generate .abc files from .ts files
21#
22# Variables
23#   sources: Paths to .ts file to compile
24#
25# Example
26#   ohos_abc("foo_abc") {
27#     sources = [ "example.ts" ]
28#     subsystem_name = "example"
29#     part_name = "example"
30#   }
31template("ohos_abc") {
32  assert(defined(invoker.subsystem_name), "subsystem_name is required")
33  assert(defined(invoker.part_name), "part_name is required")
34
35  _test_target = defined(invoker.testonly) && invoker.testonly
36  subsystem_name = invoker.subsystem_name
37  part_name = invoker.part_name
38
39  if (is_use_check_deps && !_test_target) {
40    _check_target = "${target_name}__check"
41    target_path = get_label_info(":${target_name}", "label_no_toolchain")
42    check_target(_check_target) {
43      module_deps = []
44      module_ex_deps = []
45      if (defined(invoker.deps)) {
46        module_deps += invoker.deps
47      }
48      if (defined(invoker.public_deps)) {
49        module_deps += invoker.public_deps
50      }
51      if (defined(invoker.external_deps)) {
52        module_ex_deps += invoker.external_deps
53      }
54      if (defined(invoker.public_external_deps)) {
55        module_ex_deps += invoker.public_external_deps
56      }
57    }
58  }
59
60  if (is_standard_system) {
61    output_dir = "${root_out_dir}/${subsystem_name}/${part_name}"
62  } else {
63    output_dir = "${root_out_dir}"
64  }
65
66  target_label = get_label_info(":${target_name}", "label_with_toolchain")
67  target_toolchain = get_label_info(target_label, "toolchain")
68
69  if (target_toolchain == "${current_toolchain}") {
70    ohos_abc_target = target_name
71    module_info_target = "${target_name}_info"
72    generate_module_info(module_info_target) {
73      forward_variables_from(invoker, [ "testonly" ])
74      module_name = ohos_abc_target
75      if (!defined(invoker.module_type)) {
76        module_type = "unknown"
77      } else {
78        module_type = invoker.module_type
79      }
80      module_source_dir = "$root_out_dir"
81      if (defined(output_dir)) {
82        module_source_dir = output_dir
83      }
84
85      if (defined(invoker.symlink_target_name)) {
86        symlink_target_name = invoker.symlink_target_name
87      }
88
89      module_install_name = "${ohos_abc_target}.abc"
90      if (defined(invoker.output_name)) {
91        module_install_name = "${invoker.output_name}.abc"
92      }
93
94      module_install_images = [ "system" ]
95      if (defined(invoker.install_images)) {
96        module_install_images = []
97        module_install_images += invoker.install_images
98      }
99
100      module_install_dir = "etc/abc"
101      if (defined(invoker.module_install_dir)) {
102        module_install_dir = invoker.module_install_dir
103      }
104
105      install_enable = true
106      if (defined(invoker.install_enable)) {
107        install_enable = invoker.install_enable
108      }
109
110      if (defined(invoker.relative_install_dir)) {
111        relative_install_dir = invoker.relative_install_dir
112      }
113
114      notice = "$target_out_dir/$ohos_abc_target.notice.txt"
115    }
116  }
117
118  if (!_test_target) {
119    module_label = get_label_info(":${target_name}", "label_with_toolchain")
120    _collect_target = "${target_name}__collect"
121    collect_module_target(_collect_target) {
122      forward_variables_from(invoker, [ "install_images" ])
123    }
124
125    _notice_target = "${target_name}__notice"
126    ohos_abc_target = target_name
127    collect_notice(_notice_target) {
128      forward_variables_from(invoker, [ "testonly" ])
129      if (defined(invoker.license_as_sources)) {
130        license_as_sources = invoker.license_as_sources
131      }
132      if (defined(invoker.license_file)) {
133        license_file = invoker.license_file
134      }
135      module_name = ohos_abc_target
136      module_source_dir = get_label_info(":${ohos_abc_target}", "dir")
137    }
138  }
139
140  action_with_pydeps(target_name) {
141    forward_variables_from(invoker, [ "testonly" ])
142    if (!defined(deps)) {
143      deps = []
144    }
145    if (defined(invoker.deps)) {
146      deps += invoker.deps
147    }
148    deps += es2abc_build_deps
149    if (is_use_check_deps && !_test_target) {
150      deps += [ ":$_check_target" ]
151    }
152    if (target_toolchain == "${current_toolchain}") {
153      deps += [ ":$module_info_target" ]
154    }
155    if (!_test_target) {
156      deps += [
157        ":${_collect_target}",
158        ":${_notice_target}",
159      ]
160    }
161
162    if (defined(invoker.output_name)) {
163      output_file = "${output_dir}/${invoker.output_name}.abc"
164    } else {
165      output_file = "${output_dir}/${target_name}.abc"
166    }
167    script = "//build/scripts/ohos_abc.py"
168    sources = invoker.sources
169    args = [
170      "--outputs",
171      rebase_path(output_file),
172      "--es2abc",
173      rebase_path(es2abc_build_path),
174      "--sources",
175    ]
176    args += rebase_path(sources, root_build_dir)
177    if (defined(invoker.merge_abc) && invoker.merge_abc) {
178      args += [ "--merge-abc" ]
179    }
180    if (defined(invoker.disable_module) && invoker.disable_module) {
181      args += [ "--module" ]
182    }
183    outputs = [ output_file ]
184
185    install_module_info = {
186      module_def = target_label
187      module_info_file =
188          rebase_path(get_label_info(module_def, "target_out_dir"),
189                      root_build_dir) + "/${target_name}_module_info.json"
190      toolchain = current_toolchain
191      toolchain_out_dir = rebase_path(root_out_dir, root_build_dir)
192      subsystem_name = subsystem_name
193      part_name = part_name
194    }
195    metadata = {
196      install_modules = [ install_module_info ]
197    }
198  }
199}
200