summaryrefslogtreecommitdiff
path: root/docs/usage.rst
blob: 8cc059feaf01aba5fad44f42813a81c79a28a386 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
=====
Usage
=====

Concept
=======

QFace requires one or more IDL files as input file and a generator to produce output files. The IDL files are named QFace interface documents.

.. image:: qface_concept.png

There are several ways to call the generator.


Invocation
==========

Direct Invocation
-----------------

You can call the generator directly by using the provided script. All generator should at minimum expect a series of inputs and one output path. This is normally recommended for production.

.. code-block:: sh

    ./csv.py src dst

Via qface invokation
--------------------

You can invoke your generator using the qface helper script. This allows you also to use some specific developer support. It is recommended way during generator development.

To use an existing generator just provide the path to the generator script.

.. code-block:: sh

    qface generate --generator ./csvgen.py input output


To use live reloading on changes just use the reload option:


.. code-block:: sh

    qface generate --generator ./csvgen.py input output --reload

This will observe the generator folder and the input folder for changes and re-run the generator.

Configuration Invokation
------------------------

You can also create a YAML configuration file (for example csv.yaml):


.. code-block:: yaml

    generator: ./csvgen.py
    input: input
    output: output
    reload: false


And then call the client with:

.. code-block:: sh

    qface generate --config csv.yaml



Code Generation Principle
=========================

The code generation is driven by a small script which iterates over the domain model and writes files using a template language (see http://jinja.pocoo.org) and espcially the template designer documentation (http://jinja.pocoo.org/docs/dev/templates/).

.. code-block:: python

    from qface.generator import FileSystem, Generator

    def generate(input, output):
        system = FileSystem.parse(input)
        generator = Generator(searchpath='templates')
        ctx = {'output': output, 'system': system}
        generator.write('{{output}}/modules.csv', 'modules.csv', ctx)


This script reads the input directory returns a system object form the domain model. This is used as the root object for the code generation inside the template language.

.. code-block:: jinja

    {% for module in system.modules %}
        {%- for interface in module.interfaces -%}
        SERVICE, {{module}}.{{interface}}
        {% endfor -%}
        {%- for struct in module.structs -%}
        STRUCT , {{module}}.{{struct}}
        {% endfor -%}
        {%- for enum in module.enums -%}
        ENUM   , {{module}}.{{enum}}
        {% endfor -%}
    {% endfor %}

The template iterates over the domain objects and generates text which is written into a file. The file name is also adjustable using the same template language.