[tools] 完善 scons --menuconfig 更新 rtconfig.h 文件的邏輯

This commit is contained in:
iysheng 2020-12-23 13:02:23 +08:00
parent 10823e54b4
commit e887b477f4
1 changed files with 26 additions and 17 deletions

View File

@ -27,6 +27,8 @@ import os
import re import re
import sys import sys
import shutil import shutil
import hashlib
import operator
# make rtconfig.h from .config # make rtconfig.h from .config
@ -38,7 +40,6 @@ def is_pkg_special_config(config_str):
return True return True
return False return False
def mk_rtconfig(filename): def mk_rtconfig(filename):
try: try:
config = open(filename, 'r') config = open(filename, 'r')
@ -97,6 +98,14 @@ def mk_rtconfig(filename):
rtconfig.write('#endif\n') rtconfig.write('#endif\n')
rtconfig.close() rtconfig.close()
def get_file_md5(file):
MD5 = hashlib.new('md5')
with open(file, 'r') as fp:
MD5.update(fp.read().encode('utf8'))
fp_md5 = MD5.hexdigest()
return fp_md5
def config(): def config():
mk_rtconfig('.config') mk_rtconfig('.config')
@ -219,22 +228,22 @@ def menuconfig(RTT_ROOT):
os.environ['PKGS_ROOT'] = os.path.join(env_dir, 'packages') os.environ['PKGS_ROOT'] = os.path.join(env_dir, 'packages')
fn = '.config' fn = '.config'
fn_old = '.config.old'
if os.path.isfile(fn):
mtime = os.path.getmtime(fn)
else:
mtime = -1
kconfig_cmd = os.path.join(RTT_ROOT, 'tools', 'kconfig-frontends', 'kconfig-mconf') kconfig_cmd = os.path.join(RTT_ROOT, 'tools', 'kconfig-frontends', 'kconfig-mconf')
os.system(kconfig_cmd + ' Kconfig') os.system(kconfig_cmd + ' Kconfig')
if os.path.isfile(fn): if os.path.isfile(fn):
mtime2 = os.path.getmtime(fn) if os.path.isfile(fn_old):
diff_eq = operator.eq(get_file_md5(fn), get_file_md5(fn_old))
else: else:
mtime2 = -1 diff_eq = False
else:
sys.exit(-1)
# make rtconfig.h # make rtconfig.h
if mtime != mtime2: if diff_eq == False:
shutil.copyfile(fn, fn_old)
mk_rtconfig(fn) mk_rtconfig(fn)
# guiconfig for windows and linux # guiconfig for windows and linux
@ -249,22 +258,22 @@ def guiconfig(RTT_ROOT):
os.environ['PKGS_ROOT'] = os.path.join(env_dir, 'packages') os.environ['PKGS_ROOT'] = os.path.join(env_dir, 'packages')
fn = '.config' fn = '.config'
fn_old = '.config.old'
if os.path.isfile(fn):
mtime = os.path.getmtime(fn)
else:
mtime = -1
sys.argv = ['guiconfig', 'Kconfig']; sys.argv = ['guiconfig', 'Kconfig'];
pyguiconfig._main() pyguiconfig._main()
if os.path.isfile(fn): if os.path.isfile(fn):
mtime2 = os.path.getmtime(fn) if os.path.isfile(fn_old):
diff_eq = operator.eq(get_file_md5(fn), get_file_md5(fn_old))
else: else:
mtime2 = -1 diff_eq = False
else:
sys.exit(-1)
# make rtconfig.h # make rtconfig.h
if mtime != mtime2: if diff_eq == False:
shutil.copyfile(fn, fn_old)
mk_rtconfig(fn) mk_rtconfig(fn)