1# Copyright (c) 2021-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/ohos.gni")
15import("//foundation/arkui/ace_engine/ace_config.gni")
16import("//foundation/arkui/ace_engine/build/ace_lib.gni")
17import("//foundation/arkui/ace_engine/interfaces/napi/kits/napi_lib.gni")
18
19if (is_ohos_standard_system) {
20  system_resource_hap_path =
21      get_label_info("//base/global/system_resources/systemres:systemres_hap",
22                     "target_out_dir") + "/SystemResources.hap"
23  system_resource_path =
24      get_label_info("//base/global/system_resources/systemres:systemres_hap",
25                     "target_out_dir") + "/resources"
26  system_resource_index_path =
27      get_label_info("//base/global/system_resources/systemres:systemres_hap",
28                     "target_gen_dir") + "/main_res/gen/resources.index"
29  system_resource_value_path =
30      get_label_info("//base/global/system_resources/systemres:systemres_hap",
31                     "target_out_dir") + "/resources/entry/resources.txt"
32} else {
33  system_resource_hap_path =
34      get_label_info("//base/global/system_resources/systemres:systemres_hap",
35                     "target_gen_dir") + "/SystemResources.hap"
36  system_resource_path =
37      get_label_info("//base/global/system_resources/systemres:systemres_hap",
38                     "target_gen_dir") + "/resources"
39  system_resource_index_path =
40      get_label_info("//base/global/system_resources/systemres:systemres_hap",
41                     "target_gen_dir") + "/main_res/gen/resources.index"
42  system_resource_value_path =
43      get_label_info("//base/global/system_resources/systemres:systemres_hap",
44                     "target_gen_dir") + "/resources/entry/resources.txt"
45}
46
47action("get_system_resource") {
48  script = "get_system_resources.sh"
49  deps = [ "//base/global/system_resources/systemres:systemres_hap($current_toolchain)" ]
50  args = [
51    rebase_path(system_resource_hap_path),
52    rebase_path(system_resource_path),
53  ]
54  inputs = [ system_resource_hap_path ]
55  outputs = [ system_resource_path ]
56}
57
58action("extra_system_resource") {
59  script = "./dump/dump.py"
60  deps = [ "//base/global/system_resources/systemres:main_res" ]
61  args = [
62    rebase_path(system_resource_index_path),
63    rebase_path(system_resource_value_path),
64  ]
65  outputs = [ system_resource_value_path ]
66}
67
68# Triggered only when the SDK is compiled
69if (is_ohos_standard_system) {
70  import("sharedlib_config.gni")
71
72  foreach(module, napi_modules) {
73    ohos_copy("copy_napi_${module.prefix}libs") {
74      deps = []
75      sources = []
76      foreach(shard_lib, module.shard_libs) {
77        subsystem_name = shard_lib.subsystem_name
78        part_name = shard_lib.part_name
79        deps += [ shard_lib.label ]
80        out_path = get_label_info(shard_lib.label, "root_out_dir")
81        lib_names = []
82        if (defined(shard_lib.lib_names)) {
83          lib_names += shard_lib.lib_names
84        } else {
85          cur_lib = get_label_info(shard_lib.label, "name")
86          lib_names += [ string_replace(cur_lib, "lib", "", 1) ]
87        }
88        foreach(lib_name, lib_names) {
89          sources += [ "${out_path}/${subsystem_name}/${part_name}/lib${lib_name}${dylib_suffix}" ]
90        }
91      }
92
93      # Set the output directory for all dynamic libraries.
94      if (module.prefix == "") {
95        module_source_dir = "${target_out_dir}/previewer/common/bin/module/"
96      } else {
97        module_source_dir =
98            "${target_out_dir}/previewer/common/bin/module/${module.prefix}/"
99      }
100      outputs = [ "${module_source_dir}{{source_file_part}}" ]
101      module_install_name = ""
102    }
103  }
104
105  ohos_copy("copy_abc_library") {
106    deps = [
107      "$ace_root/frameworks/bridge/declarative_frontend:ark_modifier",
108      "$ace_root/frameworks/bridge/declarative_frontend:ark_theme_control",
109      "$ace_root/frameworks/bridge/declarative_frontend:shape",
110      "$ace_root/frameworks/bridge/declarative_frontend:uicontext",
111      "$ace_root/frameworks/bridge/declarative_frontend:x_node",
112    ]
113    out_path = get_label_info(
114            "$ace_root/frameworks/bridge/declarative_frontend:ark_modifier",
115            "root_out_dir")
116    sources = [
117      "${out_path}/arkui/ace_engine/modifier.abc",
118      "${out_path}/arkui/ace_engine/node.abc",
119      "${out_path}/arkui/ace_engine/shape.abc",
120      "${out_path}/arkui/ace_engine/theme.abc",
121      "${out_path}/arkui/ace_engine/uicontext.abc",
122    ]
123
124    outputs = [ target_out_dir +
125                "/previewer/common/bin/module/arkui/{{source_file_part}}" ]
126    module_source_dir = target_out_dir + "/previewer/common/bin/module/arkui"
127    module_install_name = ""
128  }
129
130  # All dynamic libraries to be copied to the path "/previewer/common/bin/",
131  # which are related to the previewer, can be added to this script.
132  ohos_copy("copy_preview_shared_library") {
133    deps = []
134    foreach(module, napi_modules) {
135      if (!(host_os == "linux" && host_cpu == "arm64")) {
136        deps += [ ":copy_napi_${module.prefix}libs" ]
137      }
138    }
139
140    # The dynamic library here is used for local testing of the previewer.
141    if (enable_glfw_window) {
142      deps += [ "$ace_root/adapter/preview/entrance/samples:previewer_demo" ]
143    }
144
145    sources = [
146      "//third_party/icu/ohos_icu4j/data/icudt72l.dat",
147      "//third_party/skia/src/ports/skia_ohos/config/fontconfig.json",
148    ]
149
150    foreach(item, common_bin) {
151      subsystem_name = item.subsystem_name
152      part_name = item.part_name
153      deps += [ item.label ]
154      out_path = get_label_info(item.label, "root_out_dir")
155      lib_names = []
156      if (defined(item.lib_names)) {
157        lib_names += item.lib_names
158      } else {
159        lib_names +=
160            [ string_replace(get_label_info(item.label, "name"), "lib", "", 1) ]
161      }
162      foreach(lib_name, lib_names) {
163        sources += [ "${out_path}/${subsystem_name}/${part_name}/lib${lib_name}${dylib_suffix}" ]
164      }
165    }
166
167    # Set the output directory for all dynamic libraries.
168    outputs = [ target_out_dir + "/previewer/common/bin/{{source_file_part}}" ]
169    module_source_dir = target_out_dir + "/previewer/common/bin/"
170    module_install_name = ""
171  }
172
173  if (use_mingw_win) {
174    ohos_copy("copy_preview_curl_cacert") {
175      sources = [ "//third_party/curl/cacert.pem" ]
176      outputs = [ target_out_dir + "/previewer/resources/cacert.pem" ]
177      module_source_dir = target_out_dir + "/previewer/resources"
178      module_install_name = ""
179    }
180  }
181
182  ohos_copy("copy_system_resource_standard") {
183    deps = [
184      ":extra_system_resource",
185      ":get_system_resource",
186    ]
187
188    sources = [ system_resource_path ]
189
190    outputs = [ target_out_dir + "/previewer/common/{{source_file_part}}" ]
191    module_source_dir = target_out_dir + "/previewer/common"
192    module_install_name = ""
193  }
194} else {
195  ohos_copy("copy_system_resource") {
196    if (use_mac) {
197      sources = [ "//prebuilts/ace-toolkit/preview/rich/resources" ]
198      outputs = [ target_out_dir + "/tv_resources/{{source_file_part}}" ]
199      module_source_dir = target_out_dir + "/tv_resources/"
200      module_install_name = ""
201    } else {
202      deps = [
203        ":extra_system_resource",
204        ":get_system_resource",
205      ]
206
207      sources = [ system_resource_path ]
208      outputs = [ target_out_dir + "/tv_resources/{{source_file_part}}" ]
209      module_source_dir = target_out_dir + "/tv_resources/"
210      module_install_name = ""
211    }
212  }
213
214  ohos_copy("copy_system_resource_wearable") {
215    if (use_mac) {
216      sources = [ "//prebuilts/ace-toolkit/preview/rich/resources" ]
217      outputs = [ target_out_dir + "/wearable_resources/{{source_file_part}}" ]
218      module_source_dir = target_out_dir + "/wearable_resources/"
219      module_install_name = ""
220    } else {
221      deps = [
222        ":extra_system_resource",
223        ":get_system_resource",
224      ]
225
226      sources = [ system_resource_path ]
227      outputs = [ target_out_dir + "/wearable_resources/{{source_file_part}}" ]
228      module_source_dir = target_out_dir + "/wearable_resources/"
229      module_install_name = ""
230    }
231  }
232}
233