From 96b9fbe54ec978d3977837edd6d6eae2170f7cb0 Mon Sep 17 00:00:00 2001 From: Michael Kuron <m.kuron@gmx.de> Date: Tue, 27 Apr 2021 15:30:57 +0200 Subject: [PATCH] clear cache when compiler flags have changed --- pystencils/cpu/cpujit.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pystencils/cpu/cpujit.py b/pystencils/cpu/cpujit.py index cef1ee4d8..4da43010a 100644 --- a/pystencils/cpu/cpujit.py +++ b/pystencils/cpu/cpujit.py @@ -205,10 +205,23 @@ def read_config(): if config['cache']['object_cache'] is not False: config['cache']['object_cache'] = os.path.expanduser(config['cache']['object_cache']).format(pid=os.getpid()) - if config['cache']['clear_cache_on_start']: + clear_cache = False + cache_status_file = os.path.join(config['cache']['object_cache'], 'last_config.json') + if os.path.exists(cache_status_file): + # check if compiler config has changed + last_config = json.load(open(cache_status_file, 'r')) + if set(last_config.items()) != set(config['compiler'].items()): + clear_cache = True + else: + for key in last_config.keys(): + if last_config[key] != config['compiler'][key]: + clear_cache = True + + if config['cache']['clear_cache_on_start'] or clear_cache: shutil.rmtree(config['cache']['object_cache'], ignore_errors=True) create_folder(config['cache']['object_cache'], False) + json.dump(config['compiler'], open(cache_status_file, 'w'), indent=4) if config['compiler']['os'] == 'windows': from pystencils.cpu.msvc_detection import get_environment -- GitLab