Moved Jinja utility functions to S++.
This commit is contained in:
parent
7b94bc3fe0
commit
a5ba3b5d10
@ -21,7 +21,8 @@ def _parse_lib_conf(env: Environment, lib_conf: dict) -> None:
|
||||
env.Append(CPPPATH = lib_conf.get('CPPPATH', []),
|
||||
CPPDEFINES = lib_conf.get('CPPDEFINES', []),
|
||||
LIBPATH = lib_conf.get('LIBPATH', []),
|
||||
LIBS = lib_conf.get('LIBS', []))
|
||||
LIBS = lib_conf.get('LIBS', []),
|
||||
JINJA_TEMPLATE_SEARCHPATH = lib_conf.get('JINJA_TEMPLATE_SEARCHPATH', []))
|
||||
|
||||
def _inject_list(kwargs: dict, dependency: dict, list_name: str) -> None:
|
||||
if list_name not in dependency:
|
||||
@ -359,6 +360,8 @@ env.AddMethod(_wrap_builder(env.UnitySharedLibrary, is_lib = True), 'UnityShared
|
||||
if hasattr(env, 'Gch'):
|
||||
env.AddMethod(_wrap_builder(env.Gch), 'Gch')
|
||||
|
||||
if hasattr(env, 'Jinja'):
|
||||
env = SConscript('addons/jinja.py', exports = 'env')
|
||||
|
||||
if dump_env:
|
||||
print('==== Begin Environment Dump =====')
|
||||
|
35
addons/jinja.py
Normal file
35
addons/jinja.py
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
import pathlib
|
||||
|
||||
Import('env')
|
||||
|
||||
def _jinja_load_config(env, config_name):
|
||||
searched_paths = []
|
||||
for scons_path in env['JINJA_CONFIG_SEARCHPATH']:
|
||||
if hasattr(scons_path, 'abspath'):
|
||||
scons_path = scons_path.abspath
|
||||
path = pathlib.Path(scons_path) / f'{config_name}.yml'
|
||||
if path.exists():
|
||||
with path.open('r') as file:
|
||||
import yaml
|
||||
return yaml.safe_load(file)
|
||||
searched_paths.append(f'\n{path}')
|
||||
joined_paths = ''.join(searched_paths)
|
||||
raise Exception(f'Could not find Jinja config file "{config_name}.yml". Searched: {joined_paths}')
|
||||
def _wrap_jinja(orig_jinja):
|
||||
def _wrapped(env, target, **kwargs):
|
||||
if 'source' not in kwargs:
|
||||
kwargs['source'] = f'{target}.jinja'
|
||||
target = orig_jinja(**kwargs)
|
||||
if 'depends' in kwargs:
|
||||
for dependency in kwargs['depends']:
|
||||
env.Depends(target, dependency)
|
||||
# env.Depends(alias_prepare, target)
|
||||
return target
|
||||
return _wrapped
|
||||
|
||||
env.AddMethod(_wrap_jinja(env.Jinja), 'Jinja')
|
||||
env.Append(JINJA_FILTERS = {'load_config': _jinja_load_config})
|
||||
env.Append(JINJA_TEMPLATE_SEARCHPATH = ['data/jinja'])
|
||||
env['JINJA_CONFIG_SEARCHPATH'] = [env.Dir('#data/config')]
|
||||
Return('env')
|
Loading…
x
Reference in New Issue
Block a user