Exemple #1
0
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
Exemple #2
0
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")
Exemple #3
0
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"
Exemple #4
0
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"
    )
Exemple #5
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)
Exemple #6
0
def generate(tplconfig, moduleConfig, annotations, imports, src, dst):
    log.debug('run {0} {1}'.format(src, dst))
    FileSystem.strict = True
    Generator.strict = True

    # First run without imports to know the name of the modules we want to generate
    module_names = []
    system = FileSystem.parse(src)
    for module in system.modules:
        module_names.append(module.name)

    # Second run with imports to resolve all needed type information
    all_files = imports + src
    system = FileSystem.parse(all_files)
    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))

    srcFile = os.path.basename(src[0])
    srcBase = os.path.splitext(srcFile)[0]
    global_functions.currentSrcFile = srcFile
    ctx = {
        'qtASVersion': builtin_config.config["VERSION"],
        'srcFile': srcFile,
        'srcBase': srcBase
    }
    generator = CustomRuleGenerator(
        search_path=[tplconfig, builtinTemplatesPath],
        destination=dst,
        context=ctx,
        modules=module_names)
    generator.env.keep_trailing_newline = True

    global_functions.register_global_functions(generator)
    register_filters(generator)

    validateSystem(srcFile, system)

    # Make sure the config tag is available for all our symbols
    for module in system.modules:
        module.add_tag('config')
        for val, key in moduleConfig.items():
            module.add_attribute('config', val, key)
        for interface in module.interfaces:
            interface.add_tag('config')
            for property in interface.properties:
                property.add_tag('config')
            for operation in interface.operations:
                operation.add_tag('config')
            for signal in interface.signals:
                signal.add_tag('config')
        for struct in module.structs:
            struct.add_tag('config')
            for field in struct.fields:
                field.add_tag('config')
        for enum in module.enums:
            enum.add_tag('config')
            for member in enum.members:
                member.add_tag('config')

    generator.process_rules(
        os.path.dirname(tplconfig) +
        '/{0}.yaml'.format(os.path.basename(tplconfig)), system)