summaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/ifcodegen/CMakeLists.txt2
-rwxr-xr-xsrc/tools/ifcodegen/generate.py89
-rw-r--r--src/tools/ifcodegen/generator/rule_generator.py2
3 files changed, 88 insertions, 5 deletions
diff --git a/src/tools/ifcodegen/CMakeLists.txt b/src/tools/ifcodegen/CMakeLists.txt
index 317d77f5..68aaa76a 100644
--- a/src/tools/ifcodegen/CMakeLists.txt
+++ b/src/tools/ifcodegen/CMakeLists.txt
@@ -101,7 +101,7 @@ if(QT_FEATURE_python3_virtualenv AND NOT QT_FEATURE_system_qface)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/.stamp-generator-verified
${CMAKE_CURRENT_BINARY_DIR}/.stamp-cmake-rerun
- COMMAND ${VIRTUALENV_PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/verify_generator.py
+ COMMAND ${CMAKE_COMMAND} -E env IFGENERATOR_CONFIG=${CMAKE_CURRENT_BINARY_DIR}/.config ${VIRTUALENV_PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/generate.py --selfcheck
COMMAND ${CMAKE_COMMAND} -E touch .stamp-generator-verified
COMMAND ${CMAKE_COMMAND} -E touch .stamp-cmake-rerun
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/.stamp-deploy_virtualenv
diff --git a/src/tools/ifcodegen/generate.py b/src/tools/ifcodegen/generate.py
index 853e926d..ee5f7b62 100755
--- a/src/tools/ifcodegen/generate.py
+++ b/src/tools/ifcodegen/generate.py
@@ -35,7 +35,8 @@ import sys
import fnmatch
import click
import logging.config
-from path import Path
+import tempfile
+from pathlib import Path
from qface.generator import FileSystem, Generator
from qface.watch import monitor
@@ -46,7 +47,7 @@ import generator.global_functions as global_functions
from generator.filters import register_filters
from generator.rule_generator import CustomRuleGenerator
-here = Path(__file__).dirname()
+here = Path(__file__).parent
log = logging.getLogger(__file__)
@@ -181,6 +182,86 @@ def run(template_search_paths, template, moduleConfig, annotations, imports, src
exit(1)
+def self_check(ctx, param, value):
+ if not value or ctx.resilient_parsing:
+ return
+ click.echo('Running self check')
+
+ try:
+ # Parse the .config file and throw an error in case it doesn't exist or it is invalid
+ builtin_config.parse(here)
+
+ tmpDir = tempfile.TemporaryDirectory()
+ tmp = Path(tmpDir.name)
+ with open(tmp / "test.qface", 'w') as file:
+ # Write content to the file
+ file.write("""
+ module org.selftest 1.0
+
+ interface Echo {
+ string stringProperty
+ bool boolProperty
+ TestEnum enumProperty
+ TestStruct structProperty
+ string echo(string msg);
+ }
+
+ enum TestEnum {
+ value1,
+ value2
+ }
+
+ struct TestStruct {
+ int testInt
+ string testString
+ }
+ """)
+
+ with open(tmp / "selfcheck.yaml", 'w') as file:
+ # Write content to the file
+ file.write("""
+ test:
+ module:
+ documents:
+ - "{{srcBase|lower}}": "module.tpl"
+ interface:
+ documents:
+ - 'tst_{{interface|lower}}': 'interface.tpl'
+ """)
+
+ os.mkdir(tmp / "selfcheck")
+ with open(tmp / "selfcheck/module.tpl", 'w') as file:
+ # Write content to the file
+ file.write("""
+ {{module.name}}
+ """)
+
+ with open(tmp / "selfcheck/interface.tpl", 'w') as file:
+ # Write content to the file
+ file.write("""
+ {{interface.name}}
+ """)
+
+ run([tmp], 'selfcheck', {"module": "org.selftest", "force": True}, [], [], [tmp / "test.qface"], tmp)
+ click.echo('Self check finished successfully.')
+ except Exception as e:
+ raise SystemExit("""
+ Self check failed!
+
+ This might be caused by a too recent python version or
+ too recent python packages.
+ If this happens when building the qtinterfaceframework,
+ you can try installing older python packages by
+ running configure again with the following option:
+
+ -DQT_USE_MINIMAL_QFACE_PACKAGES=TRUE
+
+ The python error was:
+
+ {}
+ """.format(e))
+ ctx.exit()
+
@click.command()
@click.option('--reload/--no-reload', default=False, help=
'Specifies whether the generator should keep track of the changes in the IDL file and update '
@@ -206,6 +287,9 @@ def run(template_search_paths, template, moduleConfig, annotations, imports, src
'scanned recursively for QFace files. The QFace files found are then used to resolve '
'the information required when importing a module; this is similar to how C++ include '
'paths work.')
+@click.option('--selfcheck', is_flag=True, default=False, callback=self_check, expose_value=False, is_eager=True, help=
+ 'Runs a self check using a builtin qface file and template to verify that the generator is '
+ 'working correctly. ')
@click.argument('src', nargs=-1, type=click.Path(exists=True))
@click.argument('dst', nargs=1, type=click.Path(exists=True))
@@ -230,6 +314,5 @@ def app(src, dst, template_search_paths, template, reload, module, force, annota
}
run(template_search_paths, template, moduleConfig, annotations, imports, src, dst)
-
if __name__ == '__main__':
app()
diff --git a/src/tools/ifcodegen/generator/rule_generator.py b/src/tools/ifcodegen/generator/rule_generator.py
index 5d95afbf..902b9e00 100644
--- a/src/tools/ifcodegen/generator/rule_generator.py
+++ b/src/tools/ifcodegen/generator/rule_generator.py
@@ -31,7 +31,7 @@ import click
import logging.config
import sys
import yaml
-from path import Path
+from pathlib import Path
from qface.generator import RuleGenerator
from qface.idl.domain import Module, Interface, Property, Parameter, Field, Struct