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/adapter/preview/sdk/sharedlib_config.gni")
17import("//foundation/arkui/ace_engine/interfaces/napi/kits/napi_lib.gni")
18
19ace_devices = [
20  "phone",
21  "tv",
22  "wearable",
23  "tablet",
24  "card",
25  "car",
26]
27
28foreach(device, ace_devices) {
29  ohos_executable("ace_${device}_test") {
30    ohos_test = true
31    test_output_dir = "$root_out_dir/common/samples"
32    defines = [ "USE_GLFW_WINDOW" ]
33    cflags_cc = []
34    deps = []
35    config = {
36    }
37    if (defined(current_platform.config)) {
38      config = current_platform.config
39    }
40    if (defined(config.defines)) {
41      defines += config.defines
42    }
43    if (defined(config.cflags_cc)) {
44      cflags_cc += config.cflags_cc
45    }
46    if (defined(config.libace_target)) {
47      deps += [ config.libace_target ]
48    }
49    include_dirs = [
50      "$ace_root",
51      "$ace_root/frameworks",
52      "//foundation/window/window_manager",
53      "//ide/tools/previewer",
54    ]
55    deps += [
56      ":copy_preview_shared_library",
57      "//third_party/glfw:glfw",
58    ]
59    sources = [
60      "ace_${device}_test.cpp",
61      "event_adapter.cpp",
62    ]
63
64    external_deps = [
65      "graphic_2d:librender_service_client",
66      "previewer:ide_extension",
67      "window_manager:previewer_window",
68    ]
69
70    if (use_mingw_win) {
71      libs = [ "pthread" ]
72    }
73    subsystem_name = ace_engine_subsystem
74    part_name = ace_engine_part
75  }
76}
77
78# Install packages
79group("previewer_demo") {
80  if (is_wearable_product) {
81    deps = [ ":ace_wearable_test" ]
82  } else {
83    deps = [
84      ":ace_car_test",
85      ":ace_card_test",
86      ":ace_phone_test",
87      ":ace_tablet_test",
88      ":ace_tv_test",
89    ]
90  }
91}
92
93common_bin += [
94  # The dynamic librarys of hiviewdfx subsystem.
95  {
96    label = "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog"
97    subsystem_name = "hiviewdfx"
98    part_name = "hilog"
99  },
100
101  # The dynamic librarys of IDE subsystem.
102  {
103    label = "//ide/tools/previewer/util:ide_util"
104    subsystem_name = "ide"
105    part_name = "previewer"
106  },
107  {
108    label = "//ide/tools/previewer/jsapp/rich/external:ide_extension"
109    subsystem_name = "ide"
110    part_name = "previewer"
111  },
112
113  # The dynamic librarys of rosen window subsystem.
114  {
115    label = "//foundation/window/window_manager/previewer:previewer_window"
116    subsystem_name = "window"
117    part_name = "window_manager"
118  },
119]
120
121if (is_mingw || is_mac) {
122  common_bin += [
123    # The dynamic librarys of rosen window subsystem.
124    {
125      label =
126          "//foundation/window/window_manager/previewer:previewer_window_napi"
127      subsystem_name = "window"
128      part_name = "window_manager"
129    },
130
131    # The napi dynamic librarys of ability subsystem.
132    {
133      label = "//foundation/ability/ability_runtime/frameworks/simulator/ability_simulator:ability_simulator"
134      subsystem_name = "ability"
135      part_name = "ability_runtime"
136    },
137    {
138      label = "//foundation/ability/ability_base:string_utils"
139      subsystem_name = "ability"
140      part_name = "ability_base"
141    },
142  ]
143  napi_modules += [
144    {
145      prefix = "app/ability"
146      shard_libs = [
147        # The napi dynamic librarys of ability subsystem.
148        {
149          label = "//foundation/ability/ability_runtime/frameworks/simulator/napi_module/uiability:uiability"
150          subsystem_name = "ability"
151          part_name = "ability_runtime"
152        },
153      ]
154    },
155    {
156      prefix = "ability"
157
158      # The napi dynamic librarys of ability subsystem.
159      shard_libs = [
160        {
161          label = "//foundation/ability/ability_runtime/frameworks/simulator/napi_module/want_constant:wantconstant_napi"
162          subsystem_name = "ability"
163          part_name = "ability_runtime"
164        },
165      ]
166    },
167    {
168      prefix = "application"
169      shard_libs = [
170        # The napi dynamic librarys of rosen window subsystem.
171        {
172          label = "//foundation/window/window_manager/previewer/window_stage_modules:windowstage"
173          subsystem_name = "window"
174          part_name = "window_manager"
175          lib_names = [ "windowstage" ]
176        },
177
178        # The napi dynamic librarys of ability subsystem.
179        {
180          label = "//foundation/ability/ability_runtime/frameworks/simulator/napi_module/ability:ability_napi"
181          subsystem_name = "ability"
182          part_name = "ability_runtime"
183        },
184        {
185          label = "//foundation/ability/ability_runtime/frameworks/simulator/napi_module/ability_constant:abilityconstant"
186          subsystem_name = "ability"
187          part_name = "ability_runtime"
188        },
189        {
190          label = "//foundation/ability/ability_runtime/frameworks/simulator/napi_module/ability_context:abilitycontext_napi"
191          subsystem_name = "ability"
192          part_name = "ability_runtime"
193        },
194        {
195          label = "//foundation/ability/ability_runtime/frameworks/simulator/napi_module/ability_stage:abilitystage"
196          subsystem_name = "ability"
197          part_name = "ability_runtime"
198        },
199        {
200          label = "//foundation/ability/ability_runtime/frameworks/simulator/napi_module/ability_stage_context:abilitystagecontext_napi"
201          subsystem_name = "ability"
202          part_name = "ability_runtime"
203        },
204        {
205          label = "//foundation/ability/ability_runtime/frameworks/simulator/napi_module/application_context:applicationcontext_napi"
206          subsystem_name = "ability"
207          part_name = "ability_runtime"
208        },
209        {
210          label = "//foundation/ability/ability_runtime/frameworks/simulator/napi_module/caller:caller_napi"
211          subsystem_name = "ability"
212          part_name = "ability_runtime"
213        },
214        {
215          label = "//foundation/ability/ability_runtime/frameworks/simulator/napi_module/callee:callee"
216          subsystem_name = "ability"
217          part_name = "ability_runtime"
218        },
219        {
220          label = "//foundation/ability/ability_runtime/frameworks/simulator/napi_module/context:context_napi"
221          subsystem_name = "ability"
222          part_name = "ability_runtime"
223        },
224        {
225          label = "//foundation/ability/ability_runtime/frameworks/simulator/napi_module/configuration_constant:configurationconstant"
226          subsystem_name = "ability"
227          part_name = "ability_runtime"
228        },
229      ]
230    },
231  ]
232}
233
234# All dynamic libraries to be copied to the path "/previewer/common/bin/module/",
235# which are called by the napi framework, can be added to this script.
236foreach(module, napi_modules) {
237  ohos_copy("copy_napi_${module.prefix}libs") {
238    deps = []
239    sources = []
240    foreach(shard_lib, module.shard_libs) {
241      subsystem_name = shard_lib.subsystem_name
242      part_name = shard_lib.part_name
243      deps += [ shard_lib.label ]
244      out_path = get_label_info(shard_lib.label, "root_out_dir")
245      lib_names = []
246      if (defined(shard_lib.lib_names)) {
247        lib_names += shard_lib.lib_names
248      } else {
249        cur_lib = get_label_info(shard_lib.label, "name")
250        lib_names += [ string_replace(cur_lib, "lib", "", 1) ]
251      }
252      foreach(lib_name, lib_names) {
253        sources += [ "${out_path}/${subsystem_name}/${part_name}/lib${lib_name}${dylib_suffix}" ]
254      }
255    }
256
257    # Set the output directory for all dynamic libraries.
258    if (module.prefix == "") {
259      outputs = [ "${root_out_dir}/common/samples/module/{{source_file_part}}" ]
260    } else {
261      outputs = [ "${root_out_dir}/common/samples/module/${module.prefix}/{{source_file_part}}" ]
262    }
263  }
264}
265
266# All dynamic libraries to be copied to the path "/previewer/common/bin/",
267# which are related to the previewer, can be added to this script.
268ohos_copy("copy_preview_shared_library") {
269  deps = []
270  foreach(module, napi_modules) {
271    deps += [ ":copy_napi_${module.prefix}libs" ]
272  }
273
274  sources = [
275    "//base/global/system_resources/fonts",
276    "//third_party/icu/ohos_icu4j/data/icudt72l.dat",
277    "//third_party/skia/src/ports/skia_ohos/config/fontconfig.json",
278  ]
279
280  foreach(item, common_bin) {
281    subsystem_name = item.subsystem_name
282    part_name = item.part_name
283    deps += [ item.label ]
284    out_path = get_label_info(item.label, "root_out_dir")
285    lib_names = []
286    if (defined(item.lib_names)) {
287      lib_names += item.lib_names
288    } else {
289      lib_names +=
290          [ string_replace(get_label_info(item.label, "name"), "lib", "", 1) ]
291    }
292    foreach(lib_name, lib_names) {
293      sources += [ "${out_path}/${subsystem_name}/${part_name}/lib${lib_name}${dylib_suffix}" ]
294    }
295  }
296
297  outputs = [ "${root_out_dir}/common/samples/{{source_file_part}}" ]
298}
299