Example #1
0
def test_gen_interface():
    system = loadSystem()
    gen = Generator(search_path='tests/templates')
    template = """{{module.interfaces|join(',')}}"""
    module = system.lookup('com.pelagicore.ivi.tuner')
    text = gen.apply(template, {"module": module})
    assert text == 'BaseTuner,Tuner,TunerExtension'
Example #2
0
def run_generation(input, output):
    system = FileSystem.parse(input)
    generator = Generator(searchpath=os.path.join(here, 'templates'))
    generator.register_filter('returnType', returnType)
    generator.register_filter('parameterType', paramterType)
    ctx = {'output': output}
    for module in system.modules:
        ctx.update({'module': module})
        dst = generator.apply('{{output}}/{{module|lower}}', ctx)
        ctx.update({'dst': dst})
        generator.write('{{dst}}/qmldir', 'qmldir', ctx, preserve=True)
        generator.write('{{dst}}/plugin.cpp', 'plugin.cpp', ctx, preserve=True)
        generator.write('{{dst}}/plugin.h', 'plugin.h', ctx, preserve=True)
        generator.write('{{dst}}/{{module|lower}}.pro', 'plugin.pro', ctx, preserve=True)
        generator.write('{{dst}}/generated/generated.pri', 'generated.pri', ctx)
        generator.write('{{dst}}/generated/qml{{module.module_name|lower}}module.h', 'module.h', ctx)
        generator.write('{{dst}}/generated/qml{{module.module_name|lower}}module.cpp', 'module.cpp', ctx)
        for interface in module.interfaces:
            ctx.update({'interface': interface})
            generator.write('{{dst}}/qml{{interface|lower}}.h', 'interface.h', ctx, preserve=True)
            generator.write('{{dst}}/qml{{interface|lower}}.cpp', 'interface.cpp', ctx, preserve=True)
            generator.write('{{dst}}/generated/qmlabstract{{interface|lower}}.h', 'abstractinterface.h', ctx)
            generator.write('{{dst}}/generated/qmlabstract{{interface|lower}}.cpp', 'abstractinterface.cpp', ctx)
        for struct in module.structs:
            ctx.update({'struct': struct})
            generator.write('{{dst}}/generated/qml{{struct|lower}}.h', 'struct.h', ctx)
            generator.write('{{dst}}/generated/qml{{struct|lower}}.cpp', 'struct.cpp', ctx)
            generator.write('{{dst}}/generated/qml{{struct|lower}}model.h', 'structmodel.h', ctx)
            generator.write('{{dst}}/generated/qml{{struct|lower}}model.cpp', 'structmodel.cpp', ctx)
Example #3
0
def run(src, dst):
    log.debug('run {0} {1}'.format(src, dst))
    system = FileSystem.parse(src)
    generator = Generator(search_path=here / 'templates')
    generator.register_filter('defaultValue', Filters.defaultValue)
    generator.register_filter('propertyType', Filters.propertyType)
    ctx = {'dst': dst}
    for module in system.modules:
        module_name = module.module_name
        module_path = '/'.join(module.name_parts)
        plugin_name = "".join(module.name_parts[:2])
        ctx.update({
            'module': module,
            'module_name': module_name,
            'module_path': module_path,
            'plugin_name': plugin_name,
        })
        generator.destination = generator.apply("{{dst}}/{{module_path}}", ctx)
        generator.write('private/{{module_name}}Module.js', 'module.js', ctx)
        generator.write('qmldir', 'public_qmldir', ctx)
        generator.write('private/qmldir', 'private_qmldir', ctx)

        for interface in module.interfaces:
            ctx.update({
                'interface': interface,
            })
            generator.write('private/Abstract{{interface}}.qml',
                            'AbstractInterface.qml', ctx)
            generator.write('{{interface}}.qml',
                            'Interface.qml',
                            ctx,
                            preserve=True)
            generator.write('private/{{interface}}Provider.qml',
                            'InterfaceProvider.qml', ctx)
Example #4
0
def test_gen_module():
    system = loadSystem()
    gen = Generator(search_path='tests/templates')
    template = "{{module}}"
    module = system.lookup('com.pelagicore.ivi.tuner')
    text = gen.apply(template, {"module": module})
    assert text == 'com.pelagicore.ivi.tuner'
Example #5
0
def run(src, dst):
    log.debug('run {0} {1}'.format(src, dst))
    system = FileSystem.parse(src)
    generator = Generator(search_path=here / 'templates')
    generator.register_filter('returnType', Filters.returnType)
    generator.register_filter('parameterType', Filters.parameterType)
    generator.register_filter('defaultValue', Filters.defaultValue)
    ctx = {'dst': dst}
    for module in system.modules:
        log.debug('generate code for module %s', module)
        ctx.update({'module': module})
        dst = generator.apply('{{dst}}/{{module|lower|replace(".", "-")}}',
                              ctx)
        generator.destination = dst
        generator.write('qmldir', 'qmldir', ctx, preserve=True)
        generator.write('plugin.cpp', 'plugin.cpp', ctx, preserve=True)
        generator.write('plugin.h', 'plugin.h', ctx, preserve=True)
        generator.write('{{module|lower|replace(".", "-")}}.pro',
                        'plugin.pro',
                        ctx,
                        preserve=True)
        generator.write('generated/generated.pri', 'generated.pri', ctx)
        generator.write('generated/qml{{module.module_name|lower}}module.h',
                        'module.h', ctx)
        generator.write('generated/qml{{module.module_name|lower}}module.cpp',
                        'module.cpp', ctx)
        for interface in module.interfaces:
            log.debug('generate code for interface %s', interface)
            ctx.update({'interface': interface})
            generator.write('qml{{interface|lower}}.h',
                            'interface.h',
                            ctx,
                            preserve=True)
            generator.write('qml{{interface|lower}}.cpp',
                            'interface.cpp',
                            ctx,
                            preserve=True)
            generator.write('generated/qmlabstract{{interface|lower}}.h',
                            'abstractinterface.h', ctx)
            generator.write('generated/qmlabstract{{interface|lower}}.cpp',
                            'abstractinterface.cpp', ctx)
        for struct in module.structs:
            log.debug('generate code for struct %s', struct)
            ctx.update({'struct': struct})
            generator.write('generated/qml{{struct|lower}}.h', 'struct.h', ctx)
            generator.write('generated/qml{{struct|lower}}.cpp', 'struct.cpp',
                            ctx)
            generator.write('generated/qml{{struct|lower}}model.h',
                            'structmodel.h', ctx)
            generator.write('generated/qml{{struct|lower}}model.cpp',
                            'structmodel.cpp', ctx)
            generator.write('generated/qmlvariantmodel.h', 'variantmodel.h',
                            ctx)
            generator.write('generated/qmlvariantmodel.cpp',
                            'variantmodel.cpp', ctx)
Example #6
0
def test_gen_interface():
    system = loadSystem()
    gen = Generator(searchpath='tests/templates')
    template = """
        {%- for interface in module.interfaces -%}
            {{interface}}
        {%- endfor -%}
    """
    module = system.lookup('com.pelagicore.ivi.tuner')
    text = gen.apply(template, {"module": module})
    assert text == 'Tuner'
Example #7
0
def test_error_template_syntax_error(mock_stderr):
    tmpDir = tempfile.TemporaryDirectory()
    src = [inputPath, inputPath / 'com.pelagicore.ivi.climate.qface']
    system = FileSystem.parse(src)
    dst_template = '{{out}}/out.txt'
    ctx = {'out': tmpDir.name}
    generator = Generator(search_path='tests/templates')
    generator.write(dst_template, 'syntaxError.txt', ctx)
    path = generator.apply(dst_template, ctx)
    assert Path(path).exists() == False
    assert mock_stderr.getvalue(
    ) == "tests/templates/syntaxError.txt:1: error: Encountered unknown tag 'fooo'.\n"
Example #8
0
def test_error_template_undefined_variable(mock_stderr):
    tmpDir = tempfile.TemporaryDirectory()
    src = [inputPath, inputPath / 'com.pelagicore.ivi.climate.qface']
    system = FileSystem.parse(src)
    dst_template = '{{out}}/out.txt'
    ctx = {'out': tmpDir.name}
    generator = Generator(search_path='tests/templates')
    generator.write(dst_template, 'undefinedVariable.txt', ctx)
    path = generator.apply(dst_template, ctx)
    assert Path(path).exists() == False
    assert mock_stderr.getvalue(
    ) == "tests/templates/undefinedVariable.txt:1: error: 'this_is_not_defined' is undefined\n"
Example #9
0
def test_error_template_doesnt_exist(mock_stderr):
    tmpDir = tempfile.TemporaryDirectory()
    src = [inputPath, inputPath / 'com.pelagicore.ivi.climate.qface']
    system = FileSystem.parse(src)
    dst_template = '{{out}}/out.txt'
    ctx = {'out': tmpDir.name}
    generator = Generator(search_path='tests/templates')
    generator.write(dst_template, 'doesnt_exist.txt', ctx)
    path = generator.apply(dst_template, ctx)
    assert Path(path).exists() == False
    assert mock_stderr.getvalue(
    ) == "/doesnt_exist.txt: error: Template not found\n"
Example #10
0
def test_destination_prefix():
    system = FileSystem.parse(inputPath)
    out = Path('tests/out')
    out.rmtree_p()
    out.makedirs_p()
    generator = Generator(search_path='tests/templates')
    for module in system.modules:
        dst_template = '{{out}}/{{module|lower}}.txt'
        ctx = {'out': out.abspath(), 'module': module}
        generator.write(dst_template, 'module.txt', ctx)
        path = generator.apply(dst_template, ctx)
        assert Path(path).exists() == True
    out.rmtree_p()
Example #11
0
def run_generation(input, output):
    system = FileSystem.parse(input)
    generator = Generator(search_path=Path(here / 'facelift/templates'))
    generator.register_filter('returnType', returnType)
    generator.register_filter('cppBool', cppBool)
    generator.register_filter('parameterType', parameterType)
    generator.register_filter('nestedType', nestedType)
    generator.register_filter('requiredInclude', requiredInclude)
    generator.register_filter('requiredQMLInclude', requiredQMLInclude)
    generator.register_filter('namespaceOpen', namespaceOpen)
    generator.register_filter('namespaceClose', namespaceClose)
    generator.register_filter('fullyQualifiedName', fullyQualifiedName)
    generator.register_filter('fullyQualifiedCppName', fullyQualifiedCppName)
    generator.register_filter('fullyQualifiedPath', fullyQualifiedPath)
    generator.register_filter('toValidId', toValidId)
    generator.destination = output

    ctx = {'output': output}
    for module in system.modules:
        ctx.update({'module': module})
        module_path = '/'.join(module.name_parts)
        log.debug('process module %s' % module.module_name)
        ctx.update({'path': module_path})
        generator.write('module/{{path}}/Module.h', 'Module.template.h', ctx)
        generator.write('module/{{path}}/Module.cpp', 'Module.template.cpp', ctx)
        generator.write('ipc/{{path}}/ModuleIPC.h', 'ModuleIPC.template.h', ctx)
        generator.write('devtools/{{path}}/ModuleMonitor.h', 'ModuleMonitor.template.h', ctx)
        generator.write('devtools/{{path}}/ModuleMonitor.cpp', 'ModuleMonitor.template.cpp', ctx)
        generator.write('devtools/{{path}}/ModuleDummy.h', 'DummyModule.template.h', ctx)
        for interface in module.interfaces:
            log.debug('process interface %s' % interface)
            ctx.update({'interface': interface})
            generator.write('types/{{path}}/{{interface}}.h', 'Service.template.h', ctx)
            generator.write('types/{{path}}/{{interface}}Wrapper.h', 'ServiceWrapper.template.h', ctx)
            generator.write('types/{{path}}/{{interface}}.cpp', 'Service.template.cpp', ctx)
            generator.write('types/{{path}}/{{interface}}PropertyAdapter.h', 'ServicePropertyAdapter.template.h', ctx)
            generator.write('types/{{path}}/{{interface}}QMLImplementation.h', 'QMLImplementation.template.h', ctx)
            generator.write('types/{{path}}/{{interface}}QMLFrontend.h', 'QMLFrontend.template.h', ctx)
            generator.write('devtools/{{path}}/{{interface}}Dummy.h', 'DummyService.template.h', ctx)
            generator.write('devtools/{{path}}/{{interface}}Monitor.h', 'ServiceMonitor.template.h', ctx)
            generator.write('ipc/{{path}}/{{interface}}IPC.h', 'ServiceIPC.template.h', ctx)
        for enum in module.enums:
            ctx.update({'enum': enum})
            generator.write('types/{{path}}/{{enum}}.h', 'Enum.template.h', ctx)
            generator.write('types/{{path}}/{{enum}}.cpp', 'Enum.template.cpp', ctx)
        for struct in module.structs:
            ctx.update({'struct': struct})
            generator.write('types/{{path}}/{{struct}}.h', 'Struct.template.h', ctx)
            generator.write('types/{{path}}/{{struct}}.cpp', 'Struct.template.cpp', ctx)
def run_generation(input, output, dependency, libraryName):
    FileSystem.strict = True
    Generator.strict = True

    # Build the list of modules to be generated
    modulesToGenerate = []
    for module in FileSystem.parse(list(input)).modules:
        modulesToGenerate.append(module.name)

    system = FileSystem.parse(list(input) + list(dependency))
    generator = Generator(search_path=Path(here / 'facelift/templates'))
    generator.register_filter('cppBool', cppBool)
    generator.register_filter('toValidId', toValidId)
    generator.register_filter('hasQMLIncompatibleParameter', hasQMLIncompatibleParameter)
    generator.destination = output

    ctx = {'output': output}
    for module in system.modules:
        if module.name in modulesToGenerate:
            ctx.update({'module': module})
            module_path = '/'.join(module.name_parts)
            log.debug('process module %s' % module.module_name)
            ctx.update({'path': module_path})
            generateFile(generator, 'module/{{path}}/Module.h', 'Module.template.h', ctx, libraryName, "types")
            generateFile(generator, 'module/{{path}}/Module.cpp', 'Module.template.cpp', ctx, libraryName, "types")
            generateFile(generator, 'ipc/{{path}}/ModuleIPC.h', 'ModuleIPC.template.h', ctx, libraryName, "ipc")
            generateFile(generator, 'devtools/{{path}}/ModuleMonitor.h', 'ModuleMonitor.template.h', ctx, libraryName, "desktop_dev_tools")
            generateFile(generator, 'devtools/{{path}}/ModuleMonitor.cpp', 'ModuleMonitor.template.cpp', ctx, libraryName, "desktop_dev_tools")
            generateFile(generator, 'devtools/{{path}}/ModuleDummy.h', 'DummyModule.template.h', ctx, libraryName, "desktop_dev_tools")
            for interface in module.interfaces:
                log.debug('process interface %s' % interface)
                ctx.update({'interface': interface})
                generateFile(generator, 'types/{{path}}/{{interface}}.h', 'Service.template.h', ctx, libraryName, "types")
                generateFile(generator, 'types/{{path}}/{{interface}}.cpp', 'Service.template.cpp', ctx, libraryName, "types")
                generateFile(generator, 'types/{{path}}/{{interface}}PropertyAdapter.h', 'ServicePropertyAdapter.template.h', ctx, libraryName, "types")
                generateFile(generator, 'types/{{path}}/{{interface}}QMLImplementation.h', 'QMLImplementation.template.h', ctx, libraryName, "types")
                generateFile(generator, 'types/{{path}}/{{interface}}QMLFrontend.h', 'QMLFrontend.template.h', ctx, libraryName, "types")
                generateFile(generator, 'devtools/{{path}}/{{interface}}Dummy.h', 'DummyService.template.h', ctx, libraryName, "desktop_dev_tools")
                generateFile(generator, 'devtools/{{path}}/{{interface}}Monitor.h', 'ServiceMonitor.template.h', ctx, libraryName, "desktop_dev_tools")
                generateFile(generator, 'ipc/{{path}}/{{interface}}IPC.h', 'ServiceIPC.template.h', ctx, libraryName, "ipc")
            for enum in module.enums:
                ctx.update({'enum': enum})
                generateFile(generator, 'types/{{path}}/{{enum}}.h', 'Enum.template.h', ctx, libraryName, "types")
                generateFile(generator, 'types/{{path}}/{{enum}}.cpp', 'Enum.template.cpp', ctx, libraryName, "types")
            for struct in module.structs:
                ctx.update({'struct': struct})
                generateFile(generator, 'types/{{path}}/{{struct}}.h', 'Struct.template.h', ctx, libraryName, "types")
                generateFile(generator, 'types/{{path}}/{{struct}}.cpp', 'Struct.template.cpp', ctx, libraryName, "types")
Example #13
0
def run_generation(input, output, dependency, libraryName, all, noMocFilePath, noMocListFile):
    global generateAsyncProxy
    global generateAll
    generateAll = all
    FileSystem.strict = True
    Generator.strict = True

    # Build the list of modules to be generated
    system = FileSystem.parse(list(input))
    modulesToGenerate = [module.name for module in system.modules]

    system = FileSystem.parse(list(input) + list(dependency))
    generator = Generator(search_path=Path(here / 'templates'))
    generator.register_filter('cppBool',
                              lambda var: "true" if var else "false")
    generator.register_filter('toValidId',
                              lambda name: name.replace('.', '_'))
    generator.register_filter('hasQMLIncompatibleParameter',
                              lambda parameters: any(p.type.is_list or p.type.is_map or p.type.is_interface
                                                     for p in parameters))
    generator.destination = output

    ctx = {'output': output}
    for module in system.modules:
        if module.name in modulesToGenerate:
            ctx.update({'module': module})
            module_path = '/'.join(module.name_parts)
            log.debug('process module %s' % module.module_name)
            ctx.update({'path': module_path})
            generateFile(generator, 'module/{{path}}/ModulePrivate.h', 'ModulePrivate.template.h', ctx, libraryName, "")
            if not module.structs:
                addFileNameToNoMocList(noMocListFile, noMocFilePath, 'module/{}/ModulePrivate.h'.format(module_path))

            generateFile(generator, 'module/{{path}}/Module.h', 'Module.template.h', ctx, libraryName, "")
            generateFile(generator, 'module/{{path}}/Module.cpp', 'Module.template.cpp', ctx, libraryName, "")
            addFileNameToNoMocList(noMocListFile, noMocFilePath, 'module/{}/Module.h'.format(module_path))

            generateFile(generator, 'ipc/{{path}}/ModuleIPC.h', 'ModuleIPC.template.h', ctx, libraryName, "")
            generateFile(generator, 'ipc/{{path}}/ModuleIPC.cpp', 'ModuleIPC.template.cpp', ctx, libraryName, "")
            addFileNameToNoMocList(noMocListFile, noMocFilePath, 'ipc/{}/ModuleIPC.h'.format(module_path))

            for interface in module.interfaces:
                log.debug('process interface %s' % interface)
                ctx.update({'interface': interface})
                ctx.update({'interfaceName': interface.name})
                generateAsyncProxy = False
                ctx.update({'generateAsyncProxy': generateAsyncProxy})
                generateFile(generator, 'types/{{path}}/{{interface}}.h', 'Service.template.h', ctx, libraryName, "")
                generateFile(generator, 'types/{{path}}/{{interface}}.cpp', 'Service.template.cpp', ctx, libraryName, "")
                generateFile(generator, 'types/{{path}}/{{interface}}ImplementationBase.h', 'ImplementationBase.template.h', ctx, libraryName, "")
                generateFile(generator, 'types/{{path}}/{{interface}}ImplementationBase.cpp', 'ImplementationBase.template.cpp', ctx, libraryName, "")
                generateFile(generator, 'types/{{path}}/{{interface}}QMLAdapter.h', 'QMLAdapter.template.h', ctx, libraryName, "")
                generateFile(generator, 'types/{{path}}/{{interface}}QMLAdapter.cpp', 'QMLAdapter.template.cpp', ctx, libraryName, "")

                if isQMLImplementationEnabled(interface):
                    generateFile(generator, 'types/{{path}}/{{interface}}ImplementationBaseQML.h', 'ImplementationBaseQML.template.h', ctx, libraryName, "")

                if isIPCEnabled(interface):
                    generateFile(generator, 'ipc/{{path}}/{{interface}}IPCAdapter.h', 'IPCAdapter.template.h', ctx, libraryName, "")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}IPCAdapter.cpp', 'IPCAdapter.template.cpp', ctx, libraryName, "")

                    generateFile(generator, 'types/{{path}}/{{interface}}IPCCommon.h', 'IPCCommon.template.h', ctx, libraryName, "")
                    addFileNameToNoMocList(noMocListFile, noMocFilePath, 'types/{}/{}IPCCommon.h'.format(module_path, interface))

                    generateFile(generator, 'ipc_dbus/{{path}}/{{interface}}IPCDBusAdapter.h', 'IPCDBusServiceAdapter.template.h', ctx, libraryName, "")
                    generateFile(generator, 'ipc_dbus/{{path}}/{{interface}}IPCDBusAdapter.cpp', 'IPCDBusServiceAdapter.template.cpp', ctx, libraryName, "")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}IPCLocalServiceAdapter.h', 'IPCLocalServiceAdapter.template.h', ctx, libraryName, "")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}IPCLocalServiceAdapter.cpp', 'IPCLocalServiceAdapter.template.cpp', ctx, libraryName, "")

                if isSynchronousIPCEnabled(interface):
                    generateFile(generator, 'ipc/{{path}}/{{interface}}IPCProxy.h', 'IPCProxy.template.h', ctx, libraryName, "")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}IPCProxy.cpp', 'IPCProxy.template.cpp', ctx, libraryName, "")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}ServiceWrapper.h', 'ServiceWrapper.template.h', ctx, libraryName, "")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}ServiceWrapper.cpp', 'ServiceWrapper.template.cpp', ctx, libraryName, "")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}NotAvailableImpl.h', 'ServiceNotAvailableImpl.template.h', ctx, libraryName, "")
                    generateFile(generator, 'ipc_dbus/{{path}}/{{interface}}IPCDBusProxy.h', 'IPCDBusProxyAdapter.template.h', ctx, libraryName, "")
                    generateFile(generator, 'ipc_dbus/{{path}}/{{interface}}IPCDBusProxy.cpp', 'IPCDBusProxyAdapter.template.cpp', ctx, libraryName, "")

                if isAsynchronousIPCEnabled(interface):
                    generateAsyncProxy = True
                    ctx.update({'generateAsyncProxy': generateAsyncProxy})
                    ctx.update({'interfaceName': interface.name + interfaceNameSuffix()})
                    generateFile(generator, 'types/{{path}}/{{interface}}Async.h', 'Service.template.h', ctx, libraryName, "")
                    generateFile(generator, 'types/{{path}}/{{interface}}Async.cpp', 'Service.template.cpp', ctx, libraryName, "")
                    generateFile(generator, 'types/{{path}}/{{interface}}AsyncQMLAdapter.h', 'QMLAdapter.template.h', ctx, libraryName, "")
                    generateFile(generator, 'types/{{path}}/{{interface}}AsyncQMLAdapter.cpp', 'QMLAdapter.template.cpp', ctx, libraryName, "")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}AsyncIPCProxy.h', 'IPCProxy.template.h', ctx, libraryName, "")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}AsyncIPCProxy.cpp', 'IPCProxy.template.cpp', ctx, libraryName, "")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}AsyncServiceWrapper.h', 'ServiceWrapper.template.h', ctx, libraryName, "")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}AsyncServiceWrapper.cpp', 'ServiceWrapper.template.cpp', ctx, libraryName, "")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}AsyncNotAvailableImpl.h', 'ServiceNotAvailableImpl.template.h', ctx, libraryName, "")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}AsyncIPCLocalProxyAdapter.h', 'IPCLocalProxyAdapter.template.h', ctx, libraryName, "")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}AsyncIPCLocalProxyAdapter.cpp', 'IPCLocalProxyAdapter.template.cpp', ctx, libraryName, "")
                    generateFile(generator, 'ipc_dbus/{{path}}/{{interface}}AsyncIPCDBusProxy.h', 'IPCDBusProxyAdapter.template.h', ctx, libraryName, "")
                    generateFile(generator, 'ipc_dbus/{{path}}/{{interface}}AsyncIPCDBusProxy.cpp', 'IPCDBusProxyAdapter.template.cpp', ctx, libraryName, "")

            for enum in module.enums:
                ctx.update({'enum': enum})
                generateFile(generator, 'types/{{path}}/{{enum}}.h', 'Enum.template.h', ctx, libraryName, "")
                generateFile(generator, 'types/{{path}}/{{enum}}.cpp', 'Enum.template.cpp', ctx, libraryName, "")
            for struct in module.structs:
                ctx.update({'struct': struct})
                generateFile(generator, 'types/{{path}}/{{struct}}.h', 'Struct.template.h', ctx, libraryName, "")
                generateFile(generator, 'types/{{path}}/{{struct}}.cpp', 'Struct.template.cpp', ctx, libraryName, "")

                if isQObjectWrapperEnabled(struct):
                    generateFile(generator, 'types/{{path}}/{{struct}}QObjectWrapper.h', 'StructQObjectWrapper.template.h', ctx, libraryName, "")
                    generateFile(generator, 'types/{{path}}/{{struct}}QObjectWrapper.cpp', 'StructQObjectWrapper.template.cpp', ctx, libraryName, "")
Example #14
0
File: csv.py Project: weimerb/qface
def run(src, dst):
    system = FileSystem.parse(src)
    generator = Generator(search_path='templates')
    ctx = {'dst': dst, 'system': system}
    generator.write('{{dst}}/modules.csv', 'modules.csv', ctx)
Example #15
0
def run(src, dst):
    log.debug('run {0} {1}'.format(src, dst))
    project = Path(dst).name
    classPrefix = ''
    system = FileSystem.parse(src)
    generator = Generator(search_path=here / 'templates')
    Filters.classPrefix = classPrefix
    generator.register_filter('returnType', Filters.returnType)
    generator.register_filter('parameterType', Filters.parameterType)
    generator.register_filter('defaultValue', Filters.defaultValue)
    generator.register_filter('parse_doc', parse_doc)
    generator.register_filter('hash', qface.filters.hash)
    generator.register_filter('signalName', Filters.signalName)
    generator.register_filter('parameters', Filters.parameters)
    generator.register_filter('signature', Filters.signature)
    generator.register_filter('open_ns', Filters.open_ns)
    generator.register_filter('close_ns', Filters.close_ns)
    generator.register_filter('using_ns', Filters.using_ns)
    generator.register_filter('starts_with', startswith)

    ctx = {
        'dst': dst,
        'system': system,
        'classPrefix': classPrefix,
        'project': project,
    }

    dst = generator.apply('{{dst}}', ctx)
    generator.destination = dst

    generator.write('{{project}}.pro', 'project.pro', ctx)
    generator.write('stores/stores.pro', 'stores/stores.pro', ctx)
    generator.write('.qmake.conf', 'qmake.conf', ctx)

    generator.write('shared/shared.pri', 'shared/shared.pri', ctx)
    generator.write('shared/action.h', 'shared/action.h', ctx)

    for module in system.modules:
        ctx.update({'module': module})
        dst = generator.apply(
            '{{dst}}/stores/{{module|lower|replace(".", "-")}}', ctx)
        generator.destination = dst

        generator.write('{{module|lower|replace(".", "-")}}.pro',
                        'stores/store/store.pro', ctx)
        generator.write('{{module|lower|replace(".", "-")}}.pri',
                        'stores/store/store.pri', ctx)
        generator.write('lib{{module|lower|replace(".", "-")}}.pro',
                        'stores/store/libstore.pro', ctx)
        generator.write('plugin.h', 'stores/store/plugin.h', ctx)
        generator.write('plugin.cpp', 'stores/store/plugin.cpp', ctx)
        generator.write('qmldir', 'stores/store/qmldir', ctx)

        for interface in module.interfaces:
            ctx.update({'interface': interface})
            generator.write('{{interface|lower}}store.h',
                            'stores/store/store.h',
                            ctx,
                            preserve=True)
            generator.write('{{interface|lower}}store.cpp',
                            'stores/store/store.cpp',
                            ctx,
                            preserve=True)
            generator.write('{{interface|lower}}storebase.h',
                            'stores/store/storebase.h', ctx)
            generator.write('{{interface|lower}}storebase.cpp',
                            'stores/store/storebase.cpp', ctx)
            generator.write('{{interface|lower}}state_p.h',
                            'stores/store/state_p.h', ctx)
            generator.write('{{interface|lower}}state.h',
                            'stores/store/state.h', ctx)
            generator.write('{{interface|lower}}state_p.h',
                            'stores/store/state_p.h', ctx)
            generator.write('{{interface|lower}}state.cpp',
                            'stores/store/state.cpp', ctx)
Example #16
0
def run_generation(input, output, dependency, libraryName, all):
    global generateAsyncProxy
    global generateAll
    generateAll = all
    FileSystem.strict = True
    Generator.strict = True

    # Build the list of modules to be generated
    system = FileSystem.parse(list(input))
    modulesToGenerate = [module.name for module in system.modules]

    system = FileSystem.parse(list(input) + list(dependency))
    generator = Generator(search_path=Path(here / 'facelift' / 'templates'))
    generator.register_filter('cppBool', cppBool)
    generator.register_filter('toValidId', toValidId)
    generator.register_filter('hasQMLIncompatibleParameter', hasQMLIncompatibleParameter)
    generator.destination = output

    ctx = {'output': output}
    for module in system.modules:
        if module.name in modulesToGenerate:
            ctx.update({'module': module})
            module_path = '/'.join(module.name_parts)
            log.debug('process module %s' % module.module_name)
            ctx.update({'path': module_path})
            generateFile(generator, 'module/{{path}}/ModulePrivate.h', 'ModulePrivate.template.h', ctx, libraryName, "")
            generateFile(generator, 'module/{{path}}/Module.h', 'Module.template.h', ctx, libraryName, "")
            generateFile(generator, 'module/{{path}}/Module.cpp', 'Module.template.cpp', ctx, libraryName, "")
            generateFile(generator, 'ipc/{{path}}/ModuleIPC.h', 'ModuleIPC.template.h', ctx, libraryName, "ipc")
            generateFile(generator, 'ipc/{{path}}/ModuleIPC.cpp', 'ModuleIPC.template.cpp', ctx, libraryName, "ipc")
            generateFile(generator, 'devtools/{{path}}/ModuleMonitor.h', 'ModuleMonitor.template.h', ctx, libraryName, "desktop_dev_tools")
            generateFile(generator, 'devtools/{{path}}/ModuleMonitor.cpp', 'ModuleMonitor.template.cpp', ctx, libraryName, "desktop_dev_tools")
            generateFile(generator, 'devtools/{{path}}/ModuleDummy.h', 'DummyModule.template.h', ctx, libraryName, "desktop_dev_tools")
            for interface in module.interfaces:
                log.debug('process interface %s' % interface)
                ctx.update({'interface': interface})
                ctx.update({'interfaceName': interface.name})
                generateAsyncProxy = False
                ctx.update({'generateAsyncProxy': generateAsyncProxy})
                generateFile(generator, 'types/{{path}}/{{interface}}.h', 'Service.template.h', ctx, libraryName, "types")
                generateFile(generator, 'types/{{path}}/{{interface}}.cpp', 'Service.template.cpp', ctx, libraryName, "types")
                generateFile(generator, 'types/{{path}}/{{interface}}ImplementationBase.h', 'ImplementationBase.template.h', ctx, libraryName, "types")
                generateFile(generator, 'types/{{path}}/{{interface}}ImplementationBase.cpp', 'ImplementationBase.template.cpp', ctx, libraryName, "types")
                generateFile(generator, 'types/{{path}}/{{interface}}PropertyAdapter.h', 'ServicePropertyAdapter.template.h', ctx, libraryName, "types")
                generateFile(generator, 'types/{{path}}/{{interface}}QMLFrontend.h', 'QMLFrontend.template.h', ctx, libraryName, "types")
                generateFile(generator, 'types/{{path}}/{{interface}}QMLFrontend.cpp', 'QMLFrontend.template.cpp', ctx, libraryName, "types")
                generateFile(generator, 'devtools/{{path}}/{{interface}}Dummy.h', 'DummyService.template.h', ctx, libraryName, "desktop_dev_tools")
                generateFile(generator, 'devtools/{{path}}/{{interface}}Monitor.h', 'ServiceMonitor.template.h', ctx, libraryName, "desktop_dev_tools")

                if isQMLImplementationEnabled(interface):
                    generateFile(generator, 'types/{{path}}/{{interface}}ImplementationBaseQML.h', 'ImplementationBaseQML.template.h', ctx, libraryName, "types")

                if isIPCEnabled(interface):
                    generateFile(generator, 'ipc/{{path}}/{{interface}}IPCAdapter.h', 'IPCAdapter.template.h', ctx, libraryName, "ipc")
                    generateFile(generator, 'ipc_dbus/{{path}}/{{interface}}IPCDBus.h', 'IPCDBus.template.h', ctx, libraryName, "ipc_dbus")
                    generateFile(generator, 'ipc_dbus/{{path}}/{{interface}}IPCDBusAdapter.h', 'IPCDBusAdapter.template.h', ctx, libraryName, "ipc_dbus")
                    generateFile(generator, 'ipc_dbus/{{path}}/{{interface}}IPCDBusAdapter.cpp', 'IPCDBusAdapter.template.cpp', ctx, libraryName, "ipc_dbus")

                if isSynchronousIPCEnabled(interface):
                    generateFile(generator, 'ipc/{{path}}/{{interface}}IPCProxy.h', 'IPCProxy.template.h', ctx, libraryName, "ipc")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}IPCProxy.cpp', 'IPCProxy.template.cpp', ctx, libraryName, "ipc")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}IPC.h', 'IPC.template.h', ctx, libraryName, "ipc")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}ServiceWrapper.h', 'ServiceWrapper.template.h', ctx, libraryName, "ipc")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}ServiceWrapper.cpp', 'ServiceWrapper.template.cpp', ctx, libraryName, "ipc")
                    generateFile(generator, 'ipc_dbus/{{path}}/{{interface}}IPCDBusProxy.h', 'IPCDBusProxy.template.h', ctx, libraryName, "ipc_dbus")
                    generateFile(generator, 'ipc_dbus/{{path}}/{{interface}}IPCDBusProxy.cpp', 'IPCDBusProxy.template.cpp', ctx, libraryName, "ipc_dbus")

                if isAsynchronousIPCEnabled(interface):
                    generateAsyncProxy = True
                    ctx.update({'generateAsyncProxy': generateAsyncProxy})
                    ctx.update({'interfaceName': interface.name + interfaceNameSuffix()})
                    generateFile(generator, 'types/{{path}}/{{interface}}Async.h', 'Service.template.h', ctx, libraryName, "types")
                    generateFile(generator, 'types/{{path}}/{{interface}}Async.cpp', 'Service.template.cpp', ctx, libraryName, "types")
                    generateFile(generator, 'types/{{path}}/{{interface}}AsyncQMLFrontend.h', 'QMLFrontend.template.h', ctx, libraryName, "types")
                    generateFile(generator, 'types/{{path}}/{{interface}}AsyncQMLFrontend.cpp', 'QMLFrontend.template.cpp', ctx, libraryName, "types")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}AsyncIPCProxy.h', 'IPCProxy.template.h', ctx, libraryName, "ipc")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}AsyncIPCProxy.cpp', 'IPCProxy.template.cpp', ctx, libraryName, "ipc")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}AsyncServiceWrapper.h', 'ServiceWrapper.template.h', ctx, libraryName, "ipc")
                    generateFile(generator, 'ipc/{{path}}/{{interface}}AsyncServiceWrapper.cpp', 'ServiceWrapper.template.cpp', ctx, libraryName, "ipc")
                    generateFile(generator, 'ipc_dbus/{{path}}/{{interface}}AsyncIPCDBusProxy.h', 'IPCDBusProxy.template.h', ctx, libraryName, "ipc_dbus")
                    generateFile(generator, 'ipc_dbus/{{path}}/{{interface}}AsyncIPCDBusProxy.cpp', 'IPCDBusProxy.template.cpp', ctx, libraryName, "ipc_dbus")

            for enum in module.enums:
                ctx.update({'enum': enum})
                generateFile(generator, 'types/{{path}}/{{enum}}.h', 'Enum.template.h', ctx, libraryName, "types")
                generateFile(generator, 'types/{{path}}/{{enum}}.cpp', 'Enum.template.cpp', ctx, libraryName, "types")
            for struct in module.structs:
                ctx.update({'struct': struct})
                generateFile(generator, 'types/{{path}}/{{struct}}.h', 'Struct.template.h', ctx, libraryName, "types")
                generateFile(generator, 'types/{{path}}/{{struct}}.cpp', 'Struct.template.cpp', ctx, libraryName, "types")

                if isQObjectWrapperEnabled(struct):
                    generateFile(generator, 'types/{{path}}/{{struct}}QObjectWrapper.h', 'StructQObjectWrapper.template.h', ctx, libraryName, "types")
                    generateFile(generator, 'types/{{path}}/{{struct}}QObjectWrapper.cpp', 'StructQObjectWrapper.template.cpp', ctx, libraryName, "types")
Example #17
0
File: csv.py Project: gunnarx/qface
def generate(input, output):
    system = FileSystem.parse_dir(input)
    generator = Generator(searchpath='templates')
    ctx = {'output': output, 'system': system}
    generator.write('{{output}}/modules.csv', 'modules.csv', ctx)
Example #18
0
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)
    generator.register_filter('getter_name', getter_name)
    generator.register_filter('setter_name', setter_name)
    generator.register_filter('test_type_value', test_type_value)
    generator.register_filter('default_type_value', default_type_value)
    generator.register_filter('default_value', default_value)
    generator.register_filter('model_type', model_type)
    generator.register_filter('flag_type', flag_type)
    generator.register_filter('parse_doc', parse_doc)
    generator.register_filter('lowerfirst', lower_first_filter)
    generator.register_filter('range_low', range_low)
    generator.register_filter('range_high', range_high)
    generator.register_filter('strip_QT', strip_QT)
    generator.register_filter('domain_values', domain_values)
    generator.register_filter("enum_value", enum_value)
    generator.register_filter("tag_by_path", tag_by_path)
    generator.register_filter("conf_sim_tag", conf_sim_tag)
    generator.register_filter('jsonify', jsonify)
    generator.register_filter('has_domains', has_domains)
    generator.register_filter('json_domain', json_domain)
    generator.register_filter('qml_type', qml_type)
    generator.register_filter('qml_control', qml_control)
    generator.register_filter('qml_binding_property', qml_binding_property)
    generator.register_filter('qml_control_signal_parameters', qml_control_signal_parameters)
    generator.register_filter('struct_includes', struct_includes)
    generator.register_filter('hash', qface.filters.hash)


    srcFile = os.path.basename(src[0])
    srcBase = os.path.splitext(srcFile)[0]
    ctx = {'dst': dst, 'qtASVersion': builtin_config["VERSION"], 'srcFile':srcFile, 'srcBase':srcBase, 'features': builtin_config["FEATURES"]}
    gen_config = yaml.load(open(here / '{0}.yaml'.format(os.path.basename(tplconfig))))
    for module in system.modules:
        log.debug('generate code for module %s', module)
        module.add_tag('config')
        for val, key in moduleConfig.items():
            module.add_attribute('config', val, key)
        ctx.update({'module': module})
        # TODO: refine that, probably just use plain output folder
        dst = generator.apply('{{dst}}', ctx)
        generator.destination = dst
        module_rules = gen_config['generate_rules']['module_rules']
        force = moduleConfig['force']
        if module_rules is None: module_rules = []
        for rule in module_rules:
            preserve = rule['preserve'] if 'preserve' in rule else False
            generator.write(rule['dest_file'], rule['template_file'], ctx, preserve, force)
        for interface in module.interfaces:
            log.debug('generate backend code for interface %s', interface)
            interface.add_tag('config')
            ctx.update({'interface': interface})
            interface_rules = gen_config['generate_rules']['interface_rules']
            if interface_rules is None: interface_rules = []
            for rule in interface_rules:
                preserve = rule['preserve'] if 'preserve' in rule else False
                generator.write(rule['dest_file'], rule['template_file'], ctx, preserve, force)
        if 'struct_rules' in gen_config['generate_rules'] and isinstance(gen_config['generate_rules']['struct_rules'], list):
            for struct in module.structs:
                log.debug('generate code for struct %s', struct)
                struct.add_tag('config')
                ctx.update({'struct': struct})
                for rule in gen_config['generate_rules']['struct_rules']:
                    preserve = rule['preserve'] if 'preserve' in rule else False
                    generator.write(rule['dest_file'], rule['template_file'], ctx, preserve, force)