From a37c42f2669bdb4bdb4898e01b42b8763576ff70 Mon Sep 17 00:00:00 2001 From: xuezhou_yan Date: Tue, 4 Jun 2024 11:13:02 +0800 Subject: [PATCH] =?UTF-8?q?issue:#I9US3B=20=E5=90=8C=E6=AD=A5=20=E4=B8=BB?= =?UTF-8?q?=E5=B9=B2=20=E5=88=86=E6=94=AF=20=E5=92=8C=20OpenHarmony-5.0-Be?= =?UTF-8?q?ta1=20=E5=88=86=E6=94=AF=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xuezhou_yan --- BUILD.gn | 20 +++++----- README.md | 14 +++---- README_ZH.md | 48 +++++++++++----------- RELEASE-NOTE.txt | 2 +- bundle.json | 12 +++--- include/codec_config/syscap_define.h | 8 +++- interfaces/inner_api/syscap_interface.c | 7 ++-- napi/BUILD.gn | 11 +++-- napi/napi_query_syscap.cpp | 13 ++++-- src/create_pcid.c | 15 ++++--- src/main.c | 10 ++--- src/syscap_tool.c | 53 ++++++++++++++----------- tools/syscap_collector.py | 44 +++++++++++++------- 13 files changed, 142 insertions(+), 115 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index f9d2aee..fd0df91 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -53,12 +53,12 @@ ohos_executable("syscap_tool_bin") { sources = [ "./src/main.c" ] sources += sources_platform_common - deps += [ "//third_party/bounds_checking_function:libsec_static" ] + external_deps = [ "bounds_checking_function:libsec_static" ] if (defined(ohos_lite)) { deps += [ "//build/lite/config/component/cJSON:cjson_static" ] } else { - deps += [ "//third_party/cJSON:cjson_static" ] + external_deps += [ "cJSON:cjson_static" ] } subsystem_name = "developtools" @@ -122,9 +122,9 @@ if (defined(ohos_lite)) { "./src/endian_internal.c", "./src/syscap_tool.c", ] - deps += [ - "//third_party/bounds_checking_function:libsec_static", - "//third_party/cJSON:cjson_static", + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", ] subsystem_name = "developtools" @@ -137,7 +137,7 @@ group("syscap_tool_bin_linux") { } build_ext_component("generate_pcid") { - outputs = [ "$root_out_dir/PCID.sc" ] + outputs = [ "$root_out_dir/pcid.sc" ] deps = [ ":syscap_tool_bin_linux" ] exec_path = rebase_path(root_out_dir) preload_path = rebase_path(preloader_output_dir) @@ -150,13 +150,13 @@ build_ext_component("generate_pcid") { command += " && $cmd -P -e -i ${preload_path}/system/etc/SystemCapability.json" if (defined(ohos_lite)) { - command += " && mkdir -p $exec_path/system/etc && cp $exec_path/PCID.sc $exec_path/system/etc/PCID.sc" + command += " && mkdir -p $exec_path/system/etc && cp $exec_path/pcid.sc $exec_path/system/etc/pcid.sc" } } -ohos_prebuilt_etc("PCID.sc") { +ohos_prebuilt_etc("pcid.sc") { deps = [ ":generate_pcid" ] - source = "$root_out_dir/PCID.sc" + source = "$root_out_dir/pcid.sc" subsystem_name = "developtools" part_name = "syscap_codec" } @@ -182,7 +182,7 @@ if (syscap_codec_config_extern_path != "") { } group("pcid_sc") { - deps = [ ":PCID.sc" ] + deps = [ ":pcid.sc" ] } group("syscap_codec") { diff --git a/README.md b/README.md index 005c7bc..4ca90a9 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,17 @@ SysCap(SystemCapability) encoder and decoder tools common usage scenarios as follow: -APP development: IDE collect APP required SysCap and API verssion as in RPCID encoder input. And IDE will decode PCID to device SysCap list when it imported. This tool is only for use by the IDE, developers will not be used directly. +APP development: IDE collect APP required SysCap and API verssion as in rpcid encoder input. And IDE will decode pcid to device SysCap list when it imported. This tool is only for use by the IDE, developers will not be used directly. Main function: -1. PCID Encode: Encode SysCap list to PCID. +1. pcid Encode: Encode SysCap list to pcid. -2. PCID Decode: Decode PCID to get system SysCap list. +2. pcid Decode: Decode pcid to get system SysCap list. -3. RPCID Encode: Encode APP required SysCap list to RPCID. +3. rpcid Encode: Encode APP required SysCap list to rpcid. -4. RPCID Decode: Decode RPCID to get APP required SysCap list. +4. rpcid Decode: Decode rpcid to get APP required SysCap list. ## File Structure @@ -69,9 +69,9 @@ SysCap tools usually integrate to IDE, APP store and bundle tools. Follow instru -h, --help : how to use --R, --RPCID : encode or decode RPCID +-R, --rpcid : encode or decode rpcid --P, --PCID : encode or decode PCID +-P, --pcid : encode or decode pcid -e, --encode : to encode diff --git a/README_ZH.md b/README_ZH.md index b39cfbc..a12c356 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -2,21 +2,21 @@ 系统能力(SystemCapability, 本文中使用SysCap缩写)编解码工具应用场景如下: -应用开发时,IDE会根据应用配置的SysCap和API版本生成描述RPCID(Required Product Compatibility ID)的json文件,并调用编解码工具syscap_tool将该json文件编码成RPCID。另一方面,IDE拿到开发者导入PCID(Product Compatibility ID),使用该工具解码出设备的SysCap集合。该工具仅供IDE使用,对用户不可见。 +应用开发时,IDE会根据应用配置的SysCap和API版本生成描述rpcid(Required Product Compatibility ID)的json文件,并调用编解码工具syscap_tool将该json文件编码成rpcid。另一方面,IDE拿到开发者导入pcid(Product Compatibility ID),使用该工具解码出设备的SysCap集合。该工具仅供IDE使用,对用户不可见。 提供的主要功能: -1. PCID编码:对描述SysCap集合的文件编码生成PCID。 +1. pcid编码:对描述SysCap集合的文件编码生成pcid。 -2. PCID解码:对编码后的PCID文件解码获取SysCap集合。 +2. pcid解码:对编码后的pcid文件解码获取SysCap集合。 -3. RPCID编码:对描述应用所需的SysCap集合的文件编码生成RPCID。 +3. rpcid编码:对描述应用所需的SysCap集合的文件编码生成rpcid。 -4. RPCID解码:对编码后的RPCID文件解码获取应用所需的SysCap集合。 +4. rpcid解码:对编码后的rpcid文件解码获取应用所需的SysCap集合。 -5. 编码字符串:将sc后缀形式的PCID/RPCID编码为字符串形式。 +5. 编码字符串:将sc后缀形式的pcid/rpcid编码为字符串形式。 -6. PCID与RPCID比较:查询PCID是否满足RPCID的要求,并输出不满足的地方。 +6. pcid与rpcid比较:查询pcid是否满足rpcid的要求,并输出不满足的地方。 ## 代码目录 ``` @@ -72,8 +72,8 @@ syscap_tool PC端可执行文件编译步骤: ```shell syscap_tool -R/P -e/d -i filepath [-o outpath] -h, --help : how to use --R, --RPCID : encode or decode RPCID --P, --PCID : encode or decode PCID +-R, --rpcid : encode or decode rpcid +-P, --pcid : encode or decode pcid -C, --compare : compare pcid with rpcid string format. -s, --string : input string. -e, --encode : encode to sc format. @@ -88,31 +88,31 @@ syscap_tool v1.1.1 ``` ### 使用示例 ```shell -# 将 RPCID.json 编码为SC格式,文件名RPCID.sc -syscap_tool -Rei RPCID.json -o path/ +# 将 rpcid.json 编码为SC格式,文件名rpcid.sc +syscap_tool -Rei rpcid.json -o path/ -# 将 RPCID.sc 编码为JSON格式,文件名RPCID.json -syscap_tool -Rdi RPCID.sc -o path/ +# 将 pcid.sc 编码为JSON格式,文件名rpcid.json +syscap_tool -Rdi pcid.sc -o path/ -# 将 PCID.json 编码为SC格式,文件名PCID.sc -syscap_tool -Pei PCID.json -o path/ +# 将 pcid.json 编码为SC格式,文件名pcid.sc +syscap_tool -Pei pcid.json -o path/ -# 将 PCID.sc 编码为JSON格式,文件名PCID.json -syscap_tool -Pdi PCID.sc -o path/ +# 将 pcid.sc 编码为JSON格式,文件名pcid.json +syscap_tool -Pdi pcid.sc -o path/ -# 将 RPCID.sc 编码为字符串格式,文件名RPCID.txt -syscap_tool -Resi RPCID.sc -o path/ +# 将 pcid.sc 编码为字符串格式,文件名rpcid.txt +syscap_tool -Resi pcid.sc -o path/ -# 将 PCID.sc 编码为字符串格式,文件名PCID.txt -syscap_tool -Pesi PCID.sc -o path/ +# 将 pcid.sc 编码为字符串格式,文件名pcid.txt +syscap_tool -Pesi pcid.sc -o path/ -# 比较字符串格式的PCID和RPCID,pcid 符合条件返回成功提示,不符合则提示原因。 +# 比较字符串格式的pcid和rpcid,pcid 符合条件返回成功提示,不符合则提示原因。 syscap_tool -C pcid.txt rpcid.txt -# 功能类似 -C 选项,区别为 -SC 选项为直接输入字符串。 +# 功能类似 -C选项,区别为 -sC 选项为直接输入字符串。 syscap_tool -sC "pcidstring" "rpcidstring" -# 将字符串格式的 pcid 转为 json 格式,文件名 PCID.json。 +# 将字符串格式的 pcid 转为 json 格式,文件名 pcid.json。 syscap_tool -Pdsi pcid.txt -o path/ ``` **说明:** -o 选项指定输出目录,缺省为当前目录。 diff --git a/RELEASE-NOTE.txt b/RELEASE-NOTE.txt index 7a8e370..2bc6e3e 100644 --- a/RELEASE-NOTE.txt +++ b/RELEASE-NOTE.txt @@ -1,5 +1,5 @@ v2.0.0 reorganize syscap define. v1.1.2 add syscap "SystemCapability.ArkUI.UiAppearance". v1.1.1 add compare string pcid with rpcid function. -v1.1.0 add encode/decode string format PCID/RPCID. +v1.1.0 add encode/decode string format pcid/rpcid. v1.0.0 first release. \ No newline at end of file diff --git a/bundle.json b/bundle.json index 4b92c28..caa571e 100644 --- a/bundle.json +++ b/bundle.json @@ -16,18 +16,20 @@ "name": "syscap_codec", "subsystem": "developtools", "syscap": [ "SystemCapability.Developtools.Syscap" ], - "feature": [ "syscap_codec_config_path" ], + "feature": [ + "syscap_codec_config_path", + "syscap_codec_config_extern_path" + ], "adapted_system_type": [ "small", "standard" ], "rom": "0", "ram": "0", "deps": { "components": [ - "napi" - ], - "third_party": [ + "napi", "bounds_checking_function", "cJSON" - ] + ], + "third_party": [] }, "build": { "sub_component": [ diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 8a004cb..8fee30f 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -348,7 +348,9 @@ typedef enum SystemCapabilityNum { MULTIMEDIA_MEDIA_AVTRANSCODER, MULTIMEDIA_IMAGEEFFECT_CORE, DRIVER_DDK_EXTENSION, - FILEMANAGEMENT_SCREENLOCKFILEMANAGER, + SECURITY_SCREENLOCKFILEMANAGER, + COMMUNICATION_NETMANAGER_NETFIREWALL, + CUSTOMIZATION_CUSTOMCONFIG, // Add before here SYSCAP_BASIC_END = 500, } SyscapNum; @@ -680,7 +682,9 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.MultimodalInput.Input.InfraredEmitter", MULTIMODALINPUT_INPUT_INFRAREDEMITTER}, {"SystemCapability.Multimedia.ImageEffect.Core", MULTIMEDIA_IMAGEEFFECT_CORE}, {"SystemCapability.Driver.DDK.Extension", DRIVER_DDK_EXTENSION}, - {"SystemCapability.FileManagement.ScreenLockFileManager", FILEMANAGEMENT_SCREENLOCKFILEMANAGER}, + {"SystemCapability.Security.ScreenLockFileManager", SECURITY_SCREENLOCKFILEMANAGER}, + {"SystemCapability.Communication.NetManager.Netfirewall", COMMUNICATION_NETMANAGER_NETFIREWALL}, + {"SystemCapability.Customization.CustomConfig", CUSTOMIZATION_CUSTOMCONFIG}, }; #ifdef __cplusplus diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index 00954b1..c85b66a 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -57,7 +57,7 @@ typedef struct ProductCompatibilityID { uint8_t osSyscap[OS_SYSCAP_BYTES]; } PCIDMain; -static const char *PCID_PATH = "/system/etc/PCID.sc"; +static const char *PCID_PATH = "/system/etc/pcid.sc"; struct FreeAfterDecodeRpcidInfo { char *priSyscap; @@ -91,7 +91,7 @@ bool EncodeOsSyscap(char *output, int len) ret = GetFileContext(PCID_PATH, &contextBuffer, &bufferLen); if (ret != 0) { - PRINT_ERR("GetFileContext failed, input file : /system/etc/PCID.sc\n"); + PRINT_ERR("GetFileContext failed, input file : /system/etc/pcid.sc\n"); return false; } @@ -115,7 +115,7 @@ bool EncodePrivateSyscap(char **output, int *outputLen) ret = GetFileContext(PCID_PATH, &contextBuffer, &bufferLen); if (ret != 0) { - PRINT_ERR("GetFileContext failed, input file : /system/etc/PCID.sc\n"); + PRINT_ERR("GetFileContext failed, input file : /system/etc/pcid.sc\n"); return false; } @@ -516,7 +516,6 @@ char *DecodeRpcidToStringFormat(const char *inputFile) } PartSysCapAndOutBuffer(freeAfterDecodeRpcidInfo, outBuffer, priSyscapArray, sysCapArray); - priSyscapArray = NULL; return FreeAfterDecodeRpcidToString(freeAfterDecodeRpcidInfo, FREE_MALLOC_PRISYSCAP_AFTER_DECODE_RPCID, outBuffer); } diff --git a/napi/BUILD.gn b/napi/BUILD.gn index dc518c7..5db0659 100644 --- a/napi/BUILD.gn +++ b/napi/BUILD.gn @@ -42,9 +42,10 @@ ohos_shared_library("systemcapability") { sources = [ "napi_query_syscap.cpp" ] sources += sources_platform_common - deps = [ - ":query_syscap_js", - "//third_party/bounds_checking_function:libsec_static", + deps = [ ":query_syscap_js" ] + external_deps = [ + "bounds_checking_function:libsec_static", + "napi:ace_napi", ] if (syscap_codec_config_extern_path != "") { @@ -54,12 +55,10 @@ ohos_shared_library("systemcapability") { cflags = [ "-DSYSCAP_DEFINE_EXTERN_ENABLE" ] } - external_deps = [ "napi:ace_napi" ] - if (defined(ohos_lite)) { deps += [ "//build/lite/config/component/cJSON:cjson_static" ] } else { - deps += [ "//third_party/cJSON:cjson_static" ] + external_deps += [ "cJSON:cjson_static" ] } relative_install_dir = "module" diff --git a/napi/napi_query_syscap.cpp b/napi/napi_query_syscap.cpp index f01836f..f089b36 100644 --- a/napi/napi_query_syscap.cpp +++ b/napi/napi_query_syscap.cpp @@ -112,7 +112,7 @@ static char* GetSystemCapability() bool retBool; int retError, priOutputLen, priCapArrayCnt; char osOutput[SINGLE_SYSCAP_LEN] = {}; - + uint32_t *osCapU32 = nullptr; char *priOutput = nullptr; @@ -149,14 +149,13 @@ FREE_PRIOUTPUT: return allSyscapBuffer; } -napi_value QuerySystemCapability(napi_env env, napi_callback_info info) +napi_value PreHandleSystemCapability( + napi_env env, napi_callback_info info, SystemCapabilityAsyncContext *asyncContext) { GET_PARAMS(env, info, 1); NAPI_ASSERT(env, argc <= 1, "too many parameters"); napi_value result = nullptr; - SystemCapabilityAsyncContext* asyncContext = new SystemCapabilityAsyncContext(); - asyncContext->env = env; napi_valuetype valueType = napi_undefined; @@ -172,7 +171,13 @@ napi_value QuerySystemCapability(napi_env env, napi_callback_info info) } else { napi_get_undefined(env, &result); } + return result; +} +napi_value QuerySystemCapability(napi_env env, napi_callback_info info) +{ + SystemCapabilityAsyncContext *asyncContext = new SystemCapabilityAsyncContext(); + napi_value result = PreHandleSystemCapability(env, info, asyncContext); napi_value resource = nullptr; napi_create_string_utf8(env, "napi_value QuerySystemCapability", NAPI_AUTO_LENGTH, &resource); diff --git a/src/create_pcid.c b/src/create_pcid.c index 2c9da93..5316984 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -213,7 +213,7 @@ int32_t GetPriSyscapLen(uint32_t privateCapSize, cJSON *jsonPriSyscapObj, uint16 static int32_t CheckConvertedContextSaveAsFile(char *outDirPath, PCIDMain *pcidBuffer, uint16_t pcidLength, int32_t ret) { - const char pcidFileName[] = "PCID.sc"; + const char pcidFileName[] = "pcid.sc"; ret = ConvertedContextSaveAsFile(outDirPath, pcidFileName, (char *)pcidBuffer, pcidLength); if (ret != 0) { PRINT_ERR("Save as file failed, outDirPath:%s, filename:%s\n", outDirPath, pcidFileName); @@ -343,8 +343,7 @@ int32_t GetOsSyscap(PCIDMain *pcidMain, cJSON *sysCapObject) cJSON_Delete(capVectorPtr); return -1; } - - cJSON_Delete(capVectorPtr); + return 0; } @@ -362,7 +361,7 @@ int32_t GetPriSyscap(PCIDMain *pcidMain, cJSON *sysCapObject, size_t contextBufL return -1; } - if (contextBufLen < 0 || contextBufLen > UINT32_MAX) { + if (contextBufLen > UINT32_MAX) { PRINT_ERR("the data privateSyscapLen is out of scope."); return GetPriSyscapResult(capVectorPtr, -1); } @@ -525,7 +524,7 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) freePcidJsonInfo.sysCapObj = NULL; // avoid being released repeatedly. char *strJson = cJSON_Print(freePcidJsonInfo.jsonRootObj); - const char outputFileName[] = "PCID.json"; + const char outputFileName[] = "pcid.json"; ret = ConvertedContextSaveAsFile(outDirPath, outputFileName, strJson, strlen(strJson)); if (ret != 0) { PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:%s\n", outDirPath, outputFileName); @@ -746,7 +745,7 @@ int32_t DecodeStringPCIDToJson(char *input, char *outDirPath) PRINT_ERR("json buffer is null.\n"); goto ADD_JSON_FAILED; } - const char outputFileName[] = "PCID.json"; + const char outputFileName[] = "pcid.json"; if (ConvertedContextSaveAsFile(outDirPath, outputFileName, jsonBuffer, strlen(jsonBuffer)) != 0) { PRINT_ERR("Save as json file failed.\n"); @@ -817,7 +816,7 @@ static int32_t GetEncodePCIDOut(uint16_t priSyscapCount, uint32_t privateSyscapL } } // save as file - const char outputFileName[] = "PCID.txt"; + const char outputFileName[] = "pcid.txt"; ret = ConvertedContextSaveAsFile(freePcidInfo.outDirPathFinal, outputFileName, output, strlen(output)); if (ret != 0) { PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:%s\n", @@ -898,7 +897,7 @@ int32_t EncodePcidscToString(char *inputFile, char *outDirPath) freePcidInfo.priSyscapFull = (char *)malloc(priSyscapCount * SINGLE_SYSCAP_LEN); if (freePcidInfo.priSyscapFull == NULL) { PRINT_ERR("malloc failed\n"); - return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_PRISYSCAP_FULL_OUT, ret); + return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_CONTEXT_OUT, ret); } (void)memset_s(freePcidInfo.priSyscapFull, priSyscapCount * SINGLE_SYSCAP_LEN, 0, priSyscapCount * SINGLE_SYSCAP_LEN); diff --git a/src/main.c b/src/main.c index 388dc1d..44fd992 100644 --- a/src/main.c +++ b/src/main.c @@ -51,8 +51,8 @@ int32_t OperateByBitMap(char *const *argv, uint16_t bitMap, char *outputpath); static struct option g_longOptions[] = { {"help", no_argument, 0, 'h' }, {"version", no_argument, 0, 'v' }, - {"RPCID", no_argument, 0, 'R' }, - {"PCID", no_argument, 0, 'P' }, + {"rpcid", no_argument, 0, 'R' }, + {"pcid", no_argument, 0, 'P' }, {"compare", required_argument, 0, 'C' }, {"encode", no_argument, 0, 'e' }, {"decode", no_argument, 0, 'd' }, @@ -112,7 +112,7 @@ int32_t OperateByBitMap(char *const *argv, uint16_t bitMap, char *outputpath) ret = EncodeRpcidscToString(g_customerfileinfo.inputfile, outputpath); break; case 0x115: // 0x115, -Pesi inputfile ret = EncodePcidscToString(g_customerfileinfo.inputfile, outputpath); break; - case 0x60: // 0x60, -C PCID.txt RPCID.txt + case 0x60: // 0x60, -C pcid.txt rpcid.txt ret = ComparePcidWithRpcidString(g_customerfileinfo.pcidfile, g_customerfileinfo.rpcidfile, TYPE_FILE); break; case 0x64: // 0x64, -sC "pcidstring" "rpcidstring" @@ -195,8 +195,8 @@ void PrintHelp(void) { printf("syscap_tool -R/P -e/d -i filepath [-o outpath]\n"); printf("-h, --help\t: how to use\n"); - printf("-R, --RPCID\t: encode or decode RPCID\n"); - printf("-P, --PCID\t: encode or decode PCID\n"); + printf("-R, --rpcid\t: encode or decode rpcid\n"); + printf("-P, --pcid\t: encode or decode pcid\n"); printf("-C, --compare\t: compare pcid with rpcid string format.\n\t" "-s, --string : input string.\n"); printf("-e, --encode\t: encode to sc format.\n\t-s, --string : encode to string format.\n"); diff --git a/src/syscap_tool.c b/src/syscap_tool.c index cc6051c..3bcd76a 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -36,6 +36,7 @@ #define SYSCAP_PREFIX_LEN 17 #define SINGLE_FEAT_LEN (SINGLE_SYSCAP_LEN - SYSCAP_PREFIX_LEN) +#define DOUBLE_SPACE 2 #define UINT8_BIT 8 #define INT_BIT 32 #define RPCID_OUT_BUFFER 32 @@ -121,69 +122,73 @@ static int32_t FillOsCapLength(char *convertedBuffer, char *contextBuffer, struc return ret; } -static int32_t FreeAfterRPCIDEncode(char *convertedBuffer, char *contextBuffer, int32_t type, int32_t ret) +static int32_t FreeAfterRPCIDEncode( + cJSON *cjsonObjectRoot, char *convertedBuffer, char *contextBuffer, int32_t type, int32_t ret) { if (type == FREE_CONVERT_OUT_RPCID_ENCODE) { free(convertedBuffer); } + cJSON_Delete(cjsonObjectRoot); FreeContextBuffer(contextBuffer); return ret; } int32_t RPCIDEncode(char *inputFile, char *outputPath) { - int32_t ret; char *contextBuffer = NULL; uint32_t bufferLen, sysCapSize; - char *convertedBuffer = NULL; - uint32_t convertedBufLen = sizeof(RPCIDHead); struct JsonObjectSysCap gJsonObjectSysCap; gJsonObjectSysCap.cjsonObjectRoot = NULL; gJsonObjectSysCap.sysCapPtr = NULL; - ret = GetFileContext(inputFile, &contextBuffer, &bufferLen); - if (ret != 0) { + if (GetFileContext(inputFile, &contextBuffer, &bufferLen) != 0) { PRINT_ERR("GetFileContext failed, input file : %s\n", inputFile); - return ret; + return -1; } gJsonObjectSysCap.cjsonObjectRoot = cJSON_ParseWithLength(contextBuffer, bufferLen); if (gJsonObjectSysCap.cjsonObjectRoot == NULL) { PRINT_ERR("cJSON_Parse failed, context buffer is:\n%s\n", contextBuffer); - return FreeAfterRPCIDEncode(convertedBuffer, contextBuffer, FREE_CONTEXT_OUT_RPCID_ENCODE, -1); + return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, NULL, contextBuffer, + FREE_CONTEXT_OUT_RPCID_ENCODE, -1); } gJsonObjectSysCap.sysCapPtr = cJSON_GetObjectItem(gJsonObjectSysCap.cjsonObjectRoot, "syscap"); if (gJsonObjectSysCap.sysCapPtr == NULL || !cJSON_IsArray(gJsonObjectSysCap.sysCapPtr)) { PRINT_ERR("get \"syscap\" object failed.\n"); - return FreeAfterRPCIDEncode(convertedBuffer, contextBuffer, FREE_CONTEXT_OUT_RPCID_ENCODE, -1); + return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, NULL, contextBuffer, + FREE_CONTEXT_OUT_RPCID_ENCODE, -1); } - ret = cJSON_GetArraySize(gJsonObjectSysCap.sysCapPtr); + int32_t ret = cJSON_GetArraySize(gJsonObjectSysCap.sysCapPtr); if (ret < 0) { PRINT_ERR("get \"syscap\" array size failed\n"); - return FreeAfterRPCIDEncode(convertedBuffer, contextBuffer, FREE_CONTEXT_OUT_RPCID_ENCODE, -1); + return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, NULL, contextBuffer, + FREE_CONTEXT_OUT_RPCID_ENCODE, -1); } - sysCapSize = (uint32_t)ret; - // 2, to save SysCaptype & SysCapLength - convertedBufLen += (2 * sizeof(uint16_t) + sysCapSize * SINGLE_FEAT_LEN); - convertedBuffer = (char *)malloc(convertedBufLen); + // 2, to save SysCaptype & SysCapLength + sysCapSize = (uint32_t) ret; + uint32_t convertedBufLen = sizeof(RPCIDHead); + convertedBufLen += (DOUBLE_SPACE * sizeof(uint16_t) + sysCapSize * SINGLE_FEAT_LEN); + char *convertedBuffer = (char *) malloc(convertedBufLen); if (convertedBuffer == NULL) { PRINT_ERR("malloc failed\n"); - return FreeAfterRPCIDEncode(convertedBuffer, contextBuffer, FREE_CONTEXT_OUT_RPCID_ENCODE, -1); + return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, convertedBuffer, contextBuffer, + FREE_CONTEXT_OUT_RPCID_ENCODE, -1); } - (void)memset_s(convertedBuffer, convertedBufLen, 0, convertedBufLen); + (void) memset_s(convertedBuffer, convertedBufLen, 0, convertedBufLen); - ret = FillOsCapLength(convertedBuffer, contextBuffer, gJsonObjectSysCap, sysCapSize, ret); - if (ret == -1) { - return FreeAfterRPCIDEncode(convertedBuffer, contextBuffer, FREE_CONVERT_OUT_RPCID_ENCODE, ret); + if (FillOsCapLength(convertedBuffer, contextBuffer, gJsonObjectSysCap, sysCapSize, ret) == -1) { + return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, convertedBuffer, contextBuffer, + FREE_CONVERT_OUT_RPCID_ENCODE, -1); } - ret = ConvertedContextSaveAsFile(outputPath, "RPCID.sc", convertedBuffer, convertedBufLen); + ret = ConvertedContextSaveAsFile(outputPath, "rpcid.sc", convertedBuffer, convertedBufLen); if (ret != 0) { PRINT_ERR("ConvertedContextSaveAsFile failed, outputPath:%s, filename:rpcid.sc\n", outputPath); } - return FreeAfterRPCIDEncode(convertedBuffer, contextBuffer, FREE_CONVERT_OUT_RPCID_ENCODE, ret); + return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, convertedBuffer, contextBuffer, + FREE_CONVERT_OUT_RPCID_ENCODE, ret); } static int32_t ParseRpcidToJson(char *input, uint32_t inputLen, cJSON *rpcidJson) @@ -258,7 +263,7 @@ int32_t RPCIDDecode(char *inputFile, char *outputPath) // save to json file convertedBuffer = cJSON_Print(rpcidRoot); - ret = ConvertedContextSaveAsFile(outputPath, "RPCID.json", convertedBuffer, strlen(convertedBuffer)); + ret = ConvertedContextSaveAsFile(outputPath, "rpcid.json", convertedBuffer, strlen(convertedBuffer)); if (ret != 0) { PRINT_ERR("ConvertedContextSaveAsFile failed, outputPath:%s, filename:rpcid.json\n", outputPath); free(convertedBuffer); @@ -335,7 +340,7 @@ static int32_t PrintOutputToFile(struct FreeAfterEncodeRpcidscInfo freeAfterEnco } } - const char outputFilename[] = "RPCID.txt"; + const char outputFilename[] = "rpcid.txt"; ret = ConvertedContextSaveAsFile(outDirPath, outputFilename, freeAfterEncodeRpcidscInfo.outBuffer, strlen(freeAfterEncodeRpcidscInfo.outBuffer)); if (ret != 0) { diff --git a/tools/syscap_collector.py b/tools/syscap_collector.py index 47be694..bbc950f 100755 --- a/tools/syscap_collector.py +++ b/tools/syscap_collector.py @@ -109,7 +109,15 @@ def path_component_to_bundle(path: str) -> str: return bundle_json_path -def handle_bundle_json_file(component_path_dict: dict): +def find_false_syscap(syscap_l: list): + res = [] + for syscap in syscap_l: + if not check_syscap(syscap): + res.append(syscap.split('=')[0].strip()) + return res + + +def handle_bundle_json_file(component_path_dict: dict, product_define_dict: dict): """ from product required part bundle.json to all products parts list :param component_path_dict: @@ -118,12 +126,18 @@ def handle_bundle_json_file(component_path_dict: dict): print("start collect syscap path...") syscap_dict = dict() errors_list = list() - for product_name, path_list in component_path_dict.items(): + for product_name, path_dict in component_path_dict.items(): bundles_list = list() - for path in path_list: + for component in path_dict.keys(): + path = path_dict.get(component) bundle_json_path = path_component_to_bundle(path) bundle_syscap_list, error_list = read_json_file(bundle_json_path) - bundles_list.extend(bundle_syscap_list) + if product_define_dict.get(product_name).get(component): + false_syscap = find_false_syscap(product_define_dict.get(product_name).get(component)) + bundle_syscap_l = [sc for sc in bundle_syscap_list if sc not in false_syscap] + bundles_list.extend(bundle_syscap_l) + else: + bundles_list.extend(bundle_syscap_list) errors_list.extend(error_list) syscap_dict.update({product_name: bundles_list}) return syscap_dict, errors_list @@ -139,13 +153,13 @@ def format_component_path(component_path: str): def traversal_path(parts_path_info: dict, project_path: str, product_define_dict): component_path_dict = dict() for product_name, component_name_list in product_define_dict.items(): - component_paths = list() - for component_name in component_name_list: + component_paths = dict() + for component_name in component_name_list.keys(): component_relpath = parts_path_info.get(component_name) if component_relpath: component_path = os.path.join(project_path, component_relpath) component_path = format_component_path(component_path) - component_paths.append(component_path) + component_paths[component_name] = component_path else: logging.error(f'can\'t find component_name : {component_name}') component_path_dict.update({product_name: component_paths}) @@ -163,7 +177,7 @@ def collect_all_product_component_syscap_dict(parts_path_info: dict, project_pat if parts_path_info: print("start collect component path...") component_path_dict = traversal_path(parts_path_info, project_path, product_define_dict) - syscap_dict, errors_list = handle_bundle_json_file(component_path_dict) + syscap_dict, errors_list = handle_bundle_json_file(component_path_dict, product_define_dict) return syscap_dict, errors_list else: return 0, 0 @@ -456,24 +470,24 @@ def get_product_define_path(source_root_dir): def components_list_handler(product_file_json): - components_list = list() + components_dict = dict() for subsystems in product_file_json.get('subsystems'): for components in subsystems.get('components'): - components_list.append(components.get('component')) + components_dict[components.get('component')] = components.get('syscap') - return components_list + return components_dict def product_component_handler(product_file, product_file_path): all_components_dict = dict() - components_list = list() + components_dict = dict() try: with open(product_file_path, 'r', encoding='utf-8') as f: product_file_json = json.load(f) - components_list = components_list_handler(product_file_json) + components_dict = components_list_handler(product_file_json) except FileNotFoundError: print(f"read file {product_file_path} failed.") - all_components_dict.update({product_file.split('.')[0]: components_list}) + all_components_dict.update({product_file.split('.')[0]: components_dict}) return all_components_dict @@ -527,4 +541,4 @@ def main(): if __name__ == "__main__": - main() + main() \ No newline at end of file -- Gitee