test: reduce wine

This commit is contained in:
msojocs 2022-02-18 12:52:32 +08:00
parent 656a3ddfec
commit a54c700a3d
10 changed files with 226 additions and 69 deletions

View File

@ -9,7 +9,7 @@ on:
push:
tags:
- v*
branches: [ master ]
branches: [ master, reduce-wine]
pull_request:
branches: [ master ]
# # Allows you to run this workflow manually from the Actions tab
@ -57,41 +57,55 @@ jobs:
- name: Build
run: docker-compose up
- name: Build AppImage
run: |
sudo chmod -R 777 tmp package.nw node
bash tools/appimage.sh
wget "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage"
chmod a+x appimagetool-x86_64.AppImage
./appimagetool-x86_64.AppImage ./tmp/AppDir
env:
name: 'release-${{ steps.tag.outputs.tag }}'
ARCH: '${{ matrix.ARCH }}'
- name: Delete unused file
- name: Refactor Directory Structure
run: |
ls -l
sudo rm -rf cache tmp appimagetool-x86_64.AppImage
sudo rm -rf cache tmp
mkdir ${{ env. name }}
sudo find -maxdepth 1 -not -name ${{ env.name }} -not -name . -exec mv {} ${{ env.name }} \;
sudo cp -r "${{ env.name }}/package.nw/node_modules/nodegit" nodegit
sudo cp -r "${{ env.name }}/compiler" compiler
sudo mv ${{ env.name }}/WeChat*.AppImage .
ls -l
cd "${{ env.name }}"
env:
name: 'release-${{ steps.tag.outputs.tag }}'
name: 'WeChat_Dev_Tools_${{ steps.tag.outputs.tag }}'
- name: Compress
run: |
ls -l
tar -zvcf ${{ env.name }}.tar.gz ${{ env.name }}
tar -zvcf compiler.tar.gz compiler
tar -zvcf nodegit.tar.gz nodegit
sudo rm -rf ${{ env.name }} compiler nodegit
ls -l
env:
name: 'release-${{ steps.tag.outputs.tag }}'
name: 'WeChat_Dev_Tools_${{ steps.tag.outputs.tag }}'
- name: Build AppImage && Pack
run: |
cd ${{ env.name }} && sudo chmod -R 777 package.nw node
bash ./${{ env.name }}/tools/appimage.sh
wget "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage"
chmod a+x appimagetool-x86_64.AppImage
# build AppImage
./appimagetool-x86_64.AppImage ./${{ env.name }}/tmp/AppDir ${{ env.name }}_${{ env.ARCH }}_wine.AppImage
# pack
tar -zvcf ${{ env.name }}_${{ env.ARCH }}_wine.tar.gz ${{ env.name }}
# reduce wine
export REDUCE_WINE=true
source ${{ env.name }}/tools/fix-core
source ${{ env.name }}/tools/fix-other
bash ./${{ env.name }}/tools/appimage.sh
# build AppImage
./appimagetool-x86_64.AppImage ./${{ env.name }}/tmp/AppDir ${{ env.name }}_${{ env.ARCH }}_reduce_wine.AppImage
# pack
tar -zvcf ${{ env.name }}_${{ env.ARCH }}_reduce_wine.tar.gz ${{ env.name }}
rm -rf appimagetool-x86_64.AppImage
env:
name: 'WeChat_Dev_Tools_${{ steps.tag.outputs.tag }}'
ARCH: '${{ matrix.ARCH }}'
- name: Create release and upload artifacts
if: startsWith(github.ref, 'refs/heads/')
@ -111,9 +125,5 @@ jobs:
name: ${{ steps.tag.outputs.name }}
tag_name: ${{ steps.tag.outputs.tag }}
files: |
${{ env.name }}.tar.gz
compiler.tar.gz
nodegit.tar.gz
*.tar.gz
*.AppImage
env:
name: 'release-${{ steps.tag.outputs.tag }}'

View File

@ -7,9 +7,28 @@ export APPDATA="$( echo ~ )/.config/wechat_devtools"
export PATH="$root_dir/wine:$root_dir/node/bin:$root_dir/nwjs:$PATH"
export USERPROFILE=$( echo ~ )
if [ -d ~/.config/wechat_devtools/WeappCache ];then
echo "删除缓存"
rm -rf ~/.config/wechat_devtools/WeappCache
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
# 获取首次运行时间
if [[ -f "$APPDATA/.run_time" ]];then
run_time=`cat "$APPDATA/.run_time"`
else
run_time=0
fi
# 获取构建时间
if [[ -f "$root_dir/package.nw/.build_time" ]];then
build_time=`cat "$root_dir/package.nw/.build_time"`
else
build_time=timeStamp
fi
if [[ ! $build_time < $run_time ]];then
echo "清理缓存"
echo $timeStamp > "$APPDATA/.run_time"
rm -rf "$APPDATA/WeappCache"
rm -rf "$APPDATA/WeappVendor"
fi
EXTENSION1="--load-extension=$root_dir/nwjs/package.nw/js/ideplugin"

84
compiler/generatemd5.js Normal file
View File

@ -0,0 +1,84 @@
const path = require('path')
const fs = require('fs')
const crypto = require('crypto')
const os = require('os')
const child_process = require('child_process')
let platform = process.argv[2]
let exeList = []
const macExeList = [
'wcc',
'wcsc',
'wcc.bin'
]
const winExeList = [
'wcc.exe',
'wcsc.exe'
]
if(platform === 'darwin') {
exeList = macExeList;
} else if(platform === 'win32') {
exeList= winExeList;
} else {
exeList = macExeList.concat(winExeList)
}
function generate(vendorPath) {
let dirList = fs.readdirSync(vendorPath)
console.log(dirList)
let libs = {}
dirList.forEach((item) => {
if (item == 'dev' || item == 'quickstart' || item == 'beta') {
return
}
let itemPath = path.join(vendorPath, item)
let stat = fs.statSync(itemPath)
if (stat.isDirectory()) {
let fileList = fs.readdirSync(itemPath)
let md5Info = {}
fileList.forEach((file) => {
if (fs.statSync(path.join(itemPath, file)).isFile()) {
let fileData = fs.readFileSync(path.join(itemPath, file))
let md5sum = crypto.createHash('md5')
md5sum.update(fileData)
md5Info[file] = md5sum.digest('hex')
}
})
libs[item] = md5Info
}
})
let oldConfig = JSON.parse(fs.readFileSync(path.join(vendorPath, 'config.json'), 'utf8'))
for (var key in oldConfig.libs) {
// libs[key] = Object.assign({}, oldConfig.libs[key], libs[key])
oldConfig.libs[key] = Object.assign({}, oldConfig.libs[key], libs[key])
}
// let newLib = {}
// let keys = Object.keys(libs)
// keys.sort()
// for (var i = 0; i < keys.length; i++) {
// let key = keys[i]
// newLib[key] = libs[key]
// }
// 更新
oldConfig.configVersion = Date.now()
for (let key in exeList) {
let file = exeList[key]
let fileData = fs.readFileSync(path.join(vendorPath, file))
let md5sum = crypto.createHash('md5')
md5sum.update(fileData)
oldConfig[file] = md5sum.digest('hex')
}
fs.writeFileSync(path.join(vendorPath, 'config.json'), JSON.stringify(oldConfig, null, '\t'))
}
generate(__dirname)

View File

@ -8,4 +8,8 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
wine "$DIR/wcc.exe" "$@"
if [[ $@ =~ -ll ]];then
wine "$DIR/wcc.exe" "$@"
else
"$DIR/wcc.bin" "$@"
fi

View File

@ -8,4 +8,9 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
wine "$DIR/wcsc.exe" "$@"
if [[ $@ =~ -ll ]];then
wine "$DIR/wcsc.exe" "$@"
else
"$DIR/wcsc.bin" "$@"
fi

7
test/reduce-wine Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
export REDUCE_WINE=true
root_dir=$(cd `dirname $0`/.. && pwd -P)
$root_dir/tools/fix-core
$root_dir/tools/fix-other

View File

@ -1,13 +1,19 @@
#!/bin/bash
if [[ $REDUCE_WINE == 'true' ]];then
echo "not wine"
fi
if [[ $@ =~ -ll ]];then
echo "include"
fi
exit
echo "$@ $0 $1 $2"
root_dir=$(cd `dirname $0`/.. && pwd -P)
export PATH="$root_dir/node/bin:$PATH"
export http_proxy="http://127.0.0.1:54321"
if [[ ! -z $https_proxy || ! -z $http_proxy ]]; then
echo -e "\033[41;37m 警告: 你设置了代理,有可能导致安装出现异常 \033[0m"
fi
PY_VERSION=`python -V 2>&1|awk '{print $2}'|awk -F '.' '{print $1}'`
echo $PY_VERSION

View File

@ -17,25 +17,48 @@ node "$root_dir/tools/wxvpkg/unpack" "$package_dir/core.wxvpkg" "$tmp_dir/core.w
#
# find
open_find_result=$( grep -lr "this.props.onWindowOpenFail());" "$tmp_dir/core.wxvpkg" )
open_find_result=$( grep -lr "this.props.onWindowOpenFail());if" "$tmp_dir/core.wxvpkg" )
echo "云开发控制台启动点: $open_find_result"
# replace
new_cb_handle="this.props.onWindowOpenFail());Object.keys(window).forEach(key=>{if(!e.window[key]){try{e.window[key]=window[key];}catch(e){console.error(e);}}});"
sed -i "s/this.props.onWindowOpenFail());/$new_cb_handle/g" $open_find_result
if [[ ! -z $open_find_result ]];then
# replace
new_cb_handle="this.props.onWindowOpenFail());Object.keys(window).forEach(key=>{if(!e.window[key]){try{e.window[key]=window[key];}catch(e){console.error(e);}}});"
sed -i "s/this.props.onWindowOpenFail());/$new_cb_handle/g" $open_find_result
fi
token_find_result=$( grep -lr "constructor(){this._sessionToken=\"\",this._tokenMap={}}" "$tmp_dir/core.wxvpkg" )
echo "WebSocket token存储对象位置: $token_find_result"
new_constructor="constructor(){if(window.tokenData){/*有就直接用*/this._sessionToken=window.tokenData._sessionToken;this._tokenMap=window.tokenData._tokenMap;}else{/*没有就新建*/this._sessionToken=\"\",this._tokenMap={};window.tokenData=this;/*新建完要给中间人*/}}"
sed -i "s#constructor(){this._sessionToken=\"\",this._tokenMap={}}#$new_constructor#g" "$token_find_result"
if [[ ! -z $token_find_result ]];then
new_constructor="constructor(){if(window.tokenData){/*有就直接用*/this._sessionToken=window.tokenData._sessionToken;this._tokenMap=window.tokenData._tokenMap;}else{/*没有就新建*/this._sessionToken=\"\",this._tokenMap={};window.tokenData=this;/*新建完要给中间人*/}}"
sed -i "s#constructor(){this._sessionToken=\"\",this._tokenMap={}}#$new_constructor#g" "$token_find_result"
fi
# open -a Terminal "`pwd`" --> gnome-terminal
find_result=$( grep -lr 'open -a Terminal "`pwd`"' "$tmp_dir/core.wxvpkg" )
echo "Terminal启动位置: $find_result"
new_str="gnome-terminal"
sed -i "s#open -a Terminal \"\`pwd\`\"#$new_str#g" "$find_result"
if [[ ! -z $find_result ]];then
echo "Terminal启动位置: $find_result"
new_str="gnome-terminal"
sed -i "s#open -a Terminal \"\`pwd\`\"#$new_str#g" "$find_result"
fi
# wcc、wcsc处理设置REDUCE_WINE环境变量生效
if [[ $REDUCE_WINE == 'true' ]];then
# "wcc.exe":!0,"wcsc.exe":!0
find_result=$( grep -lr '{wcc:!0,wcsc:!0,DevToolProtector:!0}' "$tmp_dir/core.wxvpkg" )
if [[ ! -z $find_result ]];then
echo "wcc: $find_result"
new_str='{"wcc.exe":!0,"wcsc.exe":!0,"wcc.bin":!0,"wcsc.bin":!0,wcc:!0,wcsc:!0,DevToolProtector:!0}'
sed -i "s#{wcc:!0,wcsc:!0,DevToolProtector:!0}#$new_str#g" "$find_result"
new_str='"linux"===process.platform'
sed -i "s#\"darwin\"===process.platform#$new_str#g" "$find_result"
fi
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
echo $timeStamp > "${package_dir}/.build_time"
fi
# pack 路径 到 文件
echo "pack"
node "$root_dir/tools/wxvpkg/pack" "$tmp_dir/core.wxvpkg" "$package_dir/core.wxvpkg"
rm -rf "$tmp_dir/core.wxvpkg"

View File

@ -1,5 +1,5 @@
#!/bin/bash
set -e
root_dir=$(cd `dirname $0`/.. && pwd -P)
srcdir=$root_dir
tmp_dir="$root_dir/tmp"
@ -14,20 +14,11 @@ sed -i 's#module.exports = createWebviewManager;#module.exports = createWebviewM
# 修复可视化用的wcc,wcsc
echo "fix: wcc,wcsc"
mkdir "$tmp_dir/node_modules"
if [[ ! -d "$tmp_dir/node_modules" ]];then
mkdir "$tmp_dir/node_modules"
fi
cd $tmp_dir && npm install miniprogram-compiler
# wcc wcsc
# 预览编译
# cd "${package_dir}/js/vendor/" && rm -rf "wcc.exe"
# cp "${package_dir}/node_modules_tmp/node_modules/miniprogram-compiler/bin/linux/wcc" "${package_dir}/js/vendor/wcc.exe"
# wcc_md5=$( md5sum wcc.exe|cut -d ' ' -f1 ) && \
# sed -i 's/wcc.exe": ".*"/wcc.exe": "'"${wcc_md5}"'"/g' "config.json"
# cd "${package_dir}/js/vendor/" && rm -rf "wcsc.exe"
# cp "${package_dir}/node_modules_tmp/node_modules/miniprogram-compiler/bin/linux/wcsc" "${package_dir}/js/vendor/wcsc.exe"
# cd "${package_dir}/js/vendor" && \
# wcsc_md5=$( md5sum wcsc.exe|cut -d ' ' -f1 ) && \
# sed -i 's/wcsc.exe": ".*"/wcsc.exe": "'"${wcsc_md5}"'"/g' "config.json"
# 可视化编译
(cd "${package_dir}/node_modules/" \
&& rm -rf wcc wcsc \
@ -37,4 +28,20 @@ cd $tmp_dir && npm install miniprogram-compiler
&& cp -r "${srcdir}/compiler/wcc_node"/* "wcc" \
&& cp -r "${srcdir}/compiler/wcsc_node"/* "wcsc"
)
# 预览编译设置REDUCE_WINE环境变量生效
# 如果是mac执行wcc,否则wcc.exe
if [[ $REDUCE_WINE == 'true' ]];then
\cp -rf "${srcdir}/compiler/generatemd5.js" "${package_dir}/js/vendor/generatemd5.js"
\cp -rf "${srcdir}/compiler/wine/wcc" "${package_dir}/js/vendor/wcc"
\cp -rf "${srcdir}/compiler/wine/wcsc" "${package_dir}/js/vendor/wcsc"
\cp -rf "${tmp_dir}/node_modules/miniprogram-compiler/bin/linux/wcc" "${package_dir}/js/vendor/wcc.bin"
\cp -rf "${tmp_dir}/node_modules/miniprogram-compiler/bin/linux/wcsc" "${package_dir}/js/vendor/wcsc.bin"
node "${package_dir}/js/vendor/generatemd5.js"
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
echo $timeStamp > "${package_dir}/.build_time"
fi
rm -rf "$tmp_dir/node_modules"

View File

@ -187,10 +187,8 @@ const upgrade = function (extractPath) {
execSync(`rm -rf ${path.resolve(__dirname, "../nwjs/package.nw")}`)
console.log(`创建链接 ${path.resolve(__dirname, "../package.nw")}--->${path.resolve(__dirname, "../nwjs/package.nw")}`)
// 链接
fs.symlinkSync(
path.resolve(__dirname, "../package.nw"),
path.resolve(__dirname, "../nwjs/package.nw")
);
execSync(`cd ${path.resolve(__dirname, "../nwjs")} && ln -s ../package.nw package.nw`)
}
}
@ -283,14 +281,6 @@ const patch_other = function () {
info("Patching Other");
return new Promise((resolve, reject) => {
fs.copyFileSync(
path.resolve(__dirname, "../compiler/wine/wcc"),
path.resolve(__dirname, "../package.nw/js/vendor/wcc")
);
fs.copyFileSync(
path.resolve(__dirname, "../compiler/wine/wcsc"),
path.resolve(__dirname, "../package.nw/js/vendor/wcsc")
);
execSync(path.resolve(__dirname, "fix-other"))
resolve();
@ -310,6 +300,8 @@ const start = async () => {
await rebuild_wechat_devtools_node_modules();
await patch_wechat_devtools();
await patch_other();
// 写入构建时间戳
fs.writeFileSync(path.resolve(__dirname, '../package.nw/.build_time'), '' + parseInt(new Date().getTime()/1000))
console.log(
`Succeeded upgrading wechat-devtools to version ${version}`
);