Beispiel #1
0
    def test_pkg_config_has_include(self):
        p = Pkg('foo', 'bar', [])

        out = StringIO()
        generate([p], out)

        assert ('include(FindPkgConfig)' in out.getvalue())
Beispiel #2
0
    def test_pkg_config_generates_cmake(self):
        name = 'foo'
        package = 'bar'
        p = Pkg(name, package, [])

        out = StringIO()
        generate([p], out)

        assert (out.getvalue())
Beispiel #3
0
    def test_pkg_config_generates_search(self):
        name = 'foo'
        package = 'bar'
        p = Pkg(name, package, [])

        out = StringIO()
        generate([p], out)

        cmake = out.getvalue()
        assert (f'pkg_check_modules({name} REQUIRED {package})' in cmake)
Beispiel #4
0
    def test_pkg_config_generates_search(self):
        name = 'foo'
        package = 'bar'
        p = Pkg(name, package)

        files = {}
        generate([p], get_filestore_writer(files))

        cmake = files[f'{name}.cmake'].getvalue()
        assert (f'pkg_check_modules({name} REQUIRED {package})' in cmake)
Beispiel #5
0
    def test_pkg_config_has_include(self):
        p = Pkg('foo', 'bar')

        files = {}
        generate([p], get_filestore_writer(files))

        assert ('CMakeLists.txt' in files)
        cmake = files['CMakeLists.txt'].getvalue()

        assert ('include(FindPkgConfig)' in cmake)
Beispiel #6
0
    def resolve(self, name: str, seen: Dict[str, Target]) -> Target:
        deps = lookup_dependencies(name, self.dependencies, seen)

        identification = self.identify(name)

        result: Target
        if identification.type == 'group':
            assert isinstance(identification.path, Path)
            path = identification.path / 'group' / (name + '.mem')
            packages = resolve(PackageResolver(identification.path),
                               list(bde_items(path)))
            result = Group(str(identification.path), deps, packages)
            TargetResolver._add_override(identification, name, result)

        if identification.type == 'package':
            assert isinstance(identification.path, Path)
            components = build_components(identification.path)
            result = Package(str(identification.path), deps, components)
            TargetResolver._add_override(identification, name, result)

        if identification.type == 'application':
            assert isinstance(identification.path, Path)
            components = build_components(identification.path)
            main_file = str(identification.path / f'{name}.m.cpp')
            if main_file not in {c['source'] for c in components}:
                components.append({
                    'header': None,
                    'source': main_file,
                    'driver': None,
                })
            result = Application(str(identification.path), deps, components)
            TargetResolver._add_override(identification, name, result)

        if identification.type == 'cmake':
            result = CMake(name, str(identification.path), deps)

        if identification.type == 'pkg_config':
            assert isinstance(identification.package, str)
            result = Pkg(name, identification.package, deps)

        if identification.type == 'virtual':
            result = Target(name, deps)

        if name in self._providers:
            result.has_output = False

        if any(d.name in self._runtime_libraries for d in deps):
            result.lazily_bound = True

        if name in self._plugin_tests:
            result.plugin_tests = True

        return result
Beispiel #7
0
    def test_pkg_config_generates_interface_lib(self):
        name = 'foo'
        package = 'bar'
        p = Pkg(name, package, [])

        out = StringIO()
        generate([p], out)

        cmake = list(lex(out))
        _, command = find_command(cmake, 'add_library')
        assert (name == command[0])
        assert ('INTERFACE' == command[1])
Beispiel #8
0
    def test_pkg_config_generates_interface_lib(self):
        name = 'foo'
        package = 'bar'
        p = Pkg(name, package)

        files = {}
        generate([p], get_filestore_writer(files))

        cmake = list(lex(files[f'{name}.cmake']))
        _, command = find_command(cmake, 'add_library')
        assert (name == command[0])
        assert ('INTERFACE' == command[1])
Beispiel #9
0
    def test_pkg_config_generates_cmake(self):
        name = 'foo'
        package = 'bar'
        p = Pkg(name, package)

        files = {}
        generate([p], get_filestore_writer(files))

        assert ('CMakeLists.txt' in files)
        cmake = files['CMakeLists.txt'].getvalue()

        assert (f'{name}.cmake' in files)
        assert (f'include({name}.cmake)' in cmake)
Beispiel #10
0
    def test_pkg_config_generates_static_props(self):
        name = 'foo'
        package = 'bar'
        p = Pkg(name, package)

        files = {}
        generate([p], get_filestore_writer(files))

        cmake = files[f'{name}.cmake']
        commands = list(lex(cmake))
        sh_lib_start, _ = find_command(commands, 'if', ['BUILD_SHARED_LIBS'])
        stmts = parse(iter(commands[sh_lib_start:]))[0]

        static = {tuple(stmt[0]): (stmt[1], stmt[2]) for stmt in stmts[2]}

        assert ((f'{name}_STATIC_INCLUDE_DIRS', ) in static)
        includes = static[(f'{name}_STATIC_INCLUDE_DIRS', )]
        assert ([] == includes[1])
        assert (1 == len(includes[0]))
        include = includes[0][0]
        assert ('target_include_directories' == include[0])
        assert([name, 'INTERFACE', f'"${{{name}_STATIC_INCLUDE_DIRS}}"'] == \
                                                                    include[1])

        assert ((f'{name}_STATIC_LDFLAGS', ) in static)
        ldflags = static[(f'{name}_STATIC_LDFLAGS', )]
        assert ([] == ldflags[1])
        assert (1 == len(ldflags[0]))
        ldflag = ldflags[0][0]
        assert ('target_link_libraries' == ldflag[0])
        assert([name, 'INTERFACE', f'"${{{name}_STATIC_LDFLAGS}}"'] == \
                                                                     ldflag[1])

        assert ((f'{name}_STATIC_CFLAGS_OTHER', ) in static)
        cflags = static[(f'{name}_STATIC_CFLAGS_OTHER', )]
        assert ([] == cflags[1])
        assert (1 == len(cflags[0]))
        cflag = cflags[0][0]
        assert ('target_compile_options' == cflag[0])
        assert([name, 'INTERFACE', f'"${{{name}_STATIC_CFLAGS_OTHER}}"'] == \
                                                                      cflag[1])
Beispiel #11
0
    def test_pkg_config_generates_shared_props(self):
        name = 'foo'
        package = 'bar'
        p = Pkg(name, package, [])

        out = StringIO()
        generate([p], out)

        commands = list(lex(out))
        sh_lib_start, _ = find_command(commands, 'if', ['BUILD_SHARED_LIBS'])
        stmts = parse(iter(commands[sh_lib_start:]))[0]

        shared = {tuple(stmt[0]): (stmt[1], stmt[2]) for stmt in stmts[1]}

        assert ((f'{name}_INCLUDE_DIRS', ) in shared)
        includes = shared[(f'{name}_INCLUDE_DIRS', )]
        assert ([] == includes[1])
        assert (1 == len(includes[0]))
        include = includes[0][0]
        assert ('target_include_directories' == include[0])
        assert([name, 'INTERFACE', f'"${{{name}_INCLUDE_DIRS}}"'] == \
                                                                    include[1])

        assert ((f'{name}_LDFLAGS', ) in shared)
        ldflags = shared[(f'{name}_LDFLAGS', )]
        assert ([] == ldflags[1])
        assert (1 == len(ldflags[0]))
        ldflag = ldflags[0][0]
        assert ('target_link_libraries' == ldflag[0])
        assert ([name, 'INTERFACE', f'"${{{name}_LDFLAGS}}"'] == ldflag[1])

        assert ((f'{name}_CFLAGS_OTHER', ) in shared)
        cflags = shared[(f'{name}_CFLAGS_OTHER', )]
        assert ([] == cflags[1])
        assert (1 == len(cflags[0]))
        cflag = cflags[0][0]
        assert ('target_compile_options' == cflag[0])
        assert ([name, 'INTERFACE', f'"${{{name}_CFLAGS_OTHER}}"'] == cflag[1])
Beispiel #12
0
 def test_dependencies(self):
     p1 = Pkg('p1', 'p1', [])
     p2 = Pkg('p2', 'p2', [p1])
     assert(p1 in p2.dependencies())
Beispiel #13
0
 def test_package_name(self):
     p = Pkg(None, 'foo', [])
     assert('foo' == p.package)
Beispiel #14
0
 def test_name(self):
     p = Pkg('p', None, [])
     assert('p' == p.name)