unifypy 2.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. unifypy/__init__.py +7 -0
  2. unifypy/__main__.py +21 -0
  3. unifypy/cli/__init__.py +10 -0
  4. unifypy/cli/argument_parser.py +209 -0
  5. unifypy/core/__init__.py +8 -0
  6. unifypy/core/config.py +491 -0
  7. unifypy/core/context.py +36 -0
  8. unifypy/core/engine.py +93 -0
  9. unifypy/core/environment.py +509 -0
  10. unifypy/core/event_bus.py +37 -0
  11. unifypy/core/events.py +16 -0
  12. unifypy/core/platforms.py +58 -0
  13. unifypy/core/plugin.py +65 -0
  14. unifypy/core/validators/__init__.py +10 -0
  15. unifypy/core/validators/tool_validator.py +144 -0
  16. unifypy/platforms/__init__.py +10 -0
  17. unifypy/platforms/base.py +127 -0
  18. unifypy/platforms/linux/__init__.py +10 -0
  19. unifypy/platforms/linux/deb_packager.py +289 -0
  20. unifypy/platforms/linux/rpm_packager.py +332 -0
  21. unifypy/platforms/macos/__init__.py +10 -0
  22. unifypy/platforms/macos/dmg_packager.py +477 -0
  23. unifypy/platforms/macos/post_processor.py +272 -0
  24. unifypy/platforms/registry.py +108 -0
  25. unifypy/platforms/windows/__init__.py +9 -0
  26. unifypy/platforms/windows/inno_setup.py +715 -0
  27. unifypy/plugins/__init__.py +3 -0
  28. unifypy/plugins/auto_rollback_plugin.py +156 -0
  29. unifypy/plugins/cleanup_plugin.py +22 -0
  30. unifypy/plugins/config_plugin.py +42 -0
  31. unifypy/plugins/dry_run_plugin.py +22 -0
  32. unifypy/plugins/environment_plugin.py +61 -0
  33. unifypy/plugins/external_plugins_loader.py +42 -0
  34. unifypy/plugins/packaging_plugin.py +125 -0
  35. unifypy/plugins/prepare_plugin.py +89 -0
  36. unifypy/plugins/progress_plugin.py +32 -0
  37. unifypy/plugins/pyinstaller_plugin.py +95 -0
  38. unifypy/plugins/rollback_plugin.py +62 -0
  39. unifypy/plugins/summary_plugin.py +36 -0
  40. unifypy/plugins/windows_language_plugin.py +85 -0
  41. unifypy/pyinstaller/__init__.py +7 -0
  42. unifypy/pyinstaller/config_builder.py +908 -0
  43. unifypy/templates/ChineseSimplified.isl.template +403 -0
  44. unifypy/templates/setup.iss.template +51 -0
  45. unifypy/tools/create-dmg/.this-is-the-create-dmg-repo +3 -0
  46. unifypy/tools/create-dmg/LICENSE +22 -0
  47. unifypy/tools/create-dmg/Makefile +33 -0
  48. unifypy/tools/create-dmg/README.md +126 -0
  49. unifypy/tools/create-dmg/builder/create-dmg.builder +26 -0
  50. unifypy/tools/create-dmg/create-dmg +621 -0
  51. unifypy/tools/create-dmg/doc-project/Developer Notes.md +35 -0
  52. unifypy/tools/create-dmg/doc-project/Release Checklist.md +10 -0
  53. unifypy/tools/create-dmg/examples/01-main-example/installer_background.png +0 -0
  54. unifypy/tools/create-dmg/examples/01-main-example/sample +30 -0
  55. unifypy/tools/create-dmg/examples/01-main-example/source_folder/Application.app +0 -0
  56. unifypy/tools/create-dmg/support/eula-resources-template.xml +105 -0
  57. unifypy/tools/create-dmg/support/template.applescript +74 -0
  58. unifypy/tools/create-dmg/tests/007-space-in-dir-name/my files/hello.txt +1 -0
  59. unifypy/tools/create-dmg/tests/007-space-in-dir-name/run-test +5 -0
  60. unifypy/utils/__init__.py +10 -0
  61. unifypy/utils/cache_manager.py +957 -0
  62. unifypy/utils/command_runner.py +195 -0
  63. unifypy/utils/entitlements_generator.py +450 -0
  64. unifypy/utils/file_ops.py +333 -0
  65. unifypy/utils/icon_converter.py +144 -0
  66. unifypy/utils/info_plist_updater.py +247 -0
  67. unifypy/utils/macos_codesign.py +225 -0
  68. unifypy/utils/parallel_builder.py +355 -0
  69. unifypy/utils/progress.py +371 -0
  70. unifypy/utils/progress_callback_factory.py +56 -0
  71. unifypy/utils/rollback.py +484 -0
  72. unifypy/utils/tool_manager.py +701 -0
  73. unifypy-2.0.2.dist-info/METADATA +609 -0
  74. unifypy-2.0.2.dist-info/RECORD +78 -0
  75. unifypy-2.0.2.dist-info/WHEEL +5 -0
  76. unifypy-2.0.2.dist-info/entry_points.txt +2 -0
  77. unifypy-2.0.2.dist-info/licenses/LICENSE +21 -0
  78. unifypy-2.0.2.dist-info/top_level.txt +1 -0
unifypy/core/config.py ADDED
@@ -0,0 +1,491 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ 配置管理系统 处理配置文件加载、合并和验证.
5
+ """
6
+
7
+ import json
8
+ import os
9
+ from .platforms import normalize_platform
10
+ from pathlib import Path
11
+ from typing import Any, Dict, List, Optional
12
+
13
+
14
+ class ConfigManager:
15
+ """
16
+ 配置管理器,处理配置合并和验证.
17
+ """
18
+
19
+ def __init__(self, config_path: Optional[str] = None, args: Optional[Dict] = None):
20
+ """初始化配置管理器.
21
+
22
+ Args:
23
+ config_path: 配置文件路径
24
+ args: 命令行参数字典
25
+ """
26
+ self.config_path = config_path
27
+ self.args = args or {}
28
+ self.raw_config = {}
29
+ self.merged_config = {}
30
+ self.current_platform = self._detect_platform()
31
+
32
+ # 获取项目目录用于路径解析
33
+ if "project_dir" in self.args:
34
+ self.project_dir = Path(self.args["project_dir"]).resolve()
35
+ else:
36
+ self.project_dir = Path.cwd()
37
+
38
+ if config_path:
39
+ self.raw_config = self._load_config(config_path)
40
+
41
+ self.merged_config = self._merge_all_configs()
42
+ self._validate_config()
43
+
44
+ def resolve_path(self, path: str) -> Path:
45
+ """
46
+ 解析配置中的路径,相对路径相对于项目目录.
47
+
48
+ Args:
49
+ path: 配置中的路径
50
+
51
+ Returns:
52
+ Path: 解析后的绝对路径
53
+ """
54
+ if not path:
55
+ return Path()
56
+
57
+ if os.path.isabs(path):
58
+ return Path(path)
59
+ else:
60
+ return self.project_dir / path
61
+
62
+ def preprocess_paths(self, config: dict) -> dict:
63
+ """
64
+ 预处理配置中的文件路径,将相对路径转换为绝对路径.
65
+
66
+ Args:
67
+ config: 原始配置字典
68
+
69
+ Returns:
70
+ dict: 处理后的配置字典(深拷贝)
71
+ """
72
+ import copy
73
+ processed_config = copy.deepcopy(config)
74
+
75
+ # 需要处理的文件路径字段
76
+ path_fields = [
77
+ "icon", "license", "readme", "entry",
78
+ "setup_icon", "license_file", "readme_file",
79
+ "volicon", "version_file", "manifest"
80
+ ]
81
+
82
+ # 需要处理的数组路径字段
83
+ array_path_fields = ["add_data", "add_binary", "datas", "binaries"]
84
+
85
+ # 处理顶级路径字段
86
+ for field in path_fields:
87
+ if field in processed_config and processed_config[field]:
88
+ path = processed_config[field]
89
+ if not os.path.isabs(path):
90
+ processed_config[field] = str(self.project_dir / path)
91
+
92
+ # 处理数组路径字段
93
+ self._process_array_paths(processed_config, array_path_fields)
94
+
95
+ # 处理嵌套配置中的路径(如平台特定配置)
96
+ for platform_key in ["windows", "macos", "linux", "platforms"]:
97
+ if platform_key in processed_config:
98
+ platform_config = processed_config[platform_key]
99
+ if isinstance(platform_config, dict):
100
+ self._process_nested_paths(platform_config, path_fields, array_path_fields)
101
+
102
+ # 处理 PyInstaller 配置中的路径
103
+ if "pyinstaller" in processed_config:
104
+ pyinstaller_config = processed_config["pyinstaller"]
105
+ if isinstance(pyinstaller_config, dict):
106
+ self._process_nested_paths(pyinstaller_config, path_fields, array_path_fields)
107
+
108
+ return processed_config
109
+
110
+ def _process_array_paths(self, config: dict, array_path_fields: List[str]):
111
+ """
112
+ 处理数组路径字段.
113
+
114
+ Args:
115
+ config: 配置字典
116
+ array_path_fields: 数组路径字段列表
117
+ """
118
+ for field in array_path_fields:
119
+ if field in config and config[field]:
120
+ processed_list = []
121
+ for item in config[field]:
122
+ if isinstance(item, str):
123
+ processed_item = self._process_path_item(item)
124
+ processed_list.append(processed_item)
125
+ else:
126
+ processed_list.append(item)
127
+ config[field] = processed_list
128
+
129
+ def _process_path_item(self, item: str) -> str:
130
+ """
131
+ 处理单个路径项(可能包含 source:dest 格式).
132
+
133
+ Args:
134
+ item: 路径项字符串
135
+
136
+ Returns:
137
+ str: 处理后的路径项
138
+ """
139
+ # 处理 "source:dest" 格式
140
+ if ":" in item or ";" in item:
141
+ separator = ":" if ":" in item else ";"
142
+ parts = item.split(separator, 1)
143
+ if len(parts) == 2:
144
+ source, dest = parts
145
+ if not os.path.isabs(source):
146
+ source = str(self.project_dir / source)
147
+ return f"{source}{separator}{dest}"
148
+ else:
149
+ return item
150
+ else:
151
+ # 单个路径
152
+ if not os.path.isabs(item):
153
+ return str(self.project_dir / item)
154
+ return item
155
+
156
+ def _process_nested_paths(
157
+ self,
158
+ config: dict,
159
+ path_fields: List[str],
160
+ array_path_fields: List[str]
161
+ ):
162
+ """
163
+ 递归处理嵌套配置中的文件路径.
164
+
165
+ Args:
166
+ config: 配置字典
167
+ path_fields: 单个路径字段列表
168
+ array_path_fields: 数组路径字段列表
169
+ """
170
+ # 处理单个路径字段
171
+ for field in path_fields:
172
+ if field in config and config[field]:
173
+ path = config[field]
174
+ if isinstance(path, str) and not os.path.isabs(path):
175
+ config[field] = str(self.project_dir / path)
176
+
177
+ # 处理数组路径字段
178
+ self._process_array_paths(config, array_path_fields)
179
+
180
+ # 递归处理嵌套字典
181
+ for value in config.values():
182
+ if isinstance(value, dict):
183
+ self._process_nested_paths(value, path_fields, array_path_fields)
184
+
185
+ def _detect_platform(self) -> str:
186
+ """
187
+ 检测当前平台.
188
+ """
189
+ return normalize_platform()
190
+
191
+ def _load_config(self, config_path: str) -> Dict[str, Any]:
192
+ """加载JSON配置文件.
193
+
194
+ Args:
195
+ config_path: 配置文件路径
196
+
197
+ Returns:
198
+ Dict[str, Any]: 配置字典
199
+
200
+ Raises:
201
+ FileNotFoundError: 配置文件不存在
202
+ json.JSONDecodeError: 配置文件格式错误
203
+ """
204
+ if not os.path.exists(config_path):
205
+ raise FileNotFoundError(f"配置文件不存在: {config_path}")
206
+
207
+ try:
208
+ with open(config_path, "r", encoding="utf-8-sig") as f:
209
+ config = json.load(f)
210
+ return config
211
+ except json.JSONDecodeError as e:
212
+ raise json.JSONDecodeError(f"配置文件格式错误: {e}", e.doc, e.pos)
213
+ except Exception as e:
214
+ raise Exception(f"加载配置文件失败: {e}")
215
+
216
+ def _merge_all_configs(self) -> Dict[str, Any]:
217
+ """合并所有配置源 优先级: 命令行参数 > 平台特定配置 > 全局配置 > 默认配置.
218
+
219
+ Returns:
220
+ Dict[str, Any]: 合并后的配置
221
+ """
222
+ # 默认配置
223
+ default_config = self._get_default_config()
224
+
225
+ # 从原始配置开始
226
+ merged = default_config.copy()
227
+
228
+ # 合并文件配置的全局部分
229
+ if self.raw_config:
230
+ global_config = {
231
+ k: v
232
+ for k, v in self.raw_config.items()
233
+ if k not in ["platform_specific", "platforms"]
234
+ }
235
+ merged.update(global_config)
236
+
237
+ # 合并平台特定配置
238
+ platform_config = self._get_platform_config()
239
+ if platform_config:
240
+ merged.update(platform_config)
241
+
242
+ # 合并命令行参数
243
+ if self.args:
244
+ args_config = self._args_to_config(self.args)
245
+ merged.update(args_config)
246
+
247
+ return merged
248
+
249
+ def _get_default_config(self) -> Dict[str, Any]:
250
+ """
251
+ 获取默认配置.
252
+ """
253
+ return {
254
+ "name": "UnknownApp",
255
+ "version": "1.0.0",
256
+ "entry": "main.py",
257
+ "publisher": "Unknown Publisher",
258
+ "onefile": False,
259
+ "skip_installer": False,
260
+ "pyinstaller": {"clean": True, "noconfirm": True},
261
+ }
262
+
263
+ def _get_platform_config(self) -> Dict[str, Any]:
264
+ """获取当前平台的特定配置.
265
+
266
+ Returns:
267
+ Dict[str, Any]: 平台特定配置
268
+ """
269
+ if not self.raw_config:
270
+ return {}
271
+
272
+ # 尝试新格式 (platforms)
273
+ platforms = self.raw_config.get("platforms", {})
274
+ if self.current_platform in platforms:
275
+ return platforms[self.current_platform]
276
+
277
+ # 尝试旧格式 (platform_specific)
278
+ platform_specific = self.raw_config.get("platform_specific", {})
279
+ if self.current_platform in platform_specific:
280
+ return platform_specific[self.current_platform]
281
+
282
+ return {}
283
+
284
+ def _args_to_config(self, args: Dict[str, Any]) -> Dict[str, Any]:
285
+ """将命令行参数转换为配置格式.
286
+
287
+ Args:
288
+ args: 命令行参数字典
289
+
290
+ Returns:
291
+ Dict[str, Any]: 配置字典
292
+ """
293
+ config = {}
294
+
295
+ # 直接映射的参数
296
+ direct_mappings = {
297
+ "name": "name",
298
+ "display_name": "display_name",
299
+ "entry": "entry",
300
+ "version": "version",
301
+ "publisher": "publisher",
302
+ "icon": "icon",
303
+ "license": "license",
304
+ "readme": "readme",
305
+ "hooks": "hooks",
306
+ "onefile": "onefile",
307
+ "skip_installer": "skip_installer",
308
+ "skip_exe": "skip_exe",
309
+ "inno_setup_path": "inno_setup_path",
310
+ }
311
+
312
+ for arg_key, config_key in direct_mappings.items():
313
+ if arg_key in args and args[arg_key] is not None:
314
+ config[config_key] = args[arg_key]
315
+
316
+ return config
317
+
318
+ def _validate_config(self):
319
+ """
320
+ 验证配置的有效性.
321
+ """
322
+ errors = []
323
+ warnings = []
324
+
325
+ # 检查必需字段
326
+ required_fields = ["name", "entry"]
327
+ for field in required_fields:
328
+ if not self.merged_config.get(field):
329
+ errors.append(f"缺少必需配置项: {field}")
330
+
331
+ # 检查文件路径
332
+ entry_file = self.merged_config.get("entry")
333
+ if entry_file:
334
+ entry_full_path = self.resolve_path(entry_file)
335
+ if not entry_full_path.exists():
336
+ errors.append(f"入口文件不存在: {entry_file}")
337
+
338
+ icon_file = self.merged_config.get("icon")
339
+ if icon_file:
340
+ icon_full_path = self.resolve_path(icon_file)
341
+ if not icon_full_path.exists():
342
+ warnings.append(f"图标文件不存在: {icon_file}")
343
+
344
+ # 检查其他可能的文件路径
345
+ file_fields = ["license", "readme"]
346
+ for field in file_fields:
347
+ file_path = self.merged_config.get(field)
348
+ if file_path:
349
+ full_path = self.resolve_path(file_path)
350
+ if not full_path.exists():
351
+ warnings.append(f"{field}文件不存在: {file_path}")
352
+
353
+ # 检查重复配置
354
+ duplicates = self._check_duplicate_configs()
355
+ if duplicates:
356
+ warnings.extend([f"配置重复: {dup}" for dup in duplicates])
357
+
358
+ if errors:
359
+ raise ValueError(f"配置验证失败: {'; '.join(errors)}")
360
+
361
+ # 记录警告(这里可以通过日志系统输出)
362
+ for warning in warnings:
363
+ print(f"警告: {warning}")
364
+
365
+ def _check_duplicate_configs(self) -> List[str]:
366
+ """
367
+ 检查重复配置项.
368
+ """
369
+ duplicates = []
370
+
371
+ if not self.raw_config:
372
+ return duplicates
373
+
374
+ # 获取全局配置的键
375
+ global_keys = set(self.raw_config.keys()) - {"platform_specific", "platforms"}
376
+
377
+ # 检查平台配置中的重复项
378
+ platform_config = self._get_platform_config()
379
+ platform_keys = set(platform_config.keys())
380
+
381
+ duplicate_keys = global_keys.intersection(platform_keys)
382
+ duplicates.extend(duplicate_keys)
383
+
384
+ return duplicates
385
+
386
+ def get(self, key: str, default: Any = None) -> Any:
387
+ """获取配置值.
388
+
389
+ Args:
390
+ key: 配置键,支持点号分隔的嵌套键
391
+ default: 默认值
392
+
393
+ Returns:
394
+ Any: 配置值
395
+ """
396
+ keys = key.split(".")
397
+ value = self.merged_config
398
+
399
+ try:
400
+ for k in keys:
401
+ value = value[k]
402
+ return value
403
+ except (KeyError, TypeError):
404
+ return default
405
+
406
+ def get_pyinstaller_config(self) -> Dict[str, Any]:
407
+ """获取PyInstaller配置.
408
+
409
+ Returns:
410
+ Dict[str, Any]: PyInstaller配置
411
+ """
412
+ config = {}
413
+
414
+ # 从顶级配置中获取PyInstaller相关项
415
+ pyinstaller_keys = [
416
+ "onefile",
417
+ "windowed",
418
+ "console",
419
+ "icon",
420
+ "name",
421
+ "distpath",
422
+ "workpath",
423
+ "specpath",
424
+ "debug",
425
+ "clean",
426
+ "noconfirm",
427
+ "strip",
428
+ "noupx",
429
+ "optimize",
430
+ ]
431
+
432
+ for key in pyinstaller_keys:
433
+ value = self.get(key)
434
+ if value is not None:
435
+ config[key] = value
436
+
437
+ # 获取pyinstaller节中的配置
438
+ pyinstaller_section = self.get("pyinstaller", {})
439
+ config.update(pyinstaller_section)
440
+
441
+ # 处理平台特定的PyInstaller配置
442
+ platform_pyinstaller = self._get_platform_config().get("pyinstaller", {})
443
+ config.update(platform_pyinstaller)
444
+
445
+ # 添加 macOS 特定的配置
446
+ if self.current_platform == "macos":
447
+ platform_config = self._get_platform_config()
448
+
449
+ # Bundle Identifier
450
+ if "bundle_identifier" in platform_config:
451
+ config["osx_bundle_identifier"] = platform_config["bundle_identifier"]
452
+
453
+ return config
454
+
455
+ def get_platform_installer_config(self, installer_type: str) -> Dict[str, Any]:
456
+ """获取平台特定安装器配置.
457
+
458
+ Args:
459
+ installer_type: 安装器类型 (如 'inno_setup', 'create_dmg', 'deb')
460
+
461
+ Returns:
462
+ Dict[str, Any]: 安装器配置
463
+ """
464
+ platform_config = self._get_platform_config()
465
+ return platform_config.get(installer_type, {})
466
+
467
+ def get_app_info(self) -> Dict[str, Any]:
468
+ """获取应用程序基本信息.
469
+
470
+ Returns:
471
+ Dict[str, Any]: 应用信息字典
472
+ """
473
+ return {
474
+ "name": self.get("name"),
475
+ "display_name": self.get("display_name") or self.get("name"),
476
+ "version": self.get("version"),
477
+ "publisher": self.get("publisher"),
478
+ "entry": self.get("entry"),
479
+ "icon": self.get("icon"),
480
+ "license": self.get("license"),
481
+ "readme": self.get("readme"),
482
+ }
483
+
484
+ def save_merged_config(self, output_path: str):
485
+ """保存合并后的配置到文件.
486
+
487
+ Args:
488
+ output_path: 输出文件路径
489
+ """
490
+ with open(output_path, "w", encoding="utf-8") as f:
491
+ json.dump(self.merged_config, f, indent=2, ensure_ascii=False)
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ 构建上下文:贯穿生命周期的共享状态与依赖。
5
+ """
6
+
7
+ from pathlib import Path
8
+ from typing import Any, Dict, Optional
9
+
10
+
11
+ class BuildContext:
12
+ def __init__(self, args: Any):
13
+ self.args = args
14
+ self.project_dir: Path = Path(getattr(args, "project_dir", ".")).resolve()
15
+
16
+ # 运行期组件(由插件填充)
17
+ self.progress = None
18
+ self.runner = None
19
+ self.file_ops = None
20
+ self.tool_manager = None
21
+ self.packager_registry = None
22
+ self.config = None
23
+ self.env_manager = None
24
+ self.cache_manager = None
25
+
26
+ # 目录
27
+ self.temp_dir: Optional[Path] = None
28
+ self.dist_dir: Path = self.project_dir / "dist"
29
+ self.installer_dir: Path = self.project_dir / "installer"
30
+
31
+ # 其他
32
+ self.errors = [] # [(event, Exception)]
33
+ self.state: Dict[str, Any] = {}
34
+ self.exit_code: int = 0
35
+ self.should_exit: bool = False
36
+
unifypy/core/engine.py ADDED
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ 构建引擎:协调事件顺序,驱动插件化生命周期。
5
+ """
6
+
7
+ from .event_bus import EventBus
8
+ from .events import (
9
+ ON_START,
10
+ HANDLE_ROLLBACK_COMMANDS,
11
+ LOAD_CONFIG,
12
+ ENVIRONMENT_CHECK,
13
+ PREPARE,
14
+ BUILD_EXECUTABLE,
15
+ GENERATE_INSTALLERS,
16
+ ON_SUCCESS,
17
+ ON_EXIT,
18
+ ON_ERROR,
19
+ )
20
+
21
+
22
+ class Engine:
23
+ def __init__(self, context, plugin_manager):
24
+ self.context = context
25
+ self.plugin_manager = plugin_manager
26
+ self.bus = EventBus()
27
+
28
+ def setup(self):
29
+ plugins = self.plugin_manager.load_builtin_plugins()
30
+ self.plugin_manager.register_plugins(self.bus, plugins)
31
+
32
+ def run(self) -> int:
33
+ ctx = self.context
34
+ try:
35
+ # 生命周期事件顺序
36
+ self.bus.emit(ON_START, ctx)
37
+ if ctx.errors:
38
+ raise ctx.errors[-1][1]
39
+
40
+ # 回滚命令处理(列出/执行后退出)
41
+ self.bus.emit(HANDLE_ROLLBACK_COMMANDS, ctx)
42
+ if ctx.should_exit:
43
+ self.bus.emit(ON_EXIT, ctx)
44
+ return ctx.exit_code
45
+
46
+ self.bus.emit(LOAD_CONFIG, ctx)
47
+ if ctx.errors:
48
+ raise ctx.errors[-1][1]
49
+ self.bus.emit(ENVIRONMENT_CHECK, ctx)
50
+ if ctx.errors:
51
+ raise ctx.errors[-1][1]
52
+ self.bus.emit(PREPARE, ctx)
53
+ if ctx.errors:
54
+ raise ctx.errors[-1][1]
55
+
56
+ # 可执行文件构建
57
+ self.bus.emit(BUILD_EXECUTABLE, ctx)
58
+ if ctx.errors:
59
+ raise ctx.errors[-1][1]
60
+
61
+ # 安装包生成
62
+ self.bus.emit(GENERATE_INSTALLERS, ctx)
63
+ if ctx.errors:
64
+ raise ctx.errors[-1][1]
65
+
66
+ # 成功收尾
67
+ self.bus.emit(ON_SUCCESS, ctx)
68
+ self.bus.emit(ON_EXIT, ctx)
69
+ return 0
70
+
71
+ except KeyboardInterrupt:
72
+ # 友好处理用户中断
73
+ try:
74
+ if getattr(ctx, "progress", None):
75
+ ctx.progress.on_error(Exception("用户中断"), "构建过程")
76
+ finally:
77
+ try:
78
+ # 触发错误处理钩子以便自动回滚与清理
79
+ try:
80
+ self.bus.emit(ON_ERROR, ctx)
81
+ except Exception:
82
+ pass
83
+ self.bus.emit(ON_EXIT, ctx)
84
+ finally:
85
+ return 1
86
+ except Exception as e:
87
+ # 收敛异常通知
88
+ ctx.errors.append(("engine", e))
89
+ try:
90
+ self.bus.emit(ON_ERROR, ctx)
91
+ self.bus.emit(ON_EXIT, ctx)
92
+ finally:
93
+ return 1