From 069f18556d221f214f05d16d45b6a68f98c39a52 Mon Sep 17 00:00:00 2001 From: msojocs Date: Tue, 26 Apr 2022 11:14:44 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E5=8A=A8=E6=80=81=E6=9B=BF=E6=8D=A2c?= =?UTF-8?q?ore=E4=B8=AD=E7=9A=84wcc,wcsc=20return=E8=A1=A8=E8=BE=BE?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用正则匹配,最大化兼容可能发生的函数名变更 --- test/compiler-replace-test | 17 +++++++++++++++++ tools/fix-core.sh | 13 ++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100755 test/compiler-replace-test diff --git a/test/compiler-replace-test b/test/compiler-replace-test new file mode 100755 index 0000000..fcc5076 --- /dev/null +++ b/test/compiler-replace-test @@ -0,0 +1,17 @@ +#!/bin/bash +# 此脚本用于使修改 core.wxvpkg 内的代码及时生效 +set -e +root_dir=$(cd `dirname $0`/.. && pwd -P) +find_result="$root_dir/package.nw/core.wxvpkg.ext/19c6ae7eff08f795d1f2124f7b0248ad.js" +return_exp_wcc=$(cat $find_result | grep -P 'return [a-z]+\("wcc"\)' -o) # return ?("wcc") +echo "return exp: $return_exp_wcc" +return_exp_wcc_replace="${return_exp_wcc//wcc/wcc.bin}" # return ?("wcc.bin") +echo "replace exp1: $return_exp_wcc_replace" +return_exp_wcc_replace="${return_exp_wcc//return /${return_exp_wcc_replace},}" # return ?("wcc.bin") +echo "replace exp2: $return_exp_wcc_replace" + +return_exp_wcsc=$(cat $find_result | grep -P 'return [a-z]+\("wcsc"\)' -o) # return ?("wcc") +return_exp_wcsc_replace="${return_exp_wcc_replace//wcc/wcsc}" + +sed -i "s#$return_exp_wcc#$return_exp_wcc_replace#g" "$find_result" +sed -i "s#$return_exp_wcsc#$return_exp_wcsc_replace#g" "$find_result" \ No newline at end of file diff --git a/tools/fix-core.sh b/tools/fix-core.sh index dde996b..1209d76 100755 --- a/tools/fix-core.sh +++ b/tools/fix-core.sh @@ -52,9 +52,16 @@ if [[ $NO_WINE == 'true' ]];then sed -i "s#{wcc:!0,wcsc:!0}#$new_str#g" "$find_result" new_str='"linux"===process.platform' sed -i "s#\"darwin\"===process.platform#$new_str#g" "$find_result" - # TODO: 看能不能动态识别函数名j,因为不同版本会发生变化 - sed -i 's#return j("wcc")#return j("wcc.bin"),j("wcc")#g' "$find_result" - sed -i 's#return j("wcsc")#return j("wcsc.bin"),j("wcsc")#g' "$find_result" + + return_exp_wcc=$(cat $find_result | grep -P 'return [a-z]+\("wcc"\)' -o) # return ?("wcc") + return_exp_wcc_replace="${return_exp_wcc//wcc/wcc.bin}" # return ?("wcc.bin") + return_exp_wcc_replace="${return_exp_wcc//return /${return_exp_wcc_replace},}" # return ?("wcc.bin") + + return_exp_wcsc=$(cat $find_result | grep -P 'return [a-z]+\("wcsc"\)' -o) # return ?("wcsc") + return_exp_wcsc_replace="${return_exp_wcc_replace//wcc/wcsc}" + + sed -i "s#$return_exp_wcc#$return_exp_wcc_replace#g" "$find_result" + sed -i "s#$return_exp_wcsc#$return_exp_wcsc_replace#g" "$find_result" fi # 处理报错时控制台显示的环境 find_result=$( grep -lr '(env:' "$tmp_dir/core.wxvpkg" )