1# Copyright (c) 2021 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/ohos.gni")
16import("//build/ohos/ace/ace.gni")
17import("//commonlibrary/ets_utils/ets_utils_config.gni")
18import("//foundation/arkui/ace_engine/ace_config.gni")
19import("//foundation/arkui/ace_engine/build/ace_gen_obj.gni")
20
21# compile .ts to .js.
22action("build_ts_js") {
23  script = "$util_module/build_ts_js.py"
24  outFile_Path = target_out_dir + "/" + current_cpu
25  args = [
26    "--dst-file",
27    rebase_path(target_out_dir + "/util_js.js"),
28    "--module-path",
29    rebase_path("/commonlibrary/ets_utils/js_util_module/util"),
30    "--out-file",
31    rebase_path(outFile_Path + "/util_js.js"),
32    "--out-filePath",
33    rebase_path(outFile_Path),
34    "--relative-path",
35    rebase_path("//", root_build_dir),
36  ]
37  outputs = [ target_out_dir + "/util_js.js" ]
38}
39
40# compile .js to .abc.
41es2abc_gen_abc("gen_util_abc") {
42  extra_visibility = [ ":*" ]
43  src_js = rebase_path(target_out_dir + "/util_js.js")
44  dst_file = rebase_path(target_out_dir + "/util.abc")
45  in_puts = [ target_out_dir + "/util_js.js" ]
46  out_puts = [ target_out_dir + "/util.abc" ]
47  extra_args = [ "--module" ]
48  extra_dependencies = [ ":build_ts_js" ]
49}
50
51abc_output_path = get_label_info(":util_abc", "target_out_dir")
52
53gen_obj("util_js") {
54  input = "$target_out_dir/util_js.js"
55  if (use_mac || use_mingw_win || use_ios || use_linux) {
56    util_obj_path = abc_output_path + "/util.c"
57  } else {
58    util_obj_path = abc_output_path + "/util.o"
59  }
60  output = util_obj_path
61  snapshot_dep = [ ":build_ts_js" ]
62}
63
64gen_obj("util_abc") {
65  input = "$target_out_dir/util.abc"
66  if (use_mac || use_mingw_win || use_ios || use_linux) {
67    util_obj_path = abc_output_path + "/util_abc.c"
68  } else {
69    util_obj_path = abc_output_path + "/util_abc.o"
70  }
71  output = util_obj_path
72  snapshot_dep = [ ":gen_util_abc" ]
73}
74
75util_sources = [
76  "js_base64.cpp",
77  "js_stringdecoder.cpp",
78  "js_textdecoder.cpp",
79  "js_textencoder.cpp",
80  "js_types.cpp",
81  "js_uuid.cpp",
82  "native_module_util.cpp",
83]
84
85if (is_arkui_x) {
86  util_sources += [ "$platform_root/default/util_helper.cpp" ]
87  if (target_os == "android") {
88    util_sources += [ "$platform_root/android/jni_helper.cpp" ]
89  } else {
90    util_sources += [ "$platform_root/default/jni_helper.cpp" ]
91  }
92} else {
93  util_sources += [ "$platform_root/ohos/util_helper.cpp" ]
94  util_sources += [ "$platform_root/default/jni_helper.cpp" ]
95}
96
97ohos_shared_library("util") {
98  branch_protector_ret = "pac_ret"
99  sanitize = {
100    cfi = true
101    cfi_cross_dso = true
102    debug = false
103  }
104  deps = [ ":util_static" ]
105  external_deps = [ "hilog:libhilog" ]
106  subsystem_name = "commonlibrary"
107  part_name = "ets_utils"
108  relative_install_dir = "module"
109}
110
111ohos_source_set("util_static") {
112  branch_protector_ret = "pac_ret"
113  sanitize = {
114    cfi = true
115    cfi_cross_dso = true
116    debug = false
117  }
118  include_dirs = [
119    "//third_party/icu/icu4c/source/common",
120    "//third_party/icu/icu4c/source",
121    "//third_party/node/src",
122    "//third_party/openssl",
123    "//third_party/openssl/include",
124    platform_root,
125    ets_util_path,
126  ]
127  configs = [
128    "$icu_root:icu_config",
129    "$napi_root:ace_napi_config",
130  ]
131  sources = util_sources
132
133  deps = [
134    ":gen_obj_src_util_abc",
135    ":gen_obj_src_util_js",
136    "//third_party/icu/icu4c:shared_icuuc",
137    "//third_party/openssl:libcrypto_shared",
138  ]
139
140  if (is_arkui_x) {
141    include_dirs += [
142      "$plugins_root/hilog/include",
143      "$plugins_root/interfaces",
144      "//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
145    ]
146
147    configs += [ "$plugins_root/util:util_plugin_config" ]
148
149    defines = [ "__ARKUI_CROSS__" ]
150
151    deps -= [ "//third_party/icu/icu4c:shared_icuuc" ]
152
153    if (target_os == "android") {
154      defines += [ "ANDROID_PLATFORM" ]
155    }
156    if (target_os == "ios") {
157      defines += [ "IOS_PLATFORM" ]
158    }
159    deps += [
160      "$plugins_root/interfaces/native:ace_plugin_util_${target_os}",
161      "$plugins_root/libs/icu:icu_${target_os}",
162      "$plugins_root/libs/napi:napi_${target_os}",
163      "$plugins_root/libs/securec:sec_${target_os}",
164    ]
165  } else {
166    external_deps = [ "napi:ace_napi" ]
167    if (is_standard_system) {
168      external_deps += [ "hilog:libhilog" ]
169    } else {
170      external_deps += [
171        "c_utils:utils",
172        "hilog:libhilog",
173      ]
174    }
175    external_deps += [ "bounds_checking_function:libsec_shared" ]
176  }
177
178  subsystem_name = "commonlibrary"
179  part_name = "ets_utils"
180}
181
182group("util_packages") {
183  deps = [ ":util" ]
184}
185