From e887b477f4d7ae5148f7fb2ba8630852d6db079b Mon Sep 17 00:00:00 2001 From: iysheng Date: Wed, 23 Dec 2020 13:02:23 +0800 Subject: [PATCH] =?UTF-8?q?[tools]=20=E5=AE=8C=E5=96=84=20scons=20--menuco?= =?UTF-8?q?nfig=20=E6=9B=B4=E6=96=B0=20rtconfig.h=20=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E9=82=8F=E8=BC=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/menuconfig.py | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/tools/menuconfig.py b/tools/menuconfig.py index b49a2e7120..c0a33718de 100644 --- a/tools/menuconfig.py +++ b/tools/menuconfig.py @@ -27,6 +27,8 @@ import os import re import sys import shutil +import hashlib +import operator # make rtconfig.h from .config @@ -38,7 +40,6 @@ def is_pkg_special_config(config_str): return True return False - def mk_rtconfig(filename): try: config = open(filename, 'r') @@ -97,6 +98,14 @@ def mk_rtconfig(filename): rtconfig.write('#endif\n') 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(): mk_rtconfig('.config') @@ -219,22 +228,22 @@ def menuconfig(RTT_ROOT): 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 + fn_old = '.config.old' kconfig_cmd = os.path.join(RTT_ROOT, 'tools', 'kconfig-frontends', 'kconfig-mconf') os.system(kconfig_cmd + ' Kconfig') 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: - mtime2 = -1 + sys.exit(-1) # make rtconfig.h - if mtime != mtime2: + if diff_eq == False: + shutil.copyfile(fn, fn_old) mk_rtconfig(fn) # guiconfig for windows and linux @@ -249,22 +258,22 @@ def guiconfig(RTT_ROOT): 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 + fn_old = '.config.old' sys.argv = ['guiconfig', 'Kconfig']; pyguiconfig._main() 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: - mtime2 = -1 + sys.exit(-1) # make rtconfig.h - if mtime != mtime2: + if diff_eq == False: + shutil.copyfile(fn, fn_old) mk_rtconfig(fn)