feat: add allow external syscap config header.

Signed-off-by: yudechen <chenyude@huawei.com>
Change-Id: I0f4c2fce72bfa859c4535890d29431afab489995
This commit is contained in:
yudechen
2023-05-26 12:38:14 +08:00
parent e29559b804
commit a63bc6f15c
9 changed files with 274 additions and 8 deletions
+37 -3
View File
@@ -18,6 +18,10 @@ import("config.gni")
config("internal") {
include_dirs = [ "include" ]
include_dirs += [ syscap_codec_config_path ]
if (syscap_codec_config_extern_path != "") {
include_dirs += [ "${root_build_dir}" ]
cflags = [ "-DSYSCAP_DEFINE_EXTERN_ENABLE" ]
}
}
sources_platform_common = [
@@ -27,6 +31,10 @@ sources_platform_common = [
]
ohos_executable("syscap_tool_bin") {
if (syscap_codec_config_extern_path != "") {
deps = [ ":gen_syscap_define_custom" ]
inputs = [ "${root_build_dir}/syscap_define_custom.h" ]
}
output_name = "syscap_tool"
install_enable = true
include_dirs = [ "src" ]
@@ -43,7 +51,7 @@ ohos_executable("syscap_tool_bin") {
sources = [ "./src/main.c" ]
sources += sources_platform_common
deps = [ "//third_party/bounds_checking_function:libsec_static" ]
deps += [ "//third_party/bounds_checking_function:libsec_static" ]
if (defined(ohos_lite)) {
deps += [ "//build/lite/config/component/cJSON:cjson_static" ]
@@ -65,6 +73,10 @@ if (defined(ohos_lite)) {
}
} else {
shared_library("syscap_interface_shared") {
if (syscap_codec_config_extern_path != "") {
deps = [ ":gen_syscap_define_custom" ]
inputs = [ "${root_build_dir}/syscap_define_custom.h" ]
}
_version_script = rebase_path("libsyscap_interface_shared.versionscript")
if (!defined(ldflags)) {
ldflags = []
@@ -83,7 +95,7 @@ if (defined(ohos_lite)) {
"./src/syscap_tool.c",
]
deps = [
deps += [
"//build/lite/config/component/cJSON:cjson_static",
"//third_party/bounds_checking_function:libsec_static",
]
@@ -91,6 +103,10 @@ if (defined(ohos_lite)) {
}
} else {
ohos_shared_library("syscap_interface_shared") {
if (syscap_codec_config_extern_path != "") {
deps = [ ":gen_syscap_define_custom" ]
inputs = [ "${root_build_dir}/syscap_define_custom.h" ]
}
version_script = "libsyscap_interface_shared.versionscript"
include_dirs = [ "src" ]
configs = [ ":internal" ]
@@ -100,7 +116,7 @@ if (defined(ohos_lite)) {
"./src/endian_internal.c",
"./src/syscap_tool.c",
]
deps = [
deps += [
"//third_party/bounds_checking_function:libsec_static",
"//third_party/cJSON:cjson_static",
]
@@ -138,6 +154,24 @@ ohos_prebuilt_etc("PCID.sc") {
part_name = "syscap_codec"
}
# generate syscap_define_custom.h
action("gen_syscap_define_custom") {
script = "./tools/syscap_config_merge.py"
args = [
"--base",
rebase_path("include/codec_config/syscap_define.h"),
"--extern",
rebase_path(syscap_codec_config_extern_path),
"--output",
rebase_path("${root_build_dir}/syscap_define_custom.h"),
]
inputs = [
"include/codec_config/syscap_define.h",
syscap_codec_config_extern_path,
]
outputs = [ "${root_build_dir}/syscap_define_custom.h" ]
}
group("pcid_sc") {
deps = [ ":PCID.sc" ]
}
+3 -1
View File
@@ -9,10 +9,12 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
declare_args() {
syscap_codec_config_path =
# customization for head file syscap_define.h.
"//developtools/syscap_codec/include/codec_config"
syscap_codec_config_extern_path =
"include/codec_config/syscap_define_extern.h"
}
+1 -1
View File
@@ -284,7 +284,7 @@ typedef enum SystemCapabilityNum {
GRAPHIC_GRAPHIC_UTILS_LITE,
WINDOW_WINDOW_MANAGER_LITE,
// Add before here
SYSCAP_NUM_MAX = 960
SYSCAP_NUM_MAX = 500
} SyscapNum;
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SYSCAP_DEFINE_EXTERN_H
#define SYSCAP_DEFINE_EXTERN_H
#include <stdint.h>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifndef SYSCAP_DEFINE_H
#define SINGLE_SYSCAP_LEN (256 + 17)
typedef struct SystemCapabilityWithNum {
char str[SINGLE_SYSCAP_LEN];
uint16_t num;
} SyscapWithNum;
#endif
/*
* New SyscapNum must be added last and
* don't delete anyone, just comment after it.
*/
typedef enum SystemCapabilityNumExtern {
SYSCAP_EXTERN_BEGIN = 500,
ENUM_SYSCAP_AAA,
ENUM_SYSCAP_BBB,
ENUM_SYSCAP_CCC,
// Add before here
SYSCAP_EXTERN_NUM_MAX = 960
} SyscapNumExtern;
/* Sort by SyscapNum */
const static SyscapWithNum g_arraySyscapExtern[] = {
{"SystemCapability.AAA.AAAA", ENUM_SYSCAP_AAA},
{"SystemCapability.BBB.BBBB", ENUM_SYSCAP_BBB},
{"SystemCapability.CCC.CCCC", ENUM_SYSCAP_CCC},
};
uint32_t g_arraySyscapExternNum = sizeof(g_arraySyscapExtern) / sizeof(SyscapWithNum);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif // SYSCAP_DEFINE_EXTERN_H
+6 -1
View File
@@ -22,11 +22,16 @@
#include <securec.h>
#include <limits.h>
#include "cJSON.h"
#include "syscap_define.h"
#include "syscap_tool.h"
#include "endian_internal.h"
#include "syscap_interface.h"
#ifdef SYSCAP_DEFINE_EXTERN_ENABLE
#include "syscap_define_custom.h"
#else
#include "syscap_define.h"
#endif
#define OS_SYSCAP_BYTES 120
#define SYSCAP_PREFIX_LEN 17
#define SINGLE_FEAT_LEN (SINGLE_SYSCAP_LEN - SYSCAP_PREFIX_LEN)
+7
View File
@@ -46,6 +46,13 @@ ohos_shared_library("systemcapability") {
"//third_party/bounds_checking_function:libsec_static",
]
if (syscap_codec_config_extern_path != "") {
deps += [ "..:gen_syscap_define_custom" ]
inputs = [ "${root_build_dir}/syscap_define_custom.h" ]
include_dirs += [ "${root_build_dir}" ]
cflags = [ "-DSYSCAP_DEFINE_EXTERN_ENABLE" ]
}
external_deps = [ "napi:ace_napi" ]
if (defined(ohos_lite)) {
+6 -1
View File
@@ -23,9 +23,14 @@
#include "securec.h"
#include "cJSON.h"
#include "endian_internal.h"
#include "syscap_define.h"
#include "create_pcid.h"
#ifdef SYSCAP_DEFINE_EXTERN_ENABLE
#include "syscap_define_custom.h"
#else
#include "syscap_define.h"
#endif
#define SYSCAP_PREFIX_LEN 17
#define SINGLE_FEAT_LEN (SINGLE_SYSCAP_LEN - SYSCAP_PREFIX_LEN)
#define PCID_OUT_BUFFER 32
+6 -1
View File
@@ -24,10 +24,15 @@
#include "securec.h"
#include "endian_internal.h"
#include "cJSON.h"
#include "syscap_define.h"
#include "create_pcid.h"
#include "syscap_tool.h"
#ifdef SYSCAP_DEFINE_EXTERN_ENABLE
#include "syscap_define_custom.h"
#else
#include "syscap_define.h"
#endif
typedef struct RequiredProductCompatibilityIDHead {
uint16_t apiVersion : 15;
uint16_t apiVersionType : 1;
+143
View File
@@ -0,0 +1,143 @@
#! /usr/bin/python3
'''
注意:
1. base 的枚举定义,须在末尾标记最大值。
2. extern 的枚举定义,须在开始位置标记最大值。
3. base 的 syscap 数组,必须以逗号(),)结尾。
'''
import argparse
licence = '''/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'''
before_enum = '''#ifndef SYSCAP_DEFINE_H
#define SYSCAP_DEFINE_H
#include <stdint.h>
#define SINGLE_SYSCAP_LEN (256 + 17)
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef struct SystemCapabilityWithNum {
char str[SINGLE_SYSCAP_LEN];
uint16_t num;
} SyscapWithNum;
/*
* New SyscapNum must be added last and
* don't delete anyone, just comment after it.
*/
'''
after_struct = '''
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif // SYSCAP_DEFINE_H
'''
def gen_define_enum(enum:list):
header = 'typedef enum SystemCapabilityNum {\n'
tail = '} SyscapNum;\n\n'
trunk = ''.join(enum)
return header + trunk + tail
def gen_define_array(stru:list):
header = 'const static SyscapWithNum g_arraySyscap[] = {\n'
tail = '};\n\n'
trunk = ''.join(stru)
return header + trunk + tail
def read_syscap(path):
syscap_enum = []
op_flag = False
with open(path, 'r') as fb:
f = fb.readlines()
for line in f:
if line.startswith('typedef enum '):
op_flag = True
continue
elif op_flag and line.startswith('}'):
break
if op_flag:
syscap_enum.append(line)
syscap_stru = []
op_flag = False
for line in f:
if line.startswith('const static SyscapWithNum '):
op_flag = True
continue
elif op_flag and line.startswith('}'):
op_flag = False
break
if op_flag:
syscap_stru.append(line)
return syscap_enum, syscap_stru
def merge_define(base, extern):
base_enmu, base_stru = read_syscap(base)
ext_enmu, ext_stru = read_syscap(extern)
if '500' in base_enmu[-1] and '500,' in ext_enmu[0]:
res_enmu = base_enmu[:-1] + ext_enmu
else:
res_enmu = base_enmu + ext_enmu
res_stru = base_stru + ext_stru
return res_enmu, res_stru
def assemble_header_file(fenum, fstru):
enum, stru = merge_define(fenum, fstru)
enum_def = gen_define_enum(enum)
stru_def = gen_define_array(stru)
return licence + before_enum + enum_def + stru_def + after_struct
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--base',
help='base syscap config header.')
parser.add_argument('--extern',
help='extern syscap config header.')
parser.add_argument('--output',
help='output app file')
arguments = parser.parse_args()
return arguments
if __name__ == '__main__':
args = parse_args()
base_file = args.base
extern_file = args.extern
output_file = args.output
full = assemble_header_file(base_file, extern_file)
with open(output_file, 'w') as out:
out.writelines(full)