From a23a5ed53ff3fe97cfebf98b89fea546511451ef Mon Sep 17 00:00:00 2001 From: liuchunguang <345080091@qq.com> Date: Wed, 18 Mar 2026 18:38:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AD=90=E4=BB=93=E5=BA=93?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=8A=A8=E6=80=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=B7=B7=E6=B7=86=E5=AE=8F=E7=9A=84=E8=BF=87=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tool/build_env/jenkins_android_dev.groovy | 2 +- Tool/build_env/jenkins_android_release.groovy | 4 +- Tool/build_tools | 2 +- Tool/py_tools/PreHandle.py | 50 ++++++++++++++++++- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/Tool/build_env/jenkins_android_dev.groovy b/Tool/build_env/jenkins_android_dev.groovy index cafb2604b8a..46b595c5399 100644 --- a/Tool/build_env/jenkins_android_dev.groovy +++ b/Tool/build_env/jenkins_android_dev.groovy @@ -181,7 +181,7 @@ pipeline { // python脚本: Tool/py_tools/PreHandle.py sh "chmod +x $WORKSPACE/Tool/py_tools/PreHandle.py" // 使用 returnStatus 获取脚本的退出码 - def pythonResult = sh(script: "python3 $WORKSPACE/Tool/py_tools/PreHandle.py ${sdkPath} ${channelPath}", returnStatus: true) + def pythonResult = sh(script: "python3 $WORKSPACE/Tool/py_tools/PreHandle.py ${sdkPath} ${channelPath} ${OBFUZ}", returnStatus: true) if (pythonResult != 0) { def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】修改渠道文件夹失败: pythonResult=${pythonResult}" SendMessageToWechat(message) diff --git a/Tool/build_env/jenkins_android_release.groovy b/Tool/build_env/jenkins_android_release.groovy index 84c4fab66d7..3f75139fb52 100644 --- a/Tool/build_env/jenkins_android_release.groovy +++ b/Tool/build_env/jenkins_android_release.groovy @@ -89,7 +89,7 @@ def IsDev() { else if('Test' == params.Channel) return true; else - return false; + return true; } def CheckRemoteBranchExists(repoUrl, branchName) { @@ -211,7 +211,7 @@ pipeline { // python脚本: Tool/py_tools/PreHandle.py sh "chmod +x $WORKSPACE/Tool/py_tools/PreHandle.py" // 使用 returnStatus 获取脚本的退出码 - def pythonResult = sh(script: "python3 $WORKSPACE/Tool/py_tools/PreHandle.py ${sdkPath} ${channelPath}", returnStatus: true) + def pythonResult = sh(script: "python3 $WORKSPACE/Tool/py_tools/PreHandle.py ${sdkPath} ${channelPath} ${OBFUZ}", returnStatus: true) if (pythonResult != 0) { def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Release】【${CHANNEL_PARAM}】修改渠道文件夹失败: pythonResult=${pythonResult}" SendMessageToWechat(message) diff --git a/Tool/build_tools b/Tool/build_tools index 2bf88fe9a68..c1291e38095 160000 --- a/Tool/build_tools +++ b/Tool/build_tools @@ -1 +1 @@ -Subproject commit 2bf88fe9a68cf476e09829aa66dc2479f9ca0001 +Subproject commit c1291e380956bcc75f1352268fba2bf34ada52a3 diff --git a/Tool/py_tools/PreHandle.py b/Tool/py_tools/PreHandle.py index bf98bf4971f..4bb32d520ff 100644 --- a/Tool/py_tools/PreHandle.py +++ b/Tool/py_tools/PreHandle.py @@ -1,15 +1,16 @@ -# 传入参数 0:SDK_PATH 1:ChannelPath +# 传入参数 0:SDK_PATH 1:ChannelPath 2:Obfuz(可选, true/false) import sys import os import yaml def main(): if len(sys.argv) < 3: - print("Usage: python PreHandle.py ") + print("Usage: python PreHandle.py [Obfuz]") sys.exit(1) # 参数不足时返回错误码1 sdk_path = sys.argv[1] channel_path = sys.argv[2] + obfuz = sys.argv[3].lower() == 'true' if len(sys.argv) >= 4 else None if not os.path.exists(sdk_path): print(f"Error: SDK path '{sdk_path}' does not exist.") @@ -50,10 +51,55 @@ def main(): for package in packageList: HandlePackage(package, sdk_path, channel_path) + # 同步 USE_OBFUZ 宏(如果传入了 Obfuz 参数) + if obfuz is not None: + SyncUseObfuzDefine(channel_path, obfuz) + # 处理完成,正常退出 print("All packages processed successfully.") sys.exit(0) # 改为成功退出 +def SyncUseObfuzDefine(channel_path, enable): + """根据 enable 参数在 ChannelSetting.yaml 的 Define_list 中添加或移除 USE_OBFUZ""" + channel_setting_path = os.path.join(channel_path, "ChannelSetting.yaml") + if not os.path.exists(channel_setting_path): + print(f"[PreHandle] WARNING: ChannelSetting.yaml not found at {channel_setting_path}, skip USE_OBFUZ sync") + return + + try: + with open(channel_setting_path, 'r', encoding='utf-8') as f: + data = yaml.safe_load(f) or {} + except (IOError, yaml.YAMLError) as e: + print(f"[PreHandle] ERROR: Failed to read ChannelSetting.yaml: {e}") + return + + defines = data.get('Define_list') or [] + changed = False + if enable: + if 'USE_OBFUZ' not in defines: + defines.append('USE_OBFUZ') + data['Define_list'] = defines + changed = True + print('[PreHandle] Added USE_OBFUZ to Define_list') + else: + print('[PreHandle] USE_OBFUZ already in Define_list, skip') + else: + if 'USE_OBFUZ' in defines: + defines.remove('USE_OBFUZ') + data['Define_list'] = defines + changed = True + print('[PreHandle] Removed USE_OBFUZ from Define_list') + else: + print('[PreHandle] USE_OBFUZ not in Define_list, skip') + + if changed: + try: + with open(channel_setting_path, 'w', encoding='utf-8') as f: + yaml.dump(data, f, allow_unicode=True) + except IOError as e: + print(f"[PreHandle] ERROR: Failed to write ChannelSetting.yaml: {e}") + + def HandlePackage(packageDefineName, sdk_path, channel_path): # 处理包定义名称 if '@' not in packageDefineName: