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("//arkcompiler/ets_frontend/ets_frontend_config.gni") 15ts2abc_root = "//arkcompiler/ets_frontend/ts2panda" 16merge_abc_root = "//arkcompiler/ets_frontend/merge_abc" 17 18declare_args() { 19 nodejs_dir = "" 20 node_path = "" 21 node_modules = "" 22 23 ts2abc_build_deps = "" 24 ts2abc_build_path = "" 25 26 merge_abc_deps = "" 27 merge_abc_path = "" 28} 29 30node_modules = "//prebuilts/build-tools/common/ts2abc/node_modules" 31if (build_public_version) { 32 nodejs_dir = "//prebuilts/build-tools/common/nodejs" 33} else { 34 nodejs_dir = "//prebuilts/ace-toolkit/nodejs" 35} 36 37if (host_toolchain == toolchain_mac) { 38 ts2abc_build_deps = [ "$ts2abc_root:ts2abc_build_mac($toolchain_mac)" ] 39 ts2abc_build_path = 40 get_label_info("$ts2abc_root:ts2abc_build_mac($toolchain_mac)", 41 "root_out_dir") + 42 "/obj/arkcompiler/ets_frontend/ts2panda/build-mac" 43 node_path = "${nodejs_dir}/current/bin/" 44} else if (host_toolchain == toolchain_win) { 45 ts2abc_build_deps = [ "$ts2abc_root:ts2abc_build_win($toolchain_win)" ] 46 ts2abc_build_path = 47 get_label_info("$ts2abc_root:ts2abc_build_win($toolchain_win)", 48 "root_out_dir") + 49 "/obj/arkcompiler/ets_frontend/ts2panda/build_win" 50} else { 51 ts2abc_build_deps = [ "$ts2abc_root:ts2abc_build($toolchain_linux)" ] 52 ts2abc_build_path = 53 get_label_info("$ts2abc_root:ts2abc_build($toolchain_linux)", 54 "root_out_dir") + 55 "/obj/arkcompiler/ets_frontend/ts2panda/build" 56 node_path = "${nodejs_dir}/current/bin/" 57 merge_abc_deps = [ "$merge_abc_root:merge_abc(${toolchain_linux})" ] 58 merge_abc_path = 59 get_label_info("$merge_abc_root:merge_abc($toolchain_linux)", 60 "root_out_dir") + "/arkcompiler/ets_frontend/merge_abc" 61} 62 63# Generate js plugin. 64# 65# Mandatory arguments: 66# plugin_path -- plugin js file path 67# plugin_name -- name of js file, ex: BatteryPlugin.js 68# generat_file -- name of generated file 69# package_name -- name of generated file's package 70# extra_dependencies -- a list of files that should be considered as dependencies, must be label 71# out_puts 72template("ts2abc_gen_file") { 73 assert(defined(invoker.plugin_path), "plugin_path is required!") 74 assert(defined(invoker.plugin_name), "plugin_name is required!") 75 assert(defined(invoker.generat_file), "generat_file is required!") 76 assert(defined(invoker.package_name), "package_name is required!") 77 assert(defined(invoker.out_puts), "out_puts is required!") 78 79 extra_dependencies = [] 80 if (defined(invoker.extra_dependencies)) { 81 extra_dependencies += invoker.extra_dependencies 82 } 83 84 action("$target_name") { 85 script = "${ts2abc_root}/scripts/generate_plugin.py" 86 87 deps = extra_dependencies 88 deps += ts2abc_build_deps 89 args = [ 90 "--node", 91 rebase_path("${node_path}"), 92 "--frontend-tool-path", 93 rebase_path("${ts2abc_build_path}"), 94 "--node-modules", 95 rebase_path("${node_modules}"), 96 "--plugin-path", 97 invoker.plugin_path, 98 "--plugin-name", 99 invoker.plugin_name, 100 "--generated-file", 101 invoker.generat_file, 102 "--package-name", 103 invoker.package_name, 104 ] 105 106 outputs = invoker.out_puts 107 } 108} 109 110# ts2abc_gen_abc has been disabled, please use es2abc_gen_abc from es2abc_config.gni 111 112template("ts2abc_unittest_action") { 113 _target_name_ = "${target_name}" 114 invoker.module_out_path = "ark/ts2abc" 115 116 # unittest for phone running 117 ohos_unittest(_target_name_) { 118 configs = [ "${ts2abc_root}/ts2abc:ts2abc_config" ] 119 deps = [ "${ts2abc_root}/ts2abc:ts2abc_static" ] 120 forward_variables_from(invoker, "*") 121 } 122 123 _module_out_path_ = invoker.module_out_path 124 125 # unittest for host running 126 action("${_target_name_}Action") { 127 testonly = true 128 _host_test_target_ = ":${_target_name_}(${host_toolchain})" 129 _root_out_dir_ = get_label_info(_host_test_target_, "root_out_dir") 130 131 deps = [ _host_test_target_ ] 132 133 script = "${ts2abc_root}/scripts/run_tests_executable.sh" 134 135 args = [ rebase_path(_root_out_dir_) + 136 "/tests/unittest/${_module_out_path_}/${_target_name_}" ] 137 138 inputs = [ 139 "$_root_out_dir_/tests/unittest/${_module_out_path_}/${_target_name_}", 140 ] 141 outputs = [ "$target_out_dir/${_target_name_}/" ] 142 } 143} 144 145# ts2abc performs the ut test 146# 147# Mandatory arguments: 148# js_file: The name of the test use case file to execute , ex expression/TemplateExpression.test.js 149template("ts2abc_unittest") { 150 assert(defined(invoker.js_file), "js_file is required!") 151 152 action("$target_name") { 153 script = "${ts2abc_root}/scripts/run_tests.py" 154 deps = [ "${ts2abc_root}:ts2abc_tests" ] 155 156 args = [ 157 "--src-dir", 158 rebase_path("${ts2abc_root}"), 159 "--dist-dir", 160 rebase_path(target_out_dir + "/.."), 161 "--node-modules", 162 rebase_path("${node_modules}"), 163 "--js-file", 164 invoker.js_file, 165 "--gn-build", 166 ] 167 168 if (host_toolchain == toolchain_linux) { 169 args += [ 170 "--platform", 171 "linux", 172 ] 173 } else if (host_toolchain == toolchain_mac) { 174 args += [ 175 "--platform", 176 "mac", 177 ] 178 } else { 179 args += [ 180 "--platform", 181 "win", 182 ] 183 } 184 outputs = [ "$target_out_dir/${target_name}/" ] 185 } 186} 187