未验证 提交 936db0e3 编写于 作者: B Bernard Xiong 提交者: GitHub

Merge pull request #4039 from iysheng/master

[tools] 完善 scons --menuconfig 更新 rtconfig.h 文件的邏輯
...@@ -27,6 +27,8 @@ import os ...@@ -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): ...@@ -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): ...@@ -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): ...@@ -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:
diff_eq = False
else: else:
mtime2 = -1 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): ...@@ -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:
diff_eq = False
else: else:
mtime2 = -1 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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册