Updated new_source tool to respect a modules set C++ namespace. Fixed generation of modules with templates without config.json.

This commit is contained in:
Patrick 2025-06-19 16:48:28 +02:00
parent 9bfbd44e34
commit b1c461387f
5 changed files with 43 additions and 5 deletions

@ -1 +1 @@
Subproject commit c3b5244eac5187a64b6f46a1a4dc171416fff313
Subproject commit e583c5ef6c1a8dbce941014aa3ce995f2d53d05b

View File

@ -43,6 +43,16 @@ def get_project_config() -> dict:
raw = exec_get_output(('scons', '-s', '--disable_auto_update', '--dump=config', '--dump_format=json'))
return json.loads(raw)
def get_module_config() -> dict:
raw = exec_get_output(('scons', '-s', '--disable_auto_update', '--dump=modules', '--dump_format=json'))
return json.loads(raw)
def find_module_folder(subpath: Path) -> Optional[Path]:
for parent in subpath.parents:
if (parent / 'SModule').exists():
return parent
return None
def prompt(prefix: str = '> ') -> str:
sys.stdout.write(prefix)
sys.stdout.flush()

View File

@ -112,7 +112,10 @@ def load_template_config() -> None:
global _template_config
config_file = _template_folder / 'config.json'
if not config_file.exists():
_template_config = {}
_template_config = _TemplateConfig(
options=[],
new_sources=[]
)
return
with config_file.open('r') as f:
try:

View File

@ -8,7 +8,7 @@ from typing import Optional, Literal
sys.path.append(os.path.dirname(__file__))
from common import prompt_choices, prompt_path, prompt_yesno, run_script
from common import find_module_folder, get_module_config, prompt_choices, prompt_path, prompt_yesno, run_script
from common.jinja import is_jinja_installed, generate_file
@ -44,12 +44,31 @@ def _make_source_path(base_path: Path) -> Path:
def _apply_params(header_folder: Path, do_create_source: bool, base_path: Path) -> None:
global _header_path, _source_path, _namespace
_namespace = base_path.parts[0]
source_path = _make_source_path(base_path)
module_folder = find_module_folder(source_path)
namespace = None
if module_folder is not None:
module_subfolder = module_folder.relative_to(_PRIVATE_PATH)
module_key = str(module_subfolder)
if os.path.sep != '/':
module_key = module_key.replace(os.pathsep, '/')
all_module_conf = get_module_config()
module_conf = all_module_conf.get(module_key)
if module_conf is not None:
namespace = module_conf.get('cxx_namespace')
if namespace is None:
namespace = module_key.replace('/', '_')
if namespace is None:
namespace = base_path.parts[0]
_namespace = namespace
if header_folder is not None:
_header_path = _make_header_path(header_folder, base_path)
if do_create_source:
_source_path = _make_source_path(base_path)
_source_path = source_path
def query_params() -> None:
header_folder = prompt_choices('Create Header?', _HEADER_CHOICES)

View File

@ -1,6 +1,12 @@
Import('env')
env.ModuleConfig(
name = '{{name}}',
description = '',
cxx_namespace = '{{folder_name}}'
)
src_files = Split("""
main.cpp
""")