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())
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)
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())
def test_two_package_includes(self): p1_path = pj('path', 'g', 'p1') p2_path = pj('path', 'g', 'p2') g_path = pj('path', 'g') p1 = Package(p1_path, [], []) p2 = Package(p2_path, [p1], []) g = Group(g_path, [], [p2, p1]) assert([p2_path, p1_path] == list(g.includes()))
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())
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)
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)
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)
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)
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)
def test_sources_one_c_component_no_driver(self): c1_path = pj('path', 'g', 'p1', 'gp1_c1.c') p1_path = pj('path', 'g', 'p1') g_path = pj('path', 'g') p1 = Package(p1_path, [], [{ 'header': None, 'source': c1_path, 'driver': None, }]) g = Group(g_path, [], [p1]) assert([c1_path] == list(g.sources()))
def _test_package(self, name, path, deps, comps, is_test): target = Package(path, deps, comps) files = {} generate_target(target, get_filestore_writer(files), is_test) assert (f'{name}.cmake' in files) generated = files[f'{name}.cmake'] cmake = list(parse_cmake(generated)) self._check_package(cmake, name, path, deps, comps, is_test)
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
def test_sources_one_cpp_component_with_driver(self): c1_header = pj('path', 'g', 'p1', 'gp1_c1.h') c1_path = pj('path', 'g', 'p1', 'gp1_c1.cpp') c1_driver = pj('path', 'g', 'p1', 'gp1_c1.t.cpp') p1_path = pj('path', 'g', 'p1') g_path = pj('path', 'g') p1 = Package(p1_path, [], [{ 'header': c1_header, 'source': c1_path, 'driver': c1_driver, }]) g = Group(g_path, [], [p1]) assert([c1_path] == list(g.sources())) assert([c1_driver] == list(g.drivers()))
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'])
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'])
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 == 'cmake': result = bdemeta.types.CMake(name, str(identification.path)) if identification.type == 'pkg_config': assert isinstance(identification.package, str) result = bdemeta.types.Pkg(name, identification.package) 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 return result
def test_drivers(self): p = Package(pj('path', 'to', 'foo'), ['bar'], [{ 'driver': 'baz'}]) assert(['baz'] == list(p.drivers()))
def test_sources(self): p = Package(pj('path', 'to', 'foo'), ['bar'], [{ 'source': 'baz'}]) assert(['baz'] == list(p.sources()))
def test_no_sources(self): p = Package(pj('path', 'to', 'foo'), ['bar'], [{ 'source': None }]) assert([] == list(p.sources()))
def test_name(self): p = Package(pj('path', 'to', 'foo'), ['bar'], []) assert('foo' == p.name)
def test_dependencies(self): p = Package(pj('path', 'to', 'foo'), ['bar'], []) assert(['bar'] == p.dependencies())
def test_no_drivers(self): p = Package(pj('path', 'to', 'foo'), ['bar'], [{ 'driver': None }]) assert([] == list(p.drivers()))
def test_str_ness(self): p = Package(pj('path', 'to', 'foo'), ['bar'], []) assert ('foo' == p)
def test_includes(self): path = pj('path', 'to', 'foo') p = Package(path, ['bar'], 'baz') assert([path] == list(p.includes()))
def test_one_package_includes(self): p_path = pj('path', 'g', 'p') g_path = pj('path', 'g') p = Package(p_path, [], []) g = Group( g_path, [], [p]) assert([p_path] == list(g.includes()))
def resolve(self, name: str, resolved_packages: Mapping[str, Package]) -> Package: path = self._group_path / name components = build_components(path) deps = lookup_dependencies(name, self.dependencies, resolved_packages) return Package(str(path), deps, components)