• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2022 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/ets2abc_config.gni")
15import("//build/ohos.gni")
16import("//build/ohos/notice/notice.gni")
17import("//build/ohos_var.gni")
18import("//build/templates/metadata/module_info.gni")
19import("interface_config.gni")
20
21# 全局变量方法见 https://gitee.com/openharmony/build/blob/master/docs/cmake%E8%BD%ACgn%E6%8C%87%E5%AF%BC%E6%96%87%E6%A1%A3.md#gn%E5%B8%B8%E7%94%A8%E7%9A%84%E5%86%85%E7%BD%AE%E5%8F%98%E9%87%8F
22
23# 特殊场景没有拷贝interface接口信息,强基之后源码仓api不能直接使用,需要进行处理
24action("ohos_base_split") {
25  script = "//build/ohos/sdk/parse_interface_sdk.py"
26  ohos_sdk_arkts_description_file =
27      "${interface_sdk_path}/ohos_sdk_pub_description_std.json"
28  args = [
29    "--sdk-description-file",
30    rebase_path("//build/ohos/sdk/ohos_sdk_description_std.json",
31                root_build_dir),
32    "--root-build-dir",
33    rebase_path("//", root_build_dir),
34    "--node-js",
35    rebase_path(nodejs, root_build_dir),
36    "--output-arkts-sdk-desc-file",
37    rebase_path(ohos_sdk_arkts_description_file, root_build_dir),
38    "--sdk-build-public",
39    "${sdk_build_public}",
40    "--sdk-build-arkts",
41    "${sdk_build_arkts}",
42    "--npm-path",
43    rebase_path(npm, root_build_dir),
44    "--output-interface-sdk",
45    rebase_path(interface_sdk_path, root_build_dir),
46  ]
47  outputs = [ "${root_out_dir}/sdk-interface" ]
48}
49
50template("ohos_copy_internal") {
51  forward_variables_from(invoker, "*")
52  iv_input = invoker.iv_input
53  _module_info_target = "${target_name}_info"
54
55  # fullSDK中api路径
56  input_project_dir = interface_sdk_path_ets1
57  if (sdk_type == "ets2") {
58    input_project_dir = interface_sdk_path_ets2
59  }
60
61  # 调用build/templates/common/copy.gni中的ohos_copy方法
62  # 将处理完成的文件输出到中间产物对应位置 out/sdk/obj/interface/sdk-js/${target_name}
63  action_with_pydeps(target_name) {
64    # 该脚本根据传入的remove文件进行input文件规则检查,过滤不需要的文件
65    # remove文件没有对应$target_name的属性  则全部输出
66    # remove文件有对应$target_name的属性    保留base中的文件;
67    #                                      删除global_remove中的文件;
68    #                                     ispublic为真,删除sdk_build_public_remove文件。
69    deps = [ ":ohos_base_split" ]
70    deps += [ ":$_module_info_target" ]
71    inputs = []
72    outputs = [ target_out_dir + "/${sdk_type}/${target_name}" ]
73    script = "//interface/sdk-js/process_internal.py"
74    args = [
75      "--input",
76      rebase_path(iv_input, root_build_dir),
77      "--project-dir",
78      rebase_path(input_project_dir, root_build_dir),
79      "--base-dir",
80      rebase_path("//interface/sdk-js", root_build_dir),
81      "--remove",
82      rebase_path("//interface/sdk-js/remove_list.json", root_build_dir),
83      "--ispublic",
84      "${sdk_build_public}",
85      "--name",
86      "${target_name}",
87      "--output",
88      rebase_path(target_out_dir + "/${sdk_type}/${target_name}",
89                  root_build_dir),
90    ]
91  }
92  _target_name = target_name
93  generate_module_info(_module_info_target) {
94    module_type = "jsdoc"
95    module_install_name = ""
96    module_name = _target_name
97    module_source_dir = target_out_dir + "/${sdk_type}/${_target_name}"
98    install_enable = false
99  }
100}
101
102# 主要api处理template
103template("ohos_declaration_template") {
104  forward_variables_from(invoker, "*")
105  _module_info_target = "/ohos_declaration/${sdk_type}/${target_name}_info"
106
107  # fullSDK中api路径
108  input_project_dir = interface_sdk_path_ets1
109  if (sdk_type == "ets2") {
110    input_project_dir = interface_sdk_path_ets2
111  }
112  input_api_dir = input_project_dir + "/api"
113
114  action_with_pydeps(target_name) {
115    deps = [ ":ohos_base_split" ]
116    deps += [ ":$_module_info_target" ]
117    inputs = []
118    outputs = [ root_out_dir + "/ohos_declaration/${sdk_type}/${target_name}" ]
119
120    # 处理api文件下全部文件,过滤特定文件
121    script = "//interface/sdk-js/remove_internal.py"
122    args = [
123      "--input",
124      rebase_path(input_api_dir, root_build_dir),
125      "--output",
126      rebase_path(
127          root_out_dir + "/ohos_declaration/${sdk_type}/${target_name}/",
128          root_build_dir),
129    ]
130  }
131  _target_name = target_name
132  generate_module_info(_module_info_target) {
133    module_type = "jsdoc"
134    module_install_name = ""
135    module_name = _target_name
136    module_source_dir =
137        root_out_dir + "/ohos_declaration/${sdk_type}/$_target_name"
138    install_enable = false
139  }
140}
141
142# ets/api执行脚本
143ohos_declaration_template("ohos_declaration_ets") {
144  sdk_type = "ets"
145}
146
147ohos_copy("ohos_declaration_ets_api") {
148  deps = [ ":ohos_declaration_ets" ]
149  sources =
150      [ root_out_dir + "/ohos_declaration/${sdk_type}/ohos_declaration_ets" ]
151
152  outputs = [ target_out_dir + "/../api" ]
153}
154
155# ets2/api执行脚本
156ohos_declaration_template("ohos_declaration_ets2") {
157  sdk_type = "ets2"
158}
159
160# ets/api/@internal/full执行脚本
161ohos_copy_internal("ets_internal_api") {
162  sdk_type = "ets"
163  iv_input = interface_sdk_path_ets1 + "/api/@internal/ets"
164}
165
166ohos_prebuilt_etc("ets_internal_api_etc") {
167  source = "OAT.xml"
168  deps = [ ":ets_internal_api" ]
169  install_enable = false
170  output = string_replace(source, "OAT", "ets_internal_api_etc")
171  part_name = "sdk"
172  subsystem_name = "sdk"
173}
174
175# ets/arkts执行脚本
176ohos_copy_internal("bundle_arkts") {
177  sdk_type = "ets"
178  iv_input = interface_sdk_path_ets1 + "/arkts"
179}
180
181ohos_prebuilt_etc("bundle_arkts_etc") {
182  source = "OAT.xml"
183  deps = [ ":bundle_arkts" ]
184  install_enable = false
185  output = string_replace(source, "OAT", "bundle_arkts_etc")
186  part_name = "sdk"
187  subsystem_name = "sdk"
188}
189
190# ets1.2/arkts执行脚本
191ohos_copy_internal("bundle_arkts_ets1.2") {
192  sdk_type = "ets2"
193  iv_input = interface_sdk_path_ets2 + "/arkts"
194}
195
196ohos_copy_internal("ets_internal_api2") {
197  sdk_type = "ets2"
198  iv_input = interface_sdk_path_ets2 + "/api/@internal/ets"
199}
200
201if (!sdk_build_public) {
202  # ets/build-tools/ets-loader/declarations脚本
203  ohos_copy("bundle_api") {
204    sdk_type = "ets"
205    sources = [ "api/bundle/bundleStatusCallback.d.ts" ]
206    outputs =
207        [ target_out_dir + "/${sdk_type}/${target_name}/{{source_file_part}}" ]
208    module_source_dir = target_out_dir + "/${sdk_type}/${target_name}"
209    module_install_name = ""
210  }
211}
212
213# ets/component执行脚本
214ohos_copy_internal("ets_component") {
215  sdk_type = "ets"
216  iv_input = interface_sdk_path_ets1 + "/api/@internal/component/ets"
217}
218
219ohos_prebuilt_etc("ets_component_etc") {
220  source = "OAT.xml"
221  deps = [ ":ets_component" ]
222  install_enable = false
223  output = string_replace(source, "OAT", "ets_component_etc")
224  part_name = "sdk"
225  subsystem_name = "sdk"
226}
227
228# ets1.2/arkui/component执行脚本
229ohos_copy_internal("ets_component2") {
230  sdk_type = "ets2"
231  iv_input = interface_sdk_path + "/arkui_transformer_api"
232}
233
234# ets/kits执行脚本
235ohos_copy_internal("bundle_kits") {
236  sdk_type = "ets"
237  iv_input = interface_sdk_path_ets1 + "/kits"
238}
239
240ohos_prebuilt_etc("bundle_kits_etc") {
241  source = "OAT.xml"
242  deps = [ ":bundle_kits" ]
243  install_enable = false
244  output = string_replace(source, "OAT", "ohos_prebuilt_etc")
245  part_name = "sdk"
246  subsystem_name = "sdk"
247}
248
249# ets2/kits执行脚本
250ohos_copy_internal("bundle_kits2") {
251  sdk_type = "ets2"
252  iv_input = interface_sdk_path_ets2 + "/kits"
253}
254
255# js/api执行脚本
256ohos_declaration_template("ohos_declaration_common") {
257  sdk_type = "ets"
258}
259
260# js/api/@internal/full执行脚本
261ohos_copy_internal("internal_full") {
262  iv_input = interface_sdk_path_ets1 + "/api/common/full"
263}
264
265# js/api/@internal/lite执行脚本呢
266ohos_copy_internal("internal_lite") {
267  iv_input = interface_sdk_path_ets1 + "/api/common/lite"
268}
269
270# js/api/config执行脚本
271ohos_copy("config") {
272  sources = [
273    "api/config/css",
274    "api/config/hml",
275  ]
276  outputs = [ target_out_dir + "/${target_name}/{{source_file_part}}" ]
277  module_source_dir = target_out_dir + "/${target_name}"
278  module_install_name = ""
279}
280
281# js/form执行脚本
282ohos_copy("form_declaration") {
283  sources = [
284    "api/form/action",
285    "api/form/css",
286    "api/form/hml",
287  ]
288  outputs = [ target_out_dir + "/${target_name}/{{source_file_part}}" ]
289  module_source_dir = target_out_dir + "/${target_name}"
290  module_install_name = ""
291}
292
293# toolchains/syscapcheck执行脚本
294ohos_copy("syscap_check") {
295  sources = [ "api/syscapCheck/sysCapSchema.json" ]
296  outputs = [ target_out_dir + "/${target_name}/{{source_file_part}}" ]
297  module_source_dir = target_out_dir + "/${target_name}"
298  module_install_name = ""
299}
300
301action("ohos_ets_api_tmp") {
302  script = "//interface/sdk-js/ohos_copy_ets.py"
303
304  args = [
305    "--input",
306    rebase_path("//interface/sdk-js/api"),
307    "--output",
308    rebase_path("$ohos_ets_api_tmp_path"),
309    "--type",
310    "ets2",
311    "--source-root-dir",
312    rebase_path("//"),
313    "--node-js",
314    rebase_path(nodejs, root_build_dir),
315  ]
316
317  outputs = [ "$ohos_ets_api_tmp_path" ]
318}
319
320action("ohos_ets_arkts_tmp") {
321  script = "//interface/sdk-js/ohos_copy_ets.py"
322
323  args = [
324    "--input",
325    rebase_path("//interface/sdk-js/arkts"),
326    "--output",
327    rebase_path("$ohos_ets_arkts_tmp_path"),
328    "--type",
329    "ets2",
330    "--source-root-dir",
331    rebase_path("//"),
332    "--node-js",
333    rebase_path(nodejs, root_build_dir),
334  ]
335
336  outputs = [ "$ohos_ets_arkts_tmp_path" ]
337}
338
339action("ohos_ets_kits_tmp") {
340  script = "//interface/sdk-js/ohos_copy_ets.py"
341
342  args = [
343    "--input",
344    rebase_path("//interface/sdk-js/kits"),
345    "--output",
346    rebase_path("$ohos_ets_kits_tmp_path"),
347    "--type",
348    "ets2",
349    "--source-root-dir",
350    rebase_path("//"),
351    "--node-js",
352    rebase_path(nodejs, root_build_dir),
353  ]
354
355  outputs = [ "$ohos_ets_kits_tmp_path" ]
356}
357
358action("ohos_ets_api_arkui_tmp") {
359  deps = [ ":ohos_ets_api_tmp" ]
360  script = "//interface/sdk-js/arkui_transformer.py"
361
362  args = [
363    "--input",
364    rebase_path(ohos_ets_api_tmp_path + "/@internal/component/ets",
365                root_build_dir),
366    "--output",
367    rebase_path(ohos_ets_api_tmp_path + "/arkui/component", root_build_dir),
368    "--source_root_dir",
369    rebase_path("//", root_build_dir),
370    "--npm-path",
371    rebase_path(npm, root_build_dir),
372    "--node-js",
373    rebase_path(nodejs, root_build_dir),
374  ]
375  outputs = [ "$ohos_ets_api_arkui_tmp_path" ]
376}
377
378ohos_copy("ohos_ets_arkts") {
379  deps = [ ":ohos_ets_arkts_tmp" ]
380  sources = [ ohos_ets_arkts_tmp_path ]
381  outputs = [ ohos_ets_arkts_path ]
382  part_name = "sdk"
383  subsystem_name = "sdk"
384}
385
386ohos_copy("ohos_ets_kits") {
387  deps = [ ":ohos_ets_kits_tmp" ]
388  sources = [ ohos_ets_kits_tmp_path ]
389  outputs = [ ohos_ets_kits_path ]
390  part_name = "sdk"
391  subsystem_name = "sdk"
392}
393
394ohos_copy("ohos_ets_api") {
395  deps = [
396    ":ohos_ets_api_arkui_tmp",
397    ":ohos_ets_api_tmp",
398  ]
399  sources = [ ohos_ets_api_tmp_path ]
400  outputs = [ ohos_ets_api_path ]
401  part_name = "sdk"
402  subsystem_name = "sdk"
403}
404