From d53b6c88bf4a3b0ab7b81aaddf1842f5f05111fe Mon Sep 17 00:00:00 2001 From: huoqingyi Date: Tue, 7 Mar 2023 19:28:38 +0800 Subject: [PATCH] Add some options in generate_js_bytecode.py To support tests of AOT TypeInferPass under multi-file scenarios, we need to add some options in generate_js_bytecode.py to run merge_abc cmd. Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I6MBG7 Tests: arkcompiler_ets_frontend: tests of ts2abc arkcompiler_ets_runtime: typeinfer test Change-Id: Ib813557ba3a01d809ef737ca7e2d52356a6e0848 Signed-off-by: huoqingyi --- ts2panda/scripts/generate_js_bytecode.py | 38 +++++++++++++++++++++++- ts2panda/ts2abc_config.gni | 20 +++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/ts2panda/scripts/generate_js_bytecode.py b/ts2panda/scripts/generate_js_bytecode.py index 0f4aca8823..5210f46d7b 100755 --- a/ts2panda/scripts/generate_js_bytecode.py +++ b/ts2panda/scripts/generate_js_bytecode.py @@ -49,7 +49,15 @@ def parse_args(): parser.add_argument("--functionSourceCode", action='store_true', help='compile abc with function sourcecode info') parser.add_argument("--merge-abc", action='store_true', - help='Compile as merge abc') + help='compile as merge abc') + parser.add_argument("--output-proto", action='store_true', + help='output protoBin file') + parser.add_argument("--run-multi-file-tests", action='store_true', + help='run multi-file tests') + parser.add_argument("--merge-abc-path", + help='path to merge_abc binary tool') + parser.add_argument("--src-ts", + help='ts source files') arguments = parser.parse_args() return arguments @@ -68,6 +76,27 @@ def run_command(cmd, execution_path): proc.wait() +def copy_ts_files(input_arguments, path): + (output_path, name) = os.path.split(input_arguments.src_js) + remove_cmd = ['rm', '-rf', output_path] + run_command(remove_cmd, path) + + copy_cmd = ['cp', '-r', input_arguments.src_ts, output_path] + run_command(copy_cmd, path) + + +def merge_abc(input_arguments, path): + (output_path, abc_file) = os.path.split(input_arguments.dst_file) + merge_abc_cmd = [input_arguments.merge_abc_path, + "--input", + output_path, + "--output", + abc_file, + "--outputFilePath", + output_path] + run_command(merge_abc_cmd, path) + + def gen_abc_info(input_arguments): set_env(input_arguments) @@ -83,6 +112,9 @@ def gen_abc_info(input_arguments): cmd = ['npm', 'install'] run_command(cmd, path) + if input_arguments.run_multi_file_tests: + copy_ts_files(input_arguments, path) + cmd = [os.path.join(input_arguments.node, "node"), '--expose-gc', os.path.join(name, 'src/index.js'), @@ -104,8 +136,12 @@ def gen_abc_info(input_arguments): cmd.insert(8, '--function-sourcecode') if input_arguments.merge_abc: cmd.insert(9, '--merge-abc') + if input_arguments.output_proto: + cmd.insert(10, '--output-proto') run_command(cmd, path) + if input_arguments.run_multi_file_tests: + merge_abc(input_arguments, path) if __name__ == '__main__': gen_abc_info(parse_args()) diff --git a/ts2panda/ts2abc_config.gni b/ts2panda/ts2abc_config.gni index 7551feda15..a728a16268 100755 --- a/ts2panda/ts2abc_config.gni +++ b/ts2panda/ts2abc_config.gni @@ -13,6 +13,7 @@ import("//arkcompiler/ets_frontend/ets_frontend_config.gni") ts2abc_root = "//arkcompiler/ets_frontend/ts2panda" +merge_abc_root = "//arkcompiler/ets_frontend/merge_abc" declare_args() { nodejs_dir = "" @@ -21,6 +22,9 @@ declare_args() { ts2abc_build_deps = "" ts2abc_build_path = "" + + merge_abc_deps = "" + merge_abc_path = "" } node_modules = "//prebuilts/build-tools/common/ts2abc/node_modules" @@ -50,6 +54,10 @@ if (host_toolchain == toolchain_mac) { "root_out_dir") + "/obj/arkcompiler/ets_frontend/ts2panda/build" node_path = "${nodejs_dir}/node-v12.18.4-linux-x64/bin/" + merge_abc_deps = [ "$merge_abc_root:merge_abc(${toolchain_linux})" ] + merge_abc_path = + get_label_info("$merge_abc_root:merge_abc($toolchain_linux)", + "root_out_dir") + "/arkcompiler/ets_frontend/merge_abc" } # Generate js plugin. @@ -142,6 +150,18 @@ template("ts2abc_gen_abc") { args += invoker.extra_args } + if (defined(invoker.run_multi_file_tests) && invoker.run_multi_file_tests) { + assert(defined(invoker.src_ts), "src_ts is required!") + deps += merge_abc_deps + args += [ + "--merge-abc-path", + rebase_path("${merge_abc_path}"), + "--src-ts", + invoker.src_ts, + "--run-multi-file-tests", + ] + } + if (defined(invoker.in_puts)) { inputs = invoker.in_puts } -- Gitee