• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# Copyright (c) 2022 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# This file is a configuration for scaning the BUILD.gn to collection compile
17# products.
18
19
20import os
21import sys
22import argparse
23import json
24import logging
25from typing import *
26
27import preprocess
28from pkgs.simple_yaml_tool import SimpleYamlTool
29from pkgs.basic_tool import do_nothing, BasicTool
30from get_subsystem_component import SC
31from misc import *
32from template_processor import *
33"""
34只给rom_analysis.py使用
35"""
36
37
38def parse_args():
39    parser = argparse.ArgumentParser(
40        description="analysis rom size of L0 and L1 product")
41    parser.add_argument("-p", "--product_name", type=str,
42                        help="product name. eg: -p ipcamera_hispark_taurus")
43    parser.add_argument("-o", "--oh_path", type=str,
44                        default=".", help="root path of openharmony")
45    parser.add_argument("-g", "--recollect_gn",
46                        action="store_false", help="recollect gn info or not(-g)")
47    parser.add_argument("-s", "--recollect_sc", action="store_false",
48                        help="recollect subsystem_component info or not(-s)")
49    parser.add_argument("-b", "--baseline", action="store_true",
50                        help="add baseline of component to the result(-b) or not.")
51    parser.add_argument("-u", "--unit_adaptive",
52                        action="store_true", help="unit adaptive")
53    parser.add_argument("-f", "--output_file", type=str, default="rom_analysis_result",
54                        help="basename of output file, default: rom_analysis_result. eg: rom_analysis_result")
55    args = parser.parse_args()
56    return args
57
58
59logging.basicConfig(level=logging.NOTSET)
60_args = parse_args()
61
62# # global variables
63configs = SimpleYamlTool.read_yaml("config.yaml")
64result_dict: Dict[str, Any] = dict()
65product_name = _args.product_name
66if product_name not in configs.keys():
67    print(f"error: product_name '{product_name}' illegal")
68    exit(-1)
69project_path = BasicTool.abspath(_args.oh_path)
70recollect_gn = _args.recollect_gn
71baseline = _args.baseline
72unit_adapt = _args.unit_adaptive
73output_file = _args.output_file
74_recollect_sc = _args.recollect_sc
75_sc_json: Dict[Text, Text] = configs.get("subsystem_component")
76_sc_save = _sc_json.get("save")
77_target_type = configs["target_type"]
78_sc_output_path = _sc_json.get("filename")
79if _recollect_sc:
80    logging.info(
81        "satrt scanning subsystem_name and component via get_subsystem_comonent.py")
82    sub_com_dict: Dict = SC.run(project_path, _sc_output_path, _sc_save)
83else:
84    with open(_sc_output_path, 'r', encoding='utf-8') as f:
85        sub_com_dict = json.load(f)
86
87collector_config: Tuple[BaseProcessor] = (
88    DefaultProcessor(project_path=project_path,    # 项目根路径
89                     result_dict=result_dict,   # 保存结果的字典
90                     # targte的类型名称,即xxx("yyy")中的xxx
91                     target_type=_target_type[0],
92                     # 用以进行匹配的模式串,包括匹配段落时作为前缀
93                     match_pattern=fr"^( *){_target_type[0]}\(.*?\)",
94                     sub_com_dict=sub_com_dict,    # 从bundle.json中收集的subsystem_name和component_name信息
95                     target_name_parser=TargetNameParser.single_parser,  # 进行target_name解析的parser
96                     other_info_handlers={
97                         "extension": extension_handler,
98                     },    # 解析其他信息的parser,{"字段名":该字段的parser}
99                     unit_post_handler=SOPostHandler()  # 对即将进行存储的unit字典的handler,会返回一个str作为存储时的key
100                     ),
101    DefaultProcessor(project_path=project_path,
102                     result_dict=result_dict,
103                     target_type=_target_type[1],
104                     match_pattern=fr"^( *){_target_type[1]}\(.*?\)",
105                     sub_com_dict=sub_com_dict,
106                     target_name_parser=TargetNameParser.single_parser,
107                     other_info_handlers={
108                         "extension": extension_handler,
109                     },
110                     unit_post_handler=SOPostHandler(),
111                     ),
112    DefaultProcessor(project_path=project_path,
113                     result_dict=result_dict,
114                     target_type=_target_type[2],
115                     match_pattern=fr"^( *){_target_type[2]}\(.*?\)",
116                     sub_com_dict=sub_com_dict,
117                     target_name_parser=TargetNameParser.single_parser,
118                     other_info_handlers={
119                         "extension": extension_handler,
120                     },
121                     unit_post_handler=APostHandler(),
122                     ),
123    DefaultProcessor(project_path=project_path,
124                     result_dict=result_dict,
125                     target_type=_target_type[3],
126                     match_pattern=fr"^( *){_target_type[3]}\(.*?\)",
127                     sub_com_dict=sub_com_dict,
128                     target_name_parser=TargetNameParser.single_parser,
129                     other_info_handlers={
130                         "extension": extension_handler,
131                     },
132                     unit_post_handler=APostHandler(),
133                     ),
134    DefaultProcessor(project_path=project_path,
135                     result_dict=result_dict,
136                     target_type=_target_type[4],
137                     match_pattern=fr"^( *){_target_type[4]}\(.*?\)",
138                     sub_com_dict=sub_com_dict,
139                     target_name_parser=TargetNameParser.single_parser,
140                     other_info_handlers={
141                         "extension": extension_handler,
142                     },
143                     unit_post_handler=DefaultPostHandler(),
144                     ),
145    DefaultProcessor(project_path=project_path,
146                     result_dict=result_dict,
147                     target_type=_target_type[5],
148                     match_pattern=fr"^( *){_target_type[5]}\(.*?\)",
149                     sub_com_dict=sub_com_dict,
150                     target_name_parser=TargetNameParser.single_parser,
151                     other_info_handlers={
152                         "extension": extension_handler,
153                     },
154                     unit_post_handler=DefaultPostHandler(),
155                     ),
156    DefaultProcessor(project_path=project_path,
157                     result_dict=result_dict,
158                     target_type=_target_type[6],
159                     match_pattern=fr"^( *){_target_type[6]}\(.*?\)",
160                     sub_com_dict=sub_com_dict,
161                     target_name_parser=TargetNameParser.single_parser,
162                     other_info_handlers={
163                         "real_target_type": target_type_handler,
164                         "extension": extension_handler,
165                     },
166                     unit_post_handler=LiteLibPostHandler(),
167                     ud_post_handler=LiteLibS2MPostHandler,
168                     ),
169    DefaultProcessor(project_path=project_path,    # hap有个hap_name
170                     result_dict=result_dict,
171                     target_type=_target_type[7],
172                     match_pattern=fr"^( *){_target_type[7]}\(.*?\)",
173                     sub_com_dict=sub_com_dict,
174                     target_name_parser=TargetNameParser.single_parser,
175                     other_info_handlers={
176                         "hap_name": hap_name_handler,
177                         "extension": extension_handler,
178                     },
179                     unit_post_handler=HAPPostHandler(),
180                     ),
181    StrResourceProcessor(project_path=project_path,
182                         result_dict=result_dict,
183                         target_type=_target_type[8],
184                         match_pattern=fr"^( *){_target_type[8]}\(.*?\)",
185                         sub_com_dict=sub_com_dict,
186                         target_name_parser=TargetNameParser.single_parser,
187                         other_info_handlers={
188                             "extension": extension_handler,
189                         },
190                         unit_post_handler=DefaultPostHandler(),
191                         resource_field="source"
192                         ),
193    StrResourceProcessor(project_path=project_path,
194                         result_dict=result_dict,
195                         target_type=_target_type[9],
196                         match_pattern=fr"^( *){_target_type[9]}\(.*?\)",
197                         sub_com_dict=sub_com_dict,
198                         target_name_parser=TargetNameParser.single_parser,
199                         other_info_handlers={
200                             "extension": extension_handler,
201                         },
202                         unit_post_handler=DefaultPostHandler(),
203                         resource_field="source"
204                         ),
205    ListResourceProcessor(project_path=project_path,
206                          result_dict=result_dict,
207                          target_type=_target_type[10],
208                          match_pattern=fr"^( *){_target_type[10]}\(.*?\)",
209                          sub_com_dict=sub_com_dict,
210                          target_name_parser=TargetNameParser.single_parser,
211                          other_info_handlers={
212                              "extension": extension_handler,
213                          },
214                          unit_post_handler=DefaultPostHandler(),
215                          resource_field="sources"
216                          ),
217    StrResourceProcessor(project_path=project_path,
218                         result_dict=result_dict,
219                         target_type=_target_type[11],
220                         match_pattern=fr"^( *){_target_type[11]}\(.*?\)",
221                         sub_com_dict=sub_com_dict,
222                         target_name_parser=TargetNameParser.single_parser,
223                         other_info_handlers={
224                             #  "extension": extension_handler,
225                         },
226                         unit_post_handler=DefaultPostHandler(),
227                         resource_field="source"
228                         ),
229    DefaultProcessor(project_path=project_path,
230                     result_dict=result_dict,
231                     target_type=_target_type[12],
232                     match_pattern=fr"^( *){_target_type[12]}\(.*?\)",
233                     sub_com_dict=sub_com_dict,
234                     target_name_parser=TargetNameParser.single_parser,
235                     other_info_handlers={
236                         "real_target_type": target_type_handler,
237                         #  "extension": extension_handler,
238                     },
239                     unit_post_handler=LiteComponentPostHandler(),
240                     ),
241    DefaultProcessor(project_path=project_path,
242                     result_dict=result_dict,
243                     target_type=_target_type[13],
244                     match_pattern=fr"^( *){_target_type[13]}\(.*?\, .*?\)",
245                     sub_com_dict=sub_com_dict,
246                     target_name_parser=TargetNameParser.second_parser,
247                     other_info_handlers={
248                     },
249                     unit_post_handler=DefaultPostHandler(),
250                     ud_post_handler=TargetS2MPostHandler
251                     ),
252    DefaultProcessor(project_path=project_path,
253                     result_dict=result_dict,
254                     target_type=_target_type[14],
255                     match_pattern=fr"^( *){_target_type[14]}\(.*?\)",
256                     sub_com_dict=sub_com_dict,
257                     target_name_parser=TargetNameParser.single_parser,
258                     other_info_handlers={
259                         "output_extension":extension_handler
260                     },
261                     unit_post_handler=UnittestPostHandler(),
262                     ),
263    DefaultProcessor(project_path=project_path,
264                     result_dict=result_dict,
265                     target_type=_target_type[15],
266                     match_pattern=fr"^( *){_target_type[15]}\(.*?\)",
267                     sub_com_dict=sub_com_dict,
268                     target_name_parser=TargetNameParser.single_parser,
269                     other_info_handlers={
270                         "hap_name": hap_name_handler,
271                         "mode": mod_handler,
272                     },
273                     unit_post_handler=HapPackPostHandler(),
274                     ),
275    ListResourceProcessor(project_path=project_path,
276                          result_dict=result_dict,
277                          target_type=_target_type[16],
278                          match_pattern=fr"^( *){_target_type[16]}\(.*?\)",
279                          sub_com_dict=sub_com_dict,
280                          target_name_parser=TargetNameParser.single_parser,
281                          other_info_handlers={
282                          },
283                          unit_post_handler=DefaultPostHandler(),
284                          resource_field="sources"
285                          ),
286)
287
288__all__ = ["configs", "result_dict", "collector_config", "sub_com_dict"]
289