Skip to content
Snippets Groups Projects
Commit 2cb17b27 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

fixed loading of configurator script

parent 3581c12c
No related branches found
No related tags found
No related merge requests found
Pipeline #57562 failed
...@@ -5,12 +5,14 @@ project( pssfg_cmake_integration_test ) ...@@ -5,12 +5,14 @@ project( pssfg_cmake_integration_test )
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${pssfg_cmake_integration_test_SOURCE_DIR}/.cmake ) set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${pssfg_cmake_integration_test_SOURCE_DIR}/.cmake )
# Don't try this at home! # Don't try this at home!
file(MAKE_DIRECTORY .cmake)
execute_process( COMMAND sfg-cli cmake make-find-module execute_process( COMMAND sfg-cli cmake make-find-module
WORKING_DIRECTORY ${pssfg_cmake_integration_test_SOURCE_DIR}/.cmake ) WORKING_DIRECTORY ${pssfg_cmake_integration_test_SOURCE_DIR}/.cmake )
find_package( PystencilsSfg REQUIRED ) find_package( PystencilsSfg REQUIRED )
# set( PSSFG_CONFIGURATOR_SCRIPT "codegen_config.py" ) set( PystencilsSfg_CONFIGURATOR_SCRIPT codegen_config.py )
add_library( genlib ) add_library( genlib )
pystencilssfg_generate_target_sources( genlib SCRIPTS kernels.py more_kernels.py FILE_EXTENSIONS .hpp .cpp ) pystencilssfg_generate_target_sources( genlib SCRIPTS kernels.py FILE_EXTENSIONS .h .cpp )
pystencilssfg_generate_target_sources( genlib SCRIPTS more_kernels.py )
from sys import stderr
from pystencilssfg import SfgConfiguration
def sfg_config():
print("sfg_config() called!", file=stderr)
project_info = {
'B': 'A'
}
return SfgConfiguration(
header_extension='hpp',
source_extension='cpp',
base_namespace='cmake_demo',
project_info=project_info
)
from .configuration import SfgConfiguration
from .generator import SourceFileGenerator from .generator import SourceFileGenerator
from .composer import SfgComposer from .composer import SfgComposer
__all__ = [ __all__ = [
"SourceFileGenerator", "SfgComposer" "SourceFileGenerator", "SfgComposer", "SfgConfiguration"
] ]
from . import _version from . import _version
......
set(PystencilsSfg_CONFIGURATOR_SCRIPT "" CACHE FILEPATH "Configurator script for the pystencils Source File Generator" )
set(PystencilsSfg_GENERATED_SOURCES_DIR "${CMAKE_BINARY_DIR}/sfg_sources" CACHE PATH "Output directory for genenerated sources" ) set(PystencilsSfg_GENERATED_SOURCES_DIR "${CMAKE_BINARY_DIR}/sfg_sources" CACHE PATH "Output directory for genenerated sources" )
mark_as_advanced(PystencilsSfg_GENERATED_SOURCES_DIR) mark_as_advanced(PystencilsSfg_GENERATED_SOURCES_DIR)
...@@ -19,7 +18,7 @@ function(_pssfg_add_gen_source target script) ...@@ -19,7 +18,7 @@ function(_pssfg_add_gen_source target script)
get_filename_component(basename ${script} NAME_WLE) get_filename_component(basename ${script} NAME_WLE)
cmake_path(ABSOLUTE_PATH script OUTPUT_VARIABLE scriptAbsolute) cmake_path(ABSOLUTE_PATH script OUTPUT_VARIABLE scriptAbsolute)
execute_process(COMMAND ${Python_EXECUTABLE} -m pystencilssfg list-files "--sep=\;" --no-newline ${_pssfg_GENERATOR_ARGS} ${script} execute_process(COMMAND ${Python_EXECUTABLE} -m pystencilssfg list-files "--sep=;" --no-newline ${_pssfg_GENERATOR_ARGS} ${script}
OUTPUT_VARIABLE generatedSources RESULT_VARIABLE _pssfg_result OUTPUT_VARIABLE generatedSources RESULT_VARIABLE _pssfg_result
ERROR_VARIABLE _pssfg_stderr) ERROR_VARIABLE _pssfg_stderr)
...@@ -29,7 +28,7 @@ function(_pssfg_add_gen_source target script) ...@@ -29,7 +28,7 @@ function(_pssfg_add_gen_source target script)
set(generatedSourcesAbsolute) set(generatedSourcesAbsolute)
foreach (filename ${generatedSources}) foreach (filename ${generatedSources})
list(APPEND generatedSourcesAbsolute ${generatedSourcesDir}/${filename}) list(APPEND generatedSourcesAbsolute "${generatedSourcesDir}/${filename}")
endforeach () endforeach ()
file(MAKE_DIRECTORY "${generatedSourcesDir}") file(MAKE_DIRECTORY "${generatedSourcesDir}")
...@@ -54,8 +53,9 @@ function(pystencilssfg_generate_target_sources TARGET) ...@@ -54,8 +53,9 @@ function(pystencilssfg_generate_target_sources TARGET)
list(APPEND generatorArgs "--sfg-header-only") list(APPEND generatorArgs "--sfg-header-only")
endif() endif()
if(NOT (PystencilsSfg_CONFIGURATOR_SCRIPT STREQUAL "")) if(DEFINED PystencilsSfg_CONFIGURATOR_SCRIPT)
list(APPEND generatorArgs "--sfg-configurator='${_PystencilsSfg_CONFIGURATOR_SCRIPT}'") cmake_path(ABSOLUTE_PATH PystencilsSfg_CONFIGURATOR_SCRIPT OUTPUT_VARIABLE configscript)
list(APPEND generatorArgs "--sfg-configurator=${configscript}")
endif() endif()
if(DEFINED _pssfg_FILE_EXTENSIONS) if(DEFINED _pssfg_FILE_EXTENSIONS)
......
from __future__ import annotations from __future__ import annotations
import sys
from typing import Sequence, Any from typing import Sequence, Any
from os import path
from enum import Enum, auto from enum import Enum, auto
from dataclasses import dataclass, replace, asdict, InitVar from dataclasses import dataclass, replace, asdict, InitVar
from argparse import ArgumentParser from argparse import ArgumentParser
...@@ -77,7 +79,7 @@ class SfgConfiguration: ...@@ -77,7 +79,7 @@ class SfgConfiguration:
def override(self, other: SfgConfiguration): def override(self, other: SfgConfiguration):
other_dict = asdict(other) other_dict = asdict(other)
other_dict = {k: v for k, v in other_dict.items() if v is not None} other_dict: dict[str, Any] = {k: v for k, v in other_dict.items() if v is not None}
return replace(self, **other_dict) return replace(self, **other_dict)
...@@ -93,13 +95,16 @@ DEFAULT_CONFIG = SfgConfiguration( ...@@ -93,13 +95,16 @@ DEFAULT_CONFIG = SfgConfiguration(
def run_configurator(configurator_script: str): def run_configurator(configurator_script: str):
cfg_spec = iutil.spec_from_file_location(configurator_script) cfg_modulename = path.splitext(path.split(configurator_script)[1])[0]
cfg_spec = iutil.spec_from_file_location(cfg_modulename, configurator_script)
if cfg_spec is None: if cfg_spec is None:
raise SfgConfigException(SfgConfigSource.PROJECT, raise SfgConfigException(SfgConfigSource.PROJECT,
f"Unable to load configurator script {configurator_script}") f"Unable to load configurator script {configurator_script}")
configurator = iutil.module_from_spec(cfg_spec) configurator = iutil.module_from_spec(cfg_spec)
cfg_spec.loader.exec_module(configurator)
if not hasattr(configurator, "sfg_config"): if not hasattr(configurator, "sfg_config"):
raise SfgConfigException(SfgConfigSource.PROJECT, "Project configurator does not define function `sfg_config`.") raise SfgConfigException(SfgConfigSource.PROJECT, "Project configurator does not define function `sfg_config`.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment