From 7ec42956873f8fee97b2b260277c2c2dc717c916 Mon Sep 17 00:00:00 2001 From: chriswang521 Date: Wed, 24 Jul 2024 14:51:53 +0800 Subject: [PATCH] =?UTF-8?q?build:=20=E9=87=8D=E6=9E=84=E4=BA=86=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E8=84=9A=E6=9C=AC,=E6=B7=BB=E5=8A=A0=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E8=A1=8C=E5=8F=82=E6=95=B0=E8=A7=A3=E6=9E=90,?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B8=AE=E5=8A=A9,=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E5=86=85=E7=BD=91=E5=9C=B0=E5=9D=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.sh | 178 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 144 insertions(+), 34 deletions(-) diff --git a/build.sh b/build.sh index 4c908c4c..f126114f 100755 --- a/build.sh +++ b/build.sh @@ -1,46 +1,156 @@ #!/bin/bash -set -ex +# 脚本名称:build.sh +# 描述:快速构建deb脚本,用于解析参数、调用命令和显示帮助。 +# 作者:wangpenglong +# 创建日期:2024年05月10日 + +# 开启调试模式,显示脚本执行过程 -x; +# 开启错误处理,脚本执行出错时退出 -e; +# set -ex +set -e + +VERSION="1.0.0" +AUTHOR="wangpenglong" +DATE="2024年05月10日" + +# 帮助信息 +help_info() { + echo "使用方法:$0 [选项]" + echo " -h, --help 显示帮助信息" + echo " -v, --version 显示脚本版本信息" + echo " -c, --clean 清空构建的文件" + echo " -r, --replace_url 替换url为内网url" + echo " -b, --build 构建软件包" +} + +# 版本信息 +version_info() { + echo "脚本版本:${VERSION}" + echo "作者:${AUTHOR}" + echo "创建日期:${DATE}" +} #添加参数clean,清理编译出的所有内容 -if [ "$1" == "clean" ];then +function clean() { git clean -fdx -e '*.deb' -e '*.rpm' #清除新建or添加的文件 + rm -rf ../VSCode-linux-* # git reset --hard #清除修改的文件 - exit 0 -fi +} -#修改yarn.lock中地址 -# NPM_URL='https://registry.yarnpkg.com' -# NPM_LOCAL_SEVER="http://kylinos.zz.gitea.com:3000" +#替换url为内网url +function replace_url() { + #修改yarn.lock中地址 + NPM_URL='https://registry.yarnpkg.com' + NPM_LOCAL_SEVER="http://kylinos.zz.gitea.com:3000" -# for i in $(find -name yarn.lock); do -# sed -i "s#${NPM_URL}#${NPM_LOCAL_SEVER}#g" $i -# done + for i in $(find -name yarn.lock); do + sed -i "s#${NPM_URL}#${NPM_LOCAL_SEVER}#g" $i + done -#设置环境变量,构建软件包时,可不下载 electron二进制和 playwright browser包 -export ELECTRON_SKIP_BINARY_DOWNLOAD=1 -export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 + #替换calculate-deps.ts中地址 + calculate_deps_files=("build/linux/debian/calculate-deps.ts" "build/linux/debian/calculate-deps.js") + dpkgShlibdepsUrl="https://raw.githubusercontent.com/chromium" + dpkgShlibdepsUrl_local="http://127.0.0.1:9099" + for calculate_deps_file in ${calculate_deps_files[@]}; do + echo "替换${calculate_deps_file}中的地址" + sed -i "s#${dpkgShlibdepsUrl}#${dpkgShlibdepsUrl_local}#g" ${calculate_deps_file} + sed -i "s/\/third_party//" ${calculate_deps_file} + done -#start build -#CHILD_CONCURRENCY 控制并行运行以构建节点模块的子进程的数量。 -#将此数字设置为 1 将导致节点模块按顺序构建,这可以避免使用 node-gyp 的 Windows 上的链接器错误。 -# CHILD_CONCURRENCY=1 yarn --frozen-lockfile --check-files --network-timeout 180000 -yarn --frozen-lockfile --check-files --network-timeout 180000 + install_sysroot_files=("build/linux/debian/install-sysroot.ts" "build/linux/debian/install-sysroot.js") + URL_PREFIX="https://msftelectron.blob.core.windows.net" + URL_PREFIX_local="http://127.0.0.1:9099" + sysrootJSONUrl="https://raw.githubusercontent.com/electron" + sysrootJSONUrl_local="http://127.0.0.1:9099/sysroots" + for install_sysroot_file in ${install_sysroot_files[@]}; do + echo "替换${install_sysroot_file}中的地址" + sed -i "s#${URL_PREFIX}#${URL_PREFIX_local}#g" ${install_sysroot_file} + sed -i "s#${sysrootJSONUrl}#${sysrootJSONUrl_local}#g" ${install_sysroot_file} + sed -i "s/https/http/g" ${install_sysroot_file} + done + echo "[done] replace local url end." +} -#关闭telemetry,node_modules也会有地址 -./close_telemetry.sh -#检查 -yarn monaco-compile-check -yarn valid-layers-check -#编译 -yarn gulp compile-build -yarn gulp compile-extension-media -yarn gulp compile-extensions-build -#压缩代码 -yarn gulp minify-vscode -yarn gulp "vscode-linux-x64-min-ci" #this will download electron,need change code. -#打包 -yarn gulp "vscode-linux-x64-build-deb" -cp .build/linux/deb/*/deb/*.deb . +function build(){ + #start build + echo "[start] build start." + set -ex -echo "done" + #设置环境变量,构建软件包时,可不下载 electron二进制和 playwright browser包 + export ELECTRON_SKIP_BINARY_DOWNLOAD=1 + export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 + + #CHILD_CONCURRENCY 控制并行运行以构建节点模块的子进程的数量。 + #将此数字设置为 1 将导致节点模块按顺序构建,这可以避免使用 node-gyp 的 Windows 上的链接器错误。 + # CHILD_CONCURRENCY=1 yarn --frozen-lockfile --check-files --network-timeout 180000 + # yarn --frozen-lockfile --check-files --network-timeout 180000 + yarn + + #关闭telemetry,node_modules也会有地址 + ./close_telemetry.sh + #检查 + yarn monaco-compile-check + yarn valid-layers-check + #编译 + yarn gulp compile-build + yarn gulp compile-extension-media + yarn gulp compile-extensions-build + #压缩代码 + yarn gulp minify-vscode + yarn gulp "vscode-linux-x64-min-ci" #this will download electron,need change code. + #打包 + yarn gulp "vscode-linux-x64-build-deb" + cp .build/linux/deb/*/deb/*.deb . + + echo "[done] build end." +} + +# 解析参数 +parse_args() { + while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + -h|--help) + help_info + exit 0 + ;; + -v|--version) + version_info + exit 0 + ;; + -c|--clean) + clean + exit 0 + ;; + -r|--replace_url) + replace_url + exit 0 + ;; + -b|--build) + build + exit 0 + ;; + *) + echo "未知选项:$1" + help_info + exit 1 + ;; + esac + shift + done + # 没有选项时,显示帮助信息 + if [ $# -eq 0 ]; then + help_info + exit 1 + fi +} + +# 主函数 +main() { + parse_args "$@" +} + +# 调用主函数 +main "$@"