栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Windows下使用Kconfig管理编译配置

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Windows下使用Kconfig管理编译配置

Windows下使用Kconfig管理编译配置

文章目录
  • Windows下使用Kconfig管理编译配置
    • 存在的问题
    • 解决办法

存在的问题

项目开发过程中,为方便进行编译配置管理,引入了Kconfig,python的konfiglib和menuconfig很好地满足了需求。

但是,在Windows的Git-Bash环境中,不能像Linux下那样直接使用Kconfig进行编译配置管理,描述如下:

python文件:

import os
import sys
from kconfiglib import Kconfig
from menuconfig import menuconfig

def project_menuconfig(config='.config', file='Kconfig'):
    os.environ['MENUCONFIG_STYLE'] = 'default path=fg:black,bg:white separator=fg:white,bg:blue,bold selection=fg:white,bg:red,bold help=path'
    os.envrion['KCONFIG_CONFIG_HEADER'] = '#n# Automatically generated file: Do not edit !!!n#n'
    os.envrion['KCONFIG_CONFIG'] = config

    menuconfig(Kconfig(filename=file))

在Git-Bash中执行:

python3 mconfig.py

有如下报错:

Redirection is not supported.
解决办法

该问题的原因是 windows_curses 需要在终端上运行,解决办法如下:

import os
import sys
from kconfiglib import Kconfig
from menuconfig import menuconfig

def project_menuconfig(config='.config', file='Kconfig'):
    os.environ['MENUCONFIG_STYLE'] = 'default path=fg:black,bg:white separator=fg:white,bg:blue,bold selection=fg:white,bg:red,bold help=path'
    os.envrion['KCONFIG_CONFIG_HEADER'] = '#n# Automatically generated file: Do not edit !!!n#n'
    os.envrion['KCONFIG_CONFIG'] = config

    # 判断是否在Windows下执行, 若是则启动一个独立的命令行提示符窗口来执行menuconfig
    if sys.platform.startswith('win'):
        os.system('start /wait cmd.exe /c menuconfig.exe %s' % file)
    else:
        menuconfig(Kconfig(filename=file))

start:启动单独的命令提示符窗口来运行指定的程序或命令;

/wait:等待程序或命令运行结束;

menuconfig.exe 是一个python工具,使用pip安装menuconfig库后产生,需要确保python工具的相关路径被添加到Path环境变量中去。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1037177.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号