Beispiel #1
0
    def test_no_pkg_config_no_include(self):
        c = CMake('foo', 'bar', [])

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

        assert ('include(FindPkgConfig)' not in out.getvalue())
Beispiel #2
0
    def test_one_comp_package_no_deps_plugin_test(self):
        comps = [{
            'header': 'file.h',
            'source': 'file.cpp',
            'driver': 'file.t.cpp'
        }]
        target = Package(pjoin('path', 'target'), [], comps)
        target.plugin_tests = True

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

        cmake = list(lex(out))

        find_command(cmake, 'add_library', ['file.t', 'SHARED'])
        find_command(cmake, 'target_link_libraries', ['file.t', 'target'])

        apple_start, _ = find_command(cmake, 'if', ['APPLE'])
        stmts = parse(iter(cmake[apple_start:]))[0]
        _, props = find_command(stmts[1], 'set_target_properties')

        assert ([
            'file.t', 'PROPERTIES', 'LINK_FLAGS', '"-undefined',
            'dynamic_lookup"'
        ] == props)

        win32_start, _ = find_command(cmake, 'if', ['WIN32'])
        stmts = parse(iter(cmake[win32_start:]))[0]

        _, props = find_command(stmts[1], 'target_link_options')
        assert (['file.t', 'PUBLIC', '/EXPORT:main'] == props)
Beispiel #3
0
    def test_base_target_no_deps(self):
        t = Target('t', [])

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

        assert ('CMakeLists.txt' in files)
Beispiel #4
0
    def test_pkg_config_has_include(self):
        p = Pkg('foo', 'bar', [])

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

        assert ('include(FindPkgConfig)' in out.getvalue())
Beispiel #5
0
    def test_base_target_no_deps(self):
        t = Target('t', [])

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

        assert (out.getvalue())
Beispiel #6
0
    def test_two_empty_packages_no_deps_no_test(self):
        deps1 = []
        comps1 = []
        p1 = Package('p1', deps1, comps1)

        deps2 = []
        comps2 = []
        p2 = Package('p2', deps2, comps2)

        is_test = False

        files = {}
        generate([p1, p2], get_filestore_writer(files))

        assert ('p1.cmake' in files)
        assert ('p2.cmake' in files)
        generated1 = files['p1.cmake']
        generated2 = files['p2.cmake']

        cmake1 = list(lex(generated1))
        self._check_package(cmake1, 'p1', 'p1', deps1, comps1)
        cmake2 = list(lex(generated2))
        self._check_package(cmake2, 'p2', 'p2', deps2, comps2)

        assert ('CMakeLists.txt' in files)
        assert ('include(p1.cmake)' in files['CMakeLists.txt'].getvalue())
        assert ('include(p2.cmake)' in files['CMakeLists.txt'].getvalue())
Beispiel #7
0
    def test_two_empty_packages_no_deps_no_test(self):
        deps1  = []
        comps1 = []
        p1 = Package('p1', deps1, comps1)

        deps2  = []
        comps2 = []
        p2 = Package('p2', deps2, comps2)

        is_test = False

        files = {}
        generate([p1, p2], get_filestore_writer(files), {})

        assert('p1.cmake' in files)
        assert('p2.cmake' in files)
        generated1 = files['p1.cmake']
        generated2 = files['p2.cmake']

        cmake1 = list(parse_cmake(generated1))
        self._check_package(cmake1, 'p1', 'p1', deps1, comps1, is_test)
        cmake2 = list(parse_cmake(generated2))
        self._check_package(cmake2, 'p2', 'p2', deps2, comps2, is_test)

        assert('CMakeLists.txt' in files)
        assert('include(p1.cmake)' in files['CMakeLists.txt'].getvalue())
        assert('include(p2.cmake)' in files['CMakeLists.txt'].getvalue())
Beispiel #8
0
    def test_empty_package_with_override(self):
        p = Package('p', [], [])
        p.overrides = 'override.cmake'

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

        assert (f'include({p.overrides})' in out.getvalue())
Beispiel #9
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 #10
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 #11
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 #12
0
    def test_empty_package_with_override(self):
        p = Package('p', [], [])
        p.overrides = 'override.cmake'

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

        assert ('CMakeLists.txt' in files)
        assert (f'include({p.overrides})'
                in files['CMakeLists.txt'].getvalue())
Beispiel #13
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 #14
0
    def test_cmake_target(self):
        path = pjoin('foo', 'bar')
        c = CMake('bar', path)

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

        assert ('CMakeLists.txt' in files)
        cmake = files['CMakeLists.txt'].getvalue()
        assert (f'add_subdirectory({path} {c})' in cmake)
Beispiel #15
0
    def test_cmake_target(self):
        path = pjoin('foo', 'bar')
        c = CMake('bar', path)

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

        assert('CMakeLists.txt' in files)
        cmake = files['CMakeLists.txt'].getvalue()
        assert(f'add_subdirectory({path} {c})' in cmake)
Beispiel #16
0
    def test_no_pkg_config_no_include(self):
        c = CMake('foo', 'bar')

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

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

        assert ('include(FindPkgConfig)' not in cmake)
Beispiel #17
0
    def test_cmake_prologue(self):
        t = Target('t', [])

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

        cmake = list(lex(out))

        find_command(cmake, 'cmake_minimum_required')
        find_command(cmake, 'project')
Beispiel #18
0
    def test_generate_cmake(self):
        output1 = StringIO()

        run(output1, None, output1, None, ['cmake', 'bdemeta.json', 'p'])

        r       = TargetResolver(self._config)
        p       = resolve(r, 'p')
        output2 = StringIO()
        generate(p, output2)

        assert(output1.getvalue() == output2.getvalue())
Beispiel #19
0
    def test_empty_package_with_no_output_dep(self):
        p1 = Package('p1', [], [])
        p2 = Package('p2', [p1], [])
        p1.has_output = False

        files = {}
        generate([p1, p2], get_filestore_writer(files))

        cmake = list(lex(files['p2.cmake']))
        _, libs = find_command(cmake, 'target_link_libraries')
        assert ('p1' not in libs)
Beispiel #20
0
    def test_empty_package_with_no_output_dep(self):
        p1 = Package('p1', [], [])
        p2 = Package('p2', [p1], [])
        p1.has_output = False

        out = StringIO()
        generate([p1, p2], out)

        cmake = list(lex(out))
        _, libs = find_command(cmake, 'target_link_libraries', ['p2'])
        assert ('p1' not in libs)
Beispiel #21
0
    def test_cmake_target(self):
        path = pjoin('foo', 'bar')
        c = CMake('bar', path, [])

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

        # Note: CMake supports '/' for path separators on Windows (in addition
        # to Unix), so for simplicity we use '/' universally
        upath = path.replace('\\', '/')
        assert (f'add_subdirectory({upath} {c.name})' in out.getvalue())
Beispiel #22
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 #23
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 #24
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 #25
0
    def test_cmake_target(self):
        path = pjoin('foo', 'bar')
        c = CMake('bar', path)

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

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

        # Note: CMake supports '/' for path separators on Windows (in addition
        # to Unix), so for simplicity we use '/' universally
        upath = path.replace('\\', '/')
        assert (f'add_subdirectory({upath} {c.name})' in cmake)
Beispiel #26
0
    def _test_package(self, name, path, deps, comps, has_tests):
        target = Package(path, deps, comps)

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

        cmake = list(lex(out))

        self._check_package(cmake, name, path, deps, comps)

        if has_tests:
            find_command(cmake, 'add_custom_target', ['tests'])
        else:
            with self.assertRaises(LookupError):
                find_command(cmake, 'add_custom_target', ['tests'])
Beispiel #27
0
    def test_application(self):
        name = 'app'
        path = pjoin('path', 'app')
        deps = [Target('foo', [])]
        comps = [{'header': None, 'source': 'file.m.cpp', 'driver': None}]

        target = Application(path, deps, comps)

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

        cmake = list(lex(out))

        find_command(cmake, 'add_executable', [name, f'file.m.cpp'])
        find_command(cmake, 'target_link_libraries', [name, 'PUBLIC', 'foo'])
Beispiel #28
0
    def test_empty_package_lazily_bound(self):
        p = Package('p', [], [])
        p.lazily_bound = True

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

        commands = list(lex(out))

        apple_start, _ = find_command(commands, 'if', ['APPLE'])
        stmts = parse(iter(commands[apple_start:]))[0]

        _, props = find_command(stmts[1], 'set_target_properties')
        assert ([
            'p', 'PROPERTIES', 'LINK_FLAGS', '"-undefined', 'dynamic_lookup"'
        ] == props)
Beispiel #29
0
    def test_generate_cmake(self):
        output = StringIO()

        f1 = {}
        w1 = get_filestore_writer(f1)

        run(output, None, w1, None, None, ['cmake', 'p'])

        r  = TargetResolver(self._config)
        p  = resolve(r, 'p')
        f2 = {}
        w2 = get_filestore_writer(f2)
        generate(p, w2)

        assert(f1.keys() == f2.keys())
        for k in f1:
            assert(f1[k].getvalue() == f2[k].getvalue())
Beispiel #30
0
    def test_empty_package_lazily_bound(self):
        p = Package('p', [], [])
        p.lazily_bound = True

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

        assert ('p.cmake' in files)
        commands = list(lex(files['p.cmake']))

        apple_start, _ = find_command(commands, 'if', ['APPLE'])
        stmts = parse(iter(commands[apple_start:]))[0]

        _, props = find_command(stmts[1], 'set_target_properties')
        assert ([
            'p', 'PROPERTIES', 'LINK_FLAGS', '"-undefined', 'dynamic_lookup"'
        ] == props)
Beispiel #31
0
    def test_generate_cmake(self):
        output = StringIO()

        f1 = {}
        w1 = get_filestore_writer(f1)

        run(output, None, w1, None, None, ['cmake', 'p'])

        r = TargetResolver(self._config)
        p = resolve(r, 'p')
        f2 = {}
        w2 = get_filestore_writer(f2)
        generate(p, w2)

        assert (f1.keys() == f2.keys())
        for k in f1:
            assert (f1[k].getvalue() == f2[k].getvalue())
Beispiel #32
0
    def test_two_empty_packages_no_deps_no_test(self):
        deps1 = []
        comps1 = []
        p1 = Package('p1', deps1, comps1)

        deps2 = []
        comps2 = []
        p2 = Package('p2', deps2, comps2)

        is_test = False

        out = StringIO()
        generate([p1, p2], out)

        cmake = list(lex(out))
        self._check_package(cmake, 'p1', 'p1', deps1, comps1)
        self._check_package(cmake, 'p2', 'p2', deps2, comps2)
Beispiel #33
0
    def _test_package(self, name, path, deps, comps, has_tests):
        target = Package(path, deps, comps)

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

        assert (f'{name}.cmake' in files)
        generated = files[f'{name}.cmake']

        cmake = list(lex(generated))
        self._check_package(cmake, name, path, deps, comps)

        cmake = list(lex(files['CMakeLists.txt']))
        if has_tests:
            find_command(cmake, 'add_custom_target', ['tests'])
        else:
            with self.assertRaises(LookupError):
                find_command(cmake, 'add_custom_target', ['tests'])
Beispiel #34
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])