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("//foundation/arkui/ace_engine/ace_config.gni")
15
16ohos_source_set("ace_resource") {
17  if (current_os == "ohos") {
18    sanitize = {
19      integer_overflow = true
20      boundary_sanitize = true
21      debug = ace_sanitize_debug
22    }
23  }
24  subsystem_name = ace_engine_subsystem
25  part_name = ace_engine_part
26  deps = []
27  external_deps = []
28  if (is_arkui_x) {
29    deps += [ "//third_party/bounds_checking_function:libsec_static" ]
30  } else {
31    external_deps += [ "bounds_checking_function:libsec_shared" ]
32  }
33
34  # add resource file here
35  sources = [
36    "ace_res_config.cpp",
37    "ace_res_key_parser.cpp",
38    "data_provider_manager.cpp",
39    "shared_image_manager.cpp",
40  ]
41  if (current_os == "mac" || current_os == "mingw" || current_os == "ios" ||
42      current_os == "linux" || current_os == "android") {
43    deps += [ ":binary_resource_mac_and_windows" ]
44    sources += [ "internal_resource_previewer.cpp" ]
45  } else {
46    sources += [ "internal_resource.cpp" ]
47    deps += [ ":binary_resource" ]
48  }
49  configs = [ "$ace_root:ace_config" ]
50
51  if (current_os == "mingw") {
52    cflags_cc = [ "-std=c++17" ]
53  }
54
55  if (use_hilog) {
56    external_deps += [ "hilog:libhilog" ]
57  }
58}
59
60ohos_source_set("binary_resource") {
61  deps = [ ":objcopy_resource" ]
62  ace_resource_dir =
63      get_label_info(":binary_resource($current_toolchain)", "target_out_dir")
64  sources = [
65    "$ace_resource_dir/entry.o",
66    "$ace_resource_dir/errorcode.o",
67    "$ace_resource_dir/indexletter_bar.o",
68  ]
69  subsystem_name = ace_engine_subsystem
70  part_name = ace_engine_part
71}
72
73ohos_source_set("binary_resource_mac_and_windows") {
74  deps = [ ":objcopy_resource_mac_and_windows" ]
75  ace_resource_dir =
76      get_label_info(":binary_resource($current_toolchain)", "target_out_dir")
77  sources = [
78    "$ace_resource_dir/entry.c",
79    "$ace_resource_dir/errorcode.c",
80    "$ace_resource_dir/indexletter_bar.c",
81  ]
82  subsystem_name = ace_engine_subsystem
83  part_name = ace_engine_part
84}
85
86action_foreach("objcopy_resource") {
87  # add resource file here
88  sources = [
89    "binary/i18n/entry.json",
90    "binary/i18n/errorcode.json",
91    "binary/indexletter_bar.json",
92  ]
93
94  ace_resource_dir =
95      get_label_info(":binary_resource($current_toolchain)", "target_out_dir")
96
97  outputs = [ "$ace_resource_dir/{{source_name_part}}.o" ]
98
99  objcopy_tool = objcopy_default
100  script = "$ace_root/build/tools/run_objcopy.py"
101  if (target_cpu == "x86_64") {
102    objcopy_tool = objcopy_x86_64
103  }
104
105  args = [
106    "--objcopy",
107    rebase_path("$objcopy_tool"),
108    "--input",
109    "{{source}}",
110    "--output",
111    rebase_path("$ace_resource_dir/") + "{{source_name_part}}.o",
112    "--arch",
113    current_cpu,
114  ]
115}
116
117action_foreach("objcopy_resource_mac_and_windows") {
118  # add resource file here
119  sources = [
120    "binary/i18n/entry.json",
121    "binary/i18n/errorcode.json",
122    "binary/indexletter_bar.json",
123  ]
124
125  ace_resource_dir =
126      get_label_info(":binary_resource($current_toolchain)", "target_out_dir")
127
128  outputs = [ "$ace_resource_dir/{{source_name_part}}.c" ]
129
130  script = "$ace_root/build/tools/build_resource_to_bytecode.py"
131  out_target = rebase_path("$ace_resource_dir/") + "{{source_name_part}}.c"
132
133  args = [
134    "--input",
135    "{{source}}",
136    "--output",
137    out_target,
138  ]
139}
140