def conanfile(): c = ConanFile(Mock(), None) c.settings = "os", "compiler", "build_type", "arch" c.initialize( Settings({ "os": ["Windows"], "compiler": { "gcc": { "libcxx": ["libstdc++"] } }, "build_type": ["Release"], "arch": ["x86"] }), EnvValues()) c.settings.build_type = "Release" c.settings.arch = "x86" c.settings.compiler = "gcc" c.settings.compiler.libcxx = "libstdc++" c.settings.os = "Windows" c.conf = Conf() tmp_folder = temp_folder() c.folders.set_base_generators(tmp_folder) c.folders.generators = "." c.folders.set_base_build(tmp_folder) return c
def test_msvc_xp_toolsets(): c = ConanFile(Mock(), None) c.settings = "os", "compiler", "build_type", "arch" c.initialize( Settings({ "os": ["Windows"], "compiler": { "msvc": { "version": ["170"], "update": [None], "cppstd": ["98"], "toolset": [None, "v110_xp"] } }, "build_type": ["Release"], "arch": ["x86"] }), EnvValues()) c.settings.build_type = "Release" c.settings.arch = "x86" c.settings.compiler = "msvc" c.settings.compiler.version = "170" c.settings.compiler.toolset = "v110_xp" c.settings.compiler.cppstd = "98" c.settings.os = "Windows" c.conf = Conf() c.folders.set_base_generators(".") c._conan_node = Mock() c._conan_node.dependencies = [] toolchain = CMakeToolchain(c) assert 'CMAKE_GENERATOR_TOOLSET "v110_xp"' in toolchain.content assert 'Visual Studio 11 2012' in toolchain.generator # As by the CMake docs, this has no effect for VS < 2015 assert 'CMAKE_CXX_STANDARD 98' in toolchain.content
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 conanfile_apple(): c = ConanFile(Mock(), None) c.settings = "os", "compiler", "build_type", "arch" c.initialize( Settings({ "os": { "Macos": { "version": ["10.15"] } }, "compiler": { "apple-clang": { "libcxx": ["libc++"] } }, "build_type": ["Release"], "arch": ["x86"] }), EnvValues()) c.settings.build_type = "Release" c.settings.arch = "x86" c.settings.compiler = "apple-clang" c.settings.compiler.libcxx = "libc++" c.settings.os = "Macos" c.settings.os.version = "10.15" c.conf = Conf() c.folders.set_base_generators(".") c._conan_node = Mock() c._conan_node.dependencies = [] return c
def conanfile_msvc(): c = ConanFile(Mock(), None) c.settings = "os", "compiler", "build_type", "arch" c.initialize( Settings({ "os": ["Windows"], "compiler": { "msvc": { "version": ["193"], "update": [None], "cppstd": ["20"] } }, "build_type": ["Release"], "arch": ["x86"] }), EnvValues()) c.settings.build_type = "Release" c.settings.arch = "x86" c.settings.compiler = "msvc" c.settings.compiler.version = "193" c.settings.compiler.cppstd = "20" c.settings.os = "Windows" c.conf = Conf() c.folders.set_base_generators(".") c._conan_node = Mock() c._conan_node.dependencies = [] return c
def test_libcxx_abi_flag(): c = ConanFile(Mock(), None) c.settings = "os", "compiler", "build_type", "arch" c.initialize(Settings.loads(get_default_settings_yml()), EnvValues()) c.settings.build_type = "Release" c.settings.arch = "x86_64" c.settings.compiler = "gcc" c.settings.compiler.version = "11" c.settings.compiler.cppstd = "20" c.settings.compiler.libcxx = "libstdc++" c.settings.os = "Linux" c.conf = Conf() c.folders.set_base_generators(".") c._conan_node = Mock() c._conan_node.dependencies = [] toolchain = CMakeToolchain(c) content = toolchain.content assert '_GLIBCXX_USE_CXX11_ABI=0' in content c.settings.compiler.libcxx = "libstdc++11" toolchain = CMakeToolchain(c) content = toolchain.content # by default, no flag is output anymore, it is assumed the compiler default assert 'GLIBCXX_USE_CXX11_ABI' not in content # recipe workaround for older distros toolchain.blocks["libcxx"].values["glibcxx"] = "1" content = toolchain.content assert '_GLIBCXX_USE_CXX11_ABI=1' in content # but maybe the conf is better c.conf["tools.gnu:define_libcxx11_abi"] = True toolchain = CMakeToolchain(c) content = toolchain.content assert '_GLIBCXX_USE_CXX11_ABI=1' in content
def conanfile_linux_fpic(): c = ConanFile(Mock(), None) c.settings = "os", "compiler", "build_type", "arch" c.options = { "fPIC": [True, False], } c.default_options = { "fPIC": False, } c.initialize( Settings({ "os": ["Linux"], "compiler": { "gcc": { "version": ["11"], "cppstd": ["20"] } }, "build_type": ["Release"], "arch": ["x86_64"] }), EnvValues()) c.settings.build_type = "Release" c.settings.arch = "x86_64" c.settings.compiler = "gcc" c.settings.compiler.version = "11" c.settings.compiler.cppstd = "20" c.settings.os = "Linux" c.conf = Conf() c.folders.set_base_generators(".") c._conan_node = Mock() c._conan_node.dependencies = [] return c
def conanfile_windows_fpic(): c = ConanFile(Mock(), None) c.settings = "os", "compiler", "build_type", "arch" c.options = { "fPIC": [True, False], } c.default_options = { "fPIC": True, } c.initialize( Settings({ "os": ["Windows"], "compiler": { "gcc": { "libcxx": ["libstdc++"] } }, "build_type": ["Release"], "arch": ["x86"] }), EnvValues()) c.settings.build_type = "Release" c.settings.arch = "x86" c.settings.compiler = "gcc" c.settings.compiler.libcxx = "libstdc++" c.settings.os = "Windows" c.conf = Conf() c.folders.set_base_generators(".") c._conan_node = Mock() c._conan_node.dependencies = [] return c
def test_apple_cmake_osx_sysroot_sdk_mandatory(os, os_sdk, arch, expected_sdk): """ Testing if CMAKE_OSX_SYSROOT is correctly set. Issue related: https://github.com/conan-io/conan/issues/10275 """ c = ConanFile(Mock(), None) c.settings = "os", "compiler", "build_type", "arch" c.initialize(Settings.loads(get_default_settings_yml()), EnvValues()) c.settings.os = os c.settings.os.sdk = os_sdk c.settings.build_type = "Release" c.settings.arch = arch c.settings.compiler = "apple-clang" c.settings.compiler.version = "13.0" c.settings.compiler.libcxx = "libc++" c.settings.compiler.cppstd = "17" c.conf = Conf() c.folders.set_base_generators(".") c._conan_node = Mock() c._conan_node.dependencies = [] with pytest.raises(ConanException) as excinfo: CMakeToolchain(c).content() assert "Please, specify a suitable value for os.sdk." % expected_sdk in str( excinfo.value)
def test_msbuild_toolset_for_intel_cc(mode, expected_toolset): settings = Settings({ "build_type": ["Release"], "compiler": { "intel-cc": { "version": ["2021.3"], "mode": [mode] }, "msvc": { "version": ["193"], "cppstd": ["20"] } }, "os": ["Windows"], "arch": ["x86_64"] }) conanfile = ConanFile(Mock(), None) conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize(settings, EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.compiler = "intel-cc" conanfile.settings.compiler.version = "2021.3" conanfile.settings.compiler.mode = mode conanfile.settings.os = "Windows" conanfile.settings.arch = "x86_64" msbuild = MSBuildToolchain(conanfile) assert expected_toolset == msbuild.toolset
def test_msbuild_standard(): test_folder = temp_folder() settings = Settings({ "build_type": ["Release"], "compiler": { "msvc": { "version": ["193"], "cppstd": ["20"] } }, "os": ["Windows"], "arch": ["x86_64"] }) conanfile = ConanFile(Mock(), None) conanfile.folders.set_base_generators(test_folder) conanfile.folders.set_base_install(test_folder) conanfile.conf = Conf() conanfile.conf["tools.microsoft.msbuild:installation_path"] = "." conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize(settings, EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.compiler = "msvc" conanfile.settings.compiler.version = "193" conanfile.settings.compiler.cppstd = "20" conanfile.settings.os = "Windows" conanfile.settings.arch = "x86_64" msbuild = MSBuildToolchain(conanfile) props_file = os.path.join(test_folder, 'conantoolchain_release_x64.props') msbuild.generate() assert '<LanguageStandard>stdcpp20</LanguageStandard>' in load(props_file)
def test_cpp_info_name_cmakedeps_components(): conanfile = ConanFile(Mock(), None) conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize( Settings({ "os": ["Windows"], "compiler": ["gcc"], "build_type": ["Release"], "arch": ["x86"] }), EnvValues()) cpp_info = CppInfo("mypkg", "dummy_root_folder1") 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.deps_cpp_info.add("mypkg", DepCppInfo(cpp_info)) cmakedeps = CMakeDeps(conanfile) files = cmakedeps.content assert "TARGET GlobakPkgName1::MySuperPkg1" in files[ "ComplexFileName1Config.cmake"] with pytest.raises( ConanException, match="'mypkg' defines information for 'cmake_find_package_multi'" ): with environment_append({CONAN_V2_MODE_ENVVAR: "1"}): _ = cmakedeps.content
def test_msbuild_standard(): settings = Settings({ "build_type": ["Release"], "compiler": { "msvc": { "version": ["19.3"], "cppstd": ["20"] } }, "os": ["Windows"], "arch": ["x86_64"] }) conanfile = ConanFile(Mock(), None) conanfile.folders.set_base_generators(".") conanfile.install_folder = os.getcwd() conanfile.conf = ConfDefinition() conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize(settings, EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.compiler = "msvc" conanfile.settings.compiler.version = "19.3" conanfile.settings.compiler.cppstd = "20" conanfile.settings.os = "Windows" conanfile.settings.arch = "x86_64" msbuild = MSBuildToolchain(conanfile) with mock.patch("conan.tools.microsoft.visual.vcvars_path", mock.MagicMock(return_value=".")): msbuild.generate() assert '<LanguageStandard>stdcpp20</LanguageStandard>' in load( 'conantoolchain_release_x64.props')
def test_msbuild_toolset(): settings = Settings({ "build_type": ["Release"], "compiler": { "msvc": { "version": ["193"], "toolset": [None, "v142_xp"] } }, "os": ["Windows"], "arch": ["x86_64"] }) conanfile = ConanFile(Mock(), None) conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize(settings, EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.compiler = "msvc" conanfile.settings.compiler.version = "193" conanfile.settings.os = "Windows" conanfile.settings.arch = "x86_64" msbuild = MSBuildToolchain(conanfile) assert 'v143' in msbuild.toolset conanfile.settings.compiler.toolset = "v142_xp" msbuild = MSBuildToolchain(conanfile) assert 'v142_xp' in msbuild.toolset
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.settings = conanfile.settings 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") # 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("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_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_msbuildtoolchain_changing_flags_via_attributes(): test_folder = temp_folder() settings = Settings({ "build_type": ["Release"], "compiler": { "msvc": { "version": ["193"], "cppstd": ["20"] } }, "os": ["Windows"], "arch": ["x86_64"] }) conanfile = ConanFile(Mock(), None) conanfile.folders.set_base_generators(test_folder) conanfile.folders.set_base_install(test_folder) conanfile.conf = Conf() conanfile.conf["tools.microsoft.msbuild:installation_path"] = "." conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.settings_build = settings conanfile.initialize(settings, EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.compiler = "msvc" conanfile.settings.compiler.version = "193" conanfile.settings.compiler.cppstd = "20" conanfile.settings.os = "Windows" conanfile.settings.arch = "x86_64" msbuild = MSBuildToolchain(conanfile) msbuild.cxxflags.append("/flag1") msbuild.cflags.append("/flag2") msbuild.ldflags.append("/link1") msbuild.generate() toolchain = load( os.path.join(test_folder, "conantoolchain_release_x64.props")) expected_cl_compile = """ <ClCompile> <PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalOptions>/flag1 /flag2 %(AdditionalOptions)</AdditionalOptions>""" expected_link = """ <Link> <AdditionalOptions>/link1 %(AdditionalOptions)</AdditionalOptions> </Link>""" expected_resource_compile = """ <ResourceCompile> <PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalOptions>/flag1 /flag2 %(AdditionalOptions)</AdditionalOptions> </ResourceCompile>""" assert expected_cl_compile in toolchain assert expected_link in toolchain assert expected_resource_compile in toolchain
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.settings = conanfile.settings 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") # 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)}) 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_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 test_is_msvc(compiler, expected): settings = Settings({ "build_type": ["Release"], "compiler": { compiler: { "version": ["2022"] } }, "os": ["Windows"], "arch": ["x86_64"] }) conanfile = ConanFile(Mock(), None) conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize(settings, EnvValues()) conanfile.settings.compiler = compiler assert is_msvc(conanfile) == expected
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_resource_compile(): test_folder = temp_folder() settings = Settings({ "build_type": ["Release"], "compiler": { "msvc": { "version": ["193"], "cppstd": ["20"] } }, "os": ["Windows"], "arch": ["x86_64"] }) conanfile = ConanFile(Mock(), None) conanfile.folders.set_base_generators(test_folder) conanfile.folders.set_base_install(test_folder) conanfile.conf = Conf() conanfile.conf["tools.microsoft.msbuild:installation_path"] = "." conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.settings_build = settings conanfile.initialize(settings, EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.compiler = "msvc" conanfile.settings.compiler.version = "193" conanfile.settings.compiler.cppstd = "20" conanfile.settings.os = "Windows" conanfile.settings.arch = "x86_64" msbuild = MSBuildToolchain(conanfile) msbuild.preprocessor_definitions["MYTEST"] = "MYVALUE" props_file = os.path.join(test_folder, 'conantoolchain_release_x64.props') msbuild.generate() expected = """ <ResourceCompile> <PreprocessorDefinitions> MYTEST=MYVALUE;%(PreprocessorDefinitions) </PreprocessorDefinitions> <AdditionalOptions> %(AdditionalOptions)</AdditionalOptions> </ResourceCompile>""" props_file = load(props_file) # Remove all blanks and CR to compare props_file = "".join(s.strip() for s in props_file.splitlines()) assert "".join(s.strip() for s in expected.splitlines()) in props_file
def test_cmake_deps_links_flags(): # https://github.com/conan-io/conan/issues/8703 conanfile = ConanFile(Mock(), None) 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") cpp_info.sharedlinkflags = ["/NODEFAULTLIB", "/OTHERFLAG"] cpp_info.exelinkflags = ["/OPT:NOICF"] conanfile.deps_cpp_info.add("mypkg", cpp_info) 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 test_configure_arguments(): tmp = temp_folder() os.chdir(tmp) save_toolchain_args({ "configure_args": "my_configure_args", "make_args": "my_make_args" }) runner = RunnerMock() conanfile = ConanFile(Mock(), runner=runner) conanfile.settings = MockSettings({}) conanfile.folders.set_base_install(tmp) conanfile.folders.set_base_source(tmp) conanfile.conf = Conf() conanfile.conf["tools.gnu:make_program"] = "my_make" conanfile.conf["tools.build:jobs"] = "23" ab = Autotools(conanfile) ab.configure() assert "configure my_configure_args" in runner.command_called ab = Autotools(conanfile) ab.make() assert "my_make my_make_args -j23" in runner.command_called
def test_msbuild_and_intel_cc_props(mode, expected_toolset): test_folder = temp_folder() settings = Settings({ "build_type": ["Release"], "compiler": { "intel-cc": { "version": ["2021.3"], "mode": [mode] }, "msvc": { "version": ["193"], "cppstd": ["20"] } }, "os": ["Windows"], "arch": ["x86_64"] }) conanfile = ConanFile(Mock(), None) conanfile.folders.set_base_generators(test_folder) conanfile.folders.set_base_install(test_folder) conanfile.conf = Conf() conanfile.conf["tools.intel:installation_path"] = "my/intel/oneapi/path" conanfile.conf["tools.microsoft.msbuild:installation_path"] = "." conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize(settings, EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.compiler = "intel-cc" conanfile.settings.compiler.version = "2021.3" conanfile.settings.compiler.mode = mode conanfile.settings.os = "Windows" conanfile.settings.arch = "x86_64" msbuild = MSBuildToolchain(conanfile) props_file = os.path.join(test_folder, 'conantoolchain_release_x64.props') msbuild.generate() assert '<PlatformToolset>%s</PlatformToolset>' % expected_toolset in load( props_file)
def test_apple_cmake_osx_sysroot(os, os_sdk, arch, expected_sdk): """ Testing if CMAKE_OSX_SYSROOT is correctly set. Issue related: https://github.com/conan-io/conan/issues/10275 """ c = ConanFile(Mock(), None) c.settings = "os", "compiler", "build_type", "arch" c.initialize(Settings.loads(get_default_settings_yml()), EnvValues()) c.settings.os = os c.settings.os.sdk = os_sdk c.settings.build_type = "Release" c.settings.arch = arch c.settings.compiler = "apple-clang" c.settings.compiler.version = "13.0" c.settings.compiler.libcxx = "libc++" c.settings.compiler.cppstd = "17" c.conf = Conf() c.folders.set_base_generators(".") c._conan_node = Mock() c._conan_node.dependencies = [] toolchain = CMakeToolchain(c) content = toolchain.content assert 'set(CMAKE_OSX_SYSROOT %s CACHE STRING "" FORCE)' % expected_sdk in 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