def expand(nodes, is_build, is_test, is_visible): all_nodes = set(nodes) for n in nodes: conanfile = ConanFileInterface(n.conanfile) req = Requirement(n.ref, build=is_build, test=is_test, visible=is_visible) update_existing(req, conanfile) next_nodes = nodes while next_nodes: new_nodes = [] for next_node in next_nodes: for e in next_node.dependencies: if not e.build_require and not e.private and e.dst not in all_nodes: new_nodes.append(e.dst) all_nodes.add(e.dst) next_nodes = new_nodes for n in next_nodes: conanfile = ConanFileInterface(n.conanfile) req = Requirement(n.ref, build=is_build, test=is_test, direct=False, visible=is_visible) update_existing(req, conanfile)
def test_bazeldeps_dependency_transitive(): # Create main ConanFile conanfile = ConanFile(Mock(), None) cpp_info = CppInfo("mypkg", "dummy_root_folder1") cpp_info.defines = ["DUMMY_DEFINE=\"string/value\""] cpp_info.system_libs = ["system_lib1"] cpp_info.libs = ["lib1"] # Create a ConanFile for a direct dependency conanfile_dep = ConanFile(Mock(), None) conanfile_dep.cpp_info = cpp_info conanfile_dep._conan_node = Mock() conanfile_dep._conan_node.ref = ConanFileReference.loads( "OriginalDepName/1.0") package_folder = temp_folder() save(os.path.join(package_folder, "lib", "liblib1.a"), "") conanfile_dep.folders.set_base_package(package_folder) # Add dependency on the direct dependency req = Requirement(ConanFileReference.loads("OriginalDepName/1.0")) conanfile._conan_dependencies = ConanFileDependencies( {req: ConanFileInterface(conanfile_dep)}) cpp_info_transitive = CppInfo("mypkg_t", "dummy_root_folder1") cpp_info_transitive.defines = ["DUMMY_DEFINE=\"string/value\""] cpp_info_transitive.system_libs = ["system_lib1"] cpp_info_transitive.libs = ["lib_t1"] # Create a ConanFile for a transitive dependency conanfile_dep_transitive = ConanFile(Mock(), None) conanfile_dep_transitive.cpp_info = cpp_info_transitive conanfile_dep_transitive._conan_node = Mock() conanfile_dep_transitive._conan_node.ref = ConanFileReference.loads( "TransitiveDepName/1.0") conanfile_dep_transitive.folders.set_base_package("/path/to/folder_dep_t") # Add dependency from the direct dependency to the transitive dependency req = Requirement(ConanFileReference.loads("TransitiveDepName/1.0")) conanfile_dep._conan_dependencies = ConanFileDependencies( {req: ConanFileInterface(conanfile_dep_transitive)}) bazeldeps = BazelDeps(conanfile) for dependency in bazeldeps._conanfile.dependencies.host.values(): dependency_content = bazeldeps._get_dependency_buildfile_content( dependency) assert 'cc_library(\n name = "OriginalDepName",' in dependency_content assert 'defines = ["DUMMY_DEFINE=\\\\\\"string/value\\\\\\""],' in dependency_content if platform.system() == "Windows": assert 'linkopts = ["/DEFAULTLIB:system_lib1"],' in dependency_content else: assert 'linkopts = ["-lsystem_lib1"],' in dependency_content # Ensure that transitive dependency is referenced by the 'deps' attribute of the direct # dependency assert re.search( r'deps =\s*\[\s*":lib1_precompiled",\s*"@TransitiveDepName"', dependency_content)
def host_requires(self): """ :return: list of immediate direct requires and build_requires in the host context """ requires = [ConanFileInterface(edge.dst.conanfile) for edge in self._node.dependencies if not edge.build_require and not edge.private] requires.extend([ConanFileInterface(edge.dst.conanfile) for edge in self._node.dependencies if edge.build_require and edge.dst.context == CONTEXT_HOST]) return DependencyOrderedSet(requires)
def test_cpp_info_name_cmakedeps_components(using_properties): conanfile = ConanFile(Mock(), None) conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize( Settings({ "os": ["Windows"], "compiler": ["gcc"], "build_type": ["Release", "Debug"], "arch": ["x86", "x64"] }), EnvValues()) conanfile.settings.build_type = "Debug" conanfile.settings.arch = "x64" cpp_info = CppInfo("mypkg", "dummy_root_folder1") if using_properties: cpp_info.set_property("cmake_target_name", "GlobakPkgName1") cpp_info.components["mycomp"].set_property("cmake_target_name", "MySuperPkg1") cpp_info.set_property("cmake_file_name", "ComplexFileName1") else: cpp_info.names["cmake_find_package_multi"] = "GlobakPkgName1" cpp_info.components["mycomp"].names[ "cmake_find_package_multi"] = "MySuperPkg1" cpp_info.filenames["cmake_find_package_multi"] = "ComplexFileName1" conanfile_dep = ConanFile(Mock(), None) conanfile_dep.cpp_info = cpp_info with mock.patch('conans.ConanFile.ref', new_callable=mock.PropertyMock) as mock_ref: with mock.patch('conans.ConanFile.dependencies', new_callable=mock.PropertyMock) as mock_deps: mock_ref.return_value = ConanFileReference.loads( "OriginalDepName/1.0") mock_deps.return_value = Mock() conanfile_dep.package_folder = "/path/to/folder_dep" conanfile.dependencies.transitive_host_requires = [ ConanFileInterface(conanfile_dep) ] conanfile.dependencies.host_requires = [ ConanFileInterface(conanfile_dep) ] cmakedeps = CMakeDeps(conanfile) files = cmakedeps.content assert "TARGET GlobakPkgName1::MySuperPkg1" in files[ "ComplexFileName1Config.cmake"] assert 'set(GlobakPkgName1_INCLUDE_DIRS_DEBUG "${GlobakPkgName1_PACKAGE_FOLDER}/include")' \ in files["ComplexFileName1-debug-x64-data.cmake"] assert 'set(GlobakPkgName1_MySuperPkg1_INCLUDE_DIRS_DEBUG ' \ '"${GlobakPkgName1_PACKAGE_FOLDER}/include")' \ in files["ComplexFileName1-debug-x64-data.cmake"]
def test_foo(): dep1 = ConanFile(Mock(), None) dep1.cpp_info = get_cpp_info("dep1") dep1._conan_node = Mock() dep1._conan_node.ref = ConanFileReference.loads("dep1/1.0") dep1.package_folder = "/path/to/folder_dep1" dep2 = ConanFile(Mock(), None) dep2.cpp_info = get_cpp_info("dep2") dep2._conan_node = Mock() dep2._conan_node.ref = ConanFileReference.loads("dep2/1.0") dep2.package_folder = "/path/to/folder_dep2" with mock.patch('conans.ConanFile.dependencies', new_callable=mock.PropertyMock) as mock_deps: req1 = Requirement(ConanFileReference.loads("dep1/1.0")) req2 = Requirement(ConanFileReference.loads("dep2/1.0")) deps = OrderedDict() deps[req1] = ConanFileInterface(dep1) deps[req2] = ConanFileInterface(dep2) mock_deps.return_value = ConanFileDependencies(deps) consumer = ConanFile(Mock(), None) consumer.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "gcc", "compiler.libcxx": "libstdc++11", "compiler.version": "7.1", "cppstd": "17" }) deps = AutotoolsDeps(consumer) # deps.generate() env = deps.environment() assert env["LDFLAGS"] == ' dep1_shared_link_flag dep2_shared_link_flag ' \ 'dep1_exe_link_flag dep2_exe_link_flag ' \ '-framework dep1_oneframework -framework dep1_twoframework ' \ '-framework dep2_oneframework -framework dep2_twoframework ' \ '-F /path/to/folder_dep1/one/framework/path/dep1 ' \ '-F /path/to/folder_dep2/one/framework/path/dep2 ' \ '-L/path/to/folder_dep1/one/lib/path/dep1 ' \ '-L/path/to/folder_dep2/one/lib/path/dep2 ' \ '-Wl,-rpath,"/path/to/folder_dep1/one/lib/path/dep1" ' \ '-Wl,-rpath,"/path/to/folder_dep2/one/lib/path/dep2" ' \ '--sysroot=/path/to/folder/dep1' assert env[ "CXXFLAGS"] == ' dep1_a_cxx_flag dep2_a_cxx_flag --sysroot=/path/to/folder/dep1' assert env[ "CFLAGS"] == ' dep1_a_c_flag dep2_a_c_flag --sysroot=/path/to/folder/dep1'
def requires(self): # public direct requires return [ ConanFileInterface(edge.dst.conanfile) for edge in self._node.dependencies if not edge.build_require and not edge.private ]
def test_bazeldeps_main_buildfile(): expected_content = [ 'def load_conan_dependencies():', 'native.new_local_repository(', 'name="OriginalDepName",', 'path="/path/to/folder_dep",', 'build_file="conandeps/OriginalDepName/BUILD",' ] conanfile = ConanFile(Mock(), None) cpp_info = CppInfo("mypkg", "dummy_root_folder1") conanfile_dep = ConanFile(Mock(), None) conanfile_dep.cpp_info = cpp_info conanfile_dep._conan_node = Mock() conanfile_dep._conan_node.ref = ConanFileReference.loads("OriginalDepName/1.0") conanfile_dep.package_folder = "/path/to/folder_dep" with mock.patch('conans.ConanFile.dependencies', new_callable=mock.PropertyMock) as mock_deps: req = Requirement(ConanFileReference.loads("OriginalDepName/1.0")) mock_deps.return_value = ConanFileDependencies({req: ConanFileInterface(conanfile_dep)}) bazeldeps = BazelDeps(conanfile) local_repositories = [] for dependency in bazeldeps._conanfile.dependencies.host.values(): content = bazeldeps._create_new_local_repository(dependency, "conandeps/OriginalDepName/BUILD") local_repositories.append(content) content = bazeldeps._get_main_buildfile_content(local_repositories) for line in expected_content: assert line in content
def test_bazeldeps_build_dependency_buildfiles(): conanfile = ConanFile(Mock(), None) conanfile_dep = ConanFile(Mock(), None) conanfile_dep._conan_node = Mock() conanfile_dep._conan_node.ref = ConanFileReference.loads( "OriginalDepName/1.0") conanfile_dep.folders.set_base_package("/path/to/folder_dep") # FIXME: This will run infinite loop if conanfile.dependencies.host.topological_sort. # Move to integration test with mock.patch('conans.ConanFile.dependencies', new_callable=mock.PropertyMock) as mock_deps: req = Requirement(ConanFileReference.loads("OriginalDepName/1.0"), build=True) mock_deps.return_value = ConanFileDependencies( {req: ConanFileInterface(conanfile_dep)}) bazeldeps = BazelDeps(conanfile) for build_dependency in bazeldeps._conanfile.dependencies.direct_build.values( ): dependency_content = bazeldeps._get_build_dependency_buildfile_content( build_dependency) assert 'filegroup(\n name = "OriginalDepName_binaries",' in dependency_content assert 'data = glob(["**"]),' in dependency_content
def requires(self): """ :return: list of immediate direct requires, not included build or private ones """ return DependencyOrderedSet([ConanFileInterface(edge.dst.conanfile) for edge in self._node.dependencies if not edge.build_require and not edge.private])
def test_bazeldeps_dependency_buildfiles(): conanfile = ConanFile(Mock(), None) cpp_info = CppInfo("mypkg", "dummy_root_folder1") cpp_info.defines = ["DUMMY_DEFINE=\"string/value\""] cpp_info.system_libs = ["system_lib1"] cpp_info.libs = ["lib1"] conanfile_dep = ConanFile(Mock(), None) conanfile_dep.cpp_info = cpp_info conanfile_dep._conan_node = Mock() conanfile_dep._conan_node.ref = ConanFileReference.loads( "OriginalDepName/1.0") conanfile_dep.package_folder = "/path/to/folder_dep" with mock.patch('conans.ConanFile.dependencies', new_callable=mock.PropertyMock) as mock_deps: req = Requirement(ConanFileReference.loads("OriginalDepName/1.0")) mock_deps.return_value = ConanFileDependencies( {req: ConanFileInterface(conanfile_dep)}) bazeldeps = BazelDeps(conanfile) for dependency in bazeldeps._conanfile.dependencies.host.values(): dependency_content = bazeldeps._get_dependency_buildfile_content( dependency) assert 'cc_library(\n name = "OriginalDepName",' in dependency_content assert 'defines = ["DUMMY_DEFINE=\'string/value\'"],' in dependency_content assert 'linkopts = ["-lsystem_lib1"],' in dependency_content assert 'deps = [\n \n ":lib1_precompiled",' in dependency_content
def test_bazeldeps_interface_buildfiles(): conanfile = ConanFile(Mock(), None) cpp_info = CppInfo("mypkg", "dummy_root_folder2") conanfile_dep = ConanFile(Mock(), None) conanfile_dep.cpp_info = cpp_info conanfile_dep._conan_node = Mock() conanfile_dep._conan_node.ref = ConanFileReference.loads( "OriginalDepName/2.0") with mock.patch('conans.ConanFile.dependencies', new_callable=mock.PropertyMock) as mock_deps: req = Requirement(ConanFileReference.loads("OriginalDepName/1.0")) mock_deps.return_value = ConanFileDependencies( {req: ConanFileInterface(conanfile_dep)}) bazeldeps = BazelDeps(conanfile) dependency = next(iter( bazeldeps._conanfile.dependencies.host.values())) dependency_content = re.sub( r"\s", "", bazeldeps._get_dependency_buildfile_content(dependency)) assert ( dependency_content == 'load("@rules_cc//cc:defs.bzl","cc_import","cc_library")cc_library(name="OriginalDepName",hdrs=glob(["include/**"]),includes=["include"],visibility=["//visibility:public"],)' )
def test_cmake_deps_links_flags(): # https://github.com/conan-io/conan/issues/8703 conanfile = ConanFile(Mock(), None) conanfile._conan_node = Mock() conanfile._conan_node.context = "host" conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize(Settings({"os": ["Windows"], "compiler": ["gcc"], "build_type": ["Release"], "arch": ["x86"]}), EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.arch = "x86" cpp_info = CppInfo("mypkg", "dummy_root_folder1") # https://github.com/conan-io/conan/issues/8811 regression, fix with explicit - instead of / cpp_info.sharedlinkflags = ["-NODEFAULTLIB", "-OTHERFLAG"] cpp_info.exelinkflags = ["-OPT:NOICF"] conanfile_dep = ConanFile(Mock(), None) conanfile_dep.cpp_info = cpp_info conanfile_dep._conan_node = Mock() conanfile_dep._conan_node.ref = ConanFileReference.loads("mypkg/1.0") conanfile_dep._conan_node.context = "host" conanfile_dep.package_folder = "/path/to/folder_dep" with mock.patch('conans.ConanFile.dependencies', new_callable=mock.PropertyMock) as mock_deps: req = Requirement(ConanFileReference.loads("OriginalDepName/1.0")) mock_deps.return_value = ConanFileDependencies({req: ConanFileInterface(conanfile_dep)}) cmakedeps = CMakeDeps(conanfile) files = cmakedeps.content data_cmake = files["mypkg-release-x86-data.cmake"] assert "set(mypkg_SHARED_LINK_FLAGS_RELEASE -NODEFAULTLIB;-OTHERFLAG)" in data_cmake assert "set(mypkg_EXE_LINK_FLAGS_RELEASE -OPT:NOICF)" in data_cmake
def build_requires(self): """ :return: list of immediate direct build_requires """ return DependencyOrderedSet([ ConanFileInterface(edge.dst.conanfile) for edge in self._node.dependencies if edge.build_require ])
def expand(nodes, is_build): all_nodes = set(nodes) for n in nodes: conanfile = ConanFileInterface(n.conanfile) d[Requirement(n.ref, build=is_build)] = conanfile next_nodes = nodes while next_nodes: new_nodes = [] for next_node in next_nodes: for e in next_node.dependencies: if not e.build_require and not e.private and e.dst not in all_nodes: new_nodes.append(e.dst) all_nodes.add(e.dst) next_nodes = new_nodes for n in next_nodes: conanfile = ConanFileInterface(n.conanfile) d[Requirement(n.ref, build=is_build, direct=False)] = conanfile
def test_bazeldeps_shared_library_interface_buildfiles(): cpp_info = CppInfo("mypkg", "dummy_root_folder2") cpp_info.libs = ["lib1"] options = MockOptions({"shared": True}) conanfile_dep = MockConanFileDeps(ConanFileDependencies({}), Mock(), None) conanfile_dep.options = options conanfile_dep.cpp_info = cpp_info conanfile_dep._conan_node = Mock() conanfile_dep.folders.set_base_package(temp_folder()) conanfile_dep._conan_node.ref = ConanFileReference.loads( "OriginalDepName/1.0") package_folder = temp_folder() save(os.path.join(package_folder, "lib", "lib1.lib"), "") save(os.path.join(package_folder, "bin", "lib1.dll"), "") conanfile_dep.folders.set_base_package(package_folder) req = Requirement(ConanFileReference.loads("OriginalDepName/1.0")) mock_deps = ConanFileDependencies({req: ConanFileInterface(conanfile_dep)}) conanfile = MockConanFileDeps(mock_deps, Mock(), None) bazeldeps = BazelDeps(conanfile) dependency = next(iter(bazeldeps._conanfile.dependencies.host.values())) dependency_content = re.sub( r"\s", "", bazeldeps._get_dependency_buildfile_content(dependency)) expected_content = """ load("@rules_cc//cc:defs.bzl","cc_import","cc_library") cc_import( name = "lib1_precompiled", interface_library = "lib/lib1.lib", shared_library = "bin/lib1.dll", ) cc_library( name = "OriginalDepName", hdrs=glob(["include/**"]), includes=["include"], visibility=["//visibility:public"], deps = [ ":lib1_precompiled", ], ) """ assert (dependency_content == re.sub(r"\s", "", expected_content))
def test_cpp_info_name_cmakedeps_components(): conanfile = ConanFile(Mock(), None) conanfile._conan_node = Mock() conanfile._conan_node.context = "host" conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize( Settings({ "os": ["Windows"], "compiler": ["gcc"], "build_type": ["Release", "Debug"], "arch": ["x86", "x64"] }), EnvValues()) conanfile.settings.build_type = "Debug" conanfile.settings.arch = "x64" cpp_info = CppInfo("mypkg", "dummy_root_folder1") cpp_info.set_property("cmake_target_name", "GlobakPkgName1::GlobakPkgName1") cpp_info.components["mycomp"].set_property("cmake_target_name", "GlobakPkgName1::MySuperPkg1") cpp_info.set_property("cmake_file_name", "ComplexFileName1") conanfile_dep = ConanFile(Mock(), None) conanfile_dep.cpp_info = cpp_info conanfile_dep._conan_node = Mock() conanfile_dep._conan_node.ref = ConanFileReference.loads( "OriginalDepName/1.0") conanfile_dep._conan_node.context = "host" conanfile_dep.folders.set_base_package("/path/to/folder_dep") with mock.patch('conans.ConanFile.dependencies', new_callable=mock.PropertyMock) as mock_deps: req = Requirement(ConanFileReference.loads("OriginalDepName/1.0")) mock_deps.return_value = ConanFileDependencies( {req: ConanFileInterface(conanfile_dep)}) cmakedeps = CMakeDeps(conanfile) files = cmakedeps.content assert "TARGET GlobakPkgName1::MySuperPkg1" in files[ "ComplexFileName1-Target-debug.cmake"] assert 'set(OriginalDepName_INCLUDE_DIRS_DEBUG ' \ '"${OriginalDepName_PACKAGE_FOLDER_DEBUG}/include")' \ in files["ComplexFileName1-debug-x64-data.cmake"] assert 'set(OriginalDepName_GlobakPkgName1_MySuperPkg1_INCLUDE_DIRS_DEBUG ' \ '"${OriginalDepName_PACKAGE_FOLDER_DEBUG}/include")' \ in files["ComplexFileName1-debug-x64-data.cmake"]
def test_component_name_same_package(): """ When the package and the component are the same the variables declared in data and linked to the target have to be the same. https://github.com/conan-io/conan/issues/9071""" conanfile = ConanFile(Mock(), None) conanfile._conan_node = Mock() conanfile._conan_node.context = "host" conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize( Settings({ "os": ["Windows"], "compiler": ["gcc"], "build_type": ["Release"], "arch": ["x86"] }), EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.arch = "x86" cpp_info = CppInfo("mypkg", "dummy_root_folder1") # We adjust the component with the same name as the package on purpose cpp_info.components["mypkg"].includedirs = ["includedirs1"] conanfile_dep = ConanFile(Mock(), None) conanfile_dep.cpp_info = cpp_info conanfile_dep._conan_node = Mock() conanfile_dep._conan_node.context = "host" conanfile_dep._conan_node.ref = ConanFileReference.loads("mypkg/1.0") conanfile_dep.folders.set_base_package("/path/to/folder_dep") with mock.patch('conans.ConanFile.dependencies', new_callable=mock.PropertyMock) as mock_deps: req = Requirement(ConanFileReference.loads("mypkg/1.0")) mock_deps.return_value = ConanFileDependencies( {req: ConanFileInterface(conanfile_dep)}) cmakedeps = CMakeDeps(conanfile) files = cmakedeps.content target_cmake = files["mypkg-Target-release.cmake"] assert "$<$<CONFIG:Release>:${mypkg_mypkg_mypkg_INCLUDE_DIRS_RELEASE}> APPEND)" \ in target_cmake data_cmake = files["mypkg-release-x86-data.cmake"] assert 'set(mypkg_mypkg_mypkg_INCLUDE_DIRS_RELEASE ' \ '"${mypkg_PACKAGE_FOLDER_RELEASE}/includedirs1")' in data_cmake
def test_cpp_info_name_cmakedeps(using_properties): conanfile = ConanFile(Mock(), None) conanfile._conan_node = Mock() conanfile._conan_node.context = "host" conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize( Settings({ "os": ["Windows"], "compiler": ["gcc"], "build_type": ["Release"], "arch": ["x86"] }), EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.arch = "x86" cpp_info = CppInfo("mypkg", "dummy_root_folder1") if using_properties: cpp_info.set_property("cmake_target_name", "MySuperPkg1") cpp_info.set_property("cmake_file_name", "ComplexFileName1") else: cpp_info.names["cmake_find_package_multi"] = "MySuperPkg1" cpp_info.filenames["cmake_find_package_multi"] = "ComplexFileName1" conanfile_dep = ConanFile(Mock(), None) conanfile_dep.cpp_info = cpp_info conanfile_dep._conan_node = Mock() conanfile_dep._conan_node.ref = ConanFileReference.loads( "OriginalDepName/1.0") conanfile_dep._conan_node.context = "host" conanfile_dep.package_folder = "/path/to/folder_dep" with mock.patch('conans.ConanFile.dependencies', new_callable=mock.PropertyMock) as mock_deps: req = Requirement(ConanFileReference.loads("OriginalDepName/1.0")) mock_deps.return_value = ConanFileDependencies( {req: ConanFileInterface(conanfile_dep)}) cmakedeps = CMakeDeps(conanfile) files = cmakedeps.content assert "TARGET MySuperPkg1::MySuperPkg1" in files[ "ComplexFileName1-Target-release.cmake"] assert 'set(OriginalDepName_INCLUDE_DIRS_RELEASE ' \ '"${OriginalDepName_PACKAGE_FOLDER_RELEASE}/include")' \ in files["ComplexFileName1-release-x86-data.cmake"]
def test_bazeldeps_dependency_buildfiles(): conanfile = ConanFile(Mock(), None) cpp_info = CppInfo("mypkg", "dummy_root_folder1") conanfile_dep = ConanFile(Mock(), None) conanfile_dep.cpp_info = cpp_info conanfile_dep._conan_node = Mock() conanfile_dep._conan_node.ref = ConanFileReference.loads("OriginalDepName/1.0") conanfile_dep.package_folder = "/path/to/folder_dep" with mock.patch('conans.ConanFile.dependencies', new_callable=mock.PropertyMock) as mock_deps: req = Requirement(ConanFileReference.loads("OriginalDepName/1.0")) mock_deps.return_value = ConanFileDependencies({req: ConanFileInterface(conanfile_dep)}) bazeldeps = BazelDeps(conanfile) for dependency in bazeldeps._conanfile.dependencies.host.values(): dependency_content = bazeldeps._get_dependency_buildfile_content(dependency) assert 'cc_library(\n name = "OriginalDepName",' in dependency_content
def test_bazeldeps_get_lib_file_path_by_basename(): conanfile = ConanFile(Mock(), None) cpp_info = CppInfo("mypkg", "dummy_root_folder1") cpp_info.defines = ["DUMMY_DEFINE=\"string/value\""] cpp_info.system_libs = ["system_lib1"] cpp_info.libs = ["liblib1.a"] conanfile_dep = ConanFile(Mock(), None) conanfile_dep.cpp_info = cpp_info conanfile_dep._conan_node = Mock() conanfile_dep._conan_node.ref = ConanFileReference.loads( "OriginalDepName/1.0") package_folder = temp_folder() save(os.path.join(package_folder, "lib", "liblib1.a"), "") conanfile_dep.folders.set_base_package(package_folder) # FIXME: This will run infinite loop if conanfile.dependencies.host.topological_sort. # Move to integration test with mock.patch('conans.ConanFile.dependencies', new_callable=mock.PropertyMock) as mock_deps: req = Requirement(ConanFileReference.loads("OriginalDepName/1.0")) mock_deps.return_value = ConanFileDependencies( {req: ConanFileInterface(conanfile_dep)}) bazeldeps = BazelDeps(conanfile) for dependency in bazeldeps._conanfile.dependencies.host.values(): dependency_content = bazeldeps._get_dependency_buildfile_content( dependency) assert 'cc_library(\n name = "OriginalDepName",' in dependency_content assert """defines = ["DUMMY_DEFINE=\\\\\\"string/value\\\\\\""]""" in dependency_content if platform.system() == "Windows": assert 'linkopts = ["/DEFAULTLIB:system_lib1"]' in dependency_content else: assert 'linkopts = ["-lsystem_lib1"],' in dependency_content assert 'deps = [\n \n ":liblib1.a_precompiled",' in dependency_content
def test_foo(): dep1 = ConanFile(Mock(), None) dep1.cpp_info = get_cpp_info("dep1") dep1._conan_node = Mock() dep1._conan_node.ref = ConanFileReference.loads("dep1/1.0") dep1.package_folder = "/path/to/folder_dep1" dep2 = ConanFile(Mock(), None) dep2.cpp_info = get_cpp_info("dep2") dep2._conan_node = Mock() dep2._conan_node.ref = ConanFileReference.loads("dep2/1.0") dep2.package_folder = "/path/to/folder_dep2" with mock.patch('conans.ConanFile.dependencies', new_callable=mock.PropertyMock) as mock_deps: req1 = Requirement(ConanFileReference.loads("dep1/1.0")) req2 = Requirement(ConanFileReference.loads("dep2/1.0")) deps = OrderedDict() deps[req1] = ConanFileInterface(dep1) deps[req2] = ConanFileInterface(dep2) mock_deps.return_value = ConanFileDependencies(deps) consumer = ConanFile(Mock(), None) consumer.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "gcc", "compiler.libcxx": "libstdc++11", "compiler.version": "7.1", "cppstd": "17" }) deps = AutotoolsDeps(consumer) env = deps.environment # Customize the environment env.remove("LDFLAGS", "dep2_shared_link_flag") env.remove("LDFLAGS", "-F /path/to/folder_dep1/one/framework/path/dep1") env.append("LDFLAGS", "OtherSuperStuff") # The contents are of course modified assert env["LDFLAGS"] == 'dep1_shared_link_flag ' \ 'dep1_exe_link_flag dep2_exe_link_flag ' \ '-framework dep1_oneframework -framework dep1_twoframework ' \ '-framework dep2_oneframework -framework dep2_twoframework ' \ '-F /path/to/folder_dep2/one/framework/path/dep2 ' \ '-L/path/to/folder_dep1/one/lib/path/dep1 ' \ '-L/path/to/folder_dep2/one/lib/path/dep2 ' \ '-Wl,-rpath,"/path/to/folder_dep1/one/lib/path/dep1" ' \ '-Wl,-rpath,"/path/to/folder_dep2/one/lib/path/dep2" ' \ '--sysroot=/path/to/folder/dep1 OtherSuperStuff' assert env[ "CXXFLAGS"] == 'dep1_a_cxx_flag dep2_a_cxx_flag --sysroot=/path/to/folder/dep1' assert env[ "CFLAGS"] == 'dep1_a_c_flag dep2_a_c_flag --sysroot=/path/to/folder/dep1' folder = temp_folder() consumer.folders.set_base_install(folder) deps.generate() extension = ".bat" if platform.system() == "Windows" else ".sh" # The generated file also contains the changes with open( os.path.join(folder, "conanautotoolsdeps{}".format(extension))) as _f: contents = _f.read() assert "path/to/folder_dep1/one/framework/path/dep1" not in contents assert "OtherSuperStuff" in contents
def build_requires(self): return [ ConanFileInterface(edge.dst.conanfile) for edge in self._node.dependencies if edge.build_require ]