Skip to content

Commit 936db0e

Browse files
authored
Merge pull request #4039 from iysheng/master
[tools] 完善 scons --menuconfig 更新 rtconfig.h 文件的邏輯
2 parents 1708b72 + e887b47 commit 936db0e

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

tools/menuconfig.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import re
2828
import sys
2929
import shutil
30+
import hashlib
31+
import operator
3032

3133
# make rtconfig.h from .config
3234

@@ -38,7 +40,6 @@ def is_pkg_special_config(config_str):
3840
return True
3941
return False
4042

41-
4243
def mk_rtconfig(filename):
4344
try:
4445
config = open(filename, 'r')
@@ -97,6 +98,14 @@ def mk_rtconfig(filename):
9798
rtconfig.write('#endif\n')
9899
rtconfig.close()
99100

101+
102+
def get_file_md5(file):
103+
MD5 = hashlib.new('md5')
104+
with open(file, 'r') as fp:
105+
MD5.update(fp.read().encode('utf8'))
106+
fp_md5 = MD5.hexdigest()
107+
return fp_md5
108+
100109
def config():
101110
mk_rtconfig('.config')
102111

@@ -219,22 +228,22 @@ def menuconfig(RTT_ROOT):
219228
os.environ['PKGS_ROOT'] = os.path.join(env_dir, 'packages')
220229

221230
fn = '.config'
222-
223-
if os.path.isfile(fn):
224-
mtime = os.path.getmtime(fn)
225-
else:
226-
mtime = -1
231+
fn_old = '.config.old'
227232

228233
kconfig_cmd = os.path.join(RTT_ROOT, 'tools', 'kconfig-frontends', 'kconfig-mconf')
229234
os.system(kconfig_cmd + ' Kconfig')
230235

231236
if os.path.isfile(fn):
232-
mtime2 = os.path.getmtime(fn)
237+
if os.path.isfile(fn_old):
238+
diff_eq = operator.eq(get_file_md5(fn), get_file_md5(fn_old))
239+
else:
240+
diff_eq = False
233241
else:
234-
mtime2 = -1
242+
sys.exit(-1)
235243

236244
# make rtconfig.h
237-
if mtime != mtime2:
245+
if diff_eq == False:
246+
shutil.copyfile(fn, fn_old)
238247
mk_rtconfig(fn)
239248

240249
# guiconfig for windows and linux
@@ -249,22 +258,22 @@ def guiconfig(RTT_ROOT):
249258
os.environ['PKGS_ROOT'] = os.path.join(env_dir, 'packages')
250259

251260
fn = '.config'
252-
253-
if os.path.isfile(fn):
254-
mtime = os.path.getmtime(fn)
255-
else:
256-
mtime = -1
261+
fn_old = '.config.old'
257262

258263
sys.argv = ['guiconfig', 'Kconfig'];
259264
pyguiconfig._main()
260265

261266
if os.path.isfile(fn):
262-
mtime2 = os.path.getmtime(fn)
267+
if os.path.isfile(fn_old):
268+
diff_eq = operator.eq(get_file_md5(fn), get_file_md5(fn_old))
269+
else:
270+
diff_eq = False
263271
else:
264-
mtime2 = -1
272+
sys.exit(-1)
265273

266274
# make rtconfig.h
267-
if mtime != mtime2:
275+
if diff_eq == False:
276+
shutil.copyfile(fn, fn_old)
268277
mk_rtconfig(fn)
269278

270279

0 commit comments

Comments
 (0)