• 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
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      "//commonlibrary/ets_utils/js_util_module/container/" + name,
114      ets_util_path,
115    ]
116
117    sources = [ name + "/native_module_" + name + ".cpp" ]
118
119    dep_abc = ":gen_obj_src_" + name + "_abc"
120    dep_js = ":gen_obj_src_js_" + name
121    deps = [ "$container_root:gen_obj_src_js_" + name ]
122    deps += [ dep_abc ]
123    deps += [ dep_js ]
124
125    if (is_arkui_x) {
126      include_dirs += [
127        "$napi_root/interfaces/kits",
128        "$plugins_root/hilog/include",
129        "$plugins_root/interfaces",
130        "//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
131      ]
132
133      deps += [
134        "$plugins_root/libs/icu:icu_${target_os}",
135        "$plugins_root/libs/napi:napi_${target_os}",
136        "$plugins_root/libs/securec:sec_${target_os}",
137      ]
138
139      if (target_os == "android") {
140        defines = [ "ANDROID_PLATFORM" ]
141      }
142    } else {
143      external_deps = [
144        "hilog:libhilog",
145        "napi:ace_napi",
146      ]
147    }
148
149    configs = [ ":container_config" ]
150
151    subsystem_name = "commonlibrary"
152    part_name = "ets_utils"
153  }
154  ohos_shared_library(name) {
155    branch_protector_ret = "pac_ret"
156    sanitize = {
157      cfi = true
158      cfi_cross_dso = true
159      debug = false
160    }
161    deps = [ ":${name}_static" ]
162    external_deps = [ "hilog:libhilog" ]
163    subsystem_name = "commonlibrary"
164    part_name = "ets_utils"
165    relative_install_dir = "module/util"
166  }
167}
168
169container_libs = []
170foreach(item, container_names) {
171  container_lib(item) {
172  }
173  if (is_arkui_x) {
174    dep = ":" + item + "_static"
175  } else {
176    dep = ":" + item
177  }
178  container_libs += [ dep ]
179}
180
181group("container_packages") {
182  public_deps = container_libs
183}
184
185foreach(name, container_names) {
186  group(name + "_packages") {
187    if (is_arkui_x) {
188      deps = [ ":" + name + "_static" ]
189    } else {
190      deps = [ ":" + name ]
191    }
192  }
193}
194