-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathproject_analyzer_factory.py
More file actions
180 lines (146 loc) · 5.03 KB
/
project_analyzer_factory.py
File metadata and controls
180 lines (146 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
项目分析器工厂
根据编译工具类型创建相应的项目分析器
"""
from lib_IAR.project_analyzer import IARProjectAnalyzer
from lib_MDK.project_analyzer import MDKProjectAnalyzer
class ProjectAnalyzerFactory:
"""项目分析器工厂类"""
@staticmethod
def create_analyzer(compile_tool: str):
"""
根据编译工具类型创建相应的项目分析器
Args:
compile_tool: 编译工具类型 ('IAR' 或 'MDK')
Returns:
相应的项目分析器实例
"""
if compile_tool == 'IAR':
return IARProjectAnalyzer()
elif compile_tool == 'MDK':
return MDKProjectAnalyzer()
else:
# 默认使用IAR
return IARProjectAnalyzer()
@staticmethod
def get_common_methods():
"""
获取两个分析器都支持的公共方法列表
Returns:
list: 公共方法名列表
"""
return [
'find_build_outputs',
'_parse_configurations',
'analyze_icf_file', # IAR: analyze_icf_file, MDK: analyze_sct_file
'get_flash_offset_from_configuration'
]
@staticmethod
def get_iar_only_methods():
"""
获取IAR分析器独有的方法列表
Returns:
list: IAR独有方法名列表
"""
return [
'analyze_ewp_file',
'find_ewp_file',
'analyze_icf_file',
'get_flash_offset_from_configuration'
]
@staticmethod
def get_mdk_only_methods():
"""
获取MDK分析器独有的方法列表
Returns:
list: MDK独有方法名列表
"""
return [
'analyze_uvprojx_file',
'extract_flash_start_address_from_sct',
'get_project_info',
'_parse_output_directory',
'_parse_output_name',
'_parse_sct_file',
'_parse_debug_mode'
]
@staticmethod
def get_analyze_method_name(compile_tool: str) -> str:
"""
获取指定编译工具的分析方法名
Args:
compile_tool: 编译工具类型
Returns:
str: 分析方法名
"""
if compile_tool == 'IAR':
return 'analyze_ewp_file'
elif compile_tool == 'MDK':
return 'analyze_uvprojx_file'
else:
return 'analyze_ewp_file'
@staticmethod
def get_file_extension(compile_tool: str) -> str:
"""
获取指定编译工具的项目文件扩展名
Args:
compile_tool: 编译工具类型
Returns:
str: 文件扩展名
"""
if compile_tool == 'IAR':
return '.ewp'
elif compile_tool == 'MDK':
return '.uvprojx'
else:
return '.ewp'
@staticmethod
def get_config_analyze_method_name(compile_tool: str) -> str:
"""
获取指定编译工具的配置文件分析方法名
Args:
compile_tool: 编译工具类型
Returns:
str: 配置文件分析方法名
"""
if compile_tool == 'IAR':
return 'analyze_icf_file'
elif compile_tool == 'MDK':
return 'analyze_sct_file'
else:
return 'analyze_icf_file'
def create_unified_analyzer(compile_tool: str):
"""
创建统一的项目分析器
Args:
compile_tool: 编译工具类型
Returns:
统一的项目分析器实例
"""
return ProjectAnalyzerFactory.create_analyzer(compile_tool)
if __name__ == "__main__":
# 测试工厂模式
print("项目分析器工厂测试")
# 测试IAR分析器
iar_analyzer = ProjectAnalyzerFactory.create_analyzer('IAR')
print(f"IAR分析器类型: {type(iar_analyzer).__name__}")
# 测试MDK分析器
mdk_analyzer = ProjectAnalyzerFactory.create_analyzer('MDK')
print(f"MDK分析器类型: {type(mdk_analyzer).__name__}")
# 显示公共方法
common_methods = ProjectAnalyzerFactory.get_common_methods()
print(f"公共方法: {common_methods}")
# 显示IAR独有方法
iar_only_methods = ProjectAnalyzerFactory.get_iar_only_methods()
print(f"IAR独有方法: {iar_only_methods}")
# 显示MDK独有方法
mdk_only_methods = ProjectAnalyzerFactory.get_mdk_only_methods()
print(f"MDK独有方法: {mdk_only_methods}")
# 显示分析方法名
print(f"IAR分析方法: {ProjectAnalyzerFactory.get_analyze_method_name('IAR')}")
print(f"MDK分析方法: {ProjectAnalyzerFactory.get_analyze_method_name('MDK')}")
# 显示文件扩展名
print(f"IAR文件扩展名: {ProjectAnalyzerFactory.get_file_extension('IAR')}")
print(f"MDK文件扩展名: {ProjectAnalyzerFactory.get_file_extension('MDK')}")