From 7f1076e779c8663dad4b9cf88f932b423598f5d4 Mon Sep 17 00:00:00 2001 From: zhangchen168 Date: Tue, 14 Mar 2023 14:34:09 +0800 Subject: [PATCH 1/3] Support trustworthiness building of typescript Issue: https://gitee.com/openharmony/third_party_typescript/issues/I6LJEX Signed-off-by: zhangchen168 Change-Id: Ice7ca0817b4c93b86e2e1ed4b2c56fcce9845ead --- ts2panda/BUILD.gn | 37 +++++++++++++++------- ts2panda/deps/ohos-typescript-4.2.3-r2.tgz | 1 - ts2panda/npm_install_tsc.py | 23 ++++++++++++++ ts2panda/package-lock.json | 5 --- ts2panda/package.json | 1 - 5 files changed, 48 insertions(+), 19 deletions(-) delete mode 120000 ts2panda/deps/ohos-typescript-4.2.3-r2.tgz create mode 100755 ts2panda/npm_install_tsc.py diff --git a/ts2panda/BUILD.gn b/ts2panda/BUILD.gn index 0e47d53baa..ed16f02e67 100755 --- a/ts2panda/BUILD.gn +++ b/ts2panda/BUILD.gn @@ -35,10 +35,22 @@ group("ts2abc_src") { } } +action("npm_install_tsc") { + deps = [ "//third_party/typescript:build_typescript" ] + script = "npm_install_tsc.py" + args = [ + rebase_path("${root_build_dir}/typescript/typescript-4.2.3-r2.tgz"), + rebase_path("//prebuilts/build-tools/common/ts2abc"), + rebase_path(get_path_info("./", "abspath")), + ] + outputs = [ "${target_out_dir}/${target_name}.stamp" ] +} + ohos_copy("node_modules") { sources = [ rebase_path("${node_modules}") ] outputs = [ target_out_dir + "/node_modules" ] module_install_name = "" + deps = [ ":npm_install_tsc" ] } ohos_copy("config_files") { @@ -54,8 +66,7 @@ ohos_copy("config_files") { } ohos_copy("ts2abc_deps") { - sources = - [ "//third_party/typescript/build_package/ohos-typescript-4.2.3-r2.tgz" ] + sources = [ "${root_build_dir}/typescript/typescript-4.2.3-r2.tgz" ] outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] module_source_dir = target_out_dir + "/$target_name" @@ -63,11 +74,11 @@ ohos_copy("ts2abc_deps") { license_file = "//third_party/typescript/LICENSE" part_name = "ets_frontend" subsystem_name = "arkcompiler" + deps = [ "//third_party/typescript:build_typescript" ] } ohos_copy("ts2abc_deps_ets") { - sources = - [ "//third_party/typescript/build_package/ohos-typescript-4.2.3-r2.tgz" ] + sources = [ "${root_build_dir}/typescript/typescript-4.2.3-r2.tgz" ] outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] module_source_dir = target_out_dir + "/$target_name" @@ -75,11 +86,11 @@ ohos_copy("ts2abc_deps_ets") { license_file = "//third_party/typescript/LICENSE" part_name = "ets_frontend" subsystem_name = "arkcompiler" + deps = [ "//third_party/typescript:build_typescript" ] } ohos_copy("ts2abc_deps_win") { - sources = - [ "//third_party/typescript/build_package/ohos-typescript-4.2.3-r2.tgz" ] + sources = [ "${root_build_dir}/typescript/typescript-4.2.3-r2.tgz" ] outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] module_source_dir = target_out_dir + "/$target_name" @@ -87,11 +98,11 @@ ohos_copy("ts2abc_deps_win") { license_file = "//third_party/typescript/LICENSE" part_name = "ets_frontend" subsystem_name = "arkcompiler" + deps = [ "//third_party/typescript:build_typescript" ] } ohos_copy("ts2abc_deps_win_ets") { - sources = - [ "//third_party/typescript/build_package/ohos-typescript-4.2.3-r2.tgz" ] + sources = [ "${root_build_dir}/typescript/typescript-4.2.3-r2.tgz" ] outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] module_source_dir = target_out_dir + "/$target_name" @@ -99,11 +110,11 @@ ohos_copy("ts2abc_deps_win_ets") { license_file = "//third_party/typescript/LICENSE" part_name = "ets_frontend" subsystem_name = "arkcompiler" + deps = [ "//third_party/typescript:build_typescript" ] } ohos_copy("ts2abc_deps_mac") { - sources = - [ "//third_party/typescript/build_package/ohos-typescript-4.2.3-r2.tgz" ] + sources = [ "${root_build_dir}/typescript/typescript-4.2.3-r2.tgz" ] outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] module_source_dir = target_out_dir + "/$target_name" @@ -111,11 +122,11 @@ ohos_copy("ts2abc_deps_mac") { license_file = "//third_party/typescript/LICENSE" part_name = "ets_frontend" subsystem_name = "arkcompiler" + deps = [ "//third_party/typescript:build_typescript" ] } ohos_copy("ts2abc_deps_mac_ets") { - sources = - [ "//third_party/typescript/build_package/ohos-typescript-4.2.3-r2.tgz" ] + sources = [ "${root_build_dir}/typescript/typescript-4.2.3-r2.tgz" ] outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] module_source_dir = target_out_dir + "/$target_name" @@ -123,6 +134,7 @@ ohos_copy("ts2abc_deps_mac_ets") { license_file = "//third_party/typescript/LICENSE" part_name = "ets_frontend" subsystem_name = "arkcompiler" + deps = [ "//third_party/typescript:build_typescript" ] } action("ts2abc_diagnostic_ts") { @@ -160,6 +172,7 @@ action("npm_run_build") { deps = [ "$ts2abc_root:config_files", "$ts2abc_root:node_modules", + "$ts2abc_root:npm_install_tsc", "$ts2abc_root:ts2abc_diagnostic_ts", "$ts2abc_root:ts2abc_irnodes_ts", "$ts2abc_root:ts2abc_src", diff --git a/ts2panda/deps/ohos-typescript-4.2.3-r2.tgz b/ts2panda/deps/ohos-typescript-4.2.3-r2.tgz deleted file mode 120000 index 03a9d71c86..0000000000 --- a/ts2panda/deps/ohos-typescript-4.2.3-r2.tgz +++ /dev/null @@ -1 +0,0 @@ -../../../../third_party/typescript/build_package/ohos-typescript-4.2.3-r2.tgz \ No newline at end of file diff --git a/ts2panda/npm_install_tsc.py b/ts2panda/npm_install_tsc.py new file mode 100755 index 0000000000..fd3274c615 --- /dev/null +++ b/ts2panda/npm_install_tsc.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +import sys +import subprocess + +def run_cmd(cmd, execution_path = None): + res = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stdin=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd=execution_path, + shell=True) + sout, serr = res.communicate() + res.wait() + return res.pid, res.returncode, sout, serr + +def run(args): + tsc_path =args[0] + cmd = " ".join(["npm", "install", tsc_path, "--legacy-peer-deps"]) + run_cmd(cmd, args[1]) + run_cmd(cmd, args[2]) + +if __name__ == "__main__": + run(sys.argv[1:]) \ No newline at end of file diff --git a/ts2panda/package-lock.json b/ts2panda/package-lock.json index 17e3f56ffd..c65c43458f 100644 --- a/ts2panda/package-lock.json +++ b/ts2panda/package-lock.json @@ -4468,11 +4468,6 @@ "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", "dev": true }, - "typescript": { - "version": "file:deps/ohos-typescript-4.2.3-r2.tgz", - "integrity": "sha512-Kw2DlAAicDbrE0iPhktxkw9AaujBy2N0qILDVuR/DKaJcd2Jo26kBQdheHKRFkyF8h+OYwZgjOpzUjn3eNLMyg==", - "dev": true - }, "typical": { "version": "4.0.0", "resolved": "https://repo.huaweicloud.com/repository/npm/typical/-/typical-4.0.0.tgz", diff --git a/ts2panda/package.json b/ts2panda/package.json index 9b94500b79..e8e69543fd 100644 --- a/ts2panda/package.json +++ b/ts2panda/package.json @@ -29,7 +29,6 @@ "ts-loader": "^5.3.3", "tslint": "^5.11.0", "ts-sinon": "^1.2.1", - "typescript": "file:./deps/ohos-typescript-4.2.3-r2.tgz", "webpack": "^5.70.0", "webpack-cli": "^4.9.2" }, -- Gitee From 39ac9eeeaae4509948b087653db0b930ed1965f2 Mon Sep 17 00:00:00 2001 From: zhangchen168 Date: Wed, 10 May 2023 14:33:44 +0800 Subject: [PATCH 2/3] mkdir deps folder Signed-off-by: zhangchen168 Change-Id: I7283f06b9763113c9a29968222bf3f3e37fcc341 --- ts2panda/npm_install_tsc.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/ts2panda/npm_install_tsc.py b/ts2panda/npm_install_tsc.py index fd3274c615..0fffd54277 100755 --- a/ts2panda/npm_install_tsc.py +++ b/ts2panda/npm_install_tsc.py @@ -2,22 +2,39 @@ import sys import subprocess +import os def run_cmd(cmd, execution_path = None): - res = subprocess.Popen(cmd, stdout=subprocess.PIPE, + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, cwd=execution_path, shell=True) - sout, serr = res.communicate() - res.wait() - return res.pid, res.returncode, sout, serr + stdout, stderr = proc.communicate() + if proc.returncode != 0: + print(stdout.decode(), stderr.decode()) + raise Exception(stderr.decode()) def run(args): - tsc_path =args[0] - cmd = " ".join(["npm", "install", tsc_path, "--legacy-peer-deps"]) - run_cmd(cmd, args[1]) - run_cmd(cmd, args[2]) + tsc_path = args[0] + cur_path = args[2] + deps_path = os.path.join(cur_path, "deps") + if not os.path.exists(deps_path): + os.makedirs(deps_path, exist_ok= True) + + tsc_package_path = os.path.join(deps_path, "typescript-4.2.3-r2.tgz") + if not os.path.exists(tsc_package_path): + cmd = " ".join(["cp", "-f", tsc_path, deps_path]) + run_cmd(cmd) + + if not os.path.exists(os.path.join(args[1], "node_modules", "typescript")): + cmd = " ".join(["npm", "install", tsc_path, "--legacy-peer-deps"]) + run_cmd(cmd, args[1]) + + if not os.path.exists(os.path.join(cur_path, "node_modules", "typescript")): + tsc_cur_path = os.path.join(deps_path, "typescript-4.2.3-r2.tgz") + cmd = " ".join(["npm", "install", tsc_cur_path, "--legacy-peer-deps"]) + run_cmd(cmd, cur_path) if __name__ == "__main__": run(sys.argv[1:]) \ No newline at end of file -- Gitee From 5b05fc9efb692fc95f655bb1b9db8f1187938d74 Mon Sep 17 00:00:00 2001 From: zhangchen168 Date: Sat, 3 Jun 2023 14:46:53 +0800 Subject: [PATCH 3/3] Adapt incremental compilation Signed-off-by: zhangchen168 Change-Id: I53a66ddca57a41eb266396e2a2a5200529a021fa --- ts2panda/BUILD.gn | 15 ++++++++------- ts2panda/npm_install_tsc.py | 20 +++++++++----------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/ts2panda/BUILD.gn b/ts2panda/BUILD.gn index ed16f02e67..1e0c7adb54 100755 --- a/ts2panda/BUILD.gn +++ b/ts2panda/BUILD.gn @@ -39,9 +39,10 @@ action("npm_install_tsc") { deps = [ "//third_party/typescript:build_typescript" ] script = "npm_install_tsc.py" args = [ - rebase_path("${root_build_dir}/typescript/typescript-4.2.3-r2.tgz"), + rebase_path("${root_out_dir}/obj/third_party/typescript/typescript-4.2.3-r2.tgz"), rebase_path("//prebuilts/build-tools/common/ts2abc"), rebase_path(get_path_info("./", "abspath")), + rebase_path("${target_out_dir}/${target_name}.stamp"), ] outputs = [ "${target_out_dir}/${target_name}.stamp" ] } @@ -66,7 +67,7 @@ ohos_copy("config_files") { } ohos_copy("ts2abc_deps") { - sources = [ "${root_build_dir}/typescript/typescript-4.2.3-r2.tgz" ] + sources = [ "${root_out_dir}/obj/third_party/typescript/typescript-4.2.3-r2.tgz" ] outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] module_source_dir = target_out_dir + "/$target_name" @@ -78,7 +79,7 @@ ohos_copy("ts2abc_deps") { } ohos_copy("ts2abc_deps_ets") { - sources = [ "${root_build_dir}/typescript/typescript-4.2.3-r2.tgz" ] + sources = [ "${root_out_dir}/obj/third_party/typescript/typescript-4.2.3-r2.tgz" ] outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] module_source_dir = target_out_dir + "/$target_name" @@ -90,7 +91,7 @@ ohos_copy("ts2abc_deps_ets") { } ohos_copy("ts2abc_deps_win") { - sources = [ "${root_build_dir}/typescript/typescript-4.2.3-r2.tgz" ] + sources = [ "${root_out_dir}/obj/third_party/typescript/typescript-4.2.3-r2.tgz" ] outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] module_source_dir = target_out_dir + "/$target_name" @@ -102,7 +103,7 @@ ohos_copy("ts2abc_deps_win") { } ohos_copy("ts2abc_deps_win_ets") { - sources = [ "${root_build_dir}/typescript/typescript-4.2.3-r2.tgz" ] + sources = [ "${root_out_dir}/obj/third_party/typescript/typescript-4.2.3-r2.tgz" ] outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] module_source_dir = target_out_dir + "/$target_name" @@ -114,7 +115,7 @@ ohos_copy("ts2abc_deps_win_ets") { } ohos_copy("ts2abc_deps_mac") { - sources = [ "${root_build_dir}/typescript/typescript-4.2.3-r2.tgz" ] + sources = [ "${root_out_dir}/obj/third_party/typescript/typescript-4.2.3-r2.tgz" ] outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] module_source_dir = target_out_dir + "/$target_name" @@ -126,7 +127,7 @@ ohos_copy("ts2abc_deps_mac") { } ohos_copy("ts2abc_deps_mac_ets") { - sources = [ "${root_build_dir}/typescript/typescript-4.2.3-r2.tgz" ] + sources = [ "${root_out_dir}/obj/third_party/typescript/typescript-4.2.3-r2.tgz" ] outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] module_source_dir = target_out_dir + "/$target_name" diff --git a/ts2panda/npm_install_tsc.py b/ts2panda/npm_install_tsc.py index 0fffd54277..b2f83f9560 100755 --- a/ts2panda/npm_install_tsc.py +++ b/ts2panda/npm_install_tsc.py @@ -23,18 +23,16 @@ def run(args): os.makedirs(deps_path, exist_ok= True) tsc_package_path = os.path.join(deps_path, "typescript-4.2.3-r2.tgz") - if not os.path.exists(tsc_package_path): - cmd = " ".join(["cp", "-f", tsc_path, deps_path]) - run_cmd(cmd) - - if not os.path.exists(os.path.join(args[1], "node_modules", "typescript")): - cmd = " ".join(["npm", "install", tsc_path, "--legacy-peer-deps"]) - run_cmd(cmd, args[1]) + cmd = " ".join(["cp", "-f", tsc_path, deps_path]) + run_cmd(cmd) + cmd = " ".join(["npm", "install", tsc_path, "--legacy-peer-deps"]) + run_cmd(cmd, args[1]) + cmd = " ".join(["npm", "install", tsc_package_path, "--legacy-peer-deps"]) + run_cmd(cmd, cur_path) - if not os.path.exists(os.path.join(cur_path, "node_modules", "typescript")): - tsc_cur_path = os.path.join(deps_path, "typescript-4.2.3-r2.tgz") - cmd = " ".join(["npm", "install", tsc_cur_path, "--legacy-peer-deps"]) - run_cmd(cmd, cur_path) + if os.path.exists(args[3]): + cmd =" ".join(["rm", "-rf", args[3]]) + run_cmd(cmd) if __name__ == "__main__": run(sys.argv[1:]) \ No newline at end of file -- Gitee