예제 #1
0
파일: test_tags.py 프로젝트: qt/qtivi-qface
def test_merge_annotation():
    system = loadTuner()
    interface = system.lookup('com.pelagicore.ivi.tuner.Tuner')
    assert interface
    assert interface.attribute('config', 'private') is True
    assert interface.attribute('extra', 'extraA') is None
    FileSystem.merge_annotations(system, inputPath / 'tuner_annotations.yaml')
    assert interface.attribute('extra', 'extraA') is True
예제 #2
0
파일: test_tags.py 프로젝트: qt/qtivi-qface
def test_merge_empty_annotation(mock_stderr):
    system = loadTuner()
    interface = system.lookup('com.pelagicore.ivi.tuner.Tuner')
    assert interface
    FileSystem.merge_annotations(system,
                                 inputPath / 'empty_tuner_annotations.yaml')

    assert interface.attribute('extra', 'extraA') is None
    assert not mock_stderr.getvalue().__contains__("Error parsing annotation")
예제 #3
0
파일: test_tags.py 프로젝트: qt/qtivi-qface
def test_merge_invalid_annotation(mock_stderr):
    system = loadTuner()
    interface = system.lookup('com.pelagicore.ivi.tuner.Tuner')
    assert interface
    FileSystem.merge_annotations(system,
                                 inputPath / 'invalid_tuner_annotations.yaml')

    assert interface.attribute('extra', 'extraA') is None
    assert mock_stderr.getvalue(
    ) == "Error parsing annotation tests/in/invalid_tuner_annotations.yaml: not able to lookup symbol: Tunerrrrrrrr\n"
예제 #4
0
파일: test_tags.py 프로젝트: qt/qtivi-qface
def test_merge_broken_annotation(mock_stderr):
    system = loadTuner()
    interface = system.lookup('com.pelagicore.ivi.tuner.Tuner')
    assert interface
    FileSystem.merge_annotations(system,
                                 inputPath / 'broken_tuner_annotations.yaml')

    assert interface.attribute('extra', 'extraA') is None
    assert mock_stderr.getvalue().__contains__(
        "tests/in/broken_tuner_annotations.yaml:2: error: mapping values are not allowed"
    )
예제 #5
0
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")
예제 #6
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)
예제 #7
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)
예제 #8
0
def test_parse_document_list():
    input = [
        inputPath / 'com.pelagicore.ivi.tuner.qdl',
        inputPath / 'com.pelagicore.ivi.climate.qdl'
    ]
    system = FileSystem.parse(input)
    assert system.lookup('com.pelagicore.ivi.tuner')
    assert system.lookup('com.pelagicore.ivi.climate')
예제 #9
0
def test_parse_document_list():
    src = [
        inputPath / 'com.pelagicore.ivi.tuner.qface',
        inputPath / 'com.pelagicore.ivi.climate.qface'
    ]
    system = FileSystem.parse(src)
    assert system.lookup('com.pelagicore.ivi.tuner')
    assert system.lookup('com.pelagicore.ivi.climate')
예제 #10
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)
예제 #11
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"
예제 #12
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"
예제 #13
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"
예제 #14
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()
예제 #15
0
def run(config, src, dst, force=False, features=None):
    project = Path(dst).name
    system = FileSystem.parse(src)
    template_dir = config.dirname() / 'templates'

    context = {
        'dst': dst,
        'system': system,
        'project': project,
        'features': features,
    }

    generator = RuleGenerator(template_dir, destination=dst, context=context, features=features, force=force)
    generator.process_rules(config, system)
예제 #16
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)
예제 #17
0
파일: app.py 프로젝트: idleroamer/qface
def run(spec, src, dst, features, force):
    spec = Path(spec)
    project = Path(dst).name
    system = FileSystem.parse(src)

    extra_filters_path = spec.dirname() / 'filters.py'
    extra_filters = load_filters(extra_filters_path)

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

    generator = RuleGenerator(search_path=spec.dirname() / 'templates',
                              destination=dst,
                              context=ctx,
                              features=features,
                              force=force)
    generator.filters = extra_filters
    generator.process_rules(spec, system)
예제 #18
0
파일: qtro.py 프로젝트: qfacegen/qface-qtro
def run(src, dst):
    log.debug('run {0} {1}'.format(src, dst))
    project = Path(dst).name
    classPrefix = ''
    system = FileSystem.parse(src)

    context = {
        'dst': dst,
        'system': system,
        'classPrefix': classPrefix,
        'project': project,
        'features': features,
    }

    generator = RuleGenerator(search_path=here / 'templates',
                              destination=dst,
                              context=context,
                              features=features)
    Filters.classPrefix = classPrefix
    generator.filters.update({
        'defaultValue': CustomFilters.defaultValue,
        'returnType': CustomFilters.returnType,
        'parameterType': CustomFilters.parameterType,
        'parameters': CustomFilters.parameters,
        'signature': CustomFilters.signature,
        'parse_doc': parse_doc,
        'hash': qface.filters.hash,
        'jsonify': qface.filters.jsonify,
        'signalName': Filters.signalName,
        'open_ns': Filters.open_ns,
        'close_ns': Filters.close_ns,
        'using_ns': Filters.using_ns,
        'ns': Filters.ns,
        'identifier': Filters.identifier,
        'path': CustomFilters.path,
    })

    generator.process_rules(here / 'qtro.yml', system)
예제 #19
0
def test_parse():
    log.debug('test parse')
    system = FileSystem.parse(inputPath)
    assert system
예제 #20
0
def load_test():
    path = inputPath / 'com.pelagicore.test.qface'
    return FileSystem.parse_document(path)
예제 #21
0
def test_parser_exceptions():
    path = inputPath / 'org.example.failing.qface'
    system = FileSystem.parse_document(path)

    system = FileSystem.parse_document('not-exists')
예제 #22
0
파일: csv.py 프로젝트: 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)
예제 #23
0
def load_tuner():
    path = inputPath / 'com.pelagicore.ivi.tuner.qface'
    return FileSystem.parse_document(path)
예제 #24
0
def load_system():
    path = inputPath / 'com.pelagicore.ivi.climate.qdl'
    return FileSystem.parse_document(path)
예제 #25
0
def parse_document():
    stream = InputStream(document)
    return FileSystem._parse_stream(stream)
예제 #26
0
def loadEcho():
    path = inputPath / 'org.example.echo.qface'
    return FileSystem.parse_document(path)
예제 #27
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)
예제 #28
0
def loadOne():
    path = inputPath / 'com.pelagicore.one.qdl'
    return FileSystem.parse_document(path)
예제 #29
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, "")
예제 #30
0
def test_parse_document():
    system = FileSystem.parse(inputPath / 'com.pelagicore.ivi.tuner.qface')
    assert system.lookup('com.pelagicore.ivi.tuner')