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