diff --git a/BUILD.gn b/BUILD.gn index 2b09e573b8974198e8534b4bb01a4bf3a86abab9..6dce3edb72ace93760105185ce83a1b8fd8b8de6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -94,6 +94,8 @@ config("ark_toolchain_common_config") { "-Wformat=2", ] + cflags_c = [] + if (is_linux) { defines += [ "PANDA_TARGET_UNIX", @@ -163,7 +165,20 @@ config("ark_toolchain_common_config") { ] } - if (is_debug) { + if (is_fastverify) { + cflags_cc += [ + "-O3", + "-ggdb3", + "-fno-omit-frame-pointer", + "-D_GLIBCXX_ASSERTIONS", + ] + cflags_c += [ + "-O3", + "-ggdb3", + "-fno-omit-frame-pointer", + "-D_GLIBCXX_ASSERTIONS", + ] + } else if (is_debug) { cflags_cc += [ "-O0", "-ggdb3", @@ -200,6 +215,7 @@ config("ark_toolchain_public_config") { # ecmascript unit testcase config config("toolchain_test_config") { visibility = [ + "./inspector/test/*", "./test/fuzztest/*", "./tooling/test/*", "./websocket/test/*", @@ -228,6 +244,7 @@ group("ark_toolchain_unittest") { testonly = true deps = [] deps += [ + "./inspector/test:unittest", "./tooling/test:unittest", "./websocket/test:unittest", ] @@ -242,6 +259,7 @@ group("ark_toolchain_host_unittest") { # js unittest deps += [ + "./inspector/test:host_unittest", "./tooling/test:host_unittest", "./websocket/test:host_unittest", ] diff --git a/CODEOWNERS b/CODEOWNERS index a2ad37405ddc9bc4a4ccb9f7636c204c2518ac75..ece0249656096eadbe5d5522d9c01802a4429402 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -12,4 +12,5 @@ # limitations under the License. * @klooer +.* @klooer diff --git a/REVIEWERS b/REVIEWERS index 3f1d9f1d329a7762408f336a160c093665615c2d..9abad16e9470f0b4794a38b9690b1b75ca4108c7 100644 --- a/REVIEWERS +++ b/REVIEWERS @@ -12,3 +12,4 @@ # limitations under the License. * @weng-changcheng @wanghuan2022 +build/compile_script/ark.py @shirunova_viktoria @weng-changcheng @wanghuan2022 @zhuheng27 diff --git a/build/ark_var.gni b/build/ark_var.gni index 001e4dc587af8619ea1568d54045b2013a1f0afe..4739e0653338a1dd58cbadfa5136de0587772e88 100644 --- a/build/ark_var.gni +++ b/build/ark_var.gni @@ -17,6 +17,4 @@ declare_args() { # system package dir system_base_dir = "system" - - device_name = "" } diff --git a/build/compile_script/ark.py b/build/compile_script/ark.py index 7eadf1bd5abc127b345ad67dda325f4518eb1408..ce690347e4927b2ad176fa5bfc40f7d87d4aa755 100755 --- a/build/compile_script/ark.py +++ b/build/compile_script/ark.py @@ -24,6 +24,7 @@ import os import platform import subprocess import sys +from typing import List, Any, Tuple, Union, Optional CURRENT_FILENAME = os.path.basename(__file__) @@ -95,7 +96,7 @@ class ArkPy: REGRESS_TEST_LOG_FILE_NAME = "regresstest.log" PREBUILTS_DOWNLOAD_CONFIG_FILE_PATH = \ "./arkcompiler/toolchain/build/prebuilts_download/prebuilts_download_config.json" - INDENTATION_STRING_PER_LEVEL = " " # for help message + INDENTATION_STRING_PER_LEVEL = " " # for help message # In ARG_DICT, "flags" and "description" are must-keys for the leaf-dicts in it. # (Future designer need know.) ARG_DICT = { @@ -186,6 +187,12 @@ class ArkPy: "gn_args": ["is_debug=true"], "suffix_of_name_of_out_dir_of_second_level": "debug", }, + "fastverify": { + "flags": ["fastverify", "fv"], + "description": "Build for arkcompiler target(executables and libraries) for fastverify.", + "gn_args": ["is_debug=true is_fastverify=true"], + "suffix_of_name_of_out_dir_of_second_level": "fastverify", + }, }, "target": { "test262": { @@ -214,14 +221,14 @@ class ArkPy: "gn_targets_depend_on": ["default"], }, "gn_target": { - "flags": [""], # any other flags + "flags": [""], # any other flags "description": "Build for arkcompiler target assigned by user. Targets include group(ets_runtime), " "ohos_executable(ark_js_vm), ohos_shared_library(libark_jsruntime), " "ohos_static_library(static_icuuc), ohos_source_set(libark_jsruntime_set), " "ohos_unittest(EcmaVm_001_Test), action(EcmaVm_001_TestAction) and other target of user-defined " "template type in \"*.gn*\" file.", - "gn_targets_depend_on": [], # not need, depend on deps of itself in "*.gn*" file + "gn_targets_depend_on": [], # not need, depend on deps of itself in "*.gn*" file }, }, "option": { @@ -257,7 +264,7 @@ class ArkPy: "keep-going": { "flags": ["--keep-going=*", "-keep-going=*"], "description": "Keep running unittest etc. until errors occured less than N times" - " (use 0 to ignore all errors).", + " (use 0 to ignore all errors).", }, }, "help": { @@ -282,7 +289,7 @@ class ArkPy: arg_list = list(dict.fromkeys(arg_list)) # match [help] flag if len(arg_list) == 0 or ( - True in [self.is_dict_flags_match_arg(self.ARG_DICT["help"], arg) for arg in arg_list]): + True in [self.is_dict_flags_match_arg(self.ARG_DICT.get("help"), arg) for arg in arg_list]): print(self.get_help_msg_of_all()) return # match [[os_cpu].[mode]] flag @@ -300,39 +307,114 @@ class ArkPy: if fnmatch(arg_to_match, flag): return True return False - + @staticmethod - def get_test262_cmd(gn_args, out_path, x64_out_path, aot_mode, run_pgo, enable_litecg, args_to_test262_cmd, - timeout): + def libs_dir(is_arm, is_aot, is_pgo, out_dir, x64_out_dir) -> str: + if is_arm and is_aot and is_pgo: + return (f"--libs-dir ../../{out_dir}/arkcompiler/ets_runtime:" + f"../../{out_dir}/thirdparty/icu:" + f"../../{out_dir}/third_party/icu:" + f"../../thirdparty/zlib:" + f"../../prebuilts/clang/ohos/linux-x86_64/llvm/lib") + if is_arm and is_aot and not is_pgo: + return ("--libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" + f":../../{x64_out_dir}/thirdparty/icu/") + if not is_arm and is_aot: + return (f"--libs-dir ../../{out_dir}/arkcompiler/ets_runtime" + f":../../{out_dir}/thirdparty/icu:" + f"../../{out_dir}/third_party/icu:" + f"../../thirdparty/zlib:" + f"../../prebuilts/clang/ohos/linux-x86_64/llvm/lib") + # not is_arm and not is_aot + return " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" + + @staticmethod + def get_cmd(test_suite, test_script_name, test_script_path, gn_args, out_path, x64_out_path, aot_mode, run_pgo, + enable_litecg, args_to_cmd, timeout, ignore_list: Optional[str] = None): + cmd = [ + f"cd {test_script_path}", + f"&& python3 {test_script_name} {args_to_cmd}", + f"--timeout {timeout}", + f"--ark-tool=../../{out_path}/arkcompiler/ets_runtime/ark_js_vm", + "--ark-frontend=es2panda" + ] + is_arm = any('target_cpu="arm64"' in arg for arg in gn_args) + if is_arm: + cmd.append("--ark-arch aarch64") + cmd.append(f"--ark-arch-root=../../{out_path}/common/common/libc/") + cmd.append(f"--ark-frontend-binary=../../{x64_out_path}/arkcompiler/ets_frontend/es2abc") + cmd.append(f"--merge-abc-binary=../../{x64_out_path}/arkcompiler/ets_frontend/merge_abc") + if aot_mode: + cmd.append(f"--ark-aot-tool=../../{x64_out_path}/arkcompiler/ets_runtime/ark_aot_compiler") + if test_suite == "regresstest": + cmd.append(f"--stub-path=../../{x64_out_path}/gen/arkcompiler/ets_runtime/stub.an") + else: + cmd.append(f"--ark-frontend-binary=../../{out_path}/arkcompiler/ets_frontend/es2abc") + cmd.append(f"--merge-abc-binary=../../{out_path}/arkcompiler/ets_frontend/merge_abc") + if aot_mode: + cmd.append(f"--ark-aot-tool=../../{out_path}/arkcompiler/ets_runtime/ark_aot_compiler") + if test_suite == "regresstest": + cmd.append(f"--stub-path=../../{out_path}/gen/arkcompiler/ets_runtime/stub.an") + + cmd.append(ArkPy.libs_dir( + is_arm=is_arm, + is_aot=aot_mode, + is_pgo=run_pgo, + out_dir=out_path, + x64_out_dir=x64_out_path + )) + if aot_mode: - print("running test262 in AotMode\n") - if any('target_cpu="arm64"' in arg for arg in gn_args): - if run_pgo: - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {4}" \ - " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu:" \ - "../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - " --ark-arch aarch64" \ - " --ark-arch-root=../../{1}/common/common/libc/" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-aot-tool=../../{1}/arkcompiler/ets_runtime/ark_aot_compiler" \ - " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-aot" \ - " --ark-frontend=es2panda"\ - "{3}".format(args_to_test262_cmd, out_path, x64_out_path, " --run-pgo", timeout) - else: - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ - " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib:../../{2}/thirdparty/icu/" \ - " --ark-arch aarch64" \ - " --ark-arch-root=../../{1}/common/common/libc/" \ - " --ark-aot" \ - " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path, timeout) + cmd.append("--ark-aot") + mode = ["AOT"] + if run_pgo: + cmd.append("--run-pgo") + mode.append("PGO") + if enable_litecg: + cmd.append("--enable-litecg") + mode.append("LiteCG") + mode_str = " ".join(mode) + print(f"Running {test_suite} in {mode_str} Mode\n") + + if test_suite == "regresstest" and ignore_list: + cmd.append(f"--ignore-list {ignore_list}") + + if test_suite == "regresstest": + cmd.append(f"--out-dir ../../{out_path}") + + return " ".join(cmd) + + @staticmethod + def get_test262_aot_cmd(gn_args, out_path, x64_out_path, run_pgo, enable_litecg, args_to_test262_cmd, + timeout): + print("running test262 in AotMode\n") + if any('target_cpu="arm64"' in arg for arg in gn_args): + if run_pgo: + test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {4}" \ + " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu:" \ + "../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ + " --ark-arch aarch64" \ + " --ark-arch-root=../../{1}/common/common/libc/" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-aot-tool=../../{1}/arkcompiler/ets_runtime/ark_aot_compiler" \ + " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-aot" \ + " --ark-frontend=es2panda" \ + "{3}".format(args_to_test262_cmd, out_path, x64_out_path, " --run-pgo", timeout) else: test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ + " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib:../../{2}/thirdparty/icu/" \ + " --ark-arch aarch64" \ + " --ark-arch-root=../../{1}/common/common/libc/" \ + " --ark-aot" \ + " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path, timeout) + else: + test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu" \ ":../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ @@ -340,80 +422,211 @@ class ArkPy: " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ " --ark-aot" \ - " --ark-frontend=es2panda"\ + " --ark-frontend=es2panda" \ "{2}".format(args_to_test262_cmd, out_path, " --run-pgo" if run_pgo else "", timeout) - if enable_litecg: - test262_cmd = test262_cmd + " --enable-litecg" - else: - print("running test262 in AsmMode\n") - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {2}" \ - " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, timeout) + if enable_litecg: + test262_cmd = test262_cmd + " --enable-litecg" return test262_cmd @staticmethod - def get_test262_jit_cmd(gn_args, out_path, x64_out_path, args_to_test262_cmd, timeout): - print("running test262 in JIT mode\n") + def get_jit_cmd(test_suite, test_script_name, test_script_path, gn_args, out_path, x64_out_path, args_to_cmd, + timeout): + print(f"running {test_suite} in JIT mode\n") if any('target_cpu="arm64"' in arg for arg in gn_args): - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ - " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib:../../{1}/thirdparty/icu/" \ - ":../../{1}/thirdparty/bounds_checking_function" \ - ":../../{1}/arkcompiler/ets_runtime:" \ - " --ark-arch aarch64" \ - " --run-jit" \ - " --ark-arch-root=../../{1}/common/common/libc/" \ - " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path, timeout) + cmd = "cd {5} && python3 {4} {0} --timeout {3}" \ + " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib:../../{1}/thirdparty/icu/" \ + ":../../{1}/thirdparty/bounds_checking_function" \ + ":../../{1}/arkcompiler/ets_runtime:" \ + " --ark-arch aarch64" \ + " --run-jit" \ + " --ark-arch-root=../../{1}/common/common/libc/" \ + " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-frontend=es2panda".format(args_to_cmd, out_path, x64_out_path, timeout, + test_script_name, test_script_path) else: - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ - " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu" \ - ":../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - " --run-jit" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda"\ - "{2}".format(args_to_test262_cmd, out_path, x64_out_path, timeout) - return test262_cmd - + cmd = "cd arkcompiler/ets_frontend && python3 {4} {0} --timeout {3}" \ + " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu" \ + ":../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ + " --run-jit" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-frontend=es2panda" \ + "{2}".format(args_to_cmd, out_path, x64_out_path, timeout, test_script_name) + return cmd + @staticmethod - def get_test262_baseline_jit_cmd(gn_args, out_path, x64_out_path, args_to_test262_cmd, timeout): - print("running test262 in baseline JIT mode\n") + def get_baseline_jit_cmd(test_suite, test_script_name, test_script_path, gn_args, out_path, x64_out_path, + args_to_test262_cmd, timeout): + print(f"running {test_suite} in baseline JIT mode\n") if any('target_cpu="arm64"' in arg for arg in gn_args): - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ - " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - ":../../{1}/thirdparty/icu" \ - ":../../prebuilts/clang/ohos/linux-x86_64/llvm/lib/aarch64-linux-ohos" \ - ":../../{1}/thirdparty/bounds_checking_function" \ - ":../../{1}/arkcompiler/ets_runtime" \ - ":../../{1}/common/common/libc/lib" \ - " --ark-arch aarch64" \ - " --run-baseline-jit" \ - " --ark-arch-root=../../{1}/common/common/libc/" \ - " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path, timeout) + cmd = "cd {5} && python3 {4} {0} --timeout {3}" \ + " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ + ":../../{1}/thirdparty/icu" \ + ":../../prebuilts/clang/ohos/linux-x86_64/llvm/lib/aarch64-linux-ohos" \ + ":../../{1}/thirdparty/bounds_checking_function" \ + ":../../{1}/arkcompiler/ets_runtime" \ + ":../../{1}/common/common/libc/lib" \ + " --ark-arch aarch64" \ + " --run-baseline-jit" \ + " --ark-arch-root=../../{1}/common/common/libc/" \ + " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path, timeout, + test_script_name, test_script_path) else: - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ - " --libs-dir ../../{1}/lib.unstripped/arkcompiler/ets_runtime" \ - ":../../{1}/lib.unstripped/thirdparty/icu" \ - ":../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - ":../../{1}/lib.unstripped/thirdparty/bounds_checking_function/" \ - " --run-baseline-jit" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda"\ - "{2}".format(args_to_test262_cmd, out_path, x64_out_path, timeout) - return test262_cmd + cmd = "cd {5} && python3 {4} {0} --timeout {3}" \ + " --libs-dir ../../{1}/arkcompiler/ets_runtime" \ + ":../../{1}/thirdparty/icu" \ + ":../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ + ":../../{1}/thirdparty/bounds_checking_function/" \ + " --run-baseline-jit" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-frontend=es2panda" \ + "{2}".format(args_to_test262_cmd, out_path, x64_out_path, timeout, + test_script_name, test_script_path) + return cmd + + @staticmethod + def build_args_to_test262_cmd(arg_list): + args_to_test262_cmd = [] + + disable_force_gc = [arg for arg in arg_list if "disable-force-gc" in arg] + if disable_force_gc: + args_to_test262_cmd.append("--disable-force-gc") + arg_list.remove(disable_force_gc[0]) + + threads_name = "--threads" + threads_value, arg_list = ArkPy.parse_option(arg_list, option_name=threads_name, default_value=None) + if threads_value: + args_to_test262_cmd.extend([threads_name, threads_value]) + + enable_rm = [arg for arg in arg_list if "enable-rm" in arg] + if enable_rm: + args_to_test262_cmd.append("--enable-rm") + arg_list.remove(enable_rm[0]) + + if len(arg_list) == 0: + args_to_test262_cmd.append("--es2021 all") + elif len(arg_list) == 1: + arg = arg_list[0] + if ".js" in arg: + args_to_test262_cmd.append("--file test262/data/test_es2021/{}".format(arg)) + else: + args_to_test262_cmd.append("--dir test262/data/test_es2021/{}".format(arg)) + else: + print("\033[92m\"test262\" not support multiple additional arguments.\033[0m\n".format()) + sys.exit(0) + + return " ".join(args_to_test262_cmd) + + @staticmethod + def build_args_to_regress_cmd(arg_list): + args_to_regress_cmd = [] + + processes_name = "--processes" + processes_value, arg_list = ArkPy.parse_option(arg_list, option_name=processes_name, default_value=1) + args_to_regress_cmd.extend([processes_name, processes_value]) + + test_list_name = "--test-list" + test_list_value, arg_list = ArkPy.parse_option(arg_list, option_name=test_list_name, default_value=None) + if test_list_value is not None: + args_to_regress_cmd.extend([test_list_name, test_list_value]) + + if len(arg_list) == 1: + arg = arg_list[0] + if ".js" in arg: + args_to_regress_cmd.append(f"--test-file {arg}") + else: + args_to_regress_cmd.append(f"--test-dir {arg}") + elif len(arg_list) > 1: + print("\033[92m\"regresstest\" not support multiple additional arguments.\033[0m\n".format()) + sys.exit(0) + + return " ".join([str(arg) for arg in args_to_regress_cmd]) + + @staticmethod + def parse_option(arg_list: List[str], option_name: str, default_value: Optional[Union[str, int]]) \ + -> Tuple[Optional[Union[str, int]], List[str]]: + option_value, arg_list = ArkPy.__parse_option_with_space(arg_list, option_name) + if option_value is None: + option_value, arg_list = ArkPy.__parse_option_with_equal(arg_list, option_name) + if option_value is None and default_value is not None: + option_value = default_value + return option_value, arg_list + + @staticmethod + def __is_option_value_int(value: Optional[Union[str, int]]) -> Tuple[bool, Optional[int]]: + if isinstance(value, int): + return True, int(value) + else: + return False, None + + @staticmethod + def __is_option_value_str(value: Optional[Union[str, int]]) -> Tuple[bool, Optional[str]]: + if isinstance(value, str): + return True, str(value) + else: + return False, None + + @staticmethod + def __get_option_value(option_name: str, value: Optional[Union[str, int]]) -> Union[str, int]: + result, res_value = ArkPy.__is_option_value_int(value) + if result: + return res_value + result, res_value = ArkPy.__is_option_value_str(value) + if result: + return res_value + print(f"Invalid '{option_name}' value.") + sys.exit(1) + + @staticmethod + def __parse_option_with_space(arg_list: List[str], option_name: str) \ + -> Tuple[Optional[Union[str, int]], List[str]]: + if option_name in arg_list: + option_index = arg_list.index(option_name) + if len(arg_list) > option_index + 1: + option_value = ArkPy.__get_option_value(option_name, arg_list[option_index + 1]) + arg_list = arg_list[:option_index] + arg_list[option_index + 2:] + else: + print(f"Missing {option_name} value.") + sys.exit(1) + + return option_value, arg_list + return None, arg_list + + @staticmethod + def __parse_option_with_equal(arg_list: List[str], option_name: str) \ + -> Tuple[Optional[Union[str, int]], List[str]]: + for index, arg in enumerate(arg_list): + local_option_name = f"{option_name}=" + if arg.startswith(local_option_name): + option_value = arg[len(local_option_name):] + if option_value: + option_value = ArkPy.__get_option_value(option_name, option_value) + arg_list = arg_list[:index] + arg_list[index + 1:] + return option_value, arg_list + else: + print(f"Missing {option_name} value.") + sys.exit(1) + return None, arg_list + + @staticmethod + def __get_x64_out_path(out_path) -> str: + if 'release' in out_path: + return 'out/x64.release' + if 'debug' in out_path: + return 'out/x64.debug' + if 'fastverify' in out_path: + return 'out/x64.fastverify' + return "" def get_binaries(self): host_os = sys.platform @@ -431,18 +644,18 @@ class ArkPy: print("\nLogic of getting gn binary or ninja binary does not match logic of prebuilts_download." \ "\nCheck func \033[92m{0} of class {1} in file {2}\033[0m against file {3} if the name of this " \ "file had not changed!\n".format( - sys._getframe().f_code.co_name, self.__class__.__name__, CURRENT_FILENAME, - self.PREBUILTS_DOWNLOAD_CONFIG_FILE_PATH)) + sys._getframe().f_code.co_name, self.__class__.__name__, CURRENT_FILENAME, + self.PREBUILTS_DOWNLOAD_CONFIG_FILE_PATH)) raise error if self.gn_binary_path == "" or self.ninja_binary_path == "": print("\nLogic of prebuilts_download may be wrong." \ "\nCheck \033[92mdata in file {0}\033[0m against func {1} of class {2} in file {3}!\n".format( - self.PREBUILTS_DOWNLOAD_CONFIG_FILE_PATH, sys._getframe().f_code.co_name, self.__class__.__name__, - CURRENT_FILENAME)) + self.PREBUILTS_DOWNLOAD_CONFIG_FILE_PATH, sys._getframe().f_code.co_name, self.__class__.__name__, + CURRENT_FILENAME)) sys.exit(0) if not os.path.isfile(self.gn_binary_path) or not os.path.isfile(self.ninja_binary_path): print("\nStep for prebuilts_download may be ommited. (\033[92m./prebuilts_download.sh\033[0m)" \ - "\nCheck \033[92mwhether gn binary and ninja binary are under directory prebuilts\033[0m!\n".format()) + "\nCheck \033[92mwhether gn binary and ninja binary are under directory prebuilts\033[0m!\n".format()) sys.exit(0) return @@ -462,13 +675,13 @@ class ArkPy: if len(arg_to_list) == 1: os_cpu_part = arg_to_list[0] mode_part = "release" - key_to_dict_in_os_cpu_matched_arg = self.which_dict_flags_match_arg(self.ARG_DICT["os_cpu"], os_cpu_part) - key_to_dict_in_mode_matched_arg = self.which_dict_flags_match_arg(self.ARG_DICT["mode"], mode_part) + key_to_dict_in_os_cpu_matched_arg = self.which_dict_flags_match_arg(self.ARG_DICT.get("os_cpu"), os_cpu_part) + key_to_dict_in_mode_matched_arg = self.which_dict_flags_match_arg(self.ARG_DICT.get("mode"), mode_part) elif len(arg_to_list) == 2: os_cpu_part = arg_to_list[0] mode_part = arg_to_list[1] - key_to_dict_in_os_cpu_matched_arg = self.which_dict_flags_match_arg(self.ARG_DICT["os_cpu"], os_cpu_part) - key_to_dict_in_mode_matched_arg = self.which_dict_flags_match_arg(self.ARG_DICT["mode"], mode_part) + key_to_dict_in_os_cpu_matched_arg = self.which_dict_flags_match_arg(self.ARG_DICT.get("os_cpu"), os_cpu_part) + key_to_dict_in_mode_matched_arg = self.which_dict_flags_match_arg(self.ARG_DICT.get("mode"), mode_part) else: print("\"\033[92m{0}\033[0m\" combined with more than 2 flags is not supported.".format(arg)) if (key_to_dict_in_os_cpu_matched_arg == "") | (key_to_dict_in_mode_matched_arg == ""): @@ -494,12 +707,13 @@ class ArkPy: help_msg += "\033[32mCommand template:\033[0m\n{}\n\n".format( " python3 ark.py \033[92m[os_cpu].[mode] [gn_target] [option]\033[0m\n" " python3 ark.py \033[92m[os_cpu].[mode] [test262] [none or --aot] " \ - "[none or --pgo] [none or --litecg] [none, file or dir] [none or --threads=X] [option]\033[0m\n" + "[none or --pgo] [none or --litecg] [none, file or dir] [none or --threads=X] [option]\033[0m\n" " python3 ark.py \033[92m[os_cpu].[mode] [test262] [none or --jit] [none or --threads=X]\033[0m\n" - " python3 ark.py \033[92m[os_cpu].[mode] [test262] [none or --baseline-jit] [none or --threads=X]\033[0m\n" + " python3 ark.py \033[92m[os_cpu].[mode] [test262] [none or --baseline-jit] [none or --enable-rm] " \ + "[none or --threads=X]\033[0m\n" " python3 ark.py \033[92m[os_cpu].[mode] [unittest] [option]\033[0m\n" " python3 ark.py \033[92m[os_cpu].[mode] [regresstest] [none, file or dir] " \ - "[none or --processes=X]\033[0m\n") + "[none or --processes X and/or --test-list TEST_LIST_NAME]\033[0m\n") # Command examples help_msg += "\033[32mCommand examples:\033[0m\n{}\n\n".format( " python3 ark.py \033[92mx64.release\033[0m\n" @@ -510,7 +724,7 @@ class ArkPy: " python3 ark.py \033[92mx64.release test262 --threads=16\033[0m\n" " python3 ark.py \033[92mx64.release test262 --aot --pgo --litecg\033[0m\n" " python3 ark.py \033[92mx64.release test262 --aot --pgo --litecg --threads=8\033[0m\n" - " python3 ark.py \033[92mx64.release test262 --jit\033[0m\n" + " python3 ark.py \033[92mx64.release test262 --jit --enable-rm\033[0m\n" " python3 ark.py \033[92mx64.release test262 --baseline-jit\033[0m\n" " python3 ark.py \033[92mx64.release test262 built-ins/Array\033[0m\n" " python3 ark.py \033[92mx64.release test262 built-ins/Array/name.js\033[0m\n" @@ -545,8 +759,13 @@ class ArkPy: # prepare log file build_log_path = os.path.join(out_path, log_file_name) backup(build_log_path, "w") + if arg_list is not None: + build_target = " ".join([str(arg).strip() for arg in arg_list + if arg is not None or len(str(arg).strip()) > 0]) + else: + build_target = "" str_to_build_log = "================================\nbuild_time: {0}\nbuild_target: {1}\n\n".format( - str_of_time_now(), " ".join(arg_list)) + str_of_time_now(), build_target) _write(build_log_path, str_to_build_log, "a") # gn command print("=== gn gen start ===") @@ -563,13 +782,13 @@ class ArkPy: # Always add " -d keeprsp" to ninja command to keep response file("*.rsp"), thus we could get shared libraries # of an excutable from its response file. ninja_cmd = \ - self.ninja_binary_path + \ - (" -v" if self.enable_verbose else "") + \ - (" -d keepdepfile" if self.enable_keepdepfile else "") + \ - " -d keeprsp" + \ - " -C {}".format(out_path) + \ - " {}".format(" ".join(arg_list)) + \ - " -k {}".format(self.ignore_errors) + self.ninja_binary_path + \ + (" -v" if self.enable_verbose else "") + \ + (" -d keepdepfile" if self.enable_keepdepfile else "") + \ + " -d keeprsp" + \ + " -C {}".format(out_path) + \ + " {}".format(" ".join(arg_list if arg_list else [])) + \ + " -k {}".format(self.ignore_errors) print(ninja_cmd) code = call_with_output(ninja_cmd, build_log_path) if code != 0: @@ -579,123 +798,141 @@ class ArkPy: print("=== ninja success! ===\n") return - @staticmethod - def build_args_to_test262_cmd(arg_list): - args_to_test262_cmd = [] - - disable_force_gc = [arg for arg in arg_list if "disable-force-gc" in arg] - if disable_force_gc: - args_to_test262_cmd.append("--disable-force-gc") - arg_list.remove(disable_force_gc[0]) - - threads = [arg for arg in arg_list if arg.startswith("--threads=")] - if threads: - args_to_test262_cmd.extend(threads) - arg_list.remove(threads[0]) - - if len(arg_list) == 0: - args_to_test262_cmd.append("--es2021 all") - elif len(arg_list) == 1: - arg = arg_list[0] - if ".js" in arg: - args_to_test262_cmd.append("--file test262/data/test_es2021/{}".format(arg)) - else: - args_to_test262_cmd.append("--dir test262/data/test_es2021/{}".format(arg)) - else: - print("\033[92m\"test262\" not support multiple additional arguments.\033[0m\n".format()) - sys.exit(0) - - return " ".join(args_to_test262_cmd) - - def build_for_test262(self, out_path, timeout, gn_args: list, arg_list: list, log_file_name: str, - aot_mode: bool, run_pgo=False, enable_litecg=False, run_jit=False, - run_baseline_jit=False): - args_to_test262_cmd = self.build_args_to_test262_cmd(arg_list) - x64_out_path = "" + def call_build_gn_target(self, gn_args, out_path, x64_out_path, test_suite, log_file_name): if any('target_cpu="arm64"' in arg for arg in gn_args): - if 'release' in out_path: - x64_out_path = 'out/x64.release' - if 'debug' in out_path: - x64_out_path = 'out/x64.debug' gn_args.append("so_dir_for_qemu=\"../../{0}/common/common/libc/\"".format(out_path)) gn_args.append("run_with_qemu=true".format(out_path)) if not os.path.exists(x64_out_path): os.makedirs(x64_out_path) self.build_for_gn_target( - x64_out_path, ['target_os="linux"', 'target_cpu="x64"', 'is_debug=false'], - self.ARG_DICT["target"]["test262"]["gn_targets_depend_on"], log_file_name) + x64_out_path, + ['target_os="linux"', 'target_cpu="x64"', 'is_debug=false'], + self.ARG_DICT.get("target").get(test_suite).get("gn_targets_depend_on"), + log_file_name) self.build_for_gn_target( - out_path, gn_args, self.ARG_DICT["target"]["test262"]["arm64_gn_targets_depend_on"], log_file_name) + out_path, + gn_args, + self.ARG_DICT.get("target").get(test_suite).get("arm64_gn_targets_depend_on"), + log_file_name) else: self.build_for_gn_target( - out_path, gn_args, self.ARG_DICT["target"]["test262"]["gn_targets_depend_on"], log_file_name) + out_path, + gn_args, + self.ARG_DICT.get("target").get(test_suite).get("gn_targets_depend_on"), + log_file_name) + + def get_build_cmd(self, *, test_suite, test_script_name, test_script_path, + out_path, x64_out_path, gn_args: list, args_to_cmd: str, timeout, + run_jit: bool = False, run_baseline_jit: bool = False, aot_mode: bool = False, + run_pgo: bool = False, enable_litecg: bool = False, ignore_list: Optional[str] = None) -> str: if run_jit: - test262_cmd = self.get_test262_jit_cmd(gn_args, out_path, x64_out_path, args_to_test262_cmd, timeout) + cmd = self.get_jit_cmd(test_suite, test_script_name, test_script_path, + gn_args, out_path, x64_out_path, args_to_cmd, timeout) elif run_baseline_jit: - test262_cmd = self.get_test262_baseline_jit_cmd(gn_args, out_path, x64_out_path, - args_to_test262_cmd, timeout) + cmd = self.get_baseline_jit_cmd(test_suite, test_script_name, test_script_path, + gn_args, out_path, x64_out_path, args_to_cmd, timeout) + elif aot_mode and test_suite == "test262": + cmd = self.get_test262_aot_cmd(gn_args, out_path, x64_out_path, run_pgo, + enable_litecg, args_to_cmd, timeout) else: - test262_cmd = self.get_test262_cmd(gn_args, out_path, x64_out_path, aot_mode, run_pgo, - enable_litecg, args_to_test262_cmd, timeout) - test262_log_path = os.path.join(out_path, log_file_name) - str_to_test262_log = "================================\ntest262_time: {0}\ntest262_target: {1}\n\n".format( - str_of_time_now(), args_to_test262_cmd) - _write(test262_log_path, str_to_test262_log, "a") - print("=== test262 start ===") - code = call_with_output(test262_cmd, test262_log_path) + cmd = self.get_cmd(test_suite, test_script_name, test_script_path, + gn_args, out_path, x64_out_path, aot_mode, run_pgo, + enable_litecg, args_to_cmd, timeout, ignore_list) + return cmd + + def build_for_suite(self, *, test_suite, test_script_name, test_script_path, + out_path, gn_args: list, log_file_name, args_to_cmd: str, timeout, + run_jit: bool = False, run_baseline_jit: bool = False, aot_mode: bool = False, + run_pgo: bool = False, enable_litecg: bool = False, ignore_list: Optional[str] = None): + x64_out_path = self.__get_x64_out_path(out_path) + self.call_build_gn_target(gn_args, out_path, x64_out_path, test_suite, log_file_name) + cmd = self.get_build_cmd( + test_suite=test_suite, + test_script_name=test_script_name, + test_script_path=test_script_path, + out_path=out_path, + x64_out_path=x64_out_path, + gn_args=gn_args, + args_to_cmd=args_to_cmd, + timeout=timeout, + run_jit=run_jit, + run_baseline_jit=run_baseline_jit, + aot_mode=aot_mode, run_pgo=run_pgo, enable_litecg=enable_litecg, ignore_list=ignore_list) + log_path = str(os.path.join(out_path, log_file_name)) + str_to_log = "================================\n{2}_time: {0}\n{2}_target: {1}\n\n".format( + str_of_time_now(), args_to_cmd, test_suite) + _write(log_path, str_to_log, "a") + print(f"=== {test_suite} start ===") + code = call_with_output(cmd, log_path) if code != 0: - print("=== test262 fail! ===\n") + print(f"=== {test_suite} fail! ===\n") sys.exit(code) - print("=== test262 success! ===\n") + print(f"=== {test_suite} success! ===\n") + + def build_for_test262(self, out_path, gn_args: list, arg_list: list): + timeout, arg_list = self.parse_timeout(arg_list) + arg_list = arg_list[1:] - def build_for_unittest(self, out_path: str, gn_args: list, log_file_name:str): + is_aot_mode, arg_list = self.__purge_arg_list("--aot", arg_list) + is_pgo, arg_list = self.__purge_arg_list("--pgo", arg_list) + is_litecg, arg_list = self.__purge_arg_list("--litecg", arg_list) + is_jit, arg_list = self.__purge_arg_list("--jit", arg_list) + is_baseline_jit, arg_list = self.__purge_arg_list("--baseline-jit", arg_list) + print(f"Test262: arg_list = {arg_list}") + + args_to_test262_cmd = self.build_args_to_test262_cmd(arg_list) + self.build_for_suite( + test_suite="test262", + test_script_name="test262/run_test262.py", + test_script_path="arkcompiler/ets_frontend", + out_path=out_path, + gn_args=gn_args, + log_file_name=self.TEST262_LOG_FILE_NAME, + args_to_cmd=args_to_test262_cmd, + timeout=timeout, + run_jit=is_jit, + run_pgo=is_pgo, + run_baseline_jit=is_baseline_jit, + aot_mode=is_aot_mode, + enable_litecg=is_litecg + ) + + def build_for_unittest(self, out_path: str, gn_args: list, log_file_name: str): self.build_for_gn_target( - out_path, gn_args, self.ARG_DICT["target"]["unittest"]["gn_targets_depend_on"], + out_path, gn_args, self.ARG_DICT.get("target").get("unittest").get("gn_targets_depend_on"), log_file_name) return - @staticmethod - def build_args_to_regress_cmd(arg_list): - args_to_regress_cmd = [] - - processes = [arg for arg in arg_list if arg.startswith("--processes=")] - if processes: - args_to_regress_cmd.extend(processes) - arg_list.remove(processes[0]) + def build_for_regress_test(self, out_path, gn_args: list, arg_list: list): + timeout, arg_list = self.parse_option(arg_list, option_name="--timeout", default_value=200) + ignore_list, arg_list = self.parse_option(arg_list, option_name="--ignore-list", default_value=None) - if len(arg_list) == 1: - arg = arg_list[0] - if ".js" in arg: - args_to_regress_cmd.append(f"--test-file {arg}") - else: - args_to_regress_cmd.append(f"--test-dir {arg}") - elif len(arg_list) > 1: - print("\033[92m\"regresstest\" not support multiple additional arguments.\033[0m\n".format()) - sys.exit(0) + arg_list = arg_list[1:] - return " ".join(args_to_regress_cmd) + is_aot, arg_list = self.__purge_arg_list("--aot", arg_list) + is_pgo, arg_list = self.__purge_arg_list("--pgo", arg_list) + is_litecg, arg_list = self.__purge_arg_list("--litecg", arg_list) + is_jit, arg_list = self.__purge_arg_list("--jit", arg_list) + is_baseline_jit, arg_list = self.__purge_arg_list("--baseline-jit", arg_list) + print(f"Regress: arg_list = {arg_list}") - def build_for_regress_test(self, out_path, gn_args: list, arg_list: list, log_file_name: str, timeout): args_to_regress_test_cmd = self.build_args_to_regress_cmd(arg_list) - self.build_for_gn_target( - out_path, gn_args, self.ARG_DICT["target"]["regresstest"]["gn_targets_depend_on"], log_file_name) - regress_test_cmd = "python3 arkcompiler/ets_runtime/test/regresstest/run_regress_test.py --timeout {2}" \ - " --ark-tool ./{0}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary ./{0}/arkcompiler/ets_frontend/es2abc" \ - " --LD_LIBRARY_PATH ./{0}/arkcompiler/ets_runtime:./{0}/thirdparty/icu:" \ - "./prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - " --out-dir ./{0}/ {1}".format(out_path, args_to_regress_test_cmd, timeout) - regress_test_log_path = os.path.join(out_path, log_file_name) - str_to_test_log = "============\n regresstest_time: {0}\nregresstest_target: {1}\n\n".format( - str_of_time_now(), regress_test_cmd) - _write(regress_test_log_path, str_to_test_log, "a") - print("=== regresstest start ===") - code = call_with_output(regress_test_cmd, regress_test_log_path) - if code != 0: - print("=== regresstest fail! ===\n") - sys.exit(code) - print("=== regresstest success! ===\n") - return + self.build_for_suite( + test_suite="regresstest", + test_script_name="test/regresstest/run_regress_test.py", + test_script_path="arkcompiler/ets_runtime", + out_path=out_path, + gn_args=gn_args, + log_file_name=self.REGRESS_TEST_LOG_FILE_NAME, + args_to_cmd=args_to_regress_test_cmd, + timeout=timeout, + run_jit=is_jit, + run_pgo=is_pgo, + run_baseline_jit=is_baseline_jit, + aot_mode=is_aot, + enable_litecg=is_litecg, + ignore_list=ignore_list + ) def build(self, out_path: str, gn_args: list, arg_list: list): if not os.path.exists(out_path): @@ -703,105 +940,50 @@ class ArkPy: os.makedirs(out_path) if len(arg_list) == 0: self.build_for_gn_target(out_path, gn_args, ["default"], self.GN_TARGET_LOG_FILE_NAME) - elif self.is_dict_flags_match_arg(self.ARG_DICT["target"]["workload"], arg_list[0]): + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("target").get("workload"), arg_list[0]): self.build_for_workload(arg_list, out_path, gn_args, 'workload.log') - elif self.is_dict_flags_match_arg(self.ARG_DICT["target"]["test262"], arg_list[0]): - timeout, arg_list = self.parse_timeout(arg_list) - run_aot_mode = len(arg_list) >= 2 and arg_list[1] == "--aot" - run_aot_pgo_litecg = len(arg_list) >= 4 and ((arg_list[2] == "--pgo" and arg_list[3] == "--litecg") or - (arg_list[3] == "--pgo" and arg_list[2] == "--litecg")) - run_aot_pgo = len(arg_list) >= 3 and arg_list[2] == "--pgo" - run_aot_litecg = len(arg_list) >= 3 and arg_list[2] == "--litecg" - run_jit = len(arg_list) >= 2 and arg_list[1] == "--jit" - run_baseline_jit = len(arg_list) >= 2 and arg_list[1] == "--baseline-jit" - if run_aot_mode: - if run_aot_pgo_litecg: - self.build_for_test262(out_path, timeout, gn_args, arg_list[4:], self.TEST262_LOG_FILE_NAME, True, - True, True) - elif run_aot_litecg: - self.build_for_test262(out_path, timeout, gn_args, arg_list[3:], self.TEST262_LOG_FILE_NAME, True, - False, True) - elif run_aot_pgo: - self.build_for_test262(out_path, timeout, gn_args, arg_list[3:], - self.TEST262_LOG_FILE_NAME, True, True) - else: - self.build_for_test262(out_path, timeout, gn_args, arg_list[2:], self.TEST262_LOG_FILE_NAME, True) - elif run_jit: - self.build_for_test262(out_path, timeout, gn_args, arg_list[2:], - self.TEST262_LOG_FILE_NAME, False, False, - False, True) - elif run_baseline_jit: - self.build_for_test262(out_path, timeout, gn_args, arg_list[2:], - self.TEST262_LOG_FILE_NAME, False, False, - False, False, True) - else: - self.build_for_test262(out_path, timeout, gn_args, arg_list[1:], self.TEST262_LOG_FILE_NAME, False) - elif self.is_dict_flags_match_arg(self.ARG_DICT["target"]["unittest"], arg_list[0]): + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("target").get("test262"), arg_list[0]): + self.build_for_test262(out_path, gn_args, arg_list) + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("target").get("unittest"), arg_list[0]): if len(arg_list) > 1: print("\033[92m\"unittest\" not support additional arguments.\033[0m\n".format()) sys.exit(0) self.build_for_unittest(out_path, gn_args, self.UNITTEST_LOG_FILE_NAME) - elif self.is_dict_flags_match_arg(self.ARG_DICT["target"]["regresstest"], arg_list[0]): - timeout = 200 - if '--timeout' in arg_list: - timeout_index = arg_list.index('--timeout') - if len(arg_list) > timeout_index + 1: - try: - timeout = int(arg_list[timeout_index + 1]) - arg_list = arg_list[:timeout_index] + arg_list[timeout_index + 2:] - except ValueError: - print("Invalid timeout value.") - sys.exit(1) - else: - print("Missing timeout value.") - sys.exit(1) - self.build_for_regress_test(out_path, gn_args, arg_list[1:], self.REGRESS_TEST_LOG_FILE_NAME, timeout) + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("target").get("regresstest"), arg_list[0]): + self.build_for_regress_test(out_path, gn_args, arg_list) else: self.build_for_gn_target(out_path, gn_args, arg_list, self.GN_TARGET_LOG_FILE_NAME) return - def parse_timeout(self, arg_list): - timeout = 400000 - if '--timeout' in arg_list: - timeout_index = arg_list.index('--timeout') - if len(arg_list) > timeout_index + 1: - try: - timeout = int(arg_list[timeout_index + 1]) - arg_list = arg_list[:timeout_index] + arg_list[timeout_index + 2:] - except ValueError: - print("Invalid timeout value.") - sys.exit(1) - else: - print("Missing timeout value.") - sys.exit(1) - return timeout, arg_list + def parse_timeout(self, arg_list) -> Tuple[Optional[Union[str, int]], List[str]]: + return self.parse_option(arg_list, option_name="--timeout", default_value=400000) def match_options(self, arg_list: list, out_path: str) -> [list, list]: arg_list_ret = [] gn_args_ret = [] for arg in arg_list: # match [option][clean] flag - if self.is_dict_flags_match_arg(self.ARG_DICT["option"]["clean"], arg): + if self.is_dict_flags_match_arg(self.ARG_DICT.get("option").get("clean"), arg): self.clean(out_path) sys.exit(0) # match [option][clean-continue] flag - elif self.is_dict_flags_match_arg(self.ARG_DICT["option"]["clean-continue"], arg): + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("option").get("clean-continue"), arg): if not self.has_cleaned: self.clean(out_path) self.has_cleaned = True # match [option][gn-args] flag - elif self.is_dict_flags_match_arg(self.ARG_DICT["option"]["gn-args"], arg): + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("option").get("gn-args"), arg): gn_args_ret.append(arg[(arg.find("=") + 1):]) # match [option][keepdepfile] flag - elif self.is_dict_flags_match_arg(self.ARG_DICT["option"]["keepdepfile"], arg): + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("option").get("keepdepfile"), arg): if not self.enable_keepdepfile: self.enable_keepdepfile = True # match [option][verbose] flag - elif self.is_dict_flags_match_arg(self.ARG_DICT["option"]["verbose"], arg): + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("option").get("verbose"), arg): if not self.enable_verbose: self.enable_verbose = True # match [option][keep-going] flag - elif self.is_dict_flags_match_arg(self.ARG_DICT["option"]["keep-going"], arg): + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("option").get("keep-going"), arg): if self.ignore_errors == 1: input_value = arg[(arg.find("=") + 1):] try: @@ -823,6 +1005,7 @@ class ArkPy: boundary_value = '-10' run_count = '10' code_v = '' + run_interpreter = False if len(arg_list) >= 2 and arg_list[1] == 'report': report = True if len(arg_list) >= 3 and arg_list[2]: @@ -833,15 +1016,19 @@ class ArkPy: run_count = arg_list[4] if len(arg_list) >= 6 and arg_list[5]: code_v = arg_list[5] + if len(arg_list) >= 7 and arg_list[6] == '--run-interpreter': + run_interpreter = True self.build_for_gn_target(out_path, gn_args, ["default"], self.GN_TARGET_LOG_FILE_NAME) workload_cmd = "cd arkcompiler/ets_runtime/test/workloadtest/ && python3 work_load.py" \ - " --code-path {0}" \ - " --report {1}" \ - " --tools-type {2}" \ - " --boundary-value {3}" \ - " --run-count {4}" \ - " --code-v {5}" \ - .format(root_dir, report, tools, boundary_value, run_count, code_v) + " --code-path {0}" \ + " --report {1}" \ + " --tools-type {2}" \ + " --boundary-value {3}" \ + " --run-count {4}" \ + " --code-v {5}" \ + .format(root_dir, report, tools, boundary_value, run_count, code_v) + if run_interpreter: + workload_cmd += " --run-interpreter true" workload_log_path = os.path.join(out_path, log_file_name) str_to_workload_log = "================================\nwokload_time: {0}\nwokload_target: {1}\n\n".format( str_of_time_now(), 'file') @@ -859,19 +1046,24 @@ class ArkPy: self.get_binaries() # get out_path name_of_out_dir_of_second_level = \ - self.ARG_DICT["os_cpu"][os_cpu_key]["prefix_of_name_of_out_dir_of_second_level"] + \ + self.ARG_DICT.get("os_cpu").get(os_cpu_key).get("prefix_of_name_of_out_dir_of_second_level") + \ self.DELIMITER_FOR_SECOND_OUT_DIR_NAME + \ - self.ARG_DICT["mode"][mode_key]["suffix_of_name_of_out_dir_of_second_level"] + self.ARG_DICT.get("mode").get(mode_key).get("suffix_of_name_of_out_dir_of_second_level") out_path = os.path.join(self.NAME_OF_OUT_DIR_OF_FIRST_LEVEL, name_of_out_dir_of_second_level) # match [option] flag [arg_list, gn_args] = self.match_options(arg_list, out_path) # get expression which would be written to args.gn file - gn_args.extend(self.ARG_DICT["os_cpu"][os_cpu_key]["gn_args"]) - gn_args.extend(self.ARG_DICT["mode"][mode_key]["gn_args"]) + gn_args.extend(self.ARG_DICT.get("os_cpu").get(os_cpu_key).get("gn_args")) + gn_args.extend(self.ARG_DICT.get("mode").get(mode_key).get("gn_args")) # start to build self.build(out_path, gn_args, arg_list) return + def __purge_arg_list(self, option_name: str, arg_list: List[Any]) -> Tuple[bool, List[Any]]: + if option_name in arg_list: + arg_list.remove(option_name) + return True, arg_list + return False, arg_list if __name__ == "__main__": diff --git a/build/config/build_type.gni b/build/config/build_type.gni new file mode 100644 index 0000000000000000000000000000000000000000..e45ecd0799ce115aa5692221e9d17f64d8139c0d --- /dev/null +++ b/build/config/build_type.gni @@ -0,0 +1,16 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +declare_args() { + is_fastverify = false +} diff --git a/build/config/components/ets_frontend/es2abc_config.gni b/build/config/components/ets_frontend/es2abc_config.gni new file mode 100644 index 0000000000000000000000000000000000000000..a805c564fa4c122631c95cbe7474e9db056af64a --- /dev/null +++ b/build/config/components/ets_frontend/es2abc_config.gni @@ -0,0 +1,104 @@ +# Copyright (c) 2021-2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("$build_root/config/components/ets_frontend/ets_frontend_config.gni") + +es2abc_root = "//arkcompiler/ets_frontend/es2panda" +es2abc_build_path = "" +es2abc_build_deps = "" +es2abc_out_root = "" + +if (host_toolchain == toolchain_mac) { + es2abc_out_root = + get_label_info("$es2abc_root:es2panda($toolchain_mac)", "root_out_dir") + es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_mac)" ] +} else if (host_toolchain == toolchain_win) { + es2abc_out_root = + get_label_info("$es2abc_root:es2panda($toolchain_win)", "root_out_dir") + es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_win)" ] +} else { + es2abc_out_root = + get_label_info("$es2abc_root:es2panda($toolchain_linux)", "root_out_dir") + es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_linux)" ] +} +es2abc_build_path = es2abc_out_root + "/arkcompiler/ets_frontend" + +# Generate abc. +# +# Mandatory arguments: +# plugin_path -- plugin js file path +# plugin_name -- name of js file, ex: BatteryPlugin.js +# generat_file -- name of generated file +# package_name -- name of generated file's package +# extra_dependencies -- a list of files that should be considered as dependencies, must be label +# out_puts +template("es2abc_gen_abc") { + assert(defined(invoker.src_js), "src_js is required!") + assert(defined(invoker.dst_file), "dst_file is required!") + assert(defined(invoker.out_puts), "out_puts is required!") + + extra_dependencies = [] + if (defined(invoker.extra_dependencies)) { + extra_dependencies += invoker.extra_dependencies + } + + action("$target_name") { + if (defined(invoker.extra_visibility)) { + visibility = invoker.extra_visibility + } + + script = "$build_root/scripts/generate_js_bytecode.py" + + deps = extra_dependencies + deps += es2abc_build_deps + + args = [ + "--src-js", + invoker.src_js, + "--dst-file", + invoker.dst_file, + "--frontend-tool-path", + rebase_path("${es2abc_build_path}"), + ] + + if (defined(invoker.extension)) { + args += [ + "--extension", + invoker.extension, + ] + } + + if (defined(invoker.dump_symbol_table)) { + args += [ + "--dump-symbol-table", + invoker.dump_symbol_table, + ] + } + if (defined(invoker.input_symbol_table)) { + args += [ + "--input-symbol-table", + invoker.input_symbol_table, + ] + } + + if (defined(invoker.extra_args)) { + args += invoker.extra_args + } + + if (defined(invoker.in_puts)) { + inputs = invoker.in_puts + } + + outputs = invoker.out_puts + } +} diff --git a/build/config/components/ets_frontend/ets_frontend_config.gni b/build/config/components/ets_frontend/ets_frontend_config.gni new file mode 100644 index 0000000000000000000000000000000000000000..2aebf108cfe1f0bbc549aa3692f776c7a524dc16 --- /dev/null +++ b/build/config/components/ets_frontend/ets_frontend_config.gni @@ -0,0 +1,36 @@ +# Copyright (c) 2021-2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if (!defined(ark_standalone_build)) { + ark_standalone_build = false +} + +if (!ark_standalone_build) { + build_root = "//build" + ark_third_party_root = "//third_party" + import("$build_root/ohos.gni") +} else { + ark_third_party_root = "//arkcompiler/toolchain/build/third_party_gn" + import("$build_root/ark.gni") +} +import("$build_root/test.gni") + +ets_frontend_root = "//arkcompiler/ets_frontend" + +toolchain_linux = "$build_root/toolchain/linux:clang_x64" +if (host_cpu == "arm64") { + toolchain_mac = "$build_root/toolchain/mac:clang_arm64" +} else { + toolchain_mac = "$build_root/toolchain/mac:clang_x64" +} +toolchain_win = "$build_root/toolchain/mingw:mingw_x86_64" diff --git a/build/config/mac/sdk_info.py b/build/config/mac/sdk_info.py index 6396c0fe490274619bba4421d17cb93b23b94c2d..97ad4f5415fa1d9991aed1aa61c0b0c28ca82583 100755 --- a/build/config/mac/sdk_info.py +++ b/build/config/mac/sdk_info.py @@ -16,91 +16,94 @@ import sys # "iphoneos" or "macosx" generally). -def SplitVersion(version): - """Splits the Xcode version to 3 values. - - >>> list(SplitVersion('8.2.1.1')) - ['8', '2', '1'] - >>> list(SplitVersion('9.3')) - ['9', '3', '0'] - >>> list(SplitVersion('10.0')) - ['10', '0', '0'] - """ - if isinstance(version, bytes): - version = version.decode() - version = version.split('.') - return itertools.islice(itertools.chain(version, itertools.repeat('0')), 0, 3) - - -def FormatVersion(version): - """Converts Xcode version to a format required for DTXcode in Info.plist - - >>> FormatVersion('8.2.1') - '0821' - >>> FormatVersion('9.3') - '0930' - >>> FormatVersion('10.0') - '1000' - """ - major, minor, patch = SplitVersion(version) - return ('%2s%s%s' % (major, minor, patch)).replace(' ', '0') - - -def FillXcodeVersion(settings): - """Fills the Xcode version and build number into |settings|.""" - lines = subprocess.check_output(['xcodebuild', '-version']).splitlines() - settings['xcode_version'] = FormatVersion(lines[0].split()[-1]) - settings['xcode_version_int'] = int(settings['xcode_version'], 10) - settings['xcode_build'] = lines[-1].split()[-1] - - -def FillMachineOSBuild(settings): - """Fills OS build number into |settings|.""" - settings['machine_os_build'] = subprocess.check_output( - ['sw_vers', '-buildVersion']).strip() - - -def FillSDKPathAndVersion(settings, platform, xcode_version): - """Fills the SDK path and version for |platform| into |settings|.""" - settings['sdk_path'] = subprocess.check_output([ - 'xcrun', '-sdk', platform, '--show-sdk-path']).strip() - settings['sdk_version'] = subprocess.check_output([ - 'xcrun', '-sdk', platform, '--show-sdk-version']).strip() - settings['sdk_platform_path'] = subprocess.check_output([ - 'xcrun', '-sdk', platform, '--show-sdk-platform-path']).strip() - if xcode_version >= '0720': - settings['sdk_build'] = subprocess.check_output([ - 'xcrun', '-sdk', platform, '--show-sdk-build-version']).strip() - else: - settings['sdk_build'] = settings['sdk_version'] +def split_version(version): + """Splits the Xcode version to 3 values. + + >>> list(SplitVersion('8.2.1.1')) + ['8', '2', '1'] + >>> list(SplitVersion('9.3')) + ['9', '3', '0'] + >>> list(SplitVersion('10.0')) + ['10', '0', '0'] + """ + if isinstance(version, bytes): + version = version.decode() + version = version.split('.') + return itertools.islice(itertools.chain(version, itertools.repeat('0')), 0, 3) + + +def format_version(version): + """Converts Xcode version to a format required for DTXcode in Info.plist + + >>> FormatVersion('8.2.1') + '0821' + >>> FormatVersion('9.3') + '0930' + >>> FormatVersion('10.0') + '1000' + """ + major, minor, patch = split_version(version) + return ('%2s%s%s' % (major, minor, patch)).replace(' ', '0') + + +def fill_xcode_version(settings_xcode): + """Fills the Xcode version and build number into |settings_xcode|.""" + lines = subprocess.check_output(['xcodebuild', '-version']).splitlines() + settings_xcode['xcode_version'] = format_version(lines[0].split()[-1]) + settings_xcode['xcode_version_int'] = int(settings_xcode['xcode_version'], 10) + settings_xcode['xcode_build'] = lines[-1].split()[-1] + + +def fill_machine_os_build(settings_os): + """Fills OS build number into |settings_os|.""" + settings_os['machine_os_build'] = subprocess.check_output( + ['sw_vers', '-buildVersion']).strip() + + +def fill_sdk_path_and_version(settings_sdk, platform, xcode_version): + """Fills the SDK path and version for |platform| into |settings|.""" + settings_sdk['sdk_path'] = subprocess.check_output([ + 'xcrun', '-sdk', platform, '--show-sdk-path']).strip() + settings_sdk['sdk_version'] = subprocess.check_output([ + 'xcrun', '-sdk', platform, '--show-sdk-version']).strip() + settings_sdk['sdk_platform_path'] = subprocess.check_output([ + 'xcrun', '-sdk', platform, '--show-sdk-platform-path']).strip() + if xcode_version >= '0720': + settings_sdk['sdk_build'] = subprocess.check_output([ + 'xcrun', '-sdk', platform, '--show-sdk-build-version']).strip() + else: + settings_sdk['sdk_build'] = settings_sdk['sdk_version'] if __name__ == '__main__': - doctest.testmod() - - parser = argparse.ArgumentParser() - parser.add_argument("--developer_dir", required=False) - args, unknownargs = parser.parse_known_args() - if args.developer_dir: - os.environ['DEVELOPER_DIR'] = args.developer_dir - - if len(unknownargs) != 1: - sys.stderr.write( - 'usage: %s [iphoneos|iphonesimulator|macosx]\n' % - os.path.basename(sys.argv[0])) - sys.exit(1) - - settings = {} - FillMachineOSBuild(settings) - FillXcodeVersion(settings) - FillSDKPathAndVersion(settings, unknownargs[0], settings['xcode_version']) - - for key in sorted(settings): - value = settings[key] - if isinstance(value, bytes): - value = value.decode() - if key != 'xcode_version_int': - value = '"%s"' % value - print('%s=%s' % (key, value)) - else: - print('%s=%d' % (key, value)) + doctest.testmod() + + parser = argparse.ArgumentParser() + parser.add_argument("--developer_dir", required=False) + args, unknownargs = parser.parse_known_args() + if args.developer_dir: + os.environ['DEVELOPER_DIR'] = args.developer_dir + + if len(unknownargs) != 1: + sys.stderr.write( + 'usage: %s [iphoneos|iphonesimulator|macosx]\n' % + os.path.basename(sys.argv[0])) + sys.exit(1) + + settings = {} + fill_machine_os_build(settings) + fill_xcode_version(settings) + test_xcode_version = settings.get('xcode_version') + if test_xcode_version is None: + raise ValueError("Xcode version is not set or invalid.") + fill_sdk_path_and_version(settings, unknownargs[0], test_xcode_version) + + for key in sorted(settings): + value = settings[key] + if isinstance(value, bytes): + value = value.decode() + if key != 'xcode_version_int': + value = '"%s"' % value + print('%s=%s' % (key, value)) + else: + print('%s=%d' % (key, value)) diff --git a/build/core/gn/BUILD.gn b/build/core/gn/BUILD.gn index 2dc69e0b1ca55602d7a486b23ed3e32002ed04f5..c9ff832cb070efd8d0991a472addbaf0e04da5e0 100644 --- a/build/core/gn/BUILD.gn +++ b/build/core/gn/BUILD.gn @@ -11,8 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//arkcompiler/ets_frontend/ets_frontend_config.gni") -import("../../../toolchain.gni") +import("//arkcompiler/toolchain/toolchain.gni") +import("$build_root/config/components/ets_frontend/ets_frontend_config.gni") print("root_out_dir=$root_out_dir") print("root_build_dir=$root_build_dir") diff --git a/build/misc/mac/check_return_value.py b/build/misc/mac/check_return_value.py index f12ddb20556cb70049e242d92423f4cb281e40b6..33c5bc1ae828312100cc1f2d5ee35e5d8c613941 100755 --- a/build/misc/mac/check_return_value.py +++ b/build/misc/mac/check_return_value.py @@ -5,7 +5,8 @@ # found in the LICENSE file. """This program wraps an arbitrary command and prints "1" if the command ran -successfully.""" +successfully. +""" import os import subprocess diff --git a/build/prebuilts_download/prebuilts_download.py b/build/prebuilts_download/prebuilts_download.py index a4f11a19c23ceb43dafc52367d61676afb2c7775..c62d8e2dadd67e39694cbc7a108bb85ef587549a 100755 --- a/build/prebuilts_download/prebuilts_download.py +++ b/build/prebuilts_download/prebuilts_download.py @@ -88,7 +88,8 @@ def _uncompress(args, src_file, code_dir, unzip_dir, unzip_filename, mark_file_p cmd = 'tar -xvzf {} -C {};echo 0 > {}'.format(src_file, dest_dir, mark_file_path) else: cmd = 'tar -xvf {} -C {};echo 0 > {}'.format(src_file, dest_dir, mark_file_path) - _run_cmd(cmd) + _, _, returncode = _run_cmd(cmd) + return returncode def _copy_url(args, task_id, url, local_file, code_dir, unzip_dir, unzip_filename, mark_file_path): # download files @@ -100,6 +101,7 @@ def _copy_url(args, task_id, url, local_file, code_dir, unzip_dir, unzip_filenam response = urlopen(url) except urllib.error.HTTPError as e: progress.console.log("Failed to open {}, HTTPError: {}".format(url, e.code), style='red') + return 1 progress.update(task_id, total=int(response.info()["Content-length"])) with os.fdopen(os.open(local_file, flags, modes), 'wb') as dest_file: progress.start_task(task_id) @@ -107,48 +109,73 @@ def _copy_url(args, task_id, url, local_file, code_dir, unzip_dir, unzip_filenam dest_file.write(data) progress.update(task_id, advance=len(data)) progress.console.log("Downloaded {}".format(local_file)) + if not _check_sha256(url, local_file): + progress.console.log('{}, Sha256 check download FAILED.'.format(local_file), style='red') + return 1 # decompressing files progress.console.log("Decompressing {}".format(local_file)) - _uncompress(args, local_file, code_dir, unzip_dir, unzip_filename, mark_file_path) + returncode = _uncompress(args, local_file, code_dir, unzip_dir, unzip_filename, mark_file_path) progress.console.log("Decompressed {}".format(local_file)) + return returncode -def _hwcloud_download(args, config, bin_dir, code_dir): + +def _hwcloud_download_wrapper(args, config, bin_dir, code_dir, retries): + attempt = 0 + success = False + with progress: + while not success and attempt < retries: + success = _hwcloud_download(args, config, bin_dir, code_dir, retries) + attempt += 1 + return success + + +def _hwcloud_download(args, config, bin_dir, code_dir, retries): try: cnt = cpu_count() except: cnt = 1 - with progress: - with ThreadPoolExecutor(max_workers=cnt) as pool: - tasks = dict() - for config_info in config: - unzip_dir, huaweicloud_url, unzip_filename, md5_huaweicloud_url, bin_file = _config_parse(config_info, - args.tool_repo) - abs_unzip_dir = os.path.join(code_dir, unzip_dir) - if not os.path.exists(abs_unzip_dir): - os.makedirs(abs_unzip_dir) - if _check_sha256_by_mark(args, huaweicloud_url, code_dir, unzip_dir, unzip_filename): - progress.console.log('{}, Sha256 markword check OK.'.format(huaweicloud_url), style='green') - else: - _run_cmd(''.join(['rm -rf ', code_dir, '/', unzip_dir, '/*.', unzip_filename, '.mark'])) - _run_cmd(''.join(['rm -rf ', code_dir, '/', unzip_dir, '/', unzip_filename])) - local_file = os.path.join(bin_dir, ''.join([md5_huaweicloud_url, '.', bin_file])) - if os.path.exists(local_file): - if _check_sha256(huaweicloud_url, local_file): - progress.console.log('{}, Sha256 check download OK.'.format(local_file), style='green') - task = pool.submit(_uncompress, args, local_file, code_dir, unzip_dir, unzip_filename, - args.mark_file_path) - tasks[task] = os.path.basename(huaweicloud_url) - else: - os.remove(local_file) - else: - filename = huaweicloud_url.split("/")[-1] - task_id = progress.add_task("download", filename=filename, start=False) - task = pool.submit(_copy_url, args, task_id, huaweicloud_url, local_file, code_dir, unzip_dir, - unzip_filename, args.mark_file_path) - tasks[task] = os.path.basename(huaweicloud_url) - for task in as_completed(tasks): - progress.console.log('{}, download and decompress completed'.format(tasks.get(task)), style='green') + + success = False + with ThreadPoolExecutor(max_workers=cnt) as pool: + tasks = dict() + for config_info in config: + unzip_dir, huaweicloud_url, unzip_filename, md5_huaweicloud_url, bin_file = _config_parse(config_info, + args.tool_repo) + abs_unzip_dir = os.path.join(code_dir, unzip_dir) + if not os.path.exists(abs_unzip_dir): + os.makedirs(abs_unzip_dir) + if _check_sha256_by_mark(args, huaweicloud_url, code_dir, unzip_dir, unzip_filename): + progress.console.log('{}, Sha256 markword check OK.'.format(huaweicloud_url), style='green') + continue + + _run_cmd(''.join(['rm -rf ', code_dir, '/', unzip_dir, '/*.', unzip_filename, '.mark'])) + _run_cmd(''.join(['rm -rf ', code_dir, '/', unzip_dir, '/', unzip_filename])) + local_file = os.path.join(bin_dir, ''.join([md5_huaweicloud_url, '.', bin_file])) + if not os.path.exists(local_file): + filename = huaweicloud_url.split("/")[-1] + task_id = progress.add_task("download", filename=filename, start=False) + task = pool.submit(_copy_url, args, task_id, huaweicloud_url, local_file, code_dir, unzip_dir, + unzip_filename, args.mark_file_path) + tasks[task] = os.path.basename(huaweicloud_url) + continue + + if _check_sha256(huaweicloud_url, local_file): + progress.console.log('{}, Sha256 check download OK.'.format(local_file), style='green') + task = pool.submit(_uncompress, args, local_file, code_dir, unzip_dir, unzip_filename, + args.mark_file_path) + tasks[task] = os.path.basename(huaweicloud_url) + else: + os.remove(local_file) + returncode = 0 + for task in as_completed(tasks): + if task.result(): + returncode += task.result() + progress.console.log('{}, download and decompress completed, exit code: {}' + .format(tasks.get(task), task.result()), style='green') + success = returncode == 0 + return success + def _file_handle(config, code_dir): for config_info in config: @@ -203,8 +230,13 @@ def main(): elif host_platform == 'darwin': darwin_copy_config = config_info.get(host_platform).get(host_cpu).get('darwin_copy_config') copy_config.extend(darwin_copy_config) - _hwcloud_download(args, copy_config, args.bin_dir, args.code_dir) + retries = config_info.get('retries') + args.retries = 1 if retries is None else retries + if not _hwcloud_download_wrapper(args, copy_config, args.bin_dir, args.code_dir, args.retries): + return 1 _file_handle(file_handle_config, args.code_dir) + return 0 + if __name__ == '__main__': sys.exit(main()) diff --git a/build/prebuilts_download/prebuilts_download_config.json b/build/prebuilts_download/prebuilts_download_config.json index 12f968505cd71c22c46952dd19bc22152f022544..f427f90ed81e003c60e17876d9db9d6fbd184007 100644 --- a/build/prebuilts_download/prebuilts_download_config.json +++ b/build/prebuilts_download/prebuilts_download_config.json @@ -1,5 +1,6 @@ { "prebuilts_download_dir": "../openharmony_prebuilts", + "retries": 3, "file_handle_config": [ { "src": "/prebuilts/clang/ohos/linux-x86_64/clang_linux-x86_64-ef68e8-20240229", diff --git a/build/scripts/generate_js_bytecode.py b/build/scripts/generate_js_bytecode.py new file mode 100755 index 0000000000000000000000000000000000000000..f978b33d651d36cf86b8faeff01480d3642bab8b --- /dev/null +++ b/build/scripts/generate_js_bytecode.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +# coding: utf-8 + +""" +Copyright (c) 2021 Huawei Device Co., Ltd. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Description: Generate javascript byte code using es2abc +""" + +import os +import subprocess +import platform +import argparse + + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument('--src-js', + help='js source file') + parser.add_argument('--dst-file', + help='the converted target file') + parser.add_argument('--frontend-tool-path', + help='path of the frontend conversion tool') + parser.add_argument('--extension', + help='source file extension') + parser.add_argument("--debug", action='store_true', + help='whether add debuginfo') + parser.add_argument("--module", action='store_true', + help='whether is module') + parser.add_argument("--commonjs", action='store_true', + help='whether is commonjs') + parser.add_argument("--merge-abc", action='store_true', + help='whether is merge abc') + parser.add_argument("--generate-patch", action='store_true', + help='generate patch abc') + parser.add_argument("--dump-symbol-table", + help='dump symbol table of base abc') + parser.add_argument("--input-symbol-table", + help='input symbol table for patch abc') + arguments = parser.parse_args() + return arguments + + +def run_command(cmd, execution_path): + print(" ".join(cmd) + " | execution_path: " + execution_path) + proc = subprocess.Popen(cmd, cwd=execution_path) + proc.wait() + + +def gen_abc_info(input_arguments): + frontend_tool_path = input_arguments.frontend_tool_path + + (path, name) = os.path.split(frontend_tool_path) + + cmd = [os.path.join("./", name, "es2abc"), + '--output', input_arguments.dst_file, + input_arguments.src_js] + + if input_arguments.extension: + cmd += ['--extension', input_arguments.extension] + if input_arguments.dump_symbol_table: + cmd += ['--dump-symbol-table', input_arguments.dump_symbol_table] + if input_arguments.input_symbol_table: + cmd += ['--input-symbol-table', input_arguments.input_symbol_table] + if input_arguments.debug: + src_index = cmd.index(input_arguments.src_js) + cmd.insert(src_index, '--debug-info') + if input_arguments.module: + src_index = cmd.index(input_arguments.src_js) + cmd.insert(src_index, '--module') + if input_arguments.commonjs: + src_index = cmd.index(input_arguments.src_js) + cmd.insert(src_index, '--commonjs') + if input_arguments.merge_abc: + src_index = cmd.index(input_arguments.src_js) + cmd.insert(src_index, '--merge-abc') + if input_arguments.generate_patch: + src_index = cmd.index(input_arguments.src_js) + cmd.insert(src_index, '--generate-patch') + # insert d.ts option to cmd later + run_command(cmd, path) + + +if __name__ == '__main__': + gen_abc_info(parse_args()) \ No newline at end of file diff --git a/build/third_party_gn/googletest/BUILD.gn b/build/third_party_gn/googletest/BUILD.gn index 051465049606ed9c5cdb06ba780e37f43cc166b5..04449d71e8dc6af55c9c70e0bf9c660d362fcd80 100644 --- a/build/third_party_gn/googletest/BUILD.gn +++ b/build/third_party_gn/googletest/BUILD.gn @@ -19,8 +19,22 @@ config("gtest_private_config") { include_dirs = [ "$googletest_dir" ] } +config("gtest_private_config_rtti") { + visibility = [ ":*" ] + include_dirs = [ "googletest" ] + cflags = [ "-frtti" ] + cflags_objcc = [ "-frtti" ] + cflags_cc = [ "-frtti" ] +} + config("gtest_config") { include_dirs = [ "$googletest_dir/include" ] + cflags_cc = [ + "-std=c++17", + "-Wno-float-equal", + "-Wno-sign-compare", + "-Wno-reorder-init-list", + ] if (is_mingw) { cflags_cc = [ "-Wno-unused-const-variable", @@ -29,57 +43,74 @@ config("gtest_config") { } } +sources_files = [ + "$googletest_dir/include/gtest/gtest-death-test.h", + "$googletest_dir/include/gtest/gtest-matchers.h", + "$googletest_dir/include/gtest/gtest-message.h", + "$googletest_dir/include/gtest/gtest-param-test.h", + "$googletest_dir/include/gtest/gtest-printers.h", + "$googletest_dir/include/gtest/gtest-test-part.h", + "$googletest_dir/include/gtest/gtest-typed-test.h", + "$googletest_dir/include/gtest/gtest_pred_impl.h", + "$googletest_dir/include/gtest/gtest_prod.h", + "$googletest_dir/include/gtest/hwext/gtest-ext.h", + "$googletest_dir/include/gtest/hwext/gtest-filter.h", + "$googletest_dir/include/gtest/hwext/gtest-multithread.h", + "$googletest_dir/include/gtest/hwext/gtest-tag.h", + "$googletest_dir/include/gtest/hwext/utils.h", + "$googletest_dir/include/gtest/internal/custom/gtest-port.h", + "$googletest_dir/include/gtest/internal/custom/gtest-printers.h", + "$googletest_dir/include/gtest/internal/custom/gtest.h", + "$googletest_dir/include/gtest/internal/gtest-death-test-internal.h", + "$googletest_dir/include/gtest/internal/gtest-filepath.h", + "$googletest_dir/include/gtest/internal/gtest-internal.h", + "$googletest_dir/include/gtest/internal/gtest-param-util.h", + "$googletest_dir/include/gtest/internal/gtest-port-arch.h", + "$googletest_dir/include/gtest/internal/gtest-port.h", + "$googletest_dir/include/gtest/internal/gtest-string.h", + "$googletest_dir/include/gtest/internal/gtest-type-util.h", + "$googletest_dir/src/gtest-all.cc", + "$googletest_dir/src/gtest-assertion-result.cc", + "$googletest_dir/src/gtest-death-test.cc", + "$googletest_dir/src/gtest-filepath.cc", + "$googletest_dir/src/gtest-internal-inl.h", + "$googletest_dir/src/gtest-matchers.cc", + "$googletest_dir/src/gtest-port.cc", + "$googletest_dir/src/gtest-printers.cc", + "$googletest_dir/src/gtest-test-part.cc", + "$googletest_dir/src/gtest-typed-test.cc", + "$googletest_dir/src/gtest.cc", + "$googletest_dir/src/hwext/gtest-ext.cc", + "$googletest_dir/src/hwext/gtest-filter.cc", + "$googletest_dir/src/hwext/gtest-multithread.cpp", + "$googletest_dir/src/hwext/gtest-tag.cc", + "$googletest_dir/src/hwext/gtest-utils.cc", +] + static_library("gtest") { testonly = true public = [ "$googletest_dir/include/gtest/gtest-spi.h", "$googletest_dir/include/gtest/gtest.h", ] - sources = [ - "$googletest_dir/include/gtest/gtest-death-test.h", - "$googletest_dir/include/gtest/gtest-matchers.h", - "$googletest_dir/include/gtest/gtest-message.h", - "$googletest_dir/include/gtest/gtest-param-test.h", - "$googletest_dir/include/gtest/gtest-printers.h", - "$googletest_dir/include/gtest/gtest-test-part.h", - "$googletest_dir/include/gtest/gtest-typed-test.h", - "$googletest_dir/include/gtest/gtest_pred_impl.h", - "$googletest_dir/include/gtest/gtest_prod.h", - "$googletest_dir/include/gtest/hwext/gtest-ext.h", - "$googletest_dir/include/gtest/hwext/gtest-filter.h", - "$googletest_dir/include/gtest/hwext/gtest-tag.h", - "$googletest_dir/include/gtest/hwext/utils.h", - "$googletest_dir/include/gtest/internal/custom/gtest-port.h", - "$googletest_dir/include/gtest/internal/custom/gtest-printers.h", - "$googletest_dir/include/gtest/internal/custom/gtest.h", - "$googletest_dir/include/gtest/internal/gtest-death-test-internal.h", - "$googletest_dir/include/gtest/internal/gtest-filepath.h", - "$googletest_dir/include/gtest/internal/gtest-internal.h", - "$googletest_dir/include/gtest/internal/gtest-param-util.h", - "$googletest_dir/include/gtest/internal/gtest-port-arch.h", - "$googletest_dir/include/gtest/internal/gtest-port.h", - "$googletest_dir/include/gtest/internal/gtest-string.h", - "$googletest_dir/include/gtest/internal/gtest-type-util.h", - "$googletest_dir/src/gtest-all.cc", - "$googletest_dir/src/gtest-death-test.cc", - "$googletest_dir/src/gtest-filepath.cc", - "$googletest_dir/src/gtest-internal-inl.h", - "$googletest_dir/src/gtest-matchers.cc", - "$googletest_dir/src/gtest-port.cc", - "$googletest_dir/src/gtest-printers.cc", - "$googletest_dir/src/gtest-test-part.cc", - "$googletest_dir/src/gtest-typed-test.cc", - "$googletest_dir/src/gtest.cc", - "$googletest_dir/src/hwext/gtest-ext.cc", - "$googletest_dir/src/hwext/gtest-filter.cc", - "$googletest_dir/src/hwext/gtest-tag.cc", - "$googletest_dir/src/hwext/gtest-utils.cc", - ] + sources = sources_files sources -= [ "$googletest_dir/src/gtest-all.cc" ] public_configs = [ ":gtest_config" ] configs += [ ":gtest_private_config" ] } +static_library("gtest_rtti") { + testonly = true + public = [ + "$googletest_dir/include/gtest/gtest-spi.h", + "$googletest_dir/include/gtest/gtest.h", + ] + sources = sources_files + sources -= [ "$googletest_dir/src/gtest-all.cc" ] + public_configs = [ ":gtest_config" ] + configs += [ ":gtest_private_config_rtti" ] +} + static_library("gtest_main") { testonly = true sources = [ "$googletest_dir/src/gtest_main.cc" ] @@ -91,6 +122,14 @@ config("gmock_private_config") { include_dirs = [ "$googlemock_dir" ] } +config("gmock_private_config_rtti") { + visibility = [ ":*" ] + include_dirs = [ "googlemock_dir/include" ] + cflags = [ "-frtti" ] + cflags_objcc = [ "-frtti" ] + cflags_cc = [ "-frtti" ] +} + config("gmock_config") { include_dirs = [ "$googlemock_dir/include" ] @@ -104,37 +143,49 @@ config("gmock_config") { ] } +gmock_sources_files = [ + "$googlemock_dir/include/gmock/gmock-actions.h", + "$googlemock_dir/include/gmock/gmock-cardinalities.h", + "$googlemock_dir/include/gmock/gmock-function-mocker.h", + "$googlemock_dir/include/gmock/gmock-matchers.h", + "$googlemock_dir/include/gmock/gmock-more-actions.h", + "$googlemock_dir/include/gmock/gmock-more-matchers.h", + "$googlemock_dir/include/gmock/gmock-nice-strict.h", + "$googlemock_dir/include/gmock/gmock-spec-builders.h", + "$googlemock_dir/include/gmock/internal/custom/gmock-generated-actions.h", + "$googlemock_dir/include/gmock/internal/custom/gmock-matchers.h", + "$googlemock_dir/include/gmock/internal/custom/gmock-port.h", + "$googlemock_dir/include/gmock/internal/gmock-internal-utils.h", + "$googlemock_dir/include/gmock/internal/gmock-port.h", + "$googlemock_dir/include/gmock/internal/gmock-pp.h", + "$googlemock_dir/src/gmock-all.cc", + "$googlemock_dir/src/gmock-cardinalities.cc", + "$googlemock_dir/src/gmock-internal-utils.cc", + "$googlemock_dir/src/gmock-matchers.cc", + "$googlemock_dir/src/gmock-spec-builders.cc", + "$googlemock_dir/src/gmock.cc", +] + static_library("gmock") { testonly = true public = [ "$googlemock_dir/include/gmock/gmock.h" ] - sources = [ - "$googlemock_dir/include/gmock/gmock-actions.h", - "$googlemock_dir/include/gmock/gmock-cardinalities.h", - "$googlemock_dir/include/gmock/gmock-function-mocker.h", - "$googlemock_dir/include/gmock/gmock-matchers.h", - "$googlemock_dir/include/gmock/gmock-more-actions.h", - "$googlemock_dir/include/gmock/gmock-more-matchers.h", - "$googlemock_dir/include/gmock/gmock-nice-strict.h", - "$googlemock_dir/include/gmock/gmock-spec-builders.h", - "$googlemock_dir/include/gmock/internal/custom/gmock-generated-actions.h", - "$googlemock_dir/include/gmock/internal/custom/gmock-matchers.h", - "$googlemock_dir/include/gmock/internal/custom/gmock-port.h", - "$googlemock_dir/include/gmock/internal/gmock-internal-utils.h", - "$googlemock_dir/include/gmock/internal/gmock-port.h", - "$googlemock_dir/include/gmock/internal/gmock-pp.h", - "$googlemock_dir/src/gmock-all.cc", - "$googlemock_dir/src/gmock-cardinalities.cc", - "$googlemock_dir/src/gmock-internal-utils.cc", - "$googlemock_dir/src/gmock-matchers.cc", - "$googlemock_dir/src/gmock-spec-builders.cc", - "$googlemock_dir/src/gmock.cc", - ] + sources = gmock_sources_files sources -= [ "$googlemock_dir/src/gmock-all.cc" ] public_configs = [ ":gmock_config" ] configs += [ ":gmock_private_config" ] deps = [ ":gtest" ] } +static_library("gmock_rtti") { + testonly = true + public = [ "$googlemock_dir/include/gmock/gmock.h" ] + sources = gmock_sources_files + sources -= [ "$googlemock_dir/src/gmock-all.cc" ] + public_configs = [ ":gmock_config" ] + configs += [ ":gmock_private_config_rtti" ] + deps = [ ":gtest_rtti" ] +} + static_library("gmock_main") { testonly = true sources = [ "$googlemock_dir/src/gmock_main.cc" ] diff --git a/build/third_party_gn/icu/icu4c/BUILD.gn b/build/third_party_gn/icu/icu4c/BUILD.gn index 082ce8bcb295cd73ae6d28e4207194e612797c72..cafe64650980c711ca46dfef5e33212866b189da 100644 --- a/build/third_party_gn/icu/icu4c/BUILD.gn +++ b/build/third_party_gn/icu/icu4c/BUILD.gn @@ -499,13 +499,7 @@ ohos_shared_library("shared_icuuc") { "-shared", "-lm", ] - if (current_os == "ios") { - ldflags += [ - "-Wl", - "-install_name", - "@rpath/libhmicuuc.framework/libhmicuuc", - ] - } + configs = [ ":icu_config", "$build_root/config/compiler:rtti", @@ -552,14 +546,6 @@ ohos_shared_library("shared_icuuc") { install_enable = true } -if (current_os == "ios") { - ohos_combine_darwin_framework("libhmicuuc") { - deps = [ ":shared_icuuc" ] - subsystem_name = "thirdparty" - part_name = "icu" - } -} - ohos_shared_library("shared_icui18n") { ldflags = [ "-shared", diff --git a/build/third_party_gn/libuv/BUILD.gn b/build/third_party_gn/libuv/BUILD.gn index b7276c2629c4ab828d226f694304d929ed7eb283..5bb82bb0329b9ebb64dce4d017162908d2fb0217 100644 --- a/build/third_party_gn/libuv/BUILD.gn +++ b/build/third_party_gn/libuv/BUILD.gn @@ -20,6 +20,7 @@ common_source = [ "//third_party/libuv/src/random.c", "//third_party/libuv/src/strscpy.c", "//third_party/libuv/src/threadpool.c", + "//third_party/libuv/src/thread-common.c", "//third_party/libuv/src/timer.c", "//third_party/libuv/src/uv-common.c", "//third_party/libuv/src/uv-data-getter-setters.c", @@ -28,7 +29,6 @@ common_source = [ ] if (!is_mingw && !is_win) { nonwin_srcs = [ - "//third_party/libuv/src/unix/epoll.c", "//third_party/libuv/src/unix/async.c", "//third_party/libuv/src/unix/core.c", "//third_party/libuv/src/unix/dl.c", @@ -57,6 +57,7 @@ config("libuv_config") { "//third_party/libuv/src", "//third_party/libuv/src/unix", ] + defines = [] cflags = [ "-Wno-unused-parameter" ] if (is_linux || is_ohos) { cflags += [ @@ -68,7 +69,7 @@ config("libuv_config") { # Adding NDEBUG macro manually to avoid compilation # error in debug version, FIX ME # https://gitee.com/openharmony/build/pulls/1206/files - defines = [ "NDEBUG" ] + defines += [ "NDEBUG" ] } else if (is_mingw || is_win) { cflags += [ "-Wno-missing-braces", @@ -79,7 +80,7 @@ config("libuv_config") { "-Wno-error=unknown-pragmas", "-Wno-unused-variable", ] - defines = [ + defines += [ "WIN32_LEAN_AND_MEAN", "_WIN32_WINNT=0x0600", ] @@ -98,7 +99,7 @@ config("libuv_config") { "ws2_32", ] } else if (is_android) { - defines = [ "_GNU_SOURCE" ] + defines += [ "_GNU_SOURCE" ] } } @@ -122,7 +123,7 @@ ohos_source_set("libuv_source") { stack_protector_ret = false configs = [ ":libuv_config" ] sources = common_source - + external_deps = [] if (is_mac || (defined(is_ios) && is_ios)) { sources += nonwin_srcs + [ "//third_party/libuv/src/unix/bsd-ifaddrs.c", @@ -132,8 +133,9 @@ ohos_source_set("libuv_source") { "//third_party/libuv/src/unix/darwin.c", "//third_party/libuv/src/unix/fsevents.c", "//third_party/libuv/src/unix/os390-proctitle.c", + "//third_party/libuv/src/unix/log_unix.c", + "//third_party/libuv/src/unix/trace_unix.c", ] - sources -= [ "//third_party/libuv/src/unix/epoll.c" ] } else if (is_mingw || is_win) { sources += [ "//third_party/libuv/src/win/async.c", @@ -146,6 +148,7 @@ ohos_source_set("libuv_source") { "//third_party/libuv/src/win/getaddrinfo.c", "//third_party/libuv/src/win/getnameinfo.c", "//third_party/libuv/src/win/handle.c", + "//third_party/libuv/src/win/log_win.c", "//third_party/libuv/src/win/loop-watcher.c", "//third_party/libuv/src/win/pipe.c", "//third_party/libuv/src/win/poll.c", @@ -156,6 +159,7 @@ ohos_source_set("libuv_source") { "//third_party/libuv/src/win/stream.c", "//third_party/libuv/src/win/tcp.c", "//third_party/libuv/src/win/thread.c", + "//third_party/libuv/src/win/trace_win.c", "//third_party/libuv/src/win/tty.c", "//third_party/libuv/src/win/udp.c", "//third_party/libuv/src/win/util.c", @@ -164,31 +168,30 @@ ohos_source_set("libuv_source") { ] } else if (is_ohos || (defined(is_android) && is_android)) { sources += nonwin_srcs + [ - "//third_party/libuv/src/unix/linux-core.c", - "//third_party/libuv/src/unix/linux-inotify.c", - "//third_party/libuv/src/unix/linux-syscalls.c", + "//third_party/libuv/src/unix/linux.c", "//third_party/libuv/src/unix/procfs-exepath.c", - "//third_party/libuv/src/unix/pthread-fixes.c", "//third_party/libuv/src/unix/random-getentropy.c", "//third_party/libuv/src/unix/random-getrandom.c", "//third_party/libuv/src/unix/random-sysctl-linux.c", "//third_party/libuv/src/unix/proctitle.c", ] + sources += [ + "src/log_ohos.c", + "src/trace_ohos.c", + ] } else if (is_linux) { sources += nonwin_srcs + [ - "//third_party/libuv/src/unix/linux-core.c", - "//third_party/libuv/src/unix/linux-inotify.c", - "//third_party/libuv/src/unix/linux-syscalls.c", + "//third_party/libuv/src/unix/linux.c", "//third_party/libuv/src/unix/procfs-exepath.c", "//third_party/libuv/src/unix/random-getrandom.c", "//third_party/libuv/src/unix/random-sysctl-linux.c", "//third_party/libuv/src/unix/proctitle.c", + "//third_party/libuv/src/unix/log_unix.c", + "//third_party/libuv/src/unix/trace_unix.c", ] } else { sources += nonwin_srcs + [ - "//third_party/libuv/src/unix/linux-core.c", - "//third_party/libuv/src/unix/linux-inotify.c", - "//third_party/libuv/src/unix/linux-syscalls.c", + "//third_party/libuv/src/unix/linux.c", "//third_party/libuv/src/unix/procfs-exepath.c", "//third_party/libuv/src/unix/random-getrandom.c", "//third_party/libuv/src/unix/random-sysctl-linux.c", diff --git a/build/third_party_gn/libuv/src/log_ohos.c b/build/third_party_gn/libuv/src/log_ohos.c new file mode 100644 index 0000000000000000000000000000000000000000..adca6ab08d69d6cb91a7c406eb3862a12bcccf1f --- /dev/null +++ b/build/third_party_gn/libuv/src/log_ohos.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "uv_log.h" + +int uv__log_impl(enum uv__log_level level, const char* fmt, ...) +{ + return 0; +} \ No newline at end of file diff --git a/build/third_party_gn/libuv/src/trace_ohos.c b/build/third_party_gn/libuv/src/trace_ohos.c new file mode 100644 index 0000000000000000000000000000000000000000..d288639d8cb88bf6e3d65609c936eee9366a0e23 --- /dev/null +++ b/build/third_party_gn/libuv/src/trace_ohos.c @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#define UV_TRACE_TAG (1ULL << 30) + +void uv_start_trace(uint64_t tag, const char* name) {} +void uv_end_trace(uint64_t tag) {} \ No newline at end of file diff --git a/build/third_party_gn/musl/BUILD.gn b/build/third_party_gn/musl/BUILD.gn index 2b827ba2e2360f805b25df2aca7c4348eae261f7..73729d5e92377a16ae8e6babd52f13a4ce55a8f4 100644 --- a/build/third_party_gn/musl/BUILD.gn +++ b/build/third_party_gn/musl/BUILD.gn @@ -39,41 +39,46 @@ action("create_porting_src") { outdir = [ "${target_out_dir}/${musl_ported_dir}" ] src_files = musl_src_arch_file - src_files += musl_inc_root_files - src_files += musl_inc_fortify_files - src_files += musl_inc_sys_files - src_files += musl_inc_scsi_files - src_files += musl_inc_netpacket_files - src_files += musl_inc_netinet_files - src_files += musl_inc_net_files - src_files += musl_inc_arpa_files - src_files += musl_inc_bits_files - src_files += musl_src_ldso src_files += musl_src_file + src_files += musl_src_ldso + src_files += musl_inc_bits_files + src_files += musl_inc_arpa_files + src_files += musl_inc_net_files + src_files += musl_inc_netinet_files + src_files += musl_inc_netpacket_files + src_files += musl_inc_scsi_files + src_files += musl_inc_sys_files + src_files += musl_inc_fortify_files + src_files += musl_inc_root_files + src_files += musl_inc_info_files + src_files += musl_inc_trace_files src_files += [ - "scripts/create_syscall.sh", - "scripts/create_vesion.sh", - "scripts/create_alltypes.sh", - "scripts/install.py", - "tools/install.sh", - "tools/version.sh", - "VERSION", - "include/alltypes.h.in", - "arch/${musl_arch}/bits/syscall.h.in", - "arch/${musl_arch}/bits/alltypes.h.in", - "tools/mkalltypes.sed", - "crt/rcrt1.c", - "crt/crt1.c", "crt/Scrt1.c", - "crt/${musl_arch}/crtn.s", + "crt/crt1.c", + "crt/rcrt1.c", + "tools/mkalltypes.sed", + "arch/${musl_arch}/bits/alltypes.h.in", + "arch/${musl_arch}/bits/syscall.h.in", + "include/alltypes.h.in", + "VERSION", + "tools/version.sh", + "tools/install.sh", + "scripts/install.py", + "scripts/create_alltypes.sh", + "scripts/create_vesion.sh", + "scripts/create_syscall.sh", + ] + src_files += [ "crt/${musl_arch}/crti.s", + "crt/${musl_arch}/crtn.s", ] + args = [ "-i" ] + rebase_path(sources_dir) args += [ "-o" ] + rebase_path(outdir) args += [ "-p" ] + [ "${musl_target_os}" ] foreach(i, src_files) { - foreach(s, musl_src_porting_file) { + foreach(s, musl_src_files_ext) { if (i == s) { src_files -= [ "${s}" ] } @@ -85,16 +90,24 @@ action("create_porting_src") { outputs += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] } - foreach(s, musl_src_porting_file) { + foreach(s, musl_src_files_ext) { outputs += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] } + inputs = [] + foreach(i, src_files) { + foreach(s, musl_src_linux_files) { + if (i == s) { + src_files -= [ "${s}" ] + } + } + } foreach(s, src_files) { inputs += [ "${musl_dir}/${s}" ] } - foreach(s, musl_src_porting_file) { - inputs += [ "${musl_porting_dir}/${s}" ] + foreach(s, musl_src_files_ext) { + inputs += [ "${musl_dir}/${s}" ] } } @@ -149,7 +162,7 @@ action("create_syscall_h_file") { } uapi_from = "local" -uapi_full_path = rebase_path(uapi_dir) +uapi_full_path = rebase_path(musl_uapi_dir) arguments_uapi = [ "-c" ] # exclude these files because they need special treatment @@ -166,7 +179,7 @@ uspi_files = exec_script("/bin/sh", arguments_uapi, "list lines") # Generate a copy target for each file foreach(file, uspi_files) { copy("copy_uapi_${file}") { - sources = [ "${uapi_dir}/${file}" ] + sources = [ "${musl_uapi_dir}/${file}" ] outputs = [ "${target_out_dir}/${musl_inc_out_dir}/${file}" ] } } @@ -175,7 +188,7 @@ group("copy_uapi_scsi") { deps = [] sources = [] outputs = [] - uapi_scsi_dir = rebase_path("${uapi_dir}/scsi") + uapi_scsi_dir = rebase_path("${musl_uapi_dir}/scsi") arguments_scsi = [ "-c" ] arguments_scsi += [ "ls ${uapi_scsi_dir}" ] uapi_scsi_files = exec_script("/bin/sh", arguments_scsi, "list lines") @@ -183,7 +196,7 @@ group("copy_uapi_scsi") { # Generate a copy target for each file in scsi dir to avoid being influenced by musl_copy_inc_scsi output foreach(file, uapi_scsi_files) { copy("copy_uapi_scsi_${file}") { - sources += [ "${uapi_dir}/scsi/${file}" ] + sources += [ "${musl_uapi_dir}/scsi/${file}" ] outputs += [ "${target_out_dir}/${musl_inc_out_dir}/scsi/${file}" ] } deps += [ ":copy_uapi_scsi_${file}" ] @@ -197,9 +210,9 @@ copy("copy_uapi_asm") { } else { # aarch64 and x86_64 use same file file_name = "asm-arm64" } - sources = [ "${uapi_dir}/${file_name}/asm" ] + sources = [ "${musl_uapi_dir}/${file_name}/asm" ] } else { - sources = [ "${uapi_dir}/asm" ] + sources = [ "${musl_uapi_dir}/asm" ] } outputs = [ "${target_out_dir}/${musl_inc_out_dir}/asm" ] } diff --git a/build/third_party_gn/musl/musl_config.gni b/build/third_party_gn/musl/musl_config.gni index ceff6198dd837c2423985d0f917889786f025d2b..52814f23281d1df92cb18d28f97a26720d4e9ab8 100644 --- a/build/third_party_gn/musl/musl_config.gni +++ b/build/third_party_gn/musl/musl_config.gni @@ -45,10 +45,10 @@ declare_args() { declare_args() { runtime_lib_path = "//prebuilts/clang/ohos/linux-x86_64/llvm/lib/clang/15.0.4/lib" - use_jemalloc = false + musl_use_jemalloc = false musl_ported_dir = "intermidiates/${musl_target_os}/musl_src_ported" musl_inc_out_dir = "usr/include/${musl_target_triple}" - uapi_dir = "//kernel/linux/patches/linux-5.10/prebuilts/usr/include" + musl_uapi_dir = "//kernel/linux/patches/linux-5.10/prebuilts/usr/include" musl_dir = "//third_party/musl" musl_porting_dir = "//third_party/musl/porting/linux/user" } diff --git a/build/third_party_gn/musl/musl_src.gni b/build/third_party_gn/musl/musl_src.gni index eeb0267d8126784f2978f5c8d485163963591609..aa32f5ccdfeda16c5ba43fd6665ff3d2cbe00860 100644 --- a/build/third_party_gn/musl/musl_src.gni +++ b/build/third_party_gn/musl/musl_src.gni @@ -14,6 +14,7 @@ import("//third_party/FreeBSD/FreeBSD.gni") import("$build_root/third_party_gn/musl/musl_config.gni") +OPTRTDIR = "//third_party/optimized-routines/" if (musl_arch == "arm") { musl_src_arch_file = [ "src/exit/arm/__aeabi_atexit.c", @@ -21,7 +22,6 @@ if (musl_arch == "arm") { "src/fenv/arm/fenv.c", "src/ldso/arm/dlsym.s", "src/ldso/arm/dlsym_time64.S", - "src/ldso/arm/dlvsym.s", "src/ldso/arm/find_exidx.c", "src/ldso/arm/tlsdesc.S", "src/math/arm/fabs.c", @@ -44,6 +44,7 @@ if (musl_arch == "arm") { "src/thread/arm/atomics.s", "src/thread/arm/clone.s", "src/thread/arm/syscall_cp.s", + "src/linux/arm/flock.s", "compat/time32/adjtime32.c", "compat/time32/adjtimex_time32.c", "compat/time32/aio_suspend_time32.c", @@ -113,7 +114,6 @@ if (musl_arch == "arm") { musl_src_arch_file = [ "src/fenv/aarch64/fenv.s", "src/ldso/aarch64/dlsym.s", - "src/ldso/aarch64/dlvsym.s", "src/ldso/aarch64/tlsdesc.s", "src/math/aarch64/ceil.c", "src/math/aarch64/ceilf.c", @@ -152,15 +152,58 @@ if (musl_arch == "arm") { "src/thread/aarch64/__set_thread_area.s", "src/thread/aarch64/__unmapself.s", "src/thread/aarch64/clone.s", - "src/misc/aarch64/fstat.s", "src/thread/aarch64/syscall_cp.s", - "src/misc/aarch64/syscall.s", + "src/linux/aarch64/flock.s", + ] +} else if (musl_arch == "mips") { + musl_src_arch_file = [ + "src/fenv/mips/fenv-sf.c", + "src/fenv/mips/fenv.S", + "src/ldso/mips/dlsym_time64.S", + "src/ldso/mips/dlsym.s", + "src/math/mips/fabs.c", + "src/math/mips/fabsf.c", + "src/math/mips/sqrt.c", + "src/math/mips/sqrtf.c", + "src/setjmp/mips/longjmp.S", + "src/setjmp/mips/setjmp.S", + "src/signal/mips/sigsetjmp.s", + "src/thread/mips/__unmapself.s", + "src/thread/mips/clone.s", + "src/thread/mips/syscall_cp.s", + "src/unistd/mips/pipe.s", + ] +} else if (musl_arch == "riscv64") { + musl_src_arch_file = [ + "src/fenv/riscv64/fenv-sf.c", + "src/fenv/riscv64/fenv.S", + "src/ldso/riscv64/dlsym.s", + "src/ldso/riscv64/tlsdesc.s", + "src/math/riscv64/copysign.c", + "src/math/riscv64/copysignf.c", + "src/math/riscv64/fabs.c", + "src/math/riscv64/fabsf.c", + "src/math/riscv64/fma.c", + "src/math/riscv64/fmaf.c", + "src/math/riscv64/fmax.c", + "src/math/riscv64/fmaxf.c", + "src/math/riscv64/fmin.c", + "src/math/riscv64/fminf.c", + "src/math/riscv64/sqrt.c", + "src/math/riscv64/sqrtf.c", + "src/setjmp/riscv64/longjmp.S", + "src/setjmp/riscv64/setjmp.S", + "src/signal/riscv64/restore.s", + "src/signal/riscv64/sigsetjmp.s", + "src/thread/riscv64/__set_thread_area.s", + "src/thread/riscv64/__unmapself.s", + "src/thread/riscv64/clone.s", + "src/thread/riscv64/syscall_cp.s", ] } else if (musl_arch == "x86_64") { musl_src_arch_file = [ "src/fenv/x86_64/fenv.s", "src/ldso/x86_64/dlsym.s", - "src/ldso/x86_64/dlvsym.s", "src/ldso/x86_64/tlsdesc.s", "src/math/x86_64/__invtrigl.s", "src/math/x86_64/acosl.s", @@ -205,38 +248,32 @@ if (musl_arch == "arm") { "src/thread/x86_64/__unmapself.s", "src/thread/x86_64/clone.s", "src/thread/x86_64/syscall_cp.s", + "src/linux/x86_64/flock.s", ] -} else if (musl_arch == "mips") { +} else if (musl_arch == "loongarch64") { musl_src_arch_file = [ - "src/fenv/mips/fenv.S", - "src/fenv/mips/fenv-sf.c", - "src/ldso/mips/dlsym.s", - "src/ldso/mips/dlsym_time64.S", - "src/math/mips/fabs.c", - "src/math/mips/fabsf.c", - "src/math/mips/sqrt.c", - "src/math/mips/sqrtf.c", - "src/setjmp/mips/longjmp.S", - "src/setjmp/mips/setjmp.S", - "src/signal/mips/restore.s", - "src/signal/mips/sigsetjmp.s", - "src/thread/mips/__unmapself.s", - "src/thread/mips/clone.s", - "src/thread/mips/syscall_cp.s", + "src/fenv/loongarch64/fenv.S", + "src/ldso/loongarch64/dlsym.s", + "src/ldso/loongarch64/tlsdesc.s", + "src/setjmp/loongarch64/longjmp.S", + "src/setjmp/loongarch64/setjmp.S", + "src/signal/loongarch64/restore.s", + "src/signal/loongarch64/sigsetjmp.s", + "src/thread/loongarch64/__set_thread_area.s", + "src/thread/loongarch64/__unmapself.s", + "src/thread/loongarch64/clone.s", + "src/thread/loongarch64/syscall_cp.s", ] } musl_src_file = [ - "src/thread/pthread_cond_clockwait.c", - "src/thread/pthread_cond_timedwait_monotonic_np.c", - "src/thread/pthread_cond_timeout_np.c", "src/internal/pthread_impl.h", "src/internal/locale_impl.h", - "src/thread/pthread_rwlock_clockrdlock.c", + "src/internal/locale_impl.c", + "src/internal/stdio_impl.h", + "src/internal/unsupported_api.h", + "src/internal/syscall_hooks.h", "src/thread/pthread_rwlock_timedrdlock.c", - "src/thread/pthread_rwlock_timedrdlock_monotonic_np.c", - "src/thread/pthread_rwlock_clockwrlock.c", - "src/thread/pthread_rwlock_timedwrlock_monotonic_np.c", "src/thread/pthread_rwlock_timedwrlock.c", "src/aio/aio.c", "src/aio/aio_suspend.c", @@ -391,6 +428,7 @@ musl_src_file = [ "src/exit/at_quick_exit.c", "src/exit/atexit.c", "src/exit/exit.c", + "src/exit/cxa_thread_atexit_impl.c", "src/exit/quick_exit.c", "src/fcntl/creat.c", "src/fcntl/fcntl.c", @@ -398,6 +436,7 @@ musl_src_file = [ "src/fcntl/openat.c", "src/fcntl/posix_fadvise.c", "src/fcntl/posix_fallocate.c", + "src/fdsan/fdsan.c", "src/fenv/__flt_rounds.c", "src/fenv/fegetexceptflag.c", "src/fenv/feholdexcept.c", @@ -406,6 +445,8 @@ musl_src_file = [ "src/fenv/fesetround.c", "src/fenv/feupdateenv.c", "src/fortify/fortify.c", + "src/gwp_asan/gwp_asan.c", + "src/gwp_asan/gwp_asan.h", "src/internal/defsysinfo.c", "src/internal/floatscan.c", "src/internal/intscan.c", @@ -413,9 +454,7 @@ musl_src_file = [ "src/internal/procfdname.c", "src/internal/shgetc.c", "src/internal/syscall_ret.c", - "src/internal/vdso.c", "src/internal/version.c", - "src/internal/network_conf_function.c", "src/hilog/hilog_adapter.c", "src/hilog/vsnprintf_s_p.c", "src/ipc/ftok.c", @@ -488,15 +527,14 @@ musl_src_file = [ "src/linux/open_by_handle_at.c", "src/linux/personality.c", "src/linux/pivot_root.c", - "src/linux/ppoll.c", "src/linux/prctl.c", + "src/linux/preadv2.c", "src/linux/prlimit.c", "src/linux/process_vm.c", "src/linux/ptrace.c", "src/linux/quotactl.c", "src/linux/readahead.c", "src/linux/reboot.c", - "src/linux/tgkill.c", "src/linux/remap_file_pages.c", "src/linux/sbrk.c", "src/linux/sendfile.c", @@ -508,6 +546,7 @@ musl_src_file = [ "src/linux/settimeofday.c", "src/linux/signalfd.c", "src/linux/splice.c", + "src/linux/statx.c", "src/linux/stime.c", "src/linux/swap.c", "src/linux/sync_file_range.c", @@ -521,6 +560,7 @@ musl_src_file = [ "src/linux/vmsplice.c", "src/linux/wait3.c", "src/linux/wait4.c", + "src/linux/pwritev2.c", "src/linux/xattr.c", "src/locale/__lctrans.c", "src/locale/__mo_lookup.c", @@ -542,6 +582,7 @@ musl_src_file = [ "src/locale/setlocale.c", "src/locale/strcoll.c", "src/locale/strtod_l.c", + "src/locale/wcstod_l.c", "src/locale/strfmon.c", "src/locale/strxfrm.c", "src/locale/textdomain.c", @@ -556,8 +597,6 @@ musl_src_file = [ "src/malloc/mallocng/malloc.c", "src/malloc/mallocng/meta.h", "src/malloc/mallocng/realloc.c", - "src/malloc/stats.c", - "src/malloc/calloc.c", "src/malloc/free.c", "src/malloc/libc_calloc.c", "src/malloc/lite_malloc.c", @@ -1029,6 +1068,7 @@ musl_src_file = [ "src/regex/regerror.c", "src/regex/regexec.c", "src/regex/tre-mem.c", + "src/syscall_hooks/syscall_hooks.c", "src/sched/sched_cpualloc.c", "src/sched/affinity.c", "src/sched/sched_cpucount.c", @@ -1049,6 +1089,7 @@ musl_src_file = [ "src/search/tsearch.c", "src/search/twalk.c", "src/select/poll.c", + "src/select/ppoll.c", "src/select/pselect.c", "src/select/select.c", "src/setjmp/longjmp.c", @@ -1091,7 +1132,6 @@ musl_src_file = [ "src/signal/sigtimedwait.c", "src/signal/sigwait.c", "src/signal/sigwaitinfo.c", - "src/sigchain/sigchain.c", "src/stat/__xstat.c", "src/stat/chmod.c", "src/stat/fchmod.c", @@ -1250,6 +1290,7 @@ musl_src_file = [ "src/stdlib/strtol.c", "src/stdlib/wcstod.c", "src/stdlib/wcstol.c", + "src/string/strcspn.c", "src/string/bcmp.c", "src/string/bcopy.c", "src/string/bzero.c", @@ -1268,13 +1309,11 @@ musl_src_file = [ "src/string/stpcpy.c", "src/string/stpncpy.c", "src/string/strcasecmp.c", - "src/string/strcasestr.c", "src/string/strcat.c", "src/string/strchr.c", "src/string/strchrnul.c", "src/string/strcmp.c", "src/string/strcpy.c", - "src/string/strcspn.c", "src/string/strdup.c", "src/string/strerror_r.c", "src/string/strlcat.c", @@ -1415,9 +1454,6 @@ musl_src_file = [ "src/thread/pthread_mutex_lock.c", "src/thread/pthread_mutex_setprioceiling.c", "src/thread/pthread_mutex_timedlock.c", - "src/thread/pthread_mutex_clocklock.c", - "src/thread/pthread_mutex_timedlock_monotonic_np.c", - "src/thread/pthread_mutex_lock_timeout_np.c", "src/thread/pthread_mutex_trylock.c", "src/thread/pthread_mutex_unlock.c", "src/thread/pthread_mutexattr_destroy.c", @@ -1596,6 +1632,39 @@ musl_src_file = [ "src/info/application_target_sdk_version.c", "src/info/device_api_version.c", "src/info/fatal_message.c", + "arch/generic/crtbrand.s", + "crt/crtplus.c", + "ldso/namespace.h", + "ldso/ns_config.h", + "ldso/strops.h", + "ldso/cfi.h", + "ldso/ld_log.h", + "ldso/dynlink_rand.h", + "src/internal/vdso.c", + "src/internal/emulate_wait4.c", + "src/internal/malloc_config.h", + "src/internal/malloc_random.h", + "src/internal/hilog_adapter.h", + "src/internal/musl_log.h", + "src/internal/musl_log.c", + "src/internal/network_conf_function.c", + "src/internal/network_conf_function.h", + "src/internal/services.h", + "src/internal/proc_xid_impl.h", + "src/linux/tgkill.c", + "src/malloc/calloc.c", + "src/malloc/stats.c", + "src/sigchain/sigchain.c", + "src/thread/pthread_cond_clockwait.c", + "src/thread/pthread_cond_timedwait_monotonic_np.c", + "src/thread/pthread_cond_timeout_np.c", + "src/thread/pthread_mutex_clocklock.c", + "src/thread/pthread_mutex_timedlock_monotonic_np.c", + "src/thread/pthread_mutex_lock_timeout_np.c", + "src/thread/pthread_rwlock_clockrdlock.c", + "src/thread/pthread_rwlock_timedrdlock_monotonic_np.c", + "src/thread/pthread_rwlock_clockwrlock.c", + "src/thread/pthread_rwlock_timedwrlock_monotonic_np.c", ] if (musl_arch == "arm") { @@ -1718,13 +1787,54 @@ if (musl_arch == "arm") { musl_src_filterout = [ "src/fenv/fenv.c", "src/ldso/dlsym.c", + "src/ldso/tlsdesc.c", + "src/math/fabs.c", + "src/math/fabsf.c", + "src/math/sqrt.c", + "src/math/sqrtf.c", + "src/setjmp/longjmp.c", + "src/setjmp/setjmp.c", + "src/signal/restore.c", + "src/signal/sigsetjmp.c", + "src/thread/__unmapself.c", + "src/thread/clone.c", + "src/thread/syscall_cp.c", + "src/unistd/pipe.c", + ] +} else if (musl_arch == "riscv64") { + musl_src_filterout = [ + "src/fenv/fenv.c", + "src/ldso/dlsym.c", + "src/ldso/tlsdesc.c", "src/math/fabs.c", "src/math/fabsf.c", + "src/math/fma.c", "src/math/fmaf.c", + "src/math/fmax.c", + "src/math/fmaxf.c", + "src/math/fmin.c", + "src/math/fminf.c", "src/math/sqrt.c", "src/math/sqrtf.c", + "src/setjmp/longjmp.c", "src/setjmp/setjmp.c", "src/signal/restore.c", + "src/signal/sigsetjmp.c", + "src/thread/__set_thread_area.c", + "src/thread/__unmapself.c", + "src/thread/clone.c", + "src/thread/syscall_cp.c", + ] +} else if (musl_arch == "loongarch64") { + musl_src_filterout = [ + "src/fenv/fenv.c", + "src/ldso/dlsym.c", + "src/ldso/tlsdesc.c", + "src/setjmp/longjmp.c", + "src/setjmp/setjmp.c", + "src/signal/restore.c", + "src/signal/sigsetjmp.c", + "src/thread/__set_thread_area.c", "src/thread/__unmapself.c", "src/thread/clone.c", "src/thread/syscall_cp.c", @@ -1828,7 +1938,6 @@ if (musl_arch == "arm") { "arch/x86_64/bits/stat.h", "arch/x86_64/bits/stdint.h", "arch/x86_64/bits/user.h", - "arch/generic/bits/dirent.h", "arch/generic/bits/errno.h", "arch/generic/bits/hwcap.h", @@ -1855,40 +1964,115 @@ if (musl_arch == "arm") { ] } else if (musl_arch == "mips") { musl_inc_bits_files = [ - "arch/mips/bits/errno.h", - "arch/mips/bits/fcntl.h", + "arch/generic/bits/fcntl.h", "arch/mips/bits/fenv.h", "arch/mips/bits/float.h", - "arch/mips/bits/hwcap.h", - "arch/mips/bits/ioctl.h", - "arch/mips/bits/ipcstat.h", - "arch/mips/bits/mman.h", - "arch/mips/bits/msg.h", - "arch/mips/bits/poll.h", "arch/mips/bits/posix.h", - "arch/mips/bits/ptrace.h", "arch/mips/bits/reg.h", - "arch/mips/bits/resource.h", - "arch/mips/bits/sem.h", "arch/mips/bits/setjmp.h", - "arch/mips/bits/shm.h", "arch/mips/bits/signal.h", - "arch/mips/bits/socket.h", "arch/mips/bits/stat.h", - "arch/mips/bits/statfs.h", "arch/mips/bits/stdint.h", - "arch/mips/bits/termios.h", "arch/mips/bits/user.h", + "arch/generic/bits/dirent.h", + "arch/generic/bits/errno.h", + "arch/generic/bits/hwcap.h", "arch/generic/bits/ioctl_fix.h", + "arch/generic/bits/ioctl.h", "arch/generic/bits/io.h", "arch/generic/bits/ipc.h", + "arch/generic/bits/ipcstat.h", "arch/generic/bits/kd.h", "arch/generic/bits/limits.h", "arch/generic/bits/link.h", + "arch/generic/bits/mman.h", + "arch/generic/bits/msg.h", + "arch/generic/bits/poll.h", + "arch/generic/bits/ptrace.h", + "arch/generic/bits/resource.h", + "arch/generic/bits/sem.h", + "arch/generic/bits/shm.h", + "arch/generic/bits/socket.h", "arch/generic/bits/soundcard.h", + "arch/generic/bits/statfs.h", + "arch/generic/bits/termios.h", "arch/generic/bits/vt.h", ] +} else if (musl_arch == "riscv64") { + musl_inc_bits_files = [ + "arch/generic/bits/fcntl.h", + "arch/riscv64/bits/fenv.h", + "arch/riscv64/bits/float.h", + "arch/riscv64/bits/posix.h", + "arch/riscv64/bits/reg.h", + "arch/riscv64/bits/setjmp.h", + "arch/riscv64/bits/signal.h", + "arch/riscv64/bits/stat.h", + "arch/riscv64/bits/stdint.h", + "arch/riscv64/bits/user.h", + + "arch/generic/bits/dirent.h", + "arch/generic/bits/errno.h", + "arch/generic/bits/hwcap.h", + "arch/generic/bits/ioctl_fix.h", + "arch/generic/bits/ioctl.h", + "arch/generic/bits/io.h", + "arch/generic/bits/ipc.h", + "arch/generic/bits/ipcstat.h", + "arch/generic/bits/kd.h", + "arch/generic/bits/limits.h", + "arch/generic/bits/link.h", + "arch/generic/bits/mman.h", + "arch/generic/bits/msg.h", + "arch/generic/bits/poll.h", + "arch/generic/bits/ptrace.h", + "arch/generic/bits/resource.h", + "arch/generic/bits/sem.h", + "arch/generic/bits/shm.h", + "arch/generic/bits/socket.h", + "arch/generic/bits/soundcard.h", + "arch/generic/bits/statfs.h", + "arch/generic/bits/termios.h", + "arch/generic/bits/vt.h", + ] +} else if (musl_arch == "loongarch64") { + musl_inc_bits_files = [ + "arch/loongarch64/bits/fenv.h", + "arch/loongarch64/bits/float.h", + "arch/loongarch64/bits/posix.h", + "arch/loongarch64/bits/reg.h", + "arch/loongarch64/bits/setjmp.h", + "arch/loongarch64/bits/signal.h", + "arch/loongarch64/bits/stat.h", + "arch/loongarch64/bits/stdint.h", + "arch/loongarch64/bits/user.h", + + "arch/generic/bits/dirent.h", + "arch/generic/bits/errno.h", + "arch/generic/bits/hwcap.h", + "arch/generic/bits/ioctl_fix.h", + "arch/generic/bits/ioctl.h", + "arch/generic/bits/io.h", + "arch/generic/bits/ipc.h", + "arch/generic/bits/ipcstat.h", + "arch/generic/bits/kd.h", + "arch/generic/bits/link.h", + "arch/generic/bits/mman.h", + "arch/generic/bits/msg.h", + "arch/generic/bits/poll.h", + "arch/generic/bits/sem.h", + "arch/generic/bits/shm.h", + "arch/generic/bits/socket.h", + "arch/generic/bits/soundcard.h", + "arch/generic/bits/termios.h", + "arch/generic/bits/vt.h", + "arch/generic/bits/statfs.h", + "arch/generic/bits/ptrace.h", + "arch/generic/bits/resource.h", + "arch/generic/bits/fcntl.h", + "arch/generic/bits/limits.h", + ] } musl_inc_arpa_files = [ @@ -2117,239 +2301,245 @@ musl_inc_root_files = [ "include/wchar.h", "include/wctype.h", "include/wordexp.h", + "include/syscall_hooks.h", + "include/pthread_ffrt.h", ] -musl_src_porting_file = [ - "arch/aarch64/syscall_arch.h", - "arch/arm/bits/fenv.h", - "arch/generic/bits/shm.h", - "arch/generic/crtbrand.s", - "arch/x86_64/bits/float.h", - "include/ctype.h", - "include/info/application_target_sdk_version.h", - "include/info/device_api_version.h", - "include/info/fatal_message.h", - "include/malloc.h", - "include/pthread.h", - "include/fcntl.h", - "include/poll.h", - "include/stdio.h", - "include/stdlib.h", - "include/string.h", - "include/sys/stat.h", - "include/sys/sspret.h", - "include/sys/cdefs.h", - "include/fortify/fcntl.h", - "include/fortify/fortify.h", - "include/fortify/poll.h", - "include/fortify/socket.h", - "include/fortify/stat.h", - "include/fortify/stdlib.h", - "include/fortify/string.h", - "include/fortify/unistd.h", - "include/fortify/stdio.h", +musl_src_files_ext = [ + "src/internal/linux/musl_log.c", + "src/internal/linux/vdso.c", + "src/hook/linux/malloc_common.c", + "src/hook/linux/musl_preinit.c", + "src/hook/linux/musl_socket_preinit.c", + "src/hook/linux/socket_common.c", + "src/hook/linux/memory_trace.c", + "src/hook/linux/musl_fdtrack.c", + "src/hook/linux/musl_fdtrack_load.c", + "src/hook/linux/musl_preinit_common.c", + "src/hook/linux/musl_socket_preinit_common.c", + "crt/linux/crtplus.c", + "src/linux/arm/linux/flock.s", + "src/linux/aarch64/linux/flock.s", + "src/linux/x86_64/linux/flock.s", + "src/exit/linux/assert.c", + "src/exit/linux/atexit.c", + "src/fdsan/linux/fdsan.c", + "src/fortify/linux/fortify.c", + "src/gwp_asan/linux/gwp_asan.c", + "src/gwp_asan/linux/gwp_asan.h", + "src/hilog/linux/hilog_adapter.c", + "src/hilog/linux/hilog_common.h", + "src/hilog/linux/output_p.inl", + "src/hilog/linux/vsnprintf_s_p.c", + "src/hilog/linux/vsnprintf_s_p.h", + "src/linux/linux/clone.c", + "src/linux/linux/getprocpid.c", + "src/network/linux/getaddrinfo.c", + "src/syscall_hooks/linux/syscall_hooks.c", + "src/signal/linux/sigaction.c", + "src/thread/linux/pthread_create.c", + "src/trace/linux/trace_marker.c", + "include/trace/linux/trace_marker.h", + "src/info/linux/application_target_sdk_version.c", + "src/info/linux/device_api_version.c", + "src/info/linux/fatal_message.c", + "ldso/linux/cfi.c", + "ldso/linux/dynlink.c", + "ldso/linux/dynlink_rand.h", + "ldso/linux/ld_log.h", + "ldso/linux/namespace.h", + "ldso/linux/ns_config.h", + "ldso/linux/strops.c", + "ldso/linux/zip_archive.h", + "ldso/linux/cfi.h", + "ldso/linux/dynlink_rand.c", + "ldso/linux/ld_log.c", + "ldso/linux/namespace.c", + "ldso/linux/ns_config.c", + "ldso/linux/strops.h", + "include/sys/linux/capability.h", + "include/sys/linux/cdefs.h", + "include/sys/linux/sspret.h", + "include/info/linux/application_target_sdk_version.h", + "include/info/linux/device_api_version.h", + "include/info/linux/fatal_message.h", + "include/fortify/linux/fcntl.h", + "include/fortify/linux/poll.h", + "include/fortify/linux/stat.h", + "include/fortify/linux/stdlib.h", + "include/fortify/linux/unistd.h", + "include/fortify/linux/fortify.h", + "include/fortify/linux/socket.h", + "include/fortify/linux/stdio.h", + "include/fortify/linux/string.h", + "include/linux/dlfcn_ext.h", + "include/linux/sigchain.h", + "include/linux/syscall_hooks.h", + "src/ldso/arm/linux/dlvsym.s", + "src/ldso/aarch64/linux/dlvsym.s", + "src/ldso/x86_64/linux/dlvsym.s", + "src/misc/aarch64/linux/fstat.s", + "src/misc/aarch64/linux/syscall.s", + "src/malloc/linux/calloc.c", + "src/malloc/linux/stats.c", + "src/sigchain/linux/sigchain.c", + "src/internal/linux/malloc_config.h", + "src/internal/linux/proc_xid_impl.h", + "src/internal/linux/malloc_random.h", + "src/internal/linux/musl_log.h", + "src/internal/linux/syscall_hooks.h", + "src/hook/linux/common_def.h", + "src/hook/linux/musl_fdtrack.h", + "src/hook/linux/musl_fdtrack_hook.h", + "src/hook/linux/musl_malloc_dispatch.h", + "src/hook/linux/musl_malloc_dispatch_table.h", + "src/hook/linux/musl_preinit_common.h", + "src/hook/linux/musl_malloc.h", + "src/hook/linux/musl_socket_dispatch.h", + "src/hook/linux/musl_socket_preinit_common.h", + "src/hook/linux/memory_trace.h", + "src/hook/linux/musl_socket.h", +] + +musl_src_linux_files = [ + "src/internal/malloc_config.h", + "src/internal/proc_xid_impl.h", + "src/internal/malloc_random.h", + "src/internal/musl_log.h", + "src/internal/syscall_hooks.h", + "src/hook/common_def.h", + "src/hook/musl_fdtrack.h", + "src/hook/musl_fdtrack_hook.h", + "src/hook/musl_malloc_dispatch.h", + "src/hook/musl_malloc_dispatch_table.h", + "src/hook/musl_preinit_common.h", + "src/hook/musl_malloc.h", + "src/hook/musl_socket_dispatch.h", + "src/hook/musl_socket_preinit_common.h", + "src/hook/memory_trace.h", + "src/hook/musl_socket.h", + "src/internal/musl_log.c", + "src/internal/vdso.c", + "src/hook/malloc_common.c", + "src/hook/musl_preinit.c", + "src/hook/musl_socket_preinit.c", + "src/hook/socket_common.c", + "src/hook/memory_trace.c", + "src/hook/musl_fdtrack.c", + "src/hook/musl_fdtrack_load.c", + "src/hook/musl_preinit_common.c", + "src/hook/musl_socket_preinit_common.c", + "crt/crtplus.c", + "src/linux/arm/flock.s", + "src/linux/aarch64/flock.s", + "src/linux/x86_64/flock.s", + "src/exit/assert.c", + "src/exit/atexit.c", + "src/fdsan/fdsan.c", "src/fortify/fortify.c", - "include/sys/capability.h", - "include/sys/reboot.h", - "include/sys/socket.h", - "include/sys/sysinfo.h", - "include/signal.h", - "include/sigchain.h", - "include/sched.h", - "src/internal/dynlink.h", - "include/sys/tgkill.h", - "include/trace/trace_marker.h", - "include/unistd.h", - "include/dlfcn.h", - "include/dlfcn_ext.h", - "src/fcntl/open.c", + "src/gwp_asan/gwp_asan.c", + "src/gwp_asan/gwp_asan.h", + "src/hilog/hilog_adapter.c", "src/hilog/hilog_common.h", + "src/hilog/output_p.inl", + "src/hilog/vsnprintf_s_p.c", "src/hilog/vsnprintf_s_p.h", - "src/internal/hilog_adapter.h", - "src/internal/musl_log.h", - "src/info/application_target_sdk_version.c", - "src/info/device_api_version.c", - "src/info/fatal_message.c", - "src/env/__init_tls.c", - "src/env/__libc_start_main.c", - "src/internal/pthread_impl.h", - "src/internal/locale_impl.h", - "src/internal/syscall.h", - "src/internal/services.h", - "src/internal/network_conf_function.h", - "src/internal/network_conf_function.c", - "src/internal/proc_xid_impl.h", - "ldso/namespace.h", - "ldso/ns_config.h", - "ldso/strops.h", - "src/legacy/ulimit.c", "src/linux/clone.c", "src/linux/getprocpid.c", - "src/linux/reboot.c", - "src/linux/tgkill.c", - "src/malloc/mallocng/malloc_usable_size.c", - "src/malloc/mallocng/malloc.c", - "src/malloc/mallocng/meta.h", - "src/malloc/mallocng/donate.c", - "src/malloc/mallocng/aligned_alloc.c", - "src/malloc/lite_malloc.c", - "src/malloc/stats.c", - "src/malloc/calloc.c", - "src/malloc/free.c", - "src/network/getnameinfo.c", - "src/malloc/libc_calloc.c", - "src/malloc/realloc.c", - "src/network/inet_legacy.c", - "src/network/lookup_name.c", - "src/network/lookup_serv.c", - "src/network/resolvconf.c", - "src/network/socket.c", - "src/passwd/getspnam_r.c", - "src/sched/sched_setparam.c", - "src/sched/sched_getparam.c", - "src/sched/sched_setscheduler.c", - "src/sched/sched_getscheduler.c", - "src/thread/arm/clone.s", - "src/thread/arm/syscall_cp.s", - "src/thread/pthread_mutex_clocklock.c", - "src/thread/pthread_mutex_timedlock.c", - "src/thread/pthread_mutex_lock.c", - "src/thread/pthread_mutex_timedlock_monotonic_np.c", - "src/thread/pthread_mutex_lock_timeout_np.c", - "src/thread/pthread_mutex_init.c", - "src/thread/pthread_rwlock_clockrdlock.c", - "src/thread/pthread_rwlock_timedrdlock.c", - "src/thread/pthread_rwlock_timedrdlock_monotonic_np.c", - "src/thread/pthread_rwlock_init.c", - "src/thread/pthread_cond_timedwait.c", - "src/thread/pthread_cond_timedwait_monotonic_np.c", - "src/thread/pthread_cond_timeout_np.c", - "src/thread/pthread_cond_clockwait.c", - "src/thread/pthread_cond_init.c", + "src/network/getaddrinfo.c", + "src/syscall_hooks/syscall_hooks.c", + "src/signal/sigaction.c", "src/thread/pthread_create.c", - "src/thread/pthread_rwlock_clockwrlock.c", - "src/thread/pthread_rwlock_timedwrlock_monotonic_np.c", - "src/thread/pthread_rwlock_timedwrlock.c", - "src/thread/pthread_sigmask.c", "src/trace/trace_marker.c", - "src/ldso/dlclose.c", - "src/ldso/dlerror.c", + "include/trace/trace_marker.h", + "src/info/application_target_sdk_version.c", + "src/info/device_api_version.c", + "src/info/fatal_message.c", + "ldso/cfi.c", "ldso/dynlink.c", - "src/exit/atexit.c", - "crt/arm/crti.s", - "crt/aarch64/crti.s", - "crt/crtplus.c", - "ldso/cfi.h", + "ldso/dynlink_rand.h", "ldso/ld_log.h", + "ldso/namespace.h", + "ldso/ns_config.h", + "ldso/strops.c", + "ldso/zip_archive.h", + "ldso/cfi.h", + "ldso/dynlink_rand.c", "ldso/ld_log.c", "ldso/namespace.c", "ldso/ns_config.c", - "ldso/strops.c", - "ldso/cfi.c", - "ldso/dynlink_rand.c", - "ldso/dynlink_rand.h", - "src/sched/sched_cpualloc.c", - "src/signal/signal.c", - "src/signal/sigaction.c", - "src/signal/siginterrupt.c", - "include/langinfo.h", - "include/locale.h", - "src/hilog/hilog_adapter.c", - "src/hilog/vsnprintf_s_p.c", - "src/internal/libc.h", - "src/locale/dcngettext.c", - "src/locale/locale_map.c", - "src/locale/langinfo.c", - "src/locale/newlocale.c", - "src/time/__tz.c", - "src/time/gmtime_r.c", - "src/time/strftime.c", - "src/time/strptime.c", - "src/time/time_impl.h", - "src/ldso/aarch64/dlvsym.s", + "ldso/strops.h", + "include/sys/capability.h", + "include/sys/cdefs.h", + "include/sys/sspret.h", + "include/info/application_target_sdk_version.h", + "include/info/device_api_version.h", + "include/info/fatal_message.h", + "include/fortify/fcntl.h", + "include/fortify/poll.h", + "include/fortify/stat.h", + "include/fortify/stdlib.h", + "include/fortify/unistd.h", + "include/fortify/fortify.h", + "include/fortify/socket.h", + "include/fortify/stdio.h", + "include/fortify/string.h", + "include/dlfcn_ext.h", + "include/sigchain.h", + "include/syscall_hooks.h", "src/ldso/arm/dlvsym.s", - "src/ldso/riscv64/dlvsym.s", + "src/ldso/aarch64/dlvsym.s", "src/ldso/x86_64/dlvsym.s", - "src/stdio/__fdopen.c", - "src/stdio/vfprintf.c", - "src/stdio/__stdio_read.c", - "src/stdio/__stdio_write.c", - "src/stdio/__stdout_write.c", - "src/stdio/fread.c", - "src/stdio/fmemopen.c", - "src/stdio/freopen.c", - "src/stdio/stdin.c", - "src/stdio/__fmodeflags.c", - "src/stdio/fopen.c", - "src/stdio/ofl.c", - "src/stdio/fclose.c", - "src/stdio/__toread.c", - "src/stdio/__towrite.c", - "src/stdio/stderr.c", - "src/stdio/fgets.c", - "src/stdio/vsnprintf.c", - "src/stdio/vsscanf.c", - "src/internal/stdio_impl.h", - "src/internal/vdso.c", - "src/time/clock_gettime.c", - "src/time/clock_getres.c", - "src/time/gettimeofday.c", - "src/time/time.c", - "src/unistd/getpid.c", - "src/process/_Fork.c", - "src/process/vfork.c", - "src/process/arm/__vfork.s", - "src/process/x86_64/__vfork.s", - "src/linux/cache.c", - "src/sched/sched_getcpu.c", - "src/sigchain/sigchain.c", - "src/conf/legacy.c", - "src/conf/sysconf.c", - "src/env/getenv.c", - "src/string/strcasecmp.c", - "src/string/strncasecmp.c", - "src/string/strncat.c", - "src/string/stpncpy.c", - "src/string/strncpy.c", - "src/stat/fstat.c", - "src/string/strcspn.c", - "src/thread/pthread_once.c", - "src/thread/pthread_cancel.c", - "src/mq/mq_notify.c", - "src/aio/aio.c", "src/misc/aarch64/fstat.s", "src/misc/aarch64/syscall.s", - "src/stdlib/strtol.c", - "src/stdlib/strtod.c", - "src/thread/sem_timedwait.c", - "src/stdio/vfscanf.c", - "src/stdio/fileno.c", + "src/malloc/calloc.c", + "src/malloc/stats.c", + "src/sigchain/sigchain.c", ] +if (musl_arch == "arm") { + musl_src_file += [ + "src/process/arm/__vfork.s", + "src/ldso/arm/dlvsym.s", + ] +} else if (musl_arch == "aarch64") { + musl_src_file += [ + "arch/aarch64/syscall_arch.h", + "src/misc/aarch64/fstat.s", + "src/misc/aarch64/syscall.s", + "src/ldso/aarch64/dlvsym.s", + ] +} else if (musl_arch == "loongarch64") { + musl_src_file += [ "arch/loongarch64/syscall_arch.h" ] +} else if (musl_arch == "x86_64") { + musl_src_file += [ + "src/process/x86_64/__vfork.s", + "src/ldso/x86_64/dlvsym.s", + ] +} + musl_inc_hook_files = [ - "//third_party/musl/porting/linux/user/src/internal/hilog_adapter.h", - "//third_party/musl/porting/linux/user/src/internal/musl_log.h", - "//third_party/musl/porting/linux/user/src/hook/memory_trace.h", - "//third_party/musl/porting/linux/user/src/hook/musl_malloc_dispatch_table.h", - "//third_party/musl/porting/linux/user/src/hook/musl_malloc_dispatch.h", - "//third_party/musl/porting/linux/user/src/hook/musl_preinit_common.h", + "//third_party/musl/src/internal/hilog_adapter.h", + "//third_party/musl/src/internal/linux/musl_log.h", + "//third_party/musl/src/hook/linux/memory_trace.h", + "//third_party/musl/src/hook/linux/musl_fdtrack.h", + "//third_party/musl/src/hook/linux/musl_fdtrack_hook.h", + "//third_party/musl/src/hook/linux/musl_malloc_dispatch_table.h", + "//third_party/musl/src/hook/linux/musl_malloc_dispatch.h", + "//third_party/musl/src/hook/linux/musl_preinit_common.h", + "//third_party/musl/src/hook/linux/musl_socket_dispatch.h", ] added_freebsd_files = [ - "$FREEBSD_DIR/contrib/gdtoa/strtod.c", - "$FREEBSD_DIR/contrib/gdtoa/gethex.c", - "$FREEBSD_DIR/contrib/gdtoa/smisc.c", - "$FREEBSD_DIR/contrib/gdtoa/misc.c", - "$FREEBSD_DIR/contrib/gdtoa/strtord.c", - "$FREEBSD_DIR/contrib/gdtoa/hexnan.c", - "$FREEBSD_DIR/contrib/gdtoa/gmisc.c", - "$FREEBSD_DIR/contrib/gdtoa/hd_init.c", - "$FREEBSD_DIR/contrib/gdtoa/strtodg.c", - "$FREEBSD_DIR/contrib/gdtoa/ulp.c", - "$FREEBSD_DIR/contrib/gdtoa/strtof.c", - "$FREEBSD_DIR/contrib/gdtoa/sum.c", - "$FREEBSD_DIR/lib/libc/gdtoa/glue.c", - "$FREEBSD_DIR/lib/libc/stdio/parsefloat.c", + "$FREEBSD_DIR/contrib/tcp_wrappers/strcasecmp.c", + "$FREEBSD_DIR/lib/libc/gen/arc4random.c", + "$FREEBSD_DIR/lib/libc/gen/arc4random_uniform.c", + "$FREEBSD_DIR/lib/libc/stdlib/qsort.c", + "$FREEBSD_DIR/lib/libc/stdlib/strtoimax.c", + "$FREEBSD_DIR/lib/libc/stdlib/strtoul.c", + "$FREEBSD_DIR/lib/libc/stdlib/strtoumax.c", ] +freebsd_headers = [ "$FREEBSD_DIR/contrib/libexecinfo/execinfo.h" ] + freebsd_sys_headers = [ "$FREEBSD_DIR/sys/sys/queue.h" ] diff --git a/build/third_party_gn/musl/musl_template.gni b/build/third_party_gn/musl/musl_template.gni index 21f5dd2c10f19c62b0f37623336aad1a4ad6704f..c62f882fa666d5916e7a52046c09ac0d5266cd17 100644 --- a/build/third_party_gn/musl/musl_template.gni +++ b/build/third_party_gn/musl/musl_template.gni @@ -170,8 +170,8 @@ template("musl_libs") { ] } - if (!is_standard_system && defined(enable_musl_log)) { - if (enable_musl_log) { + if (!is_standard_system && defined(musl_enable_musl_log)) { + if (musl_enable_musl_log) { defines += [ "ENABLE_MUSL_LOG" ] } } @@ -302,6 +302,7 @@ template("musl_libs") { "//third_party/jemalloc/include/", "//third_party/jemalloc/include/jemalloc/internal", "//third_party/jemalloc/include/jemalloc", + "//third_party/FreeBSD/contrib/libexecinfo", ] } @@ -333,25 +334,43 @@ template("musl_libs") { source_set("soft_musl_src") { sources_orig = [] sources = [] - + include_dirs = [] sources_orig = musl_src_arch_file + musl_src_file + sources_orig -= musl_src_filterout sources_orig -= [ - "src/env/__stack_chk_fail.c", - "src/env/__libc_start_main.c", - "src/env/__init_tls.c", - "src/string/memset.c", "src/string/mempcpy.c", + "src/string/memset.c", + "src/env/__init_tls.c", + "src/env/__libc_start_main.c", + "src/env/__stack_chk_fail.c", "src/stdlib/qsort.c", "src/stdlib/qsort_nr.c", - ] - if (musl_arch == "mips") { - sources_orig += [ "src/string/memset.c" ] - } - sources_orig -= musl_src_filterout - - sources += [ - "$FREEBSD_DIR/contrib/tcp_wrappers/strcasecmp.c", - "$FREEBSD_DIR/lib/libc/stdlib/qsort.c", + "src/string/strncpy.c", + ] + + freebsd_files = [ + "//third_party/FreeBSD/contrib/gdtoa/strtod.c", + "//third_party/FreeBSD/contrib/gdtoa/gethex.c", + "//third_party/FreeBSD/contrib/gdtoa/smisc.c", + "//third_party/FreeBSD/contrib/gdtoa/misc.c", + "//third_party/FreeBSD/contrib/gdtoa/strtord.c", + "//third_party/FreeBSD/contrib/gdtoa/hexnan.c", + "//third_party/FreeBSD/contrib/gdtoa/gmisc.c", + "//third_party/FreeBSD/contrib/gdtoa/hd_init.c", + "//third_party/FreeBSD/contrib/gdtoa/strtodg.c", + "//third_party/FreeBSD/contrib/gdtoa/ulp.c", + "//third_party/FreeBSD/contrib/gdtoa/strtof.c", + "//third_party/FreeBSD/contrib/gdtoa/sum.c", + "//third_party/FreeBSD/lib/libc/gdtoa/glue.c", + "//third_party/FreeBSD/lib/libc/stdio/parsefloat.c", + "//third_party/FreeBSD/contrib/tcp_wrappers/strcasecmp.c", + "//third_party/FreeBSD/lib/libc/gen/arc4random.c", + "//third_party/FreeBSD/lib/libc/gen/arc4random_uniform.c", + "//third_party/FreeBSD/lib/libc/stdlib/qsort.c", + "//third_party/FreeBSD/lib/libc/stdlib/strtoimax.c", + "//third_party/FreeBSD/lib/libc/stdlib/strtoul.c", + "//third_party/FreeBSD/lib/libc/stdlib/strtoumax.c", + "//third_party/musl/third_party/openbsd/lib/libc/string/strncpy.c", ] if (musl_arch == "arm") { @@ -382,6 +401,7 @@ template("musl_libs") { "src/math/powl.c", "src/math/sinf.c", "src/math/cosf.c", + "src/linux/flock.c", ] } else if (musl_arch == "aarch64") { sources_orig -= [ @@ -416,12 +436,23 @@ template("musl_libs") { "src/math/sincos.c", "src/math/pow.c", "src/math/powf.c", + "src/linux/flock.c", ] } else if (musl_arch == "x86_64") { - sources_orig -= [ "src/thread/${musl_arch}/__set_thread_area.s" ] + sources_orig -= [ + "src/thread/${musl_arch}/__set_thread_area.s", + "src/linux/flock.c", + ] } defines = [] + defines += [ "FEATURE_ICU_LOCALE" ] + + # There are two ways to implement cxa_thread_atexit_impl: + # - CXA_THREAD_USE_TSD(default): use pthread_key_xxx to implement cxa_thread_atexit_impl. + # - CXA_THREAD_USE_TLS: put dtors in pthread to implement cxa_thread_atexit_impl. + defines += [ "CXA_THREAD_USE_TSD" ] + if (musl_arch == "arm") { defines += [ "MUSL_ARM_ARCH" ] } @@ -477,8 +508,7 @@ template("musl_libs") { "$OPTRTDIR/string/arm/strcmp.S", "$OPTRTDIR/string/arm/strlen-armv6t2.S", ] - - sources += added_freebsd_files + sources += freebsd_files asmflags = [ "-D__memcpy_arm = memcpy", "-D__memchr_arm = memchr", @@ -487,6 +517,7 @@ template("musl_libs") { "-D__strlen_armv6t2 = strlen", ] } else if (musl_arch == "aarch64") { + sources += freebsd_files if (defined(ARM_FEATURE_SVE)) { sources += [ "$OPTRTDIR/string/aarch64/memchr-sve.S", @@ -565,7 +596,6 @@ template("musl_libs") { "$OPTRTDIR/string/aarch64/strnlen.S", "$OPTRTDIR/string/aarch64/strrchr.S", ] - sources += added_freebsd_files asmflags = [ "-D__memmove_aarch64 = memmove", "-D__memcpy_aarch64 = memcpy", @@ -588,37 +618,19 @@ template("musl_libs") { cflags = [ "-O3", "-fPIC", - "-ffreestanding", "-fstack-protector-strong", - "-flto", ] - if (use_jemalloc) { - defines += [ "USE_JEMALLOC" ] - if (use_jemalloc_dfx_intf) { - defines += [ "USE_JEMALLOC_DFX_INTF" ] - } - include_dirs = [ "//third_party/jemalloc/include/jemalloc" ] - } - - if (!defined(include_dirs)) { - if (musl_arch == "aarch64") { - include_dirs = [ "//third_party/FreeBSD/lib/libc/aarch64" ] - } - if (musl_arch == "arm") { - include_dirs = [ "//third_party/FreeBSD/lib/libc/arm" ] - } - } else { - if (musl_arch == "aarch64") { - include_dirs += [ "//third_party/FreeBSD/lib/libc/aarch64" ] - } - if (musl_arch == "arm") { - include_dirs += [ "//third_party/FreeBSD/lib/libc/arm" ] - } - } - configs -= musl_inherited_configs configs += [ ":soft_musl_config" ] + if (musl_arch == "aarch64") { + include_dirs += [ "//third_party/FreeBSD/lib/libc/aarch64" ] + } else if (musl_arch == "arm") { + include_dirs += [ "//third_party/FreeBSD/lib/libc/arm" ] + } + include_dirs += [ "//third_party/FreeBSD/lib/libc/include" ] + include_dirs += [ "//third_party/FreeBSD/contrib/libexecinfo" ] + include_dirs += [ "//third_party/FreeBSD/crypto/openssh/openbsd-compat" ] if (!defined(defines)) { defines = [] @@ -633,7 +645,8 @@ template("musl_libs") { defines += [ "TARGET_GUARD_SIZE=${_product_config.device_guard_size}" ] } } - + external_deps = [] + external_deps += [ "FreeBSD:libc_static" ] deps = porting_deps } @@ -827,6 +840,8 @@ template("musl_libs") { ":soft_musl_src_nossp", ":soft_musl_src_optimize", ] + external_deps = [] + external_deps = [ "FreeBSD:libc_static" ] output_name = "libc" complete_static_lib = true } diff --git a/build/third_party_gn/openssl/BUILD.gn b/build/third_party_gn/openssl/BUILD.gn index 0b311628d66d8c7ea64c6fe3e95da9d81b267c9c..cae0e8ea69d4ef5c96eb868b3671c7ee6ae3b524 100644 --- a/build/third_party_gn/openssl/BUILD.gn +++ b/build/third_party_gn/openssl/BUILD.gn @@ -636,6 +636,10 @@ libdefault_common_sources = [ "//third_party/openssl/providers/implementations/ciphers/cipher_cts.c", "//third_party/openssl/providers/implementations/ciphers/cipher_null.c", "//third_party/openssl/providers/implementations/ciphers/cipher_sm4.c", + "//third_party/openssl/providers/implementations/ciphers/cipher_sm4_ccm.c", + "//third_party/openssl/providers/implementations/ciphers/cipher_sm4_ccm_hw.c", + "//third_party/openssl/providers/implementations/ciphers/cipher_sm4_gcm.c", + "//third_party/openssl/providers/implementations/ciphers/cipher_sm4_gcm_hw.c", "//third_party/openssl/providers/implementations/ciphers/cipher_sm4_hw.c", "//third_party/openssl/providers/implementations/ciphers/cipher_tdes.c", "//third_party/openssl/providers/implementations/ciphers/cipher_tdes_common.c", diff --git a/bundle.json b/bundle.json index 818542d818c16abc21fb636d877623863a5a439c..4b3ca904e064db31b970b68e38a83dc4da9e561c 100644 --- a/bundle.json +++ b/bundle.json @@ -34,7 +34,6 @@ "libuv", "cJSON", "openssl", - "zlib", "ffrt" ], "third_party": [] diff --git a/inspector/BUILD.gn b/inspector/BUILD.gn index 68cd485affa2d43f546791f98a9449d60b2b02c3..ed21732614f9decd6f01e42641b8cf13ecb437c3 100644 --- a/inspector/BUILD.gn +++ b/inspector/BUILD.gn @@ -43,6 +43,11 @@ ohos_source_set("ark_debugger_static") { external_deps += [ "bounds_checking_function:libsec_shared" ] deps += hiviewdfx_deps + if (is_ohos && is_standard_system && !is_arkui_x) { + defines += [ "ENABLE_FFRT_INTERFACES" ] + external_deps += [ "ffrt:libffrt" ] + } + configs = [ "..:ark_toolchain_common_config" ] subsystem_name = "arkcompiler" part_name = "toolchain" @@ -64,6 +69,7 @@ ohos_shared_library("ark_debugger") { innerapi_tags = [ "platformsdk" ] subsystem_name = "arkcompiler" part_name = "toolchain" + output_name = "ark_inspector" } ohos_source_set("connectserver_debugger_static") { @@ -113,4 +119,5 @@ ohos_shared_library("connectserver_debugger") { innerapi_tags = [ "platformsdk" ] subsystem_name = "arkcompiler" part_name = "toolchain" + output_name = "ark_connect_inspector" } diff --git a/inspector/connect_inspector.cpp b/inspector/connect_inspector.cpp index 200d2842bc081437fe47a030c1b10cfafd2476be..7622db24f9a025dbed13f4fa4a31c99411966565 100644 --- a/inspector/connect_inspector.cpp +++ b/inspector/connect_inspector.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -26,6 +26,8 @@ static constexpr char REQUEST_MESSAGE[] = "tree"; static constexpr char STOPDEBUGGER_MESSAGE[] = "stopDebugger"; static constexpr char OPEN_ARKUI_STATE_PROFILER[] = "ArkUIStateProfilerOpen"; static constexpr char CLOSE_ARKUI_STATE_PROFILER[] = "ArkUIStateProfilerClose"; +static constexpr char START_RECORD_MESSAGE[] = "rsNodeStartRecord"; +static constexpr char STOP_RECORD_MESSAGE[] = "rsNodeStopRecord"; std::function g_setConnectCallBack; void* HandleDebugManager(void* const server) @@ -67,6 +69,25 @@ void OnOpenMessage(const std::string& message) } } +void OnInspectorRecordMessage(const std::string& message) +{ + if (message.find(START_RECORD_MESSAGE, 0) != std::string::npos) { + if (g_inspector->startRecord_ != nullptr && !g_inspector->isRecording_) { + LOGI("record start"); + g_inspector->startRecord_(); + g_inspector->isRecording_ = true; + } + } + + if (message.find(STOP_RECORD_MESSAGE, 0) != std::string::npos) { + if (g_inspector->stopRecord_ != nullptr && g_inspector->isRecording_) { + LOGI("record stop"); + g_inspector->stopRecord_(); + g_inspector->isRecording_ = false; + } + } +} + void OnMessage(const std::string& message) { std::lock_guard lock(g_connectMutex); @@ -74,12 +95,10 @@ void OnMessage(const std::string& message) LOGE("message is empty"); return; } - LOGI("ConnectServer OnMessage: %{public}s", message.c_str()); if (g_inspector != nullptr && g_inspector->connectServer_ != nullptr) { g_inspector->ideMsgQueue_.push(message); OnConnectedMessage(message); - OnOpenMessage(message); if (message.find(CLOSE_MESSAGE, 0) != std::string::npos) { if (g_setConnectCallBack != nullptr) { @@ -115,6 +134,7 @@ void OnMessage(const std::string& message) g_inspector->setDebugMode_(); } } + OnInspectorRecordMessage(message); } } @@ -269,4 +289,14 @@ void SetProfilerCallback(const std::function &setArkUIStateProfilerS g_inspector->setArkUIStateProfilerStatus_ = setArkUIStateProfilerStatus; } +void SetRecordCallback(const std::function &startRecordFunc, + const std::function &stopRecordFunc) +{ + std::lock_guard lock(g_connectMutex); + if (g_inspector == nullptr) { + g_inspector = std::make_unique(); + } + g_inspector->startRecord_ = startRecordFunc; + g_inspector->stopRecord_ = stopRecordFunc; +} } // OHOS::ArkCompiler::Toolchain diff --git a/inspector/connect_inspector.h b/inspector/connect_inspector.h index 4225304f53635762659b4d854707e32914a2072f..2d0420a8dadf8afe1a6f687aef5dde960b9d23ac 100644 --- a/inspector/connect_inspector.h +++ b/inspector/connect_inspector.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -59,6 +59,9 @@ void SetSwitchCallBack(const std::function& setSwitchStatus, void SetProfilerCallback(const std::function &setArkUIStateProfilerStatus); +void SetRecordCallback(const std::function &startRecordFunc, + const std::function &stopRecordFunc); + #ifdef __cplusplus #if __cplusplus } @@ -86,6 +89,9 @@ public: std::function createLayoutInfo_; std::function setDebugMode_; int32_t instanceId_ = -1; + std::function startRecord_; + std::function stopRecord_; + bool isRecording_ = false; }; } // namespace OHOS::ArkCompiler::Toolchain diff --git a/inspector/inspector.cpp b/inspector/inspector.cpp index 3b77b608e65784c43780ed585e0d5488e322004a..f684b793ff22778aa3e09e03e60d4c59c38525cb 100644 --- a/inspector/inspector.cpp +++ b/inspector/inspector.cpp @@ -33,6 +33,10 @@ #include "tooling/debugger_service.h" #endif +#if defined(ENABLE_FFRT_INTERFACES) +#include "ffrt.h" +#endif + namespace OHOS::ArkCompiler::Toolchain { namespace { enum DispatchStatus : int32_t { @@ -67,11 +71,11 @@ thread_local void* g_vm = nullptr; #if !defined(IOS_PLATFORM) #if defined(WINDOWS_PLATFORM) -constexpr char ARK_DEBUGGER_SHARED_LIB[] = "libark_ecma_debugger.dll"; +constexpr char ARK_DEBUGGER_SHARED_LIB[] = "libark_tooling.dll"; #elif defined(MAC_PLATFORM) -constexpr char ARK_DEBUGGER_SHARED_LIB[] = "libark_ecma_debugger.dylib"; +constexpr char ARK_DEBUGGER_SHARED_LIB[] = "libark_tooling.dylib"; #else -constexpr char ARK_DEBUGGER_SHARED_LIB[] = "libark_ecma_debugger.so"; +constexpr char ARK_DEBUGGER_SHARED_LIB[] = "libark_tooling.so"; #endif #endif @@ -281,20 +285,37 @@ void Inspector::OnMessage(std::string&& msg) }); } else { #if defined(OHOS_PLATFORM) - debuggerPostTask_([tid = tidForSocketPair_, vm = vm_] { - if (tid != static_cast(syscall(SYS_gettid))) { + debuggerPostTask_([tid = tidForSocketPair_, vm = vm_, this] { + uint64_t threadOrTaskId = GetThreadOrTaskId(); + if (tid != static_cast(threadOrTaskId)) { LOGE("Task not in debugger thread for socketpair"); return; } g_processMessage(vm); }); -#endif +#endif // defined(OHOS_PLATFORM) } } else { LOGW("No debuggerPostTask provided"); } } +#if defined(OHOS_PLATFORM) +uint64_t Inspector::GetThreadOrTaskId() +{ +#if defined(ENABLE_FFRT_INTERFACES) + uint64_t threadOrTaskId = ffrt_this_task_get_id(); + if (threadOrTaskId != 0) { + return threadOrTaskId; + } else { + return static_cast(getproctid()); + } +#else + return static_cast(getproctid()); +#endif // defined(ENABLE_FFRT_INTERFACES) +} +#endif // defined(OHOS_PLATFORM) + const DebuggerPostTask &GetDebuggerPostTask(int tid) { std::shared_lock lock(g_mutex); diff --git a/inspector/inspector.h b/inspector/inspector.h index f4f890dbc3cf1cf9042255e50048c945b911d6c3..893eac981b23a446f1ed2ac0118677c4dfed3e79 100644 --- a/inspector/inspector.h +++ b/inspector/inspector.h @@ -57,6 +57,9 @@ public: ~Inspector() = default; void OnMessage(std::string&& msg); +#if defined(OHOS_PLATFORM) + uint64_t GetThreadOrTaskId(); +#endif // defined(OHOS_PLATFORM) static constexpr int32_t DELAY_CHECK_DISPATCH_STATUS = 100; diff --git a/inspector/test/BUILD.gn b/inspector/test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4153eb438535faba525b090d29df14adaf56d7a9 --- /dev/null +++ b/inspector/test/BUILD.gn @@ -0,0 +1,69 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//arkcompiler/toolchain/test/test_helper.gni") +import("//arkcompiler/toolchain/toolchain.gni") + +module_output_path = "arkcompiler/toolchain" + +host_unittest_action("InspectorConnectTest") { + module_out_path = module_output_path + + include_dirs = [ "$toolchain_root/inspector" ] + + sources = [ + # test file + "connect_server_test.cpp", + ] + + configs = [ "$toolchain_root:toolchain_test_config" ] + + deps = [ + "$toolchain_root/inspector:connectserver_debugger", + "$toolchain_root/websocket:websocket_client", + "$toolchain_root/websocket:websocket_server", + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + if (is_arkui_x && target_os == "ios") { + external_deps += [ "openssl:libcrypto_static" ] + } else { + external_deps += [ "openssl:libcrypto_shared" ] + } + + external_deps += [ "bounds_checking_function:libsec_shared" ] + deps += hiviewdfx_deps +} + +group("unittest") { + testonly = true + + # deps file + deps = [ ":InspectorConnectTest" ] + + if (is_mac) { + deps -= [ ":InspectorConnectTest" ] + } +} + +group("host_unittest") { + testonly = true + + # deps file + deps = [ ":InspectorConnectTestAction" ] + + if (is_mac) { + deps -= [ ":InspectorConnectTestAction" ] + } +} diff --git a/inspector/test/connect_server_test.cpp b/inspector/test/connect_server_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f589c6b498ffde2ddb4c1af68427e8e91e1084f1 --- /dev/null +++ b/inspector/test/connect_server_test.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include "inspector/connect_inspector.h" +#include "inspector/connect_server.h" +#include "websocket/client/websocket_client.h" +#include "websocket/server/websocket_server.h" + +using namespace OHOS::ArkCompiler::Toolchain; + +namespace panda::test { +class ConnectServerTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "ConnectServerTest::SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "ConnectServerTest::TearDownTestCase"; + } + + void SetUp() override {} + + void TearDown() override {} +#if defined(OHOS_PLATFORM) + static constexpr char CONNECTED_MESSAGE_TEST[] = "connected"; + static constexpr char OPEN_MESSAGE_TEST[] = "layoutOpen"; + static constexpr char CLOSE_MESSAGE_TEST[] = "layoutClose"; + static constexpr char REQUEST_MESSAGE_TEST[] = "tree"; + static constexpr char STOPDEBUGGER_MESSAGE_TEST[] = "stopDebugger"; + static constexpr char OPEN_ARKUI_STATE_PROFILER_TEST[] = "ArkUIStateProfilerOpen"; + static constexpr char CLOSE_ARKUI_STATE_PROFILER_TEST[] = "ArkUIStateProfilerClose"; + static constexpr char START_RECORD_MESSAGE_TEST[] = "rsNodeStartRecord"; + static constexpr char STOP_RECORD_MESSAGE_TEST[] = "rsNodeStopRecord"; + + static constexpr char HELLO_INSPECTOR_CLIENT[] = "hello inspector client"; + static constexpr char INSPECTOR_SERVER_OK[] = "inspector server ok"; + static constexpr char INSPECTOR_RUN[] = "inspector run"; + static constexpr char INSPECTOR_QUIT[] = "inspector quit"; +#endif +}; + +bool g_profilerFlag = false; +bool g_connectFlag = false; +bool g_switchStatus = false; +int32_t g_createInfoId = 0; +int32_t g_instanceId = 1; + +void CallbackInit() +{ + auto profilerCb = [](bool flag) -> void { + g_profilerFlag = flag; + }; + SetProfilerCallback(profilerCb); + + auto connectCb = [](bool flag) -> void { + g_connectFlag = flag; + }; + SetConnectCallback(connectCb); + + auto debugModeCb = []() -> void { + GTEST_LOG_(INFO) << "Execute DebugModeCallBack."; + }; + SetDebugModeCallBack(debugModeCb); + + auto switchStatusCb = [](bool flag) -> void { + g_switchStatus = flag; + }; + auto createInfoCb = [](int32_t id) -> void { + g_createInfoId = id; + }; + SetSwitchCallBack(switchStatusCb, createInfoCb, g_instanceId); + + auto startRecordFunc = []() -> void {}; + auto stopRecordFunc = []() -> void {}; + SetRecordCallback(startRecordFunc, stopRecordFunc); + GTEST_LOG_(INFO) << "ConnectServerTest::CallbackInit finished"; +} + +HWTEST_F(ConnectServerTest, InspectorBasicTest, testing::ext::TestSize.Level0) +{ + ASSERT_TRUE(WaitForConnection()); +} + +HWTEST_F(ConnectServerTest, InspectorConnectTest, testing::ext::TestSize.Level0) +{ + CallbackInit(); +#if defined(OHOS_PLATFORM) + int appPid = getprocpid(); + int oldProcessfd = -2; + StartServerForSocketPair(oldProcessfd); + StoreMessage(g_instanceId, HELLO_INSPECTOR_CLIENT); + pid_t pid = fork(); + if (pid == 0) { + WebSocketClient clientSocket; + ASSERT_TRUE(clientSocket.InitToolchainWebSocketForSockName(std::to_string(appPid))); + ASSERT_TRUE(clientSocket.ClientSendWSUpgradeReq()); + ASSERT_TRUE(clientSocket.ClientRecvWSUpgradeRsp()); + EXPECT_TRUE(clientSocket.SendReply(OPEN_ARKUI_STATE_PROFILER_TEST)); + EXPECT_TRUE(clientSocket.SendReply(REQUEST_MESSAGE_TEST)); + EXPECT_TRUE(clientSocket.SendReply(OPEN_MESSAGE_TEST)); + EXPECT_TRUE(clientSocket.SendReply(CONNECTED_MESSAGE_TEST)); + EXPECT_TRUE(clientSocket.SendReply(START_RECORD_MESSAGE_TEST)); + EXPECT_TRUE(clientSocket.SendReply(STOP_RECORD_MESSAGE_TEST)); + + EXPECT_STREQ(clientSocket.Decode().c_str(), HELLO_INSPECTOR_CLIENT); + + std::string recv = clientSocket.Decode(); + EXPECT_STREQ(recv.c_str(), INSPECTOR_SERVER_OK); + if (strcmp(recv.c_str(), INSPECTOR_SERVER_OK) == 0) { + EXPECT_TRUE(clientSocket.SendReply(CLOSE_MESSAGE_TEST)); + EXPECT_TRUE(clientSocket.SendReply(STOPDEBUGGER_MESSAGE_TEST)); + EXPECT_TRUE(clientSocket.SendReply(CLOSE_ARKUI_STATE_PROFILER_TEST)); + } + + EXPECT_STREQ(clientSocket.Decode().c_str(), INSPECTOR_RUN); + EXPECT_STREQ(clientSocket.Decode().c_str(), INSPECTOR_QUIT); + clientSocket.Close(); + exit(0); + } else if (pid > 0) { + // Waiting for executing the message instruction sent by the client + sleep(2); + ASSERT_TRUE(g_profilerFlag); + ASSERT_EQ(g_createInfoId, g_instanceId); + ASSERT_TRUE(g_switchStatus); + ASSERT_TRUE(g_connectFlag); + ASSERT_FALSE(WaitForConnection()); + + SendMessage(INSPECTOR_SERVER_OK); + SendLayoutMessage(INSPECTOR_RUN); + + // Waiting for executing the message instruction sent by the client + sleep(2); + ASSERT_FALSE(g_profilerFlag); + ASSERT_FALSE(g_switchStatus); + ASSERT_FALSE(g_connectFlag); + + SendProfilerMessage(INSPECTOR_QUIT); + + StopServer("InspectorConnectTest"); + } else { + std::cerr << "InspectorConnectTest::fork failed" << std::endl; + } + RemoveMessage(g_instanceId); +#endif +} + +} // namespace panda::test \ No newline at end of file diff --git a/inspector/ws_server.cpp b/inspector/ws_server.cpp index 9d6ee164d838efff51fb78547d6abc4d4bd195f2..0a77d285b1d10812a023267906022fa18da0e68e 100644 --- a/inspector/ws_server.cpp +++ b/inspector/ws_server.cpp @@ -116,9 +116,7 @@ void WsServer::StopServer() webSocket_->Close(); } } -#if defined(OHOS_PLATFORM) pthread_join(tid_, nullptr); -#endif if (webSocket_ != nullptr) { webSocket_.reset(); } diff --git a/test/resource/tooling/ohos_test.xml b/test/resource/tooling/ohos_test.xml index a733d13e32a5499b4157a90a530a424e0d399741..5b9dc623bc688c595e4b79096efbd3052be9a5a5 100755 --- a/test/resource/tooling/ohos_test.xml +++ b/test/resource/tooling/ohos_test.xml @@ -275,4 +275,9 @@