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