import json from pathlib import Path from spp import get_spp, TargetType spp = get_spp() def _should_generate() -> bool: # check if any program or library target has been built for target in spp.targets: if target.target_type in (TargetType.PROGRAM, TargetType.STATIC_LIBRARY, TargetType.SHARED_LIBRARY): return True return False def post_finalize(**kwargs) -> None: if not _should_generate(): return cache_file = Path(spp.env['CACHE_DIR']) / 'config_cache.json' cache = {} if cache_file.exists(): try: with cache_file.open('r') as f: cache = json.load(f) except Exception as e: spp.env.Warn(f'Error while loading config cache: {e}.') cache['build_type'] = spp.env['BUILD_TYPE'] try: with cache_file.open('w') as f: json.dump(cache, f) except Exception as e: spp.env.Warn(f'Error while saving config cache: {e}.')