1# Copyright (c) 2022 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/ts2panda/ts2abc_config.gni") 15import("//arkcompiler/runtime_core/ark_config.gni") 16 17src_dir = target_out_dir + "/src" 18src_dir_full_path = rebase_path("${ts2abc_root}/src") 19arguments = [ "-c" ] 20arguments += [ "ls ${src_dir_full_path} " ] 21src_files = exec_script("/bin/sh", arguments, "list lines") 22 23foreach(file, src_files) { 24 ohos_copy("ts2abc_src_${file}") { 25 sources = [ "${ts2abc_root}/src/${file}" ] 26 outputs = [ "${src_dir}/${file}" ] 27 module_install_name = "" 28 } 29} 30 31group("ts2abc_src") { 32 deps = [] 33 foreach(file, src_files) { 34 deps += [ ":ts2abc_src_${file}" ] 35 } 36} 37 38ohos_copy("node_modules") { 39 sources = [ rebase_path("${node_modules}") ] 40 outputs = [ target_out_dir + "/node_modules" ] 41 module_install_name = "" 42} 43 44ohos_copy("config_files") { 45 sources = [ 46 "${ts2abc_root}/package-lock.json", 47 "${ts2abc_root}/package.json", 48 "${ts2abc_root}/tsconfig.json", 49 "${ts2abc_root}/webpack.config.js", 50 ] 51 52 outputs = [ target_out_dir + "/{{source_file_part}}" ] 53 module_install_name = "" 54} 55 56ohos_copy("ts2abc_deps") { 57 sources = 58 [ "//third_party/typescript/build_package/ohos-typescript-4.2.3-r2.tgz" ] 59 60 outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] 61 module_source_dir = target_out_dir + "/$target_name" 62 module_install_name = "" 63 license_file = "//third_party/typescript/LICENSE" 64 part_name = "ets_frontend" 65 subsystem_name = "arkcompiler" 66} 67 68ohos_copy("ts2abc_deps_ets") { 69 sources = 70 [ "//third_party/typescript/build_package/ohos-typescript-4.2.3-r2.tgz" ] 71 72 outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] 73 module_source_dir = target_out_dir + "/$target_name" 74 module_install_name = "" 75 license_file = "//third_party/typescript/LICENSE" 76 part_name = "ets_frontend" 77 subsystem_name = "arkcompiler" 78} 79 80ohos_copy("ts2abc_deps_win") { 81 sources = 82 [ "//third_party/typescript/build_package/ohos-typescript-4.2.3-r2.tgz" ] 83 84 outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] 85 module_source_dir = target_out_dir + "/$target_name" 86 module_install_name = "" 87 license_file = "//third_party/typescript/LICENSE" 88 part_name = "ets_frontend" 89 subsystem_name = "arkcompiler" 90} 91 92ohos_copy("ts2abc_deps_win_ets") { 93 sources = 94 [ "//third_party/typescript/build_package/ohos-typescript-4.2.3-r2.tgz" ] 95 96 outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] 97 module_source_dir = target_out_dir + "/$target_name" 98 module_install_name = "" 99 license_file = "//third_party/typescript/LICENSE" 100 part_name = "ets_frontend" 101 subsystem_name = "arkcompiler" 102} 103 104ohos_copy("ts2abc_deps_mac") { 105 sources = 106 [ "//third_party/typescript/build_package/ohos-typescript-4.2.3-r2.tgz" ] 107 108 outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] 109 module_source_dir = target_out_dir + "/$target_name" 110 module_install_name = "" 111 license_file = "//third_party/typescript/LICENSE" 112 part_name = "ets_frontend" 113 subsystem_name = "arkcompiler" 114} 115 116ohos_copy("ts2abc_deps_mac_ets") { 117 sources = 118 [ "//third_party/typescript/build_package/ohos-typescript-4.2.3-r2.tgz" ] 119 120 outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] 121 module_source_dir = target_out_dir + "/$target_name" 122 module_install_name = "" 123 license_file = "//third_party/typescript/LICENSE" 124 part_name = "ets_frontend" 125 subsystem_name = "arkcompiler" 126} 127 128action("ts2abc_diagnostic_ts") { 129 visibility = [ ":*" ] 130 script = "scripts/gen_diagnostic.rb" 131 args = [ 132 "--template", 133 rebase_path("templates/diagnostic.ts.erb", root_build_dir), 134 "--data", 135 rebase_path("scripts/diagnosticMessages.json", root_build_dir), 136 "--output", 137 rebase_path("${src_dir}/diagnostic.ts"), 138 ] 139 140 outputs = [ "${src_dir}/diagnostic.ts" ] 141 deps = [ "$ts2abc_root:ts2abc_src" ] 142} 143 144ark_gen_file("ts2abc_irnodes_ts") { 145 template_file = "templates/irnodes.ts.erb" 146 data_file = "$root_gen_dir/isa/isa.yaml" 147 requires = [ 148 "$ark_root/isa/isapi.rb", 149 "$ark_root/libpandafile/pandafile_isapi.rb", 150 ] 151 output_file = "$src_dir/irnodes.ts" 152 extra_dependencies = [ 153 "$ts2abc_root:ts2abc_src", 154 "$ark_root/isa:isa_combine", 155 ] 156} 157 158action("npm_run_build") { 159 visibility = [ ":*" ] 160 deps = [ 161 "$ts2abc_root:config_files", 162 "$ts2abc_root:node_modules", 163 "$ts2abc_root:ts2abc_diagnostic_ts", 164 "$ts2abc_root:ts2abc_irnodes_ts", 165 "$ts2abc_root:ts2abc_src", 166 ] 167 168 if (is_linux || is_mingw || is_mac) { 169 deps += [ "$ts2abc_root/ts2abc:ts2abc" ] 170 } 171 172 script = "${ts2abc_root}/scripts/run.py" 173 args = [ 174 "--src-dir", 175 rebase_path(ts2abc_root), 176 "--dist-dir", 177 rebase_path(target_out_dir), 178 "--node", 179 rebase_path(node_path), 180 "--node-modules", 181 rebase_path(node_modules), 182 ] 183 184 if (is_linux) { 185 args += [ 186 "--platform", 187 "linux", 188 "--js2abc", 189 rebase_path("${root_out_dir}/arkcompiler/ets_frontend/js2abc"), 190 ] 191 } else if (is_mingw) { 192 args += [ 193 "--platform", 194 "win", 195 "--js2abc", 196 rebase_path("${root_out_dir}/arkcompiler/ets_frontend/js2abc.exe"), 197 ] 198 } else if (is_mac) { 199 args += [ 200 "--platform", 201 "mac", 202 "--js2abc", 203 rebase_path("${root_out_dir}/arkcompiler/ets_frontend/js2abc"), 204 ] 205 } 206 207 if (is_debug) { 208 args += [ 209 "--buildMode", 210 "debug", 211 ] 212 } else { 213 args += [ 214 "--buildMode", 215 "release", 216 ] 217 } 218 219 outputs = [] 220 if (is_mingw) { 221 outputs += [ "${root_out_dir}/arkcompiler/ets_frontend/build-win" ] 222 } else if (is_mac) { 223 outputs += [ "${root_out_dir}/arkcompiler/ets_frontend/build-mac" ] 224 } else { 225 outputs += [ "${root_out_dir}/arkcompiler/ets_frontend/build" ] 226 } 227} 228 229if (is_linux) { 230 ohos_copy("ts2abc_build") { 231 deps = [ "$ts2abc_root:npm_run_build" ] 232 sources = [ "${root_out_dir}/arkcompiler/ets_frontend/build" ] 233 outputs = [ "${target_out_dir}/build-tmp" ] 234 module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend/build" 235 module_install_name = "" 236 } 237 238 ohos_copy("ts2abc_build_ets") { 239 deps = [ "$ts2abc_root:npm_run_build" ] 240 241 sources = [ "${root_out_dir}/arkcompiler/ets_frontend/build" ] 242 outputs = [ "${root_out_dir}/arkcompiler/ets_frontend/build-ets" ] 243 module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend/build-ets" 244 module_install_name = "" 245 } 246} 247 248if (is_mingw) { 249 ohos_copy("ts2abc_build_win") { 250 deps = [ "$ts2abc_root:npm_run_build" ] 251 sources = [ "${root_out_dir}/arkcompiler/ets_frontend/build-win" ] 252 outputs = [ "${target_out_dir}/build-tmp" ] 253 module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend/build-win" 254 module_install_name = "" 255 } 256 257 ohos_copy("ts2abc_build_win_ets") { 258 deps = [ "$ts2abc_root:npm_run_build" ] 259 sources = [ "${root_out_dir}/arkcompiler/ets_frontend/build-win" ] 260 outputs = [ "${root_out_dir}/arkcompiler/ets_frontend/build-win-ets" ] 261 module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend/build-win-ets" 262 module_install_name = "" 263 } 264} 265 266if (is_mac) { 267 ohos_copy("ts2abc_build_mac") { 268 deps = [ "$ts2abc_root:npm_run_build" ] 269 sources = [ "${root_out_dir}/arkcompiler/ets_frontend/build-mac" ] 270 outputs = [ "${target_out_dir}/build-tmp" ] 271 module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend/build-mac" 272 module_install_name = "" 273 } 274 275 ohos_copy("ts2abc_build_mac_ets") { 276 deps = [ "$ts2abc_root:npm_run_build" ] 277 sources = [ "${root_out_dir}/arkcompiler/ets_frontend/build-mac" ] 278 outputs = [ "${root_out_dir}/arkcompiler/ets_frontend/build-mac-ets" ] 279 module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend/build-mac-ets" 280 module_install_name = "" 281 } 282} 283 284ohos_copy("panda_ts2abc") { 285 sources = [ "${ts2abc_root}/scripts/ts2abc.js" ] 286 287 outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] 288 module_source_dir = target_out_dir + "/$target_name/" 289 module_install_name = "" 290} 291 292ohos_copy("panda_ts2abc_ets") { 293 sources = [ "${ts2abc_root}/scripts/ts2abc.js" ] 294 outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] 295 module_source_dir = target_out_dir + "/$target_name/" 296 module_install_name = "" 297} 298 299ohos_copy("ts2abc_js_file") { 300 sources = [ "${ts2abc_root}/scripts/ts2abc.js" ] 301 outputs = [ target_out_dir + "/{{source_file_part}}" ] 302} 303 304group("ark_ts2abc_build") { 305 deps = [] 306 if (host_os != "mac") { 307 deps += [ 308 "${ts2abc_root}:ts2abc_build(${toolchain_linux})", 309 "${ts2abc_root}:ts2abc_build_ets(${toolchain_linux})", 310 ] 311 } else { 312 deps += [ 313 "${ts2abc_root}:ts2abc_build_mac(${toolchain_mac})", 314 "${ts2abc_root}:ts2abc_build_mac_ets(${toolchain_mac})", 315 ] 316 } 317} 318 319group("ark_ts2abc_build_win") { 320 deps = [ 321 "${ts2abc_root}:ts2abc_build_win(${toolchain_win})", 322 "${ts2abc_root}:ts2abc_build_win_ets(${toolchain_win})", 323 ] 324} 325 326ohos_copy("copy_ts2abc_tests") { 327 sources = [ "${ts2abc_root}/tests" ] 328 deps = [ ":npm_run_build" ] 329 330 outputs = [ target_out_dir + "/tests" ] 331 module_install_name = "" 332} 333 334if (!ark_standalone_build) { 335 group("ts2abc_unittests") { 336 if (host_os == "linux") { 337 testonly = true 338 deps = [ 339 "tests:ts2abc_ts_instruction_type_test(${toolchain_linux})", 340 "tests:ts2abc_ts_type_system_test(${toolchain_linux})", 341 "tests:ts2abc_ts_ut_test(${toolchain_linux})", 342 ] 343 } 344 } 345} 346