59 Star 127 Fork 1.5K

OpenHarmony/build

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
generate_kconfig.py 3.48 KB
一键复制 编辑 原始数据 按行查看 历史
林昱晔 提交于 2个月前 . "告警处理"
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright (c) 2021 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.
"""
import argparse
import json
import os
import stat
KCONFIG_STR = 'config {}\n\
bool "{}"\n\
default n\n'
PROPERTIES_STR = 'config {}\n\
string "{}"\n\
default ""\n'
KMENU_STR = 'menu "{}"\n'
FEATURE_STR = 'config feature$$%s\n\
string "feature"\n\
default ""\n\
depends on %s\n'
def create_config(name: str, comment: str):
return KCONFIG_STR.format(name, comment)
def create_property(name: str, comment: str):
return PROPERTIES_STR.format(name, comment)
def create_menu(name: str):
return KMENU_STR.format(name)
def end_menu():
return "endmenu\n"
def create_feature(name: str):
return FEATURE_STR % (name, name)
def read_json(file: str):
data = {}
with open(file, "rb") as f:
data = json.load(f)
return data
def write_kconfig(result: str, outdir: str):
outpath = os.path.join(outdir, "kconfig")
with os.fdopen(os.open(outpath,
os.O_RDWR | os.O_CREAT, stat.S_IWUSR | stat.S_IRUSR), 'w') as f:
f.writelines(result)
print("output file in: ", os.path.abspath(outpath))
def gen_kconfig(config_path: str, outdir: str):
data = read_json(config_path)
subsystems = data.get("subsystems")
result = 'mainmenu "Subsystem Component Kconfig Configuration"\n'
for prop, _ in data.items():
if prop == "subsystems":
continue
result += create_property("property$${}".format(prop), prop)
for subsys_dict in subsystems:
subsys_name = subsys_dict.get("subsystem")
result += create_menu(subsys_name)
for component_dict in subsys_dict.get("components"):
component_name = component_dict.get("component")
result += create_config("{}$${}".format(subsys_name, component_name), component_name)
result += create_feature("{}$${}".format(subsys_name, component_name))
result += end_menu()
write_kconfig(result, outdir)
if __name__ == "__main__":
INTRO = 'Genenrate newly kconfig input file.\n\
For example: python3 generate_kconfig.py\n\
or python3 generate_kconfig.py --base_product={$repo}/productdefine/common/base/base_product.json --outdir=./'
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description=INTRO
)
parser.add_argument('--base_product', type=str, default="./../../../productdefine/common/base/base_product.json",
help='Basic config path in repo prodcutdefine,\
default={$repo}/productdefine/common/base/base_product.json')
parser.add_argument('--outdir', type=str, default="./",
help="define output file path dir, default={$current_dir}")
args = parser.parse_args()
print("read base_product file: ", os.path.abspath(args.base_product))
gen_kconfig(args.base_product, args.outdir)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openharmony/build.git
git@gitee.com:openharmony/build.git
openharmony
build
build
master

搜索帮助