1# Copyright (c) 2025 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/ets_frontend/ets_frontend_config.gni") 15import("//build/ohos_var.gni") 16 17ets2abc_root = "ets_frontend" 18ets2abc_build_path = "" 19ets2abc_build_deps = "" 20ets2abc_out_root = "" 21static_linker_root = "runtime_core" 22static_linker_build_path = "" 23static_linker_build_deps = "" 24static_linker_out_root = "" 25libes2panda_public_build_deps = "" 26ohos_ets_koala_wrapper_deps = "" 27libes2panda_public_build_path = "" 28ohos_ets_libes2panda_public_path = "" 29bootpath_json_file = "" 30 31if (host_toolchain == toolchain_mac) { 32 ets2abc_out_root = 33 get_label_info("$ets2abc_root:ets2panda($toolchain_mac)", "root_out_dir") 34 ets2abc_build_deps = "$ets2abc_root:ets2panda($toolchain_mac)" 35 static_linker_out_root = 36 get_label_info("$static_linker_root:ark_link($toolchain_mac)", 37 "root_out_dir") 38 static_linker_build_deps = "$static_linker_root:ark_link($toolchain_mac)" 39 libes2panda_public_build_deps = 40 "$ets2abc_root:libes2panda_public($toolchain_mac)" 41 ohos_ets_koala_wrapper_deps = 42 "ace_ets2bundle:ohos_ets_koala_wrapper($toolchain_mac)" 43 libes2panda_public_build_path = 44 static_linker_out_root + "/arkcompiler/ets_frontend/libes2panda_public.so" 45 ohos_ets_libes2panda_public_path = 46 "$root_build_dir/ohos_ets/build-tools/ets2panda/lib/libes2panda_public.so" 47} else if (host_toolchain == toolchain_win) { 48 ets2abc_out_root = 49 get_label_info("$ets2abc_root:ets2panda($toolchain_win)", "root_out_dir") 50 ets2abc_build_deps = "$ets2abc_root:ets2panda($toolchain_win)" 51 static_linker_out_root = 52 get_label_info("$static_linker_root:ark_link($toolchain_win)", 53 "root_out_dir") 54 static_linker_build_deps = "$static_linker_root:ark_link($toolchain_win)" 55 libes2panda_public_build_deps = 56 "$ets2abc_root:libes2panda_public($toolchain_win)" 57 ohos_ets_koala_wrapper_deps = 58 "ace_ets2bundle:ohos_ets_koala_wrapper($toolchain_win)" 59 libes2panda_public_build_path = 60 static_linker_out_root + 61 "/arkcompiler/ets_frontend/libes2panda_public.dll" 62 ohos_ets_libes2panda_public_path = "$root_build_dir/ohos_ets/build-tools/ets2panda/lib/libes2panda_public.dll" 63} else { 64 ets2abc_out_root = get_label_info("$ets2abc_root:ets2panda($toolchain_linux)", 65 "root_out_dir") 66 ets2abc_build_deps = "$ets2abc_root:ets2panda($toolchain_linux)" 67 static_linker_out_root = 68 get_label_info("$static_linker_root:ark_link($toolchain_linux)", 69 "root_out_dir") 70 static_linker_build_deps = "$static_linker_root:ark_link($toolchain_linux)" 71 libes2panda_public_build_deps = 72 "$ets2abc_root:libes2panda_public($toolchain_linux)" 73 ohos_ets_koala_wrapper_deps = 74 "ace_ets2bundle:ohos_ets_koala_wrapper($toolchain_linux)" 75 libes2panda_public_build_path = 76 static_linker_out_root + "/arkcompiler/ets_frontend/libes2panda_public.so" 77 ohos_ets_libes2panda_public_path = 78 "$root_build_dir/ohos_ets/build-tools/ets2panda/lib/libes2panda_public.so" 79} 80ets2abc_build_path = ets2abc_out_root + "/arkcompiler/ets_frontend/es2panda" 81static_linker_build_path = 82 static_linker_out_root + "/arkcompiler/runtime_core/ark_link" 83 84ohos_ets_kits_deps = "sdk:ohos_ets_kits" 85ohos_ets_api_deps = "sdk:ohos_ets_api" 86ohos_ets_arkts_deps = "sdk:ohos_ets_arkts" 87ohos_ets_stdlib_deps = "runtime_core:ohos_ets_stdlib" 88ohos_ets_es2panda_deps = 89 "//build/config/components/ets_frontend:ohos_ets_es2panda" 90ohos_ets_ark_link_deps = 91 "//build/config/components/ets_frontend:ohos_ets_ark_link" 92ohos_ets_libes2panda_public_deps = 93 "//build/config/components/ets_frontend:ohos_ets_libes2panda_public" 94ohos_ets_build_system_deps = "ets_frontend:ohos_ets_build_system" 95ohos_ets_ui_plugins_deps = "ace_ets2bundle:ohos_ets_ui_plugins" 96 97ohos_ets_api_tmp_path = "$root_build_dir/ohos_ets_tmp/api" 98ohos_ets_api_arkui_tmp_path = "$root_build_dir/ohos_ets_tmp/api/arkui/component" 99ohos_ets_arkts_tmp_path = "$root_build_dir/ohos_ets_tmp/arkts" 100ohos_ets_kits_tmp_path = "$root_build_dir/ohos_ets_tmp/kits" 101ohos_ets_api_path = "$root_build_dir/ohos_ets/api" 102ohos_ets_api_arkui_path = "$root_build_dir/ohos_ets/api/arkui/component" 103ohos_ets_arkts_path = "$root_build_dir/ohos_ets/arkts" 104ohos_ets_kits_path = "$root_build_dir/ohos_ets/kits" 105ohos_ets_inner_path = "$root_build_dir/ohos_ets/inner" 106ohos_ets_es2panda_path = 107 "$root_build_dir/ohos_ets/build-tools/ets2panda/bin/es2panda" 108ohos_ets_ark_link_path = 109 "$root_build_dir/ohos_ets/build-tools/ets2panda/bin/ark_link" 110ohos_ets_stdlib_path = 111 "$root_build_dir/ohos_ets/build-tools/ets2panda/lib/stdlib" 112ohos_ets_build_system_path = 113 "$root_build_dir/ohos_ets/build-tools/driver/build-system" 114ohos_ets_ui_plugins_path = "$root_build_dir/ohos_ets/build-tools/ui-plugins" 115ohos_ets_koala_wrapper_path = 116 "$root_build_dir/ohos_ets/build-tools/koala-wrapper" 117build_sdk_path = "$root_build_dir/ohos_ets" 118 119if (host_os == "mac") { 120 node_path = 121 "//prebuilts/build-tools/common/nodejs/node-v16.20.2-darwin-x64/bin" 122} else { 123 node_path = 124 "//prebuilts/build-tools/common/nodejs/node-v16.20.2-linux-x64/bin" 125} 126 127if (ohos_indep_compiler_enable) { 128 ark_link_target_out_path = 129 get_label_info(static_linker_build_deps, "target_out_dir") + 130 "/clang_x64/libs/ark_link" 131 ets2panda_target_out_path = 132 get_label_info(ets2abc_build_deps, "target_out_dir") + 133 "/clang_x64/libs/es2panda" 134 libes2panda_public_out_path = 135 get_label_info(libes2panda_public_build_deps, "target_out_dir") + 136 "/clang_x64/libs/libes2panda_public.so" 137} else { 138 ark_link_target_out_path = "$static_linker_build_path" 139 ets2panda_target_out_path = "$ets2abc_build_path" 140 libes2panda_public_out_path = "$libes2panda_public_build_path" 141} 142 143bootpath_json_file = root_out_dir + "/obj/arkcompiler/ets_frontend/ets2panda/aot/build/config/components/ets_frontend/bootpath.json" 144 145template("generate_static_abc") { 146 dependencies = [] 147 external_dependencies = [] 148 if (defined(invoker.dependencies)) { 149 dependencies += invoker.dependencies 150 } 151 if (defined(invoker.external_dependencies)) { 152 external_dependencies += invoker.external_dependencies 153 } 154 155 action("$target_name") { 156 if (defined(invoker.extra_visibility)) { 157 visibility = invoker.extra_visibility 158 } 159 160 script = "//build/config/components/ets_frontend/generate_static_abc.py" 161 162 deps = dependencies 163 deps += [ 164 ohos_ets_ark_link_deps, 165 ohos_ets_es2panda_deps, 166 ] 167 external_deps = external_dependencies 168 external_deps += [ ohos_ets_stdlib_deps ] 169 170 args = [ 171 "--bootpath-json-file", 172 rebase_path("${bootpath_json_file}"), 173 ] 174 175 ui_enable = "False" 176 if (defined(invoker.ui_enable)) { 177 ui_enable = invoker.ui_enable 178 } 179 args += [ 180 "--ui-enable", 181 ui_enable, 182 ] 183 184 if (ui_enable == "False") { 185 args += [ 186 "--es2panda", 187 rebase_path("$ohos_ets_es2panda_path"), 188 "--ark-link", 189 rebase_path("$ohos_ets_ark_link_path"), 190 "--env-path", 191 rebase_path("${static_linker_out_root}/arkcompiler/runtime_core/"), 192 ] 193 } 194 195 if (ui_enable == "True") { 196 assert(defined(invoker.files), "files is required!") 197 assert(defined(invoker.base_url), "base_url is required!") 198 deps += [ ohos_ets_libes2panda_public_deps ] 199 external_deps += [ 200 ohos_ets_api_deps, 201 ohos_ets_arkts_deps, 202 ohos_ets_build_system_deps, 203 ohos_ets_kits_deps, 204 ohos_ets_koala_wrapper_deps, 205 ohos_ets_ui_plugins_deps, 206 ] 207 args += [ 208 "--base-url", 209 rebase_path("${invoker.base_url}"), 210 "--build-sdk-path", 211 rebase_path("$build_sdk_path"), 212 "--memo-plugin", 213 rebase_path( 214 "$build_sdk_path/build-tools/ui-plugins/lib/memo-plugins/index.js"), 215 "--entry-path", 216 rebase_path( 217 "$build_sdk_path/build-tools/driver/build-system/dist/entry.js"), 218 "--env-path", 219 rebase_path("$build_sdk_path/build-tools/ets2panda/lib"), 220 "--node-path", 221 rebase_path("$node_path"), 222 ] 223 224 only_memo = "False" 225 if (defined(invoker.only_memo)) { 226 only_memo = invoker.only_memo 227 } 228 229 # if set only_memo, skip other plugins 230 if (only_memo != "True") { 231 args += [ 232 "--ui-plugin", 233 rebase_path( 234 "$build_sdk_path/build-tools/ui-plugins/lib/ui-plugins/index.js"), 235 ] 236 } 237 238 file_paths = [] 239 foreach(path, invoker.files) { 240 file_paths += [ rebase_path(path) ] 241 } 242 args += [ "--files" ] + file_paths 243 244 if (defined(invoker.package)) { 245 args += [ 246 "--package", 247 invoker.package, 248 ] 249 } 250 251 if (defined(invoker.paths_keys) && defined(invoker.paths_values)) { 252 args += [ "--paths-keys" ] + invoker.paths_keys 253 paths_values = [] 254 foreach(path, invoker.paths_values) { 255 paths_values += [ rebase_path(path) ] 256 } 257 args += [ "--paths-values" ] + paths_values 258 } 259 } else if (defined(invoker.base_url)) { 260 external_deps += [ 261 ohos_ets_api_deps, 262 ohos_ets_arkts_deps, 263 ] 264 args += [ 265 "--base-url", 266 rebase_path("${invoker.base_url}"), 267 "--root-dir", 268 rebase_path("//"), 269 "--scan-path", 270 rebase_path("$ohos_ets_api_path"), 271 rebase_path("$ohos_ets_arkts_path"), 272 rebase_path("$ohos_ets_inner_path"), 273 "--std-path", 274 rebase_path("$ohos_ets_stdlib_path/std"), 275 "--escompat-path", 276 rebase_path("$ohos_ets_stdlib_path/escompat"), 277 ] 278 279 if (defined(invoker.paths_keys) && defined(invoker.paths_values)) { 280 args += [ "--paths-keys" ] + invoker.paths_keys 281 paths_values = [] 282 foreach(path, invoker.paths_values) { 283 paths_values += [ rebase_path(path) ] 284 } 285 args += [ "--paths-values" ] + paths_values 286 } 287 288 if (defined(invoker.include)) { 289 include_paths = [] 290 foreach(path, invoker.include) { 291 include_paths += [ rebase_path(path) ] 292 } 293 args += [ "--include" ] + include_paths 294 } 295 296 if (defined(invoker.exclude)) { 297 exclude_paths = [] 298 foreach(path, invoker.exclude) { 299 exclude_paths += [ rebase_path(path) ] 300 } 301 args += [ "--exclude" ] + exclude_paths 302 } 303 304 if (defined(invoker.files)) { 305 file_paths = [] 306 foreach(path, invoker.files) { 307 file_paths += [ rebase_path(path) ] 308 } 309 args += [ "--files" ] + file_paths 310 } 311 312 if (defined(invoker.package)) { 313 args += [ 314 "--package", 315 invoker.package, 316 ] 317 } 318 } 319 320 if (defined(invoker.timeout_limit)) { 321 args += [ 322 "--timeout-limit", 323 invoker.timeout_limit, 324 ] 325 } 326 327 if (defined(invoker.is_stdlib)) { 328 args += [ 329 "--is-stdlib", 330 invoker.is_stdlib, 331 ] 332 } 333 334 if (defined(invoker.is_boot_abc)) { 335 args += [ 336 "--is-boot-abc", 337 invoker.is_boot_abc, 338 ] 339 if (invoker.is_boot_abc == "True") { 340 assert( 341 defined(invoker.device_dst_file), 342 "The 'device_dst_file' parameter is required if 'is_boot_abc' is True!") 343 args += [ 344 "--device-dst-file", 345 invoker.device_dst_file, 346 "--target-name", 347 "$target_name", 348 ] 349 } 350 } 351 352 cache_path = "$target_out_dir/$target_name/cache" 353 if (defined(invoker.cache_path)) { 354 cache_path = invoker.cache_path 355 } 356 args += [ 357 "--cache-path", 358 rebase_path(cache_path), 359 ] 360 361 arktsconfig = "$target_out_dir/$target_name.json" 362 if (defined(invoker.arktsconfig)) { 363 arktsconfig = invoker.arktsconfig 364 } 365 args += [ 366 "--arktsconfig", 367 rebase_path(arktsconfig), 368 ] 369 370 dst_file = "$target_out_dir/$target_name.abc" 371 if (defined(invoker.dst_file)) { 372 dst_file = invoker.dst_file 373 } 374 args += [ 375 "--dst-file", 376 rebase_path(dst_file), 377 ] 378 379 if (defined(invoker.in_puts)) { 380 inputs = invoker.in_puts 381 } 382 383 if (defined(invoker.out_puts)) { 384 outputs = invoker.out_puts 385 } else { 386 outputs = [ dst_file ] 387 } 388 } 389} 390