Added COMPILATIONDB_FILTER_FILES option and auto update if there was no update since boot.

This commit is contained in:
Patrick 2024-06-28 18:22:57 +02:00
parent 3171d112ce
commit 27f6869a1f

View File

@ -1,7 +1,9 @@
import copy import copy
import os import os
import psutil
import sys import sys
import time
def _cook(env: Environment, recipe_name: str, *args, **kwargs): def _cook(env: Environment, recipe_name: str, *args, **kwargs):
import importlib.util import importlib.util
@ -30,7 +32,7 @@ def _inject_list(kwargs: dict, dependency: dict, list_name: str) -> None:
return return
if list_name not in kwargs: if list_name not in kwargs:
kwargs[list_name] = [] 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: def _inject_dependency(dependency, kwargs: dict, add_sources: bool = True) -> None:
if isinstance(dependency, dict): if isinstance(dependency, dict):
@ -219,6 +221,7 @@ vars.Add('LINK', 'The Linker')
vars.Add('CCFLAGS', 'C/C++ Compiler Flags') vars.Add('CCFLAGS', 'C/C++ Compiler Flags')
vars.Add('LINKFLAGS', 'Linker Flags') vars.Add('LINKFLAGS', 'Linker Flags')
vars.Add('PYTHON', 'Python Executable', 'python') 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'] tools = ['default', 'compilation_db', 'unity_build']
if 'TOOLS' in config: if 'TOOLS' in config:
@ -239,6 +242,7 @@ except:
print(f'Creating spp cache dir failed, using fallback: {env["SYSTEM_CACHE_DIR"]}.') 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! 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) # allow compiling to variant directories (each gets their own bin/lib/cache dirs)
if variant: if variant:
env['BIN_DIR'] = Dir(f'#bin_{variant}').abspath env['BIN_DIR'] = Dir(f'#bin_{variant}').abspath
@ -249,12 +253,13 @@ if variant:
else: else:
env['VARIANT_DIR'] = None env['VARIANT_DIR'] = None
env['COMPILATIONDB_USE_ABSPATH'] = True 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') comp_db = env.CompilationDatabase(target = '#compile_commands.json')
Default(comp_db) Default(comp_db)
env['BIN_DIR'] = Dir('#bin').abspath env['BIN_DIR'] = Dir('#bin').abspath
env['LIB_DIR'] = Dir('#lib').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['UNITY_CACHE_DIR'] = Dir(f'{env["CACHE_DIR"]}/unity')
env['BUILD_TYPE'] = build_type env['BUILD_TYPE'] = build_type
env.Append(LIBPATH = [env['LIB_DIR']]) # to allow submodules to link to each other without hassle 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: with open(cache_gitignore, 'w') as f:
f.write('*\n') 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 # create the clone and system cache dirs
os.makedirs(env['CLONE_DIR'], exist_ok=True) os.makedirs(env['CLONE_DIR'], exist_ok=True)