libclang.so路径修改和文件级统计工具文件路径固定

Signed-off-by: zhangwuf <zhangwu47@huawei.com>
This commit is contained in:
zhangwuf 2024-04-26 16:54:26 +08:00
parent 38e3801bbe
commit f12201b2c7
3 changed files with 38 additions and 6 deletions

View File

@ -24,6 +24,7 @@ class ToolNameType(enum.Enum):
DIFF = 'diff'
CHECK = 'check'
COLLECT_H = 'collect_h'
COLLECT_FILE = 'collect_file'
tool_name_type_set = [
@ -53,6 +54,8 @@ def run_tools(options):
check.curr_entry(options.parser_path)
elif tool_name == ToolNameType['COLLECT_H'].value:
parser.parser_direct(options.parser_path)
elif tool_name == ToolNameType['COLLECT_FILE'].value:
parser.parser_file_level(options.output_path)
else:
print("工具名称错误")
@ -78,6 +81,13 @@ class Config(object):
"type": str,
"help": "解析路径"
},
{
"name": "--output-path",
"abbr": "-O",
"required": True,
"type": str,
"help": "collect_file工具输出文件路径"
},
{
"name": "--diff-path-old",
"abbr": "-old",

View File

@ -332,7 +332,7 @@ def get_dir_file_path(dir_path):
for dir_name in dir_names:
link_include_path.append(os.path.join(dir_path, dir_name))
for file in filenames:
if file.endswith('.h'):
if 'build-tools' not in dir_path and file.endswith('.h'):
file_path_list.append(os.path.join(dir_path, file))
return file_path_list, link_include_path
@ -362,19 +362,21 @@ def get_file_api_json(data_total):
if 'name' in one_file_data and 'kit_name' in one_file_data and 'sub_system' in one_file_data:
api_message_obj = OneFileApiMessage(one_file_data['name'], one_file_data['kit_name'],
one_file_data['sub_system'], file_api_num)
api_message_obj.set_file_path(api_message_obj.get_file_path().replace('\\', '/'))
current_file = os.path.dirname(__file__)
kit_json_file_path = os.path.abspath(os.path.join(current_file,
r"kit_sub_system/c_file_kit_sub_system.json"))
complete_kit_or_system(api_message_obj, kit_json_file_path)
api_obj_total_list.append(api_message_obj)
api_obj_total_json = json.dumps(api_obj_total_list, default=lambda obj: obj.__dict__, indent=4,
ensure_ascii=False)
return api_obj_total_json
def generate_file_api_json(json_data):
with open(StringConstant.FILE_LEVEL_API_DATA.value, 'w', encoding='utf-8') as fs:
def generate_file_api_json(json_data, output_path=''):
if not output_path:
output_path = StringConstant.FILE_LEVEL_API_DATA.value
with open(output_path, 'w', encoding='utf-8') as fs:
fs.write(json_data)
fs.close()
@ -395,7 +397,7 @@ def get_kit_system_data(json_path, relative_path):
with open(json_path, 'r', encoding='utf-8') as fs:
kit_system_data = json.load(fs)
for data in kit_system_data['data']:
if 'filePath' in data and relative_path == data['filePath'].replace('/', '\\'):
if 'filePath' in data and relative_path in data['filePath']:
kit_name = data['kitName']
sub_system_name = data['subSystem']
break
@ -421,3 +423,23 @@ def parser_direct(path): # 目录路径
generating_tables.get_api_data(data_total, StringConstant.PARSER_DIRECT_EXCEL_NAME.value)
return data_total
def parser_file_level(output_path):
current_file = os.path.dirname(__file__)
parser_path = os.path.abspath(os.path.join(current_file, r'../../../../..'))
file_path_list = []
link_include_path = [] # 装链接头文件路径
dir_path = ''
if os.path.isdir(parser_path):
file_path_total, link_include_total = get_dir_file_path(parser_path)
file_path_list.extend(file_path_total)
link_include_path.extend(link_include_total)
dir_path = parser_path
else:
print('c_path is incorrect')
data_total = parse_include.get_include_file(file_path_list, link_include_path, dir_path)
file_api_json = get_file_api_json(data_total)
generate_file_api_json(file_api_json, output_path)
return data_total

View File

@ -19,7 +19,7 @@ import enum
class StringConstant(enum.Enum):
LIB_CLG_PATH = r'home/tools/llvm/lib/libclang.so' # 共享库
LIB_CLG_PATH = r'/home/tools/llvm/lib/libclang.so' # 共享库
FUNK_NAME = "ohos_ndk_headers"
REPLACE_WAREHOUSE = '\\interface_sdk_c\\interface_sdk_c' # 拉到本地仓路径(去掉磁盘)
# 拉到本地仓的三方库绝对路径