diff options
author | Dominik Holland <dominik.holland@pelagicore.com> | 2018-05-17 15:46:18 +0200 |
---|---|---|
committer | Robert Griebl <robert.griebl@pelagicore.com> | 2018-05-18 15:12:59 +0000 |
commit | 4e41d2509d9561946164637dcb8c7a8a3ecfa653 (patch) | |
tree | df871d756e9c82974446d16e3ef6c08ab49c0aa9 | |
parent | d25a8d402020b5ff525a4356745a2e1fefa00bd6 (diff) |
Add support for additional annotation files
The ivigenerator as well as its qmake integration now support to pass
additional annotation files. This can be useful when annotations only
need to be applied for a specific part, e.g. the backend plugin.
This change also makes use of the feature in the autotests which now
use a no-private.yaml annotation file for testing the same qface file
as we use for our normal generation tests.
Task-number: QTAUTO-848
Change-Id: Ib626775d2339ebf2002bc689da8303e7caf6edfa
Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
11 files changed, 59 insertions, 68 deletions
diff --git a/mkspecs/features/ivigenerator.prf b/mkspecs/features/ivigenerator.prf index d4c49a5..8d36aae 100644 --- a/mkspecs/features/ivigenerator.prf +++ b/mkspecs/features/ivigenerator.prf @@ -7,6 +7,7 @@ # QFACE_MODULE_NAME = my_module_name # QFACE_FORMAT = frontend (or backend, simulator... -- defaults to "frontend") # QFACE_OUTPUT_DIR = my_output_dir (defaults to current build dir) +# QFACE_ANNOTATIONS += additional.yaml # QT_FOR_CONFIG += ivicore-private @@ -28,7 +29,7 @@ QFACE_ABS_PWD = $$absolute_path($$QFACE_PWD, $$_PRO_FILE_PWD_) QFACE_FILE = $$basename(QFACE_SOURCES) QFACE_BASE_NAME = $$replace(QFACE_FILE, .qface, ) QFACE_YAML = $$QFACE_ABS_PWD/$${QFACE_BASE_NAME}.yaml -OTHER_FILES += $$QFACE_FILE +OTHER_FILES += $$QFACE_ABS_PWD/$$QFACE_FILE # The 'click' library used by the generator needs to have a utf8 locale setup. equals(QMAKE_HOST.os, Windows): ENV = chcp 65001 && @@ -65,6 +66,13 @@ IVI_GENERATOR = $$VIRTUALENV_PYTHON $$IVI_GENERATOR_PATH/generate.py PRI = $$QFACE_OUTPUT_DIR/$$lower($${QFACE_BASE_NAME}).pri IVI_GENERATOR_OPTIONS = --format=$$QFACE_FORMAT --force !isEmpty(QFACE_MODULE_NAME): IVI_GENERATOR_OPTIONS += --module=$${QFACE_MODULE_NAME} +for (ANNOTATION, QFACE_ANNOTATIONS) { + file = $$absolute_path($$ANNOTATION, $$_PRO_FILE_PWD_) + + IVI_GENERATOR_OPTIONS += -A $$shell_path($$file) + qface_sources.depends += $$file + OTHER_FILES += $$file +} # Windows doesn't offer any other way to sleep for a time inside non-interactive scripts equals(QMAKE_HOST.os, Windows): SLEEP = ping -n 2 127.0.0.1 >nul diff --git a/src/ivicore/doc/src/ivigenerator/generator-usage.qdoc b/src/ivicore/doc/src/ivigenerator/generator-usage.qdoc index 688633b..f387422 100644 --- a/src/ivicore/doc/src/ivigenerator/generator-usage.qdoc +++ b/src/ivicore/doc/src/ivigenerator/generator-usage.qdoc @@ -55,8 +55,11 @@ The options and parameters are: \li -f, --format [frontend|backend_simulator|control_panel|backend_qtro|server_qtro|<folder>] \li see below \row - \li --help - \li Show options and exit. + \li -A, --annotations <annotation-file> + \li Merges the given annotation file with annotions already in the qface file and the + implicit annotation file. The annotation files will be merged in the order they are passed + to the generator. Providing a duplicate key in the YAML file will override the previously + set value. This option can be used multiple times. \row \li source \li Path or paths to the IDL source files. In case of multiple entries present, each one @@ -65,6 +68,9 @@ The options and parameters are: \row \li outputdir \li Generation destination folder + \row + \li --help + \li Show options and exit. \endtable At the moment the generator is able to generate 5 kinds of projects given an interface IDL file @@ -155,6 +161,10 @@ the YAML file accompanying the main IDL file and named after it. During the pars QFace picks this file up automatically and merges annotation specified in this YAML file with those defined in the IDL file. +As the accompanying YAML file is automatically picked up in all cases, this doesn't work for +annoations which are only needed for some specific projects e.g. when generating a backend plugin. +For this use case you can pass multiple additional annotation YAML files to the generator. + For QtIvi there are following annotations used for the IDL definition: \table diff --git a/src/ivicore/doc/src/ivigenerator/qmake-integration.qdoc b/src/ivicore/doc/src/ivigenerator/qmake-integration.qdoc index 3085efc..21f9604 100644 --- a/src/ivicore/doc/src/ivigenerator/qmake-integration.qdoc +++ b/src/ivicore/doc/src/ivigenerator/qmake-integration.qdoc @@ -48,6 +48,7 @@ QFACE_FORMAT = frontend QFACE_SOURCES = example.qface QFACE_MODULE_NAME = myModule QFACE_OUTPUT_DIR = myOutputDir +QFACE_ANNOTATIONS = annotation.yaml \endcode Available QMake Variables: @@ -65,6 +66,9 @@ Available QMake Variables: \li QFACE_OUTPUT_DIR \li Output folder where the generated code will be created. The default is to use the current build folder + \row + \li QFACE_ANNOTATIONS + \li list of additional annotation YAML files. \endtable diff --git a/src/tools/ivigenerator/generate.py b/src/tools/ivigenerator/generate.py index 3b55f04..4838a22 100755 --- a/src/tools/ivigenerator/generate.py +++ b/src/tools/ivigenerator/generate.py @@ -559,11 +559,19 @@ def struct_includes(symbol): return includesSet -def generate(tplconfig, moduleConfig, src, dst): +def generate(tplconfig, moduleConfig, annotations, src, dst): log.debug('run {0} {1}'.format(src, dst)) FileSystem.strict = True Generator.strict = True system = FileSystem.parse(src) + for annotations_file in annotations: + log.debug('{0}'.format(annotations_file)) + if not os.path.isabs(annotations_file): + annotations_file = Path.getcwd() / str(annotations_file) + if not Path(annotations_file).exists(): + print('no such annotation file: {0}'.format(annotations_file)) + exit(1) + FileSystem.merge_annotations(system, Path(annotations_file)) generator = Generator(search_path=[tplconfig, here / "common"]) generator.register_filter('return_type', return_type) generator.register_filter('parameter_type', parameter_type) @@ -632,13 +640,13 @@ def generate(tplconfig, moduleConfig, src, dst): generator.write(rule['dest_file'], rule['template_file'], ctx, preserve, force) -def run(format, moduleConfig, src, dst): +def run(format, moduleConfig, annotations, src, dst): if format in IVI_DEFAULT_TEMPLATES: tplConfig = 'templates_{0}'.format(format) - generate(here / tplConfig, moduleConfig, src, dst) + generate(here / tplConfig, moduleConfig, annotations, src, dst) else: if os.path.exists(format): - generate(format, moduleConfig, src, dst) + generate(format, moduleConfig, annotations, src, dst) else: print('Format "{0}" is invalid. Should be one of {1} or an existing template folder'.format(format, IVI_DEFAULT_TEMPLATES)) exit(1) @@ -650,10 +658,15 @@ def run(format, moduleConfig, src, dst): @click.option('--module', default=False, help='The name of the Qt module the autogenerator is generating. This is automatically used by the qmake integration and passed directly to the qface templates.') @click.option('--validation_info', is_flag=True, default=False, help='Annotates every interface with additional JSON code containing all the options used to generate this interface. This can be used to validate the generation of the interface.') @click.option('--force', is_flag=True, default=False, help='Always write all output files') +@click.option('--annotations', '-A', multiple=True, default=False, help= + 'Merges the given annotation file with annotions already in the qface file and the ' + 'implicit annotation file. The annotation files will be merged in the order they are passed ' + 'to the generator. Providing a duplicate key in the YAML file will override the previously ' + 'set value. This option can be used multiple times.') @click.argument('src', nargs=-1, type=click.Path(exists=True)) @click.argument('dst', nargs=1, type=click.Path(exists=True)) -def app(src, dst, format, reload, module, validation_info, force): +def app(src, dst, format, reload, module, validation_info, force, annotations): """ The QtIvi Autogenerator (ivigenerator) @@ -678,7 +691,7 @@ def app(src, dst, format, reload, module, validation_info, force): "validation_info": validation_info, "force": force } - run(format, moduleConfig, src, dst) + run(format, moduleConfig, annotations, src, dst) if __name__ == '__main__': diff --git a/tests/auto/core/ivigenerator/no-private.yaml b/tests/auto/core/ivigenerator/no-private.yaml new file mode 100644 index 0000000..f502f08 --- /dev/null +++ b/tests/auto/core/ivigenerator/no-private.yaml @@ -0,0 +1,4 @@ +org.example.echo: + config: + disablePrivateIVI: true + interfaceBuilder: false diff --git a/tests/auto/core/ivigenerator/org.example.echo.noprivate.qface b/tests/auto/core/ivigenerator/org.example.echo.noprivate.qface deleted file mode 100644 index 33878dd..0000000 --- a/tests/auto/core/ivigenerator/org.example.echo.noprivate.qface +++ /dev/null @@ -1,53 +0,0 @@ -/** - * module - */ -@config: {"disablePrivateIVI": true} -module org.example.echo.noprivate 1.0 - -/** - * @brief the brief - * @description the description - * continues {@link http://qt.io} - * @deprecated - * @see org.example.echo.Echo - * @see org.example - * @see http://qt.io - * @anything hello - */ -@config: {"id": "org.foo.id.1.0"} -interface Echo { - /** - * @brief brief message - * @details long message - * - * @param msg the message - * @return the echo - */ - readonly string lastMessage; - int intValue; - string stringValue; - - string echo(string msg); - string id(); - - signal valueChanged(int value); -} - -@config: {"id": "org.foo.idz.1.0", "zoned": true} -interface EchoZoned { - /** - * @brief brief message - * @details long message - * - * @param msg the message - * @return the echo - */ - readonly string lastMessage; - int intValue; - string stringValue; - - string echo(string msg); - string id(); - - signal valueChanged(int value); -} diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/backend_simulator/backend_simulator.pro b/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/backend_simulator/backend_simulator.pro index ac43530..9cfc036 100644 --- a/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/backend_simulator/backend_simulator.pro +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/backend_simulator/backend_simulator.pro @@ -13,4 +13,5 @@ PLUGIN_CLASS_NAME = QIviServiceInterface QT += core ivicore QFACE_FORMAT = backend_simulator -QFACE_SOURCES = ../../../org.example.echo.noprivate.qface +QFACE_SOURCES = ../../../org.example.echo.qface +QFACE_ANNOTATIONS += ../../../no-private.yaml diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/control_panel/control_panel.pro b/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/control_panel/control_panel.pro index 029b372..04b6964 100644 --- a/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/control_panel/control_panel.pro +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/control_panel/control_panel.pro @@ -7,4 +7,5 @@ CONFIG += ivigenerator QT += ivicore ivicore-private qml quick QFACE_FORMAT = control_panel -QFACE_SOURCES = ../../../org.example.echo.noprivate.qface +QFACE_SOURCES = ../../../org.example.echo.qface +QFACE_ANNOTATIONS += ../../../no-private.yaml diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/frontend/frontend.pro b/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/frontend/frontend.pro index 13144fc..6d81dbd 100644 --- a/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/frontend/frontend.pro +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/frontend/frontend.pro @@ -6,9 +6,10 @@ CONFIG += ivigenerator QT += ivicore ivicore-private qml quick -DEFINES += QT_BUILD_NOPRIVATE_LIB +DEFINES += QT_BUILD_ECHO_LIB macos: QMAKE_SONAME_PREFIX = @rpath -QFACE_SOURCES = ../../../org.example.echo.noprivate.qface +QFACE_SOURCES = ../../../org.example.echo.qface +QFACE_ANNOTATIONS += ../../../no-private.yaml diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/test/test.pro b/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/test/test.pro index 16bbead..b154779 100644 --- a/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/test/test.pro +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/test/test.pro @@ -11,4 +11,5 @@ LIBS += -L$$OUT_PWD/.. -l$$qtLibraryTarget(echo_noprivate_frontend) QMAKE_RPATHDIR += $$OUT_PWD/.. QFACE_FORMAT = test -QFACE_SOURCES = ../../../org.example.echo.noprivate.qface +QFACE_SOURCES = ../../../org.example.echo.qface +QFACE_ANNOTATIONS += ../../../no-private.yaml diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/validator/validator.pro b/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/validator/validator.pro index 4ee6345..016c77d 100644 --- a/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/validator/validator.pro +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/validator/validator.pro @@ -13,4 +13,5 @@ INCLUDEPATH += $$OUT_PWD/../frontend QT += qml quick core ivicore QFACE_FORMAT = generation_validator -QFACE_SOURCES = ../../../org.example.echo.noprivate.qface +QFACE_SOURCES = ../../../org.example.echo.qface +QFACE_ANNOTATIONS += ../../../no-private.yaml |