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") 15 16es2abc_root = "//arkcompiler/ets_frontend/es2panda" 17es2abc_build_path = "" 18es2abc_build_deps = "" 19es2abc_out_root = "" 20 21if (host_toolchain == toolchain_mac) { 22 es2abc_out_root = 23 get_label_info("$es2abc_root:es2panda($toolchain_mac)", "root_out_dir") 24 es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_mac)" ] 25} else if (host_toolchain == toolchain_win) { 26 es2abc_out_root = 27 get_label_info("$es2abc_root:es2panda($toolchain_win)", "root_out_dir") 28 es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_win)" ] 29} else if (!ark_standalone_build && host_toolchain == toolchain_ohos) { 30 es2abc_out_root = 31 get_label_info("$es2abc_root:es2panda($toolchain_ohos)", "root_out_dir") 32 es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_ohos)" ] 33} else { 34 es2abc_out_root = 35 get_label_info("$es2abc_root:es2panda($toolchain_linux)", "root_out_dir") 36 es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_linux)" ] 37} 38es2abc_build_path = es2abc_out_root + "/arkcompiler/ets_frontend" 39 40# Generate abc. 41# 42# Mandatory arguments: 43# plugin_path -- plugin js file path 44# plugin_name -- name of js file, ex: BatteryPlugin.js 45# generat_file -- name of generated file 46# package_name -- name of generated file's package 47# extra_dependencies -- a list of files that should be considered as dependencies, must be label 48# out_puts 49template("es2abc_gen_abc") { 50 assert(defined(invoker.src_js), "src_js is required!") 51 assert(defined(invoker.dst_file), "dst_file is required!") 52 assert(defined(invoker.out_puts), "out_puts is required!") 53 54 extra_dependencies = [] 55 if (defined(invoker.extra_dependencies)) { 56 extra_dependencies += invoker.extra_dependencies 57 } 58 59 action("$target_name") { 60 if (defined(invoker.extra_visibility)) { 61 visibility = invoker.extra_visibility 62 } 63 64 script = "${es2abc_root}/scripts/generate_js_bytecode.py" 65 66 deps = extra_dependencies 67 deps += es2abc_build_deps 68 69 args = [ 70 "--src-js", 71 invoker.src_js, 72 "--dst-file", 73 invoker.dst_file, 74 "--frontend-tool-path", 75 rebase_path("${es2abc_build_path}"), 76 ] 77 78 if (defined(invoker.extension)) { 79 args += [ 80 "--extension", 81 invoker.extension, 82 ] 83 } 84 85 if (defined(invoker.dump_symbol_table)) { 86 args += [ 87 "--dump-symbol-table", 88 invoker.dump_symbol_table, 89 ] 90 } 91 if (defined(invoker.input_symbol_table)) { 92 args += [ 93 "--input-symbol-table", 94 invoker.input_symbol_table, 95 ] 96 } 97 98 if (defined(invoker.extra_args)) { 99 args += invoker.extra_args 100 } 101 102 if (defined(invoker.in_puts)) { 103 inputs = invoker.in_puts 104 } 105 106 outputs = invoker.out_puts 107 } 108} 109 110template("es2abc_gen_newest_abc") { 111 assert(defined(invoker.src_js), "src_js is required!") 112 assert(defined(invoker.dst_file), "dst_file is required!") 113 assert(defined(invoker.out_puts), "out_puts is required!") 114 115 extra_dependencies = [] 116 if (defined(invoker.extra_dependencies)) { 117 extra_dependencies += invoker.extra_dependencies 118 } 119 120 action("$target_name") { 121 if (defined(invoker.extra_visibility)) { 122 visibility = invoker.extra_visibility 123 } 124 125 script = "${es2abc_root}/scripts/generate_js_bytecode.py" 126 127 deps = extra_dependencies 128 deps += es2abc_build_deps 129 130 args = [ 131 "--src-js", 132 invoker.src_js, 133 "--dst-file", 134 invoker.dst_file, 135 "--frontend-tool-path", 136 rebase_path("${es2abc_build_path}"), 137 ] 138 139 if (defined(invoker.extension)) { 140 args += [ 141 "--extension", 142 invoker.extension, 143 ] 144 } 145 146 if (defined(invoker.dump_symbol_table)) { 147 args += [ 148 "--dump-symbol-table", 149 invoker.dump_symbol_table, 150 ] 151 } 152 if (defined(invoker.input_symbol_table)) { 153 args += [ 154 "--input-symbol-table", 155 invoker.input_symbol_table, 156 ] 157 } 158 159 if (defined(invoker.extra_args)) { 160 args += invoker.extra_args 161 } 162 163 if (defined(invoker.in_puts)) { 164 inputs = invoker.in_puts 165 } 166 167 args += [ "--target-api-sub-version=beta3" ] 168 169 outputs = invoker.out_puts 170 } 171} 172