Made private/public module folders adjustable via config and fixed Jinja get_sources() function for targets with nested nodes in sources.

This commit is contained in:
Patrick Wuttke
2026-01-08 14:35:13 +01:00
parent b9335a6247
commit 7fa3855498

View File

@@ -114,12 +114,12 @@ def _cook(env: Environment, recipe_name: str):
return dependency.cook_result
def _normalize_module_path(env: Environment, path: str) -> str|None:
module_root = env.Dir('#/private').abspath
module_root = env.Dir('#').abspath
try:
relative = os.path.relpath(path, module_root)
if relative[:2] == '..':
return None
return relative
return os.path.join(*os.path.split(relative)[1:])
except ValueError: # may be thrown on Windows if the module is on a different drive than the project
return None
@@ -680,13 +680,13 @@ def _generate_project(project_type: str) -> None:
return result
def _get_modules() -> list:
result = []
for folder, config in env['SPP_MODULES'].items():
for folder, module in env['SPP_MODULES'].items():
result.append({
'name': config.name,
'private_folder': os.path.join('private', folder),
'public_folder': os.path.join('public', folder),
'description': config.description,
'cxx_namespace': config.cxx_namespace
'name': module.name,
'private_folder': os.path.join(config['PRIVATE_FOLDER'], folder),
'public_folder': os.path.join(config['PUBLIC_FOLDER'], folder),
'description': module.description,
'cxx_namespace': module.cxx_namespace
})
return result
def _escape_path(input: str) -> str:
@@ -721,7 +721,7 @@ def _generate_project(project_type: str) -> None:
def _get_sources(target_dict: dict) -> list[str]:
target : Target = target_dict['target']
sources = target.kwargs.get('source')
return [str(pathlib.Path(source.abspath).relative_to(root_path)) for source in sources]
return [str(pathlib.Path(source.abspath).relative_to(root_path)) for source in Flatten(sources)]
def _get_headers(folder: str) -> list[str]:
result = []
@@ -773,15 +773,15 @@ def _generate_project(project_type: str) -> None:
source_path = pathlib.Path(source_folder)
target_path = pathlib.Path(target_folder)
config = {}
config_file = source_path / 'template.json'
if config_file.exists():
with config_file.open('r') as f:
config = json.load(f)
files_config = config.get('files', {})
tmpl_config = {}
tmpl_config_file = source_path / 'template.json'
if tmpl_config_file.exists():
with tmpl_config_file.open('r') as f:
tmpl_config = json.load(f)
files_config = tmpl_config.get('files', {})
for source_file in source_path.rglob('*'):
if source_file == config_file:
if source_file == tmpl_config_file:
continue
if not source_file.is_file():
continue
@@ -976,6 +976,7 @@ def _sanitize_identifier(name: str) -> str:
chrs.append('_')
return ''.join(chrs)
config: dict
Import('config')
if not config.get('PROJECT_NAME'):
@@ -988,6 +989,10 @@ if not config.get('PREPROCESSOR_PREFIX'):
config['PREPROCESSOR_PREFIX'] = _sanitize_identifier(config['PROJECT_NAME']).upper() # TODO: may be nicer?
if not config.get('SPP_TARGET_VERSION'):
config['SPP_TARGET_VERSION'] = (1, 0, 0)
if not config.get('PRIVATE_FOLDER'):
config['PRIVATE_FOLDER'] = 'private'
if not config.get('PUBLIC_FOLDER'):
config['PUBLIC_FOLDER'] = 'public'
if 'COMPILATIONDB_FILTER_FILES' not in config:
config['COMPILATIONDB_FILTER_FILES'] = True