From 27f6869a1f8cf30437a1009a8851cd52b90b4e06 Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Fri, 28 Jun 2024 18:22:57 +0200 Subject: [PATCH] Added COMPILATIONDB_FILTER_FILES option and auto update if there was no update since boot. --- SConscript | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/SConscript b/SConscript index c99e84f..4513115 100644 --- a/SConscript +++ b/SConscript @@ -1,7 +1,9 @@ import copy import os +import psutil import sys +import time def _cook(env: Environment, recipe_name: str, *args, **kwargs): import importlib.util @@ -30,7 +32,7 @@ def _inject_list(kwargs: dict, dependency: dict, list_name: str) -> None: return if list_name not in kwargs: kwargs[list_name] = [] - kwargs[list_name].extend(dependency[list_name]) # TODO: eliminiate duplicates? + kwargs[list_name].extend(dependency[list_name]) # TODO: eliminate duplicates? def _inject_dependency(dependency, kwargs: dict, add_sources: bool = True) -> None: if isinstance(dependency, dict): @@ -219,6 +221,7 @@ vars.Add('LINK', 'The Linker') vars.Add('CCFLAGS', 'C/C++ Compiler Flags') vars.Add('LINKFLAGS', 'Linker Flags') vars.Add('PYTHON', 'Python Executable', 'python') +vars.Add('COMPILATIONDB_FILTER_FILES', 'Removes source files from the compilation DB that are not from the current project.', True) tools = ['default', 'compilation_db', 'unity_build'] if 'TOOLS' in config: @@ -239,6 +242,7 @@ except: print(f'Creating spp cache dir failed, using fallback: {env["SYSTEM_CACHE_DIR"]}.') os.makedirs(env['SYSTEM_CACHE_DIR'], exist_ok=True) # no more safeguards! +env['SHARED_CACHE_DIR'] = Dir(f'#cache').abspath # allow compiling to variant directories (each gets their own bin/lib/cache dirs) if variant: env['BIN_DIR'] = Dir(f'#bin_{variant}').abspath @@ -249,12 +253,13 @@ if variant: else: env['VARIANT_DIR'] = None env['COMPILATIONDB_USE_ABSPATH'] = True - env['COMPILATIONDB_PATH_FILTER'] = f"{Dir('#').abspath}/*" + if env['COMPILATIONDB_FILTER_FILES']: + env['COMPILATIONDB_PATH_FILTER'] = f"{Dir('#').abspath}/*" comp_db = env.CompilationDatabase(target = '#compile_commands.json') Default(comp_db) env['BIN_DIR'] = Dir('#bin').abspath env['LIB_DIR'] = Dir('#lib').abspath - env['CACHE_DIR'] = Dir(f'#cache').abspath + env['CACHE_DIR'] = env['SHARED_CACHE_DIR'] env['UNITY_CACHE_DIR'] = Dir(f'{env["CACHE_DIR"]}/unity') env['BUILD_TYPE'] = build_type env.Append(LIBPATH = [env['LIB_DIR']]) # to allow submodules to link to each other without hassle @@ -273,6 +278,29 @@ if not os.path.exists(cache_gitignore): with open(cache_gitignore, 'w') as f: f.write('*\n') +if env['CACHE_DIR'] != env['SHARED_CACHE_DIR']: + os.makedirs(env['SHARED_CACHE_DIR'], exist_ok=True) + cache_gitignore = f'{env["SHARED_CACHE_DIR"]}/.gitignore' + if not os.path.exists(cache_gitignore): + with open(cache_gitignore, 'w') as f: + f.write('*\n') + +# check whether repositories where updated since last boot +update_stamp_file = f'{env["SHARED_CACHE_DIR"]}/last_update.stamp' +update_time = 0.0 +if os.path.exists(update_stamp_file): + with open(update_stamp_file, 'r') as f: + try: + update_time = float(f.read()) + except: + pass +boot_time = psutil.boot_time() +if boot_time > update_time: + print('Didn\'t update repositories since last boot, doing it now...') + env['UPDATE_REPOSITORIES'] = True +if env['UPDATE_REPOSITORIES']: + with open(update_stamp_file, 'w') as f: + f.write(str(time.time())) # create the clone and system cache dirs os.makedirs(env['CLONE_DIR'], exist_ok=True)