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("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni") 15import("//build/ohos.gni") 16import("//commonlibrary/ets_utils/ets_utils_config.gni") 17import("//foundation/arkui/ace_engine/ace_config.gni") 18import("//foundation/arkui/ace_engine/build/ace_gen_obj.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 + "/json_js.js"), 27 "--module-path", 28 rebase_path("/commonlibrary/ets_utils/js_util_module/json"), 29 "--out-file", 30 rebase_path(outFile_Path + "/json_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 + "/json_js.js" ] 37} 38 39# compile .js to .abc. 40es2abc_gen_abc("gen_json_abc") { 41 extra_visibility = [ ":*" ] 42 src_js = rebase_path(target_out_dir + "/json_js.js") 43 dst_file = rebase_path(target_out_dir + "/json.abc") 44 in_puts = [ target_out_dir + "/json_js.js" ] 45 out_puts = [ target_out_dir + "/json.abc" ] 46 extra_args = [ "--module" ] 47 extra_dependencies = [ ":build_ts_js" ] 48} 49 50abc_output_path = get_label_info(":json_abc", "target_out_dir") 51 52gen_obj("json_js") { 53 input = "$target_out_dir/json_js.js" 54 if (use_mac || use_mingw_win || use_ios || use_linux) { 55 json_js_obj_path = abc_output_path + "/json.c" 56 } else { 57 json_js_obj_path = abc_output_path + "/json.o" 58 } 59 output = json_js_obj_path 60 snapshot_dep = [ ":build_ts_js" ] 61} 62 63gen_obj("json_abc") { 64 input = "$target_out_dir/json.abc" 65 if (use_mac || use_mingw_win || use_ios || use_linux) { 66 json_js_obj_path = abc_output_path + "/json_abc.c" 67 } else { 68 json_js_obj_path = abc_output_path + "/json_abc.o" 69 } 70 output = json_js_obj_path 71 snapshot_dep = [ ":gen_json_abc" ] 72} 73 74json_sources = [ "native_module_json.cpp" ] 75 76ohos_shared_library("json") { 77 branch_protector_ret = "pac_ret" 78 sanitize = { 79 cfi = true 80 cfi_cross_dso = true 81 debug = false 82 } 83 deps = [ ":json_static" ] 84 external_deps = [ "hilog:libhilog" ] 85 subsystem_name = "commonlibrary" 86 part_name = "ets_utils" 87 relative_install_dir = "module/util" 88} 89 90ohos_source_set("json_static") { 91 branch_protector_ret = "pac_ret" 92 sanitize = { 93 cfi = true 94 cfi_cross_dso = true 95 debug = false 96 } 97 include_dirs = [ 98 "include", 99 "//third_party/icu/icu4c/source/common", 100 "//third_party/node/src", 101 ets_util_path, 102 ] 103 configs = [ 104 "$icu_root:icu_config", 105 "$napi_root:ace_napi_config", 106 ] 107 sources = json_sources 108 109 deps = [ 110 ":gen_obj_src_json_abc", 111 ":gen_obj_src_json_js", 112 ] 113 114 if (is_arkui_x) { 115 include_dirs += [ 116 "$plugins_root/hilog/include", 117 "$plugins_root/interfaces", 118 "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", 119 ] 120 121 if (target_os == "android") { 122 defines = [ "ANDROID_PLATFORM" ] 123 } else if (target_os == "ios") { 124 defines = [ "IOS_PLATFORM" ] 125 } 126 deps += [ 127 "$plugins_root/libs/icu:icu_${target_os}", 128 "$plugins_root/libs/napi:napi_${target_os}", 129 "$plugins_root/libs/securec:sec_${target_os}", 130 ] 131 } else { 132 deps += [ "//third_party/icu/icu4c:shared_icuuc" ] 133 134 external_deps = [ 135 "bounds_checking_function:libsec_shared", 136 "hilog:libhilog", 137 "napi:ace_napi", 138 ] 139 140 deps += [ "//third_party/icu/icu4c:shared_icuuc" ] 141 } 142 subsystem_name = "commonlibrary" 143 part_name = "ets_utils" 144} 145 146group("json_packages") { 147 public_deps = [ ":json" ] 148} 149