Compare commits

...

2 Commits

2 changed files with 63 additions and 12 deletions

View File

@ -244,6 +244,11 @@ def _find_lib(env: Environment, name: str, paths: 'list[str]', type : str = 'sta
return None
raise Exception(f'Could not find library with name {name} in paths: "{", ".join(paths)}" filename: "{fname}".')
def _info(env: Environment, message: str) -> None:
if not GetOption('silent'):
print(message)
def _error(env: Environment, message: str):
print(message, file=sys.stderr)
Exit(1)
@ -727,11 +732,30 @@ AddOption(
)
AddOption(
'--dump_env',
dest = 'dump_env',
'--disable_auto_update',
dest = 'disable_auto_update',
action = 'store_true'
)
AddOption(
'--dump',
dest = 'dump',
type = 'choice',
choices = ('env', 'config'),
nargs = 1,
action = 'store'
)
AddOption(
'--dump_format',
dest = 'dump_format',
type = 'choice',
choices = ('text', 'json'),
nargs = 1,
action = 'store',
default = 'text'
)
AddOption(
'--generate_project',
dest = 'generate_project',
@ -750,7 +774,9 @@ enable_asan = GetOption('enable_asan')
config_file = GetOption('config_file')
compiler = GetOption('compiler')
update_repositories = GetOption('update_repositories')
dump_env = GetOption('dump_env')
disable_auto_update = GetOption('disable_auto_update')
dump = GetOption('dump')
dump_format = GetOption('dump_format')
generate_project = GetOption('generate_project')
default_CC = {
@ -796,12 +822,12 @@ env['DEPS_CFLAGS'] = []
env['DEPS_CXXFLAGS'] = []
env['DEPS_LINKFLAGS'] = []
print(f'Detected system cache directory: {env["SYSTEM_CACHE_DIR"]}')
_info(None, f'Detected system cache directory: {env["SYSTEM_CACHE_DIR"]}')
try:
os.makedirs(env['SYSTEM_CACHE_DIR'], exist_ok=True)
except:
env['SYSTEM_CACHE_DIR'] = os.path.join(_get_fallback_cache_dir(), 'spp_cache')
print(f'Creating spp cache dir failed, using fallback: {env["SYSTEM_CACHE_DIR"]}.')
_info(None, 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['CLONE_DIR'] = os.path.join(env['SYSTEM_CACHE_DIR'], 'cloned')
env['DOWNLOAD_DIR'] = os.path.join(env['SYSTEM_CACHE_DIR'], 'downloaded')
@ -878,8 +904,8 @@ if os.path.exists(update_stamp_file):
except:
pass
boot_time = psutil.boot_time()
if boot_time > update_time:
print('Didn\'t update repositories since last boot, doing it now...')
if not disable_auto_update and boot_time > update_time:
_info(None, '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:
@ -1008,6 +1034,7 @@ env.AddMethod(_make_interface, 'MakeInterface')
env.AddMethod(_lib_filename, 'LibFilename')
env.AddMethod(_find_executable, 'FindExecutable')
env.AddMethod(_find_lib, 'FindLib')
env.AddMethod(_info, 'Info')
env.AddMethod(_error, 'Error')
env.AddMethod(_wrap_builder(env.Library, TargetType.STATIC_LIBRARY), 'Library')
env.AddMethod(_wrap_builder(env.StaticLibrary, TargetType.STATIC_LIBRARY), 'StaticLibrary')
@ -1025,15 +1052,33 @@ env.AddMethod(_finalize, 'Finalize')
env.AddMethod(_find_target, 'FindTarget')
if hasattr(env, 'Gch'):
env.AddMethod(_wrap_builder(env.Gch), 'Gch')
env.AddMethod(_wrap_builder(env.Gch, TargetType.STATIC_LIBRARY), 'Gch')
for addon_file in env.Glob('addons/*.py'):
env = SConscript(addon_file, exports = 'env')
if dump_env:
print('==== Begin Environment Dump =====')
print(env.Dump())
print('==== End Environment Dump =====')
if dump is not None:
def _dump_as_text(data: Any) -> str:
from pprint import pformat
dump_name = {
'env': 'Environment',
'config': 'Configuration'
}[dump]
return '\n'.join((
f'==== Begin {dump_name} Dump ====',
pformat(data),
f'==== End {dump_name} Dump ===='
))
data = {
'env': env.Dictionary,
'config': lambda: config
}[dump]()
dump_fn = {
'text': _dump_as_text,
'json': json.dumps
}[dump_format]
print(dump_fn(data))
Exit(0)
Return('env')

6
contrib/run_scons.py Normal file
View File

@ -0,0 +1,6 @@
# use this to start SCons from the IDE for debugging
import sys
from SCons.Script.Main import main
if __name__ == '__main__':
sys.exit(main())