Add scons --pyconfig command for configure project.
This commit is contained in:
parent
e166da9961
commit
937e22fc8b
|
@ -335,6 +335,16 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
|
|||
menuconfig(Rtt_Root)
|
||||
exit(0)
|
||||
|
||||
AddOption('--pyconfig',
|
||||
dest = 'pyconfig',
|
||||
action = 'store_true',
|
||||
default = False,
|
||||
help = 'make menuconfig for RT-Thread BSP')
|
||||
if GetOption('pyconfig'):
|
||||
from menuconfig import pyconfig
|
||||
pyconfig(Rtt_Root)
|
||||
exit(0)
|
||||
|
||||
configfn = GetOption('useconfig')
|
||||
if configfn:
|
||||
from menuconfig import mk_rtconfig
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -20,8 +20,12 @@
|
|||
# Change Logs:
|
||||
# Date Author Notes
|
||||
# 2017-12-29 Bernard The first version
|
||||
# 2018-07-31.....weety Support pyconfig
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import pymenuconfig
|
||||
|
||||
# make rtconfig.h from .config
|
||||
|
||||
|
@ -32,7 +36,7 @@ def mk_rtconfig(filename):
|
|||
print('open config:%s failed' % filename)
|
||||
return
|
||||
|
||||
rtconfig = file('rtconfig.h', 'w')
|
||||
rtconfig = file('rtconfig.h', 'wb')
|
||||
rtconfig.write('#ifndef RT_CONFIG_H__\n')
|
||||
rtconfig.write('#define RT_CONFIG_H__\n\n')
|
||||
|
||||
|
@ -88,8 +92,12 @@ def get_env_dir():
|
|||
if os.environ.get('ENV_ROOT'):
|
||||
return os.environ.get('ENV_ROOT')
|
||||
|
||||
home_dir = os.environ['HOME']
|
||||
env_dir = os.path.join(home_dir, '.env')
|
||||
if sys.platform == 'win32':
|
||||
home_dir = os.environ['USERPROFILE']
|
||||
env_dir = os.path.join(home_dir, '.env')
|
||||
else:
|
||||
home_dir = os.environ['HOME']
|
||||
env_dir = os.path.join(home_dir, '.env')
|
||||
|
||||
if not os.path.exists(env_dir):
|
||||
return None
|
||||
|
@ -97,23 +105,79 @@ def get_env_dir():
|
|||
return env_dir
|
||||
|
||||
def touch_env():
|
||||
home_dir = os.environ['HOME']
|
||||
env_dir = os.path.join(home_dir, '.env')
|
||||
if not os.path.exists(env_dir):
|
||||
os.mkdir(env_dir)
|
||||
os.mkdir(os.path.join(env_dir, 'local_pkgs'))
|
||||
os.mkdir(os.path.join(env_dir, 'packages'))
|
||||
if sys.platform != 'win32':
|
||||
home_dir = os.environ['HOME']
|
||||
env_dir = os.path.join(home_dir, '.env')
|
||||
if not os.path.exists(env_dir):
|
||||
os.mkdir(env_dir)
|
||||
os.mkdir(os.path.join(env_dir, 'local_pkgs'))
|
||||
os.mkdir(os.path.join(env_dir, 'packages'))
|
||||
|
||||
os.system('git clone https://github.com/RT-Thread/packages.git ~/.env/packages/packages')
|
||||
os.system('git clone https://github.com/RT-Thread/packages.git ~/.env/packages/packages')
|
||||
|
||||
kconfig = file(os.path.join(env_dir, 'packages', 'Kconfig'), 'w')
|
||||
kconfig.write('source "$PKGS_DIR/packages/Kconfig"')
|
||||
kconfig = file(os.path.join(env_dir, 'packages', 'Kconfig'), 'w')
|
||||
kconfig.write('source "$PKGS_DIR/packages/Kconfig"')
|
||||
|
||||
os.mkdir(os.path.join(env_dir, 'tools'))
|
||||
os.system('git clone https://github.com/RT-Thread/env.git ~/.env/tools/scripts')
|
||||
os.mkdir(os.path.join(env_dir, 'tools'))
|
||||
os.system('git clone https://github.com/RT-Thread/env.git ~/.env/tools/scripts')
|
||||
|
||||
env_sh = file(os.path.join(env_dir, 'env.sh'), 'w')
|
||||
env_sh.write('export PATH=~/.env/tools/scripts:$PATH')
|
||||
env_sh = file(os.path.join(env_dir, 'env.sh'), 'w')
|
||||
env_sh.write('export PATH=~/.env/tools/scripts:$PATH')
|
||||
else:
|
||||
home_dir = os.environ['USERPROFILE']
|
||||
env_dir = os.path.join(home_dir, '.env')
|
||||
if not os.path.exists(env_dir):
|
||||
os.mkdir(env_dir)
|
||||
os.mkdir(os.path.join(env_dir, 'local_pkgs'))
|
||||
os.mkdir(os.path.join(env_dir, 'packages'))
|
||||
os.mkdir(os.path.join(env_dir, 'tools'))
|
||||
kconfig = file(os.path.join(env_dir, 'packages', 'Kconfig'), 'wb')
|
||||
kconfig.close()
|
||||
|
||||
if not os.path.exists(os.path.join(env_dir, 'packages', 'packages')):
|
||||
try:
|
||||
ret = os.system('git clone https://github.com/RT-Thread/packages.git %s' % os.path.join(env_dir, 'packages', 'packages'))
|
||||
if ret != 0:
|
||||
shutil.rmtree(os.path.join(env_dir, 'packages', 'packages'))
|
||||
print("********************************************************************************\n"
|
||||
"* Run command error for \"git clone https://github.com/RT-Thread/packages.git\".\n"
|
||||
"* This error may have been caused by not found a git tool or network error.\n"
|
||||
"* If the git tool is not installed, install the git tool first.\n"
|
||||
"* If the git utility is installed, check whether the git command is added to the system PATH.\n"
|
||||
"* This error may cause the RT-Thread packages to not work properly.\n"
|
||||
"********************************************************************************\n")
|
||||
else:
|
||||
kconfig = file(os.path.join(env_dir, 'packages', 'Kconfig'), 'wb')
|
||||
kconfig.write('source "$PKGS_DIR/packages/Kconfig"')
|
||||
kconfig.close()
|
||||
except:
|
||||
print("********************************************************************************\n"
|
||||
"* Run command error for \"git clone https://github.com/RT-Thread/packages.git\". \n"
|
||||
"* This error may have been caused by not found a git tool or git tool not in the system PATH. \n"
|
||||
"* This error may cause the RT-Thread packages to not work properly. \n"
|
||||
"********************************************************************************\n")
|
||||
|
||||
if not os.path.exists(os.path.join(env_dir, 'tools', 'scripts')):
|
||||
try:
|
||||
ret = os.system('git clone https://github.com/RT-Thread/env.git %s' % os.path.join(env_dir, 'tools', 'scripts'))
|
||||
if ret != 0:
|
||||
shutil.rmtree(os.path.join(env_dir, 'tools', 'scripts'))
|
||||
print("********************************************************************************\n"
|
||||
"* Run command error for \"git clone https://github.com/RT-Thread/env.git\".\n"
|
||||
"* This error may have been caused by not found a git tool or network error.\n"
|
||||
"* If the git tool is not installed, install the git tool first.\n"
|
||||
"* If the git utility is installed, check whether the git command is added to the system PATH.\n"
|
||||
"* This error may cause script tools to fail to work properly.\n"
|
||||
"********************************************************************************\n")
|
||||
except:
|
||||
print("********************************************************************************\n"
|
||||
"* Run command error for \"git clone https://github.com/RT-Thread/env.git\". \n"
|
||||
"* This error may have been caused by not found a git tool or git tool not in the system PATH. \n"
|
||||
"* This error may cause script tools to fail to work properly. \n"
|
||||
"********************************************************************************\n")
|
||||
|
||||
if os.path.exists(os.path.join(env_dir, 'tools', 'scripts')):
|
||||
os.environ["PATH"] = os.path.join(env_dir, 'tools', 'scripts') + ';' + os.environ["PATH"]
|
||||
|
||||
# menuconfig for Linux
|
||||
def menuconfig(RTT_ROOT):
|
||||
|
@ -146,3 +210,31 @@ def menuconfig(RTT_ROOT):
|
|||
if mtime != mtime2:
|
||||
mk_rtconfig(fn)
|
||||
|
||||
# pyconfig for windows and linux
|
||||
def pyconfig(RTT_ROOT):
|
||||
|
||||
env_dir = get_env_dir()
|
||||
if not env_dir:
|
||||
touch_env()
|
||||
env_dir = get_env_dir()
|
||||
|
||||
os.environ['PKGS_ROOT'] = os.path.join(env_dir, 'packages')
|
||||
|
||||
fn = '.config'
|
||||
|
||||
if os.path.isfile(fn):
|
||||
mtime = os.path.getmtime(fn)
|
||||
else:
|
||||
mtime = -1
|
||||
|
||||
pymenuconfig.main(['--kconfig', 'Kconfig', '--config', '.config'])
|
||||
|
||||
if os.path.isfile(fn):
|
||||
mtime2 = os.path.getmtime(fn)
|
||||
else:
|
||||
mtime2 = -1
|
||||
|
||||
# make rtconfig.h
|
||||
if mtime != mtime2:
|
||||
mk_rtconfig(fn)
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue