2727import re
2828import sys
2929import 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-
4243def 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+
100109def 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