From 53835213bda931659a148a74973a920f34e7c7ae Mon Sep 17 00:00:00 2001 From: aodongbiao Date: Tue, 9 Aug 2022 10:46:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BAsyscap=E4=B8=80=E8=87=B4=E6=80=A7?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=B7=A5=E5=85=B7=E6=8F=90=E4=BE=9B=E4=BA=86?= =?UTF-8?q?=E7=9F=AD=E5=88=AB=E5=90=8D=EF=BC=8C=E5=B9=B6=E4=B8=BA--project?= =?UTF-8?q?=5Fpath=E5=A2=9E=E5=8A=A0=E9=BB=98=E8=AE=A4=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E4=B8=BA=E5=BD=93=E5=89=8D=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: aodongbiao --- README.md | 27 ++++++++++++++------------- README_ZH.md | 37 ++++++++++++++++++++++++++++--------- tools/syscap_check.py | 41 ++++++++++++++++++++++++++++++----------- 3 files changed, 72 insertions(+), 33 deletions(-) mode change 100644 => 100755 tools/syscap_check.py diff --git a/README.md b/README.md index 8a7a6bb..005c7bc 100644 --- a/README.md +++ b/README.md @@ -82,13 +82,19 @@ SysCap tools usually integrate to IDE, APP store and bundle tools. Follow instru -o outpath, --input outpath : output path ``` -### Description and usage of Syscap Consistency Check Tool +## Syscap consistency check tool + +### Functions and dependencies The tool provides the following functions: -1. Collect syscap fields of all components (or specified components), compare them with arraySyscap in developtools/syscap_codec/include/syscap_define.h, and output the check results. If they are inconsistent, output the cause of the discrepancy -2. Collect the syscap fields of all components and compare them with the @syscap property set in *.d.ts in the interface/sdk-js/api directory. If the check results are inconsistent, output the cause of the inconsistency -3. Compare syscap attributes in all *.d.ts in interface/ sdk-js/api directory with arraySyscap in developtools/syscap_codec/include/syscap_define.h. If they are inconsistent, output the cause of the the inconsistency +1. Collect syscap fields of all components (or specified components), compare them with arraySyscap in developtools/ syscap_codec/include/syscap_define.h, and output the check results. If they are inconsistent, output the cause of the discrepancy. +2. Collect the syscap fields of all components and compare them with the @syscap property set in *.d.ts in the Interface/sdk-js/api directory. If the check results are inconsistent, output the cause of the inconsistency. +3. Compare syscap attributes in *.d.ts in all interface/ sdK-JS/API directories with arraySyscap in developtools/syscap_codec/include/syscap_define.h. If they are inconsistent, output the cause of the inconsistency. + +### How to use it + +This tool is written in Python language and needs to be executed using the Python interpreter. requirements: @@ -99,22 +105,17 @@ prettytable==3.3.0 usage: ```shell -# see the help -python3 syscap-check.py --help - -# The comparison of these three different types of data is mainly controlled by the check_target parameter, which has three values to choose from:component_codec、component_sdk、sdk_codec - # check syscap field in all components for consistency with arraySyscap in syscap_define.h -python3 syscap_check.py --project_path path_of_openarmony --check_target component_codec +python3 syscap_check.py -p path_of_openarmony -t component_codec # check that the SYSCAP field in bundle.json of the specified part is consistent with arraySyscap in syscap_define.h. Note: --bundles is valid only if --check_target is component_codec -python3 syscap_check.py --project_path path_of_openarmony --check_target component_codec --bundles path_of_component1/bundle.json path_of_component2/bundle.json +python3 syscap_check.py -p path_of_openarmony -t component_codec -b path_of_component1/bundle.json path_of_component2/bundle.json # check the consistency of the syscap field of all components with the "@syscap" property set in *.d.ts -python3 syscap_check.py --project_path path_of_openarmony --check_target component_sdk +python3 syscap_check.py -p path_of_openarmony -t component_sdk # check the "@syscap" attribute set in *.d.ts for consistency with arraSyscap in syscap_define.h -python3 syscap_check.py --project_path path_of_openarmony --check_target sdk_codec +python3 syscap_check.py -p path_of_openarmony -t sdk_codec ``` ### Release Note diff --git a/README_ZH.md b/README_ZH.md index 88d5004..9e8e72e 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -1,4 +1,5 @@ # 系统能力编解码工具 + 系统能力(SystemCapability, 本文中使用SysCap缩写)编解码工具应用场景如下: 应用开发时,IDE会根据应用配置的SysCap和API版本生成描述RPCID(Required Product Compatibility ID)的json文件,并调用编解码工具syscap_tool将该json文件编码成RPCID。另一方面,IDE拿到开发者导入PCID(Product Compatibility ID),使用该工具解码出设备的SysCap集合。该工具仅供IDE使用,对用户不可见。 @@ -116,7 +117,9 @@ syscap_tool -Pdsi pcid.txt -o path/ ``` **说明:** -o 选项指定输出目录,缺省为当前目录。 -### syscap一致性看护脚本的说明与使用 +## syscap一致性检查工具 + +### 功能及依赖 本工具主要提供如下功能: @@ -124,31 +127,47 @@ syscap_tool -Pdsi pcid.txt -o path/ 2. 收集所有部件的syscap字段并与interface/sdk-js/api目录下的*.d.ts中的“@syscap”属性集合比较,输出检查结果,若不一致,输出不一致的原因 3. 收集所有interface/sdk-js/api目录下的*.d.ts中的syscap属性与developtools/syscap_codec/include/syscap_define.h中的arraySyscap比较,若不一致,输出不一致的原因 +### 使用方法 + +本工具使用python语言编写,需使用python解释器进行执行。 + requirements: ```txt prettytable==3.3.0 ``` -使用方法: +使用python3 syscap-check.py -h或python3 syscap-check.py --help查看用法: ```shell -# 查看帮助 -python3 syscap-check.py --help +usage: syscap_check.py [-h] [-p PROJECT_PATH] -t {component_codec,component_sdk,sdk_codec} + [-b [BUNDLES [BUNDLES ...]]] -# 上述三种不同数据的比较主要通过--check_target参数控制,该参数有三个值可选:component_codec、component_sdk、sdk_codec +optional arguments: + -h, --help show this help message and exit + -p PROJECT_PATH, --project_path PROJECT_PATH + root path of project. default: ./ + -t {component_codec,component_sdk,sdk_codec}, --check_target {component_codec,component_sdk,sdk_codec} + the target to be compared + -b [BUNDLES [BUNDLES ...]], --bundles [BUNDLES [BUNDLES ...]] + this option will take effect only when the check_target is component_codec. allow multiple + json file. default: all bundle.json file +``` +使用示例: + +```shell # 检查所有部件的syscap字段与syscap_define.h中的arraySyscap一致性情况 -python3 syscap_check.py --project_path path_of_openarmony --check_target component_codec +python3 syscap_check.py -p path_of_openarmony -t component_codec # 检查指定的部件的bundle.json中的syscap字段与syscap_define.h中的arraySyscap一致性情况,注意,只要当--check_target为component_codec时,--bundles才生效 -python3 syscap_check.py --project_path path_of_openarmony --check_target component_codec --bundles path_of_component1/bundle.json path_of_component2/bundle.json +python3 syscap_check.py -p path_of_openarmony -t component_codec -b path_of_component1/bundle.json path_of_component2/bundle.json # 检查所有部件的syscap字段与*.d.ts中的“@syscap”属性集合的一致性情况 -python3 syscap_check.py --project_path path_of_openarmony --check_target component_sdk +python3 syscap_check.py -p path_of_openarmony -t component_sdk # 检查*.d.ts中的“@syscap"属性集合与syscap_define.h中的arraSyscap的一致性情况 -python3 syscap_check.py --project_path path_of_openarmony --check_target sdk_codec +python3 syscap_check.py -p path_of_openarmony -t sdk_codec ``` diff --git a/tools/syscap_check.py b/tools/syscap_check.py old mode 100644 new mode 100755 index fd425f4..ffd7eaf --- a/tools/syscap_check.py +++ b/tools/syscap_check.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (c) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,11 +24,16 @@ table.hrules = ALL def get_args(): - parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser(add_help=True) parser.add_argument( - "--project_path", type=str, required=True, help="root path of project" + "-p", + "--project_path", + default=r"./", + type=str, + help="root path of project. default: ./", ) parser.add_argument( + "-t", "--check_target", type=str, choices=["component_codec", "component_sdk", "sdk_codec"], @@ -35,10 +41,11 @@ def get_args(): help="the target to be compared", ) parser.add_argument( + "-b", "--bundles", nargs="*", type=str, - help="this option will take effect only when the check_target is component_codec. allow multiple file. default: all", + help="this option will take effect only when the check_target is component_codec. allow multiple json file. default: all bundle.json file", ) args = parser.parse_args() return args @@ -55,6 +62,12 @@ def read_value_from_json(filepath, key_hierarchy, result_dict): :param filepath: fullpath of file :return: result_dict, {filepath:value_list} """ + if os.path.exists(filepath) is False: + print('error: file "{}" not exists.'.format(filepath)) + return result_dict + if os.path.isfile(filepath) is False: + print('error: "{}" is not a file.') + return result_dict with open(filepath, "r") as f: data = json.load(f) for key in key_hierarchy: @@ -98,10 +111,16 @@ def collect_syscap_from_component(project_path, bundles=None): "find {} -name bundle.json".format(os.path.join(project_path, ss)) ) for line in output: - read_value_from_json(line.strip(), key_heirarchy, result_dict) + try: + read_value_from_json(line.strip(), key_heirarchy, result_dict) + except Exception as e: + print(e.with_traceback()) else: for b in bundles: - result_dict = read_value_from_json(b, key_heirarchy, result_dict) + try: + result_dict = read_value_from_json(b, key_heirarchy, result_dict) + except Exception as e: + print(e.with_traceback()) result_set = set() for v in result_dict.values(): result_set.update(v) @@ -169,7 +188,7 @@ def check_component_and_codec(project_path, bundles=None): if 0 != len(component_diff_array): table.field_names = ["Syscap Only in Component", "Files"] for syscap, files in value_files_dict.items(): - table.add_row([syscap, list_to_multiline(list_to_multiline(files))]) + table.add_row([syscap, list_to_multiline(sorted(files))]) elif 0 == len(component_diff_array): table.field_names = ["All Syscap in Component have been Covered by Codec"] print("\n") @@ -177,7 +196,7 @@ def check_component_and_codec(project_path, bundles=None): table.clear() if 0 != len(array_diff_component): table.field_names = ["SysCap Only in Codec"] - table.add_row([list_to_multiline(list(array_diff_component))]) + table.add_row([list_to_multiline(sorted(list(array_diff_component)))]) elif 0 == len(array_diff_component): table.field_names = ["All SysCap in Codec have been Covered by Component"] print("\n") @@ -204,7 +223,7 @@ def check_component_and_sdk(project_path): if 0 != len(component_diff_ts): table.field_names = ["SysCap Only in Component", "Files"] for syscap, files in value_component_dict.items(): - table.add_row([syscap, list_to_multiline(list(files))]) + table.add_row([syscap, list_to_multiline(sorted(list(files)))]) elif 0 == len(component_diff_ts): table.field_names = ["SysCap in Component have been Covered by SDK"] print("\n") @@ -213,7 +232,7 @@ def check_component_and_sdk(project_path): if 0 != len(ts_diff_component): table.field_names = ["SysCap Only in SDK", "Files"] for syscap, files in value_ts_dict.items(): - table.add_row([syscap, list_to_multiline(list(files))]) + table.add_row([syscap, list_to_multiline(sorted(list(files)))]) elif 0 == len(ts_diff_component): table.field_names = ["All SysCap in SDK have been Covered by Component"] print("\n") @@ -239,7 +258,7 @@ def check_sdk_and_codec(project_path): if 0 != len(ts_diff_array): table.field_names = ["SysCap Only in SDK", "Files"] for syscap, files in value_ts_dict.items(): - table.add_row([syscap, list_to_multiline(list(files))]) + table.add_row([syscap, list_to_multiline(sorted(list(files)))]) elif 0 == len(ts_diff_array): table.field_names = ["SysCap in SDK have been Covered by Codec"] print("\n") @@ -247,7 +266,7 @@ def check_sdk_and_codec(project_path): table.clear() if 0 != len(array_diff_ts): table.field_names = ["SysCap Only in Codec"] - table.add_row([list_to_multiline(list(array_diff_ts))]) + table.add_row([list_to_multiline(sorted(list(array_diff_ts)))]) elif 0 == len(array_diff_ts): table.field_names = ["SysCap in Codec have been Covered by SDK"] print("\n")