添加了kconfiglib的支持,并兼容env-windows v2.0
This commit is contained in:
parent
bc30ca4743
commit
5cf711488c
|
@ -164,8 +164,21 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
|
|||
|
||||
# set RTT_ROOT in ENV
|
||||
Env['RTT_ROOT'] = Rtt_Root
|
||||
os.environ["RTT_DIR"] = Rtt_Root
|
||||
# set BSP_ROOT in ENV
|
||||
Env['BSP_ROOT'] = Dir('#').abspath
|
||||
os.environ["BSP_DIR"] = Dir('#').abspath
|
||||
# set PKGS_ROOT in ENV
|
||||
if "PKGS_DIR" in os.environ:
|
||||
pass
|
||||
elif "PKGS_ROOT" in os.environ:
|
||||
os.environ["PKGS_DIR"] = os.environ["PKGS_ROOT"]
|
||||
elif "ENV_ROOT" in os.environ:
|
||||
os.environ["PKGS_DIR"] = os.path.join(os.environ["ENV_ROOT"], "packages")
|
||||
elif sys.platform == "win32":
|
||||
os.environ["PKGS_DIR"] = os.path.join(os.environ["USERPROFILE"], ".env", "packages")
|
||||
else:
|
||||
os.environ["PKGS_DIR"] = os.path.join(os.environ["HOME"], ".env", "packages")
|
||||
|
||||
sys.path = sys.path + [os.path.join(Rtt_Root, 'tools')]
|
||||
|
||||
|
@ -299,27 +312,25 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
|
|||
from WCS import ThreadStackStaticAnalysis
|
||||
ThreadStackStaticAnalysis(Env)
|
||||
exit(0)
|
||||
if platform.system() != 'Windows':
|
||||
if GetOption('menuconfig'):
|
||||
from menuconfig import menuconfig
|
||||
menuconfig(Rtt_Root)
|
||||
exit(0)
|
||||
|
||||
if GetOption('menuconfig'):
|
||||
menuconfig = utils.ImportModule('menuconfig')
|
||||
menuconfig.menuconfig(Rtt_Root)
|
||||
exit(0)
|
||||
|
||||
if GetOption('pyconfig_silent'):
|
||||
from menuconfig import guiconfig_silent
|
||||
|
||||
guiconfig_silent(Rtt_Root)
|
||||
menuconfig = utils.ImportModule('menuconfig')
|
||||
menuconfig.guiconfig_silent(Rtt_Root)
|
||||
exit(0)
|
||||
elif GetOption('pyconfig'):
|
||||
from menuconfig import guiconfig
|
||||
|
||||
guiconfig(Rtt_Root)
|
||||
menuconfig = utils.ImportModule('menuconfig')
|
||||
menuconfig.guiconfig(Rtt_Root)
|
||||
exit(0)
|
||||
|
||||
configfn = GetOption('useconfig')
|
||||
if configfn:
|
||||
from menuconfig import mk_rtconfig
|
||||
mk_rtconfig(configfn)
|
||||
menuconfig = utils.ImportModule('menuconfig')
|
||||
menuconfig.mk_rtconfig(configfn)
|
||||
exit(0)
|
||||
|
||||
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# Copyright (c) 2019, Ulf Magnusson
|
||||
# SPDX-License-Identifier: ISC
|
||||
|
||||
"""
|
||||
Reads a specified configuration file, then writes a new configuration file.
|
||||
This can be used to initialize the configuration from e.g. an arch-specific
|
||||
configuration file. This input configuration file would usually be a minimal
|
||||
configuration file, as generated by e.g. savedefconfig.
|
||||
|
||||
The default output filename is '.config'. A different filename can be passed in
|
||||
the KCONFIG_CONFIG environment variable.
|
||||
"""
|
||||
import argparse
|
||||
|
||||
import kconfiglib
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
description=__doc__)
|
||||
|
||||
parser.add_argument(
|
||||
"--kconfig",
|
||||
default="Kconfig",
|
||||
help="Base Kconfig file (default: Kconfig)")
|
||||
|
||||
parser.add_argument(
|
||||
"config",
|
||||
metavar="CONFIGURATION",
|
||||
help="Input configuration file")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
kconf = kconfiglib.Kconfig(args.kconfig)
|
||||
print(kconf.load_config(args.config))
|
||||
print(kconf.write_config())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -1,32 +0,0 @@
|
|||
import os
|
||||
|
||||
def genconfig() :
|
||||
from SCons.Script import SCons
|
||||
|
||||
PreProcessor = SCons.cpp.PreProcessor()
|
||||
|
||||
try:
|
||||
f = open('rtconfig.h', 'r')
|
||||
contents = f.read()
|
||||
f.close()
|
||||
except :
|
||||
print("Open rtconfig.h file failed.")
|
||||
|
||||
PreProcessor.process_contents(contents)
|
||||
options = PreProcessor.cpp_namespace
|
||||
|
||||
try:
|
||||
f = open('.config', 'w')
|
||||
for (opt, value) in options.items():
|
||||
if type(value) == type(1):
|
||||
f.write("CONFIG_%s=%d\n" % (opt, value))
|
||||
|
||||
if type(value) == type('') and value == '':
|
||||
f.write("CONFIG_%s=y\n" % opt)
|
||||
elif type(value) == type('str'):
|
||||
f.write("CONFIG_%s=%s\n" % (opt, value))
|
||||
|
||||
print("Generate .config done!")
|
||||
f.close()
|
||||
except:
|
||||
print("Generate .config file failed.")
|
7024
tools/kconfiglib.py
7024
tools/kconfiglib.py
File diff suppressed because it is too large
Load Diff
|
@ -238,25 +238,21 @@ def exclude_utestcases(RTT_ROOT):
|
|||
if line.find('examples/utest/testcases/Kconfig') == -1:
|
||||
f.write(line)
|
||||
|
||||
# menuconfig for Linux
|
||||
# guiconfig for windows and linux
|
||||
def menuconfig(RTT_ROOT):
|
||||
import menuconfig
|
||||
|
||||
# Exclude utestcases
|
||||
exclude_utestcases(RTT_ROOT)
|
||||
|
||||
kconfig_dir = os.path.join(RTT_ROOT, 'tools', 'kconfig-frontends')
|
||||
os.system('scons -C ' + kconfig_dir)
|
||||
|
||||
touch_env()
|
||||
env_dir = get_env_dir()
|
||||
|
||||
os.environ['PKGS_ROOT'] = os.path.join(env_dir, 'packages')
|
||||
if sys.platform != 'win32':
|
||||
touch_env()
|
||||
|
||||
fn = '.config'
|
||||
fn_old = '.config.old'
|
||||
|
||||
kconfig_cmd = os.path.join(RTT_ROOT, 'tools', 'kconfig-frontends', 'kconfig-mconf')
|
||||
os.system(kconfig_cmd + ' Kconfig')
|
||||
sys.argv = ['menuconfig', 'Kconfig']
|
||||
menuconfig._main()
|
||||
|
||||
if os.path.isfile(fn):
|
||||
if os.path.isfile(fn_old):
|
||||
|
@ -273,7 +269,7 @@ def menuconfig(RTT_ROOT):
|
|||
|
||||
# guiconfig for windows and linux
|
||||
def guiconfig(RTT_ROOT):
|
||||
import pyguiconfig
|
||||
import guiconfig
|
||||
|
||||
# Exclude utestcases
|
||||
exclude_utestcases(RTT_ROOT)
|
||||
|
@ -289,7 +285,7 @@ def guiconfig(RTT_ROOT):
|
|||
fn_old = '.config.old'
|
||||
|
||||
sys.argv = ['guiconfig', 'Kconfig']
|
||||
pyguiconfig._main()
|
||||
guiconfig._main()
|
||||
|
||||
if os.path.isfile(fn):
|
||||
if os.path.isfile(fn_old):
|
||||
|
@ -326,3 +322,34 @@ def guiconfig_silent(RTT_ROOT):
|
|||
|
||||
# silent mode, force to make rtconfig.h
|
||||
mk_rtconfig(fn)
|
||||
|
||||
def genconfig() :
|
||||
from SCons.Script import SCons
|
||||
|
||||
PreProcessor = SCons.cpp.PreProcessor()
|
||||
|
||||
try:
|
||||
f = open('rtconfig.h', 'r')
|
||||
contents = f.read()
|
||||
f.close()
|
||||
except :
|
||||
print("Open rtconfig.h file failed.")
|
||||
|
||||
PreProcessor.process_contents(contents)
|
||||
options = PreProcessor.cpp_namespace
|
||||
|
||||
try:
|
||||
f = open('.config', 'w')
|
||||
for (opt, value) in options.items():
|
||||
if type(value) == type(1):
|
||||
f.write("CONFIG_%s=%d\n" % (opt, value))
|
||||
|
||||
if type(value) == type('') and value == '':
|
||||
f.write("CONFIG_%s=y\n" % opt)
|
||||
elif type(value) == type('str'):
|
||||
f.write("CONFIG_%s=%s\n" % (opt, value))
|
||||
|
||||
print("Generate .config done!")
|
||||
f.close()
|
||||
except:
|
||||
print("Generate .config file failed.")
|
||||
|
|
|
@ -104,19 +104,18 @@ def AddOptions():
|
|||
action = 'store_true',
|
||||
default = False,
|
||||
help = 'print verbose information during build')
|
||||
AddOption('--pyconfig',
|
||||
AddOption('--pyconfig', '--guiconfig',
|
||||
dest = 'pyconfig',
|
||||
action = 'store_true',
|
||||
default = False,
|
||||
help = 'Python GUI menuconfig for RT-Thread BSP')
|
||||
AddOption('--pyconfig-silent',
|
||||
AddOption('--pyconfig-silent', '--defconfig',
|
||||
dest = 'pyconfig_silent',
|
||||
action = 'store_true',
|
||||
default = False,
|
||||
help = 'Don`t show pyconfig window')
|
||||
if platform.system() != 'Windows':
|
||||
AddOption('--menuconfig',
|
||||
dest = 'menuconfig',
|
||||
action = 'store_true',
|
||||
default = False,
|
||||
help = 'make menuconfig for RT-Thread BSP')
|
||||
AddOption('--menuconfig',
|
||||
dest = 'menuconfig',
|
||||
action = 'store_true',
|
||||
default = False,
|
||||
help = 'make menuconfig for RT-Thread BSP')
|
||||
|
|
2314
tools/pyguiconfig.py
2314
tools/pyguiconfig.py
File diff suppressed because it is too large
Load Diff
|
@ -293,3 +293,15 @@ def ReloadModule(module):
|
|||
reload(module)
|
||||
|
||||
return
|
||||
|
||||
def ImportModule(module):
|
||||
import sys
|
||||
if sys.version_info.major >= 3:
|
||||
import importlib.util
|
||||
path = os.path.dirname(__file__)
|
||||
spec = importlib.util.spec_from_file_location(module, os.path.join(path, module+".py"))
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
else:
|
||||
return __import__(module, fromlist=[module])
|
Loading…
Reference in New Issue