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 20container_names = [ 21 "arraylist", 22 "deque", 23 "queue", 24 "vector", 25 "linkedlist", 26 "list", 27 "stack", 28 "struct", 29 "treemap", 30 "treeset", 31 "hashmap", 32 "hashset", 33 "lightweightmap", 34 "lightweightset", 35 "plainarray", 36] 37 38# compile .ts to .js. 39action("build_js_ts") { 40 script = "${ets_util_path}/js_util_module/container/build_ts_js.py" 41 outFile_Path = target_out_dir + "/" + current_cpu 42 args = [ 43 "--dst-file", 44 rebase_path(target_out_dir + "/"), 45 "--out-filePath", 46 rebase_path(outFile_Path), 47 "--relative-path", 48 rebase_path("//", root_build_dir), 49 ] 50 51 outputs = [] 52 foreach(item, container_names) { 53 dep = target_out_dir + "/js_" + item + ".js" 54 outputs += [ dep ] 55 } 56} 57 58config("container_config") { 59 cflags_cc = [ 60 "-std=c++17", 61 "-Wno-deprecated-declarations", 62 ] 63} 64 65# libs 66template("container_lib") { 67 forward_variables_from(invoker, "*") 68 69 name = target_name 70 base_output_path = get_label_info(":js_" + name, "target_out_dir") 71 gen_obj("js_" + name) { 72 input = "$target_out_dir/js_" + name + ".js" 73 if (use_mac || use_mingw_win || use_ios || use_linux) { 74 js_container_obj_path = base_output_path + name + ".c" 75 } else { 76 js_container_obj_path = base_output_path + name + ".o" 77 } 78 output = js_container_obj_path 79 snapshot_dep = [ ":build_js_ts" ] 80 } 81 82 # compile .js to .abc. 83 es2abc_gen_abc("gen_" + name + "_abc") { 84 extra_visibility = [ ":*" ] 85 src_js = rebase_path(target_out_dir + "/js_" + name + ".js") 86 dst_file = rebase_path(target_out_dir + "/" + name + ".abc") 87 in_puts = [ target_out_dir + "/js_" + name + ".js" ] 88 out_puts = [ target_out_dir + "/" + name + ".abc" ] 89 extra_args = [ "--module" ] 90 extra_dependencies = [ ":build_js_ts" ] 91 } 92 93 abc_output_path = get_label_info(":" + name + "_abc", "target_out_dir") 94 gen_obj(name + "_abc") { 95 input = "$target_out_dir/" + name + ".abc" 96 if (use_mac || use_mingw_win || use_ios || use_linux) { 97 arraylist_abc_obj_path = abc_output_path + "/" + name + "_abc.c" 98 } else { 99 arraylist_abc_obj_path = abc_output_path + "/" + name + "_abc.o" 100 } 101 output = arraylist_abc_obj_path 102 snapshot_dep = [ ":gen_" + target_name ] 103 } 104 105 ohos_source_set(name + "_static") { 106 branch_protector_ret = "pac_ret" 107 sanitize = { 108 cfi = true 109 cfi_cross_dso = true 110 debug = false 111 } 112 include_dirs = [ 113 "//third_party/node/src", 114 "//commonlibrary/ets_utils/js_util_module/container/" + name, 115 ets_util_path, 116 ] 117 118 sources = [ name + "/native_module_" + name + ".cpp" ] 119 120 dep_abc = ":gen_obj_src_" + name + "_abc" 121 dep_js = ":gen_obj_src_js_" + name 122 deps = [ "$container_root:gen_obj_src_js_" + name ] 123 deps += [ dep_abc ] 124 deps += [ dep_js ] 125 126 if (is_arkui_x) { 127 include_dirs += [ 128 "$napi_root/interfaces/kits", 129 "$plugins_root/hilog/include", 130 "$plugins_root/interfaces", 131 "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", 132 ] 133 134 deps += [ 135 "$plugins_root/libs/icu:icu_${target_os}", 136 "$plugins_root/libs/napi:napi_${target_os}", 137 "$plugins_root/libs/securec:sec_${target_os}", 138 ] 139 140 if (target_os == "android") { 141 defines = [ "ANDROID_PLATFORM" ] 142 } 143 } else { 144 external_deps = [ 145 "hilog:libhilog", 146 "napi:ace_napi", 147 ] 148 } 149 150 configs = [ ":container_config" ] 151 152 subsystem_name = "commonlibrary" 153 part_name = "ets_utils" 154 } 155 ohos_shared_library(name) { 156 branch_protector_ret = "pac_ret" 157 sanitize = { 158 cfi = true 159 cfi_cross_dso = true 160 debug = false 161 } 162 deps = [ ":${name}_static" ] 163 external_deps = [ "hilog:libhilog" ] 164 subsystem_name = "commonlibrary" 165 part_name = "ets_utils" 166 relative_install_dir = "module/util" 167 } 168} 169 170container_libs = [] 171foreach(item, container_names) { 172 container_lib(item) { 173 } 174 if (is_arkui_x) { 175 dep = ":" + item + "_static" 176 } else { 177 dep = ":" + item 178 } 179 container_libs += [ dep ] 180} 181 182group("container_packages") { 183 public_deps = container_libs 184} 185 186foreach(name, container_names) { 187 group(name + "_packages") { 188 if (is_arkui_x) { 189 deps = [ ":" + name + "_static" ] 190 } else { 191 deps = [ ":" + name ] 192 } 193 } 194} 195