From 311234bd74d3e512b3d811838458731b6278d0b8 Mon Sep 17 00:00:00 2001 From: shenlei Date: Tue, 3 Nov 2026 12:04:32 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20readoorDict=20=E6=89=93=E5=8C=85?= =?UTF-8?q?=E6=8C=89=E7=89=88=E6=9C=AC=E8=BD=A8=E9=81=93=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=20IPA=20=E7=89=88=E6=9C=AC=E5=8F=B7=E4=B8=8E=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- backend/services/project_patcher.py | 15 +++++++++++++++ tests/test_project_patcher.py | 12 +++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/backend/services/project_patcher.py b/backend/services/project_patcher.py index 60bb0a9..53ebc03 100644 --- a/backend/services/project_patcher.py +++ b/backend/services/project_patcher.py @@ -202,6 +202,20 @@ def _apply_dictionary_config(build_dir: Path, config: dict, messages: list[str]) messages.append("已替换词典版本配置") +def _apply_dictionary_version(build_dir: Path, config: dict, messages: list[str]): + """词典包的 IPA 版本号与构建号同样按版本轨道写入工程(与 readoor31 一致,替换工程内全部构建配置)。""" + project = build_dir / "readoor.xcodeproj" / "project.pbxproj" + version, build_version = config.get("VERSION", ""), config.get("BUILD_VERSION", "") + replacements = [ + ("MARKETING_VERSION =", f"\t\t\t\tMARKETING_VERSION = {version};"), + ("CURRENT_PROJECT_VERSION =", f"\t\t\t\tCURRENT_PROJECT_VERSION = {build_version};"), + ] + missing = [keyword for keyword, line in replacements if _replace_lines(project, keyword, line) == 0] + if missing: + raise ProjectPatchError(f"未找到待替换配置: {', '.join(missing)}") + messages.append(f"已替换词典包版本: {version} ({build_version})") + + def apply_project_config(build_dir: Path, config: dict, definition: dict = None) -> list[str]: """写入项目配置,返回适合实时日志展示的变更说明。 @@ -213,6 +227,7 @@ def apply_project_config(build_dir: Path, config: dict, definition: dict = None) messages: list[str] = [] if config.get("SCHEME") == "readoorDict": _apply_dictionary_config(build_dir, config, messages) + _apply_dictionary_version(build_dir, config, messages) _write_export_options(build_dir, config) return messages diff --git a/tests/test_project_patcher.py b/tests/test_project_patcher.py index 24c11fa..a60e572 100644 --- a/tests/test_project_patcher.py +++ b/tests/test_project_patcher.py @@ -145,11 +145,17 @@ def _dict_build(tmp_path): macro = tmp_path / "readoor" / "BookShelf" / "Classes" / "Macro" / "STSConstantsMacro.h" macro.parent.mkdir(parents=True) macro.write_text(_DICT_MACRO, encoding="utf-8") + project = tmp_path / "readoor.xcodeproj" + project.mkdir() + (project / "project.pbxproj").write_text( + "\t\t\t\tMARKETING_VERSION = 2.192.3;\n\t\t\t\tCURRENT_PROJECT_VERSION = 2.192.3;\n", encoding="utf-8" + ) return macro def _dict_config(**extra): - return {"SCHEME": "readoorDict", "VERSION": "2.0.0", "SERVER": "词典测试", "APPID": "1593413622", + return {"SCHEME": "readoorDict", "VERSION": "2.0.0", "BUILD_VERSION": "2.0.0.3", + "SERVER": "词典测试", "APPID": "1593413622", "NO_CERT": True, "BUILD_TYPE": "Ad_Hoc", **extra} @@ -159,6 +165,10 @@ def test_dict_env_macros_replaced_only_in_targettype_2(tmp_path): content = macro.read_text() assert '#define SOURCE_VERSION @"2.0.0"' in content + pbxproj = (tmp_path / "readoor.xcodeproj" / "project.pbxproj").read_text() + assert "MARKETING_VERSION = 2.0.0;" in pbxproj + assert "CURRENT_PROJECT_VERSION = 2.0.0.3;" in pbxproj + assert "2.192.3" not in pbxproj assert '#define APPID @"1593413622"' in content assert '#define SERVERURL @"http://api-stage3/"' in content assert '#define LOGSERVERURL @"http://log-dev/"' in content