• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2024 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("//commonlibrary/ets_utils/ets_utils_config.gni")
18
19# compile .ts to .js.
20action("build_ts_js") {
21  script = "$util_module/build_ts_js.py"
22  outFile_Path = target_out_dir + "/" + current_cpu
23  args = [
24    "--dst-file",
25    rebase_path(target_out_dir + "/json_js.js"),
26    "--module-path",
27    rebase_path("/commonlibrary/ets_utils/js_util_module/json"),
28    "--out-file",
29    rebase_path(outFile_Path + "/json_js.js"),
30    "--out-filePath",
31    rebase_path(outFile_Path),
32    "--relative-path",
33    rebase_path("//", root_build_dir),
34  ]
35  outputs = [ target_out_dir + "/json_js.js" ]
36}
37
38# compile .js to .abc.
39es2abc_gen_abc("gen_json_abc") {
40  extra_visibility = [ ":*" ]
41  src_js = rebase_path(target_out_dir + "/json_js.js")
42  dst_file = rebase_path(target_out_dir + "/json.abc")
43  in_puts = [ target_out_dir + "/json_js.js" ]
44  out_puts = [ target_out_dir + "/json.abc" ]
45  extra_args = [ "--module" ]
46  extra_dependencies = [ ":build_ts_js" ]
47}
48
49abc_output_path = get_label_info(":json_abc", "target_out_dir")
50
51gen_obj("json_js") {
52  input = "$target_out_dir/json_js.js"
53  if (use_mac || use_mingw_win || use_ios || use_linux) {
54    json_js_obj_path = abc_output_path + "/json.c"
55  } else {
56    json_js_obj_path = abc_output_path + "/json.o"
57  }
58  output = json_js_obj_path
59  snapshot_dep = [ ":build_ts_js" ]
60}
61
62gen_obj("json_abc") {
63  input = "$target_out_dir/json.abc"
64  if (use_mac || use_mingw_win || use_ios || use_linux) {
65    json_js_obj_path = abc_output_path + "/json_abc.c"
66  } else {
67    json_js_obj_path = abc_output_path + "/json_abc.o"
68  }
69  output = json_js_obj_path
70  snapshot_dep = [ ":gen_json_abc" ]
71}
72
73json_sources = [ "native_module_json.cpp" ]
74
75ohos_shared_library("json") {
76  branch_protector_ret = "pac_ret"
77  sanitize = {
78    cfi = true
79    cfi_cross_dso = true
80    debug = false
81  }
82  deps = [ ":json_static" ]
83  external_deps = [ "hilog:libhilog" ]
84  subsystem_name = "commonlibrary"
85  part_name = "ets_utils"
86  relative_install_dir = "module/util"
87}
88
89ohos_source_set("json_static") {
90  branch_protector_ret = "pac_ret"
91  sanitize = {
92    cfi = true
93    cfi_cross_dso = true
94    debug = false
95  }
96  include_dirs = [
97    "include",
98    "//third_party/icu/icu4c/source/common",
99    "//third_party/node/src",
100    ets_util_path,
101  ]
102
103  sources = json_sources
104
105  deps = [
106    ":gen_obj_src_json_abc",
107    ":gen_obj_src_json_js",
108  ]
109
110  if (is_arkui_x) {
111    include_dirs += [
112      "$plugins_root/hilog/include",
113      "$plugins_root/interfaces",
114      "//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
115    ]
116
117    if (target_os == "android") {
118      defines = [ "ANDROID_PLATFORM" ]
119    } else if (target_os == "ios") {
120      defines = [ "IOS_PLATFORM" ]
121    }
122    deps += [
123      "$plugins_root/libs/icu:icu_${target_os}",
124      "$plugins_root/libs/napi:napi_${target_os}",
125      "$plugins_root/libs/securec:sec_${target_os}",
126    ]
127  } else {
128    external_deps = [
129      "bounds_checking_function:libsec_shared",
130      "hilog:libhilog",
131      "icu:shared_icuuc",
132      "napi:ace_napi",
133    ]
134  }
135  subsystem_name = "commonlibrary"
136  part_name = "ets_utils"
137}
138
139group("json_packages") {
140  public_deps = [ ":json" ]
141}
142