def test_apple_isysrootflag(): """Even when no cross building it is adjusted because it could target a Mac version""" conanfile = ConanFileMock() conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"} conanfile.settings_build = MockSettings({ "build_type": "Debug", "os": "Macos", "arch": "x86_64" }) conanfile.settings = MockSettings({ "build_type": "Debug", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) expected = "-isysroot /path/to/sdk" assert be.apple_isysroot_flag == expected env = be.vars() assert expected in env["CXXFLAGS"] assert expected in env["CFLAGS"] assert expected in env["LDFLAGS"] # Only set when crossbuilding conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Debug", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) assert be.apple_isysroot_flag is None
def test_cxx11_abi_define(): conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "gcc", "compiler.libcxx": "libstdc++", "compiler.version": "7.1", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) assert be.gcc_cxx11_abi == "_GLIBCXX_USE_CXX11_ABI=0" env = be.environment() assert "-D_GLIBCXX_USE_CXX11_ABI=0" in env["CPPFLAGS"] conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "gcc", "compiler.libcxx": "libstdc++11", "compiler.version": "7.1", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) env = be.environment() assert be.gcc_cxx11_abi is None assert "-D_GLIBCXX_USE_CXX11_ABI=0" not in env["CPPFLAGS"]
def test_sdk(): conanfile = ConanFileMock() conf = ConfDefinition() conf.loads("tools.apple:sdk_path=mypath") conanfile.conf = conf conanfile.settings = MockSettings({"os": "Macos", "os.sdk": "macosx"}) xcodebuild = XcodeBuild(conanfile) xcodebuild.build("app.xcodeproj") # sdk_path takes preference assert "SDKROOT=mypath " in conanfile.command conf = ConfDefinition() conanfile.conf = conf xcodebuild = XcodeBuild(conanfile) xcodebuild.build("app.xcodeproj") assert "SDKROOT=macosx " in conanfile.command conanfile.settings = MockSettings({ "os": "Macos", "os.sdk": "macosx", "os.sdk_version": "12.1" }) xcodebuild = XcodeBuild(conanfile) xcodebuild.build("app.xcodeproj") assert "SDKROOT=macosx12.1 " in conanfile.command conanfile.settings = MockSettings({}) xcodebuild = XcodeBuild(conanfile) xcodebuild.build("app.xcodeproj") assert "SDKROOT" not in conanfile.command
def test_apple_arch_flag(): conanfile = ConanFileMock() conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"} conanfile.settings_build = MockSettings({ "build_type": "Debug", "os": "Macos", "arch": "x86_64" }) conanfile.settings = MockSettings({ "build_type": "Debug", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) expected = "-arch arm64" assert be.apple_arch_flag == expected env = be.vars() assert expected in env["CXXFLAGS"] assert expected in env["CFLAGS"] assert expected in env["LDFLAGS"] # Only set when crossbuilding conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Debug", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) assert be.apple_arch_flag is None
def test_cppstd(): # Using "cppstd" is discarded conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "gcc", "compiler.libcxx": "libstdc++11", "compiler.version": "7.1", "cppstd": "17" }) be = AutotoolsToolchain(conanfile) env = be.vars() assert "-std=c++17" not in env["CXXFLAGS"] # Using "compiler.cppstd" works conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "gcc", "compiler.libcxx": "libstdc++11", "compiler.version": "7.1", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) env = be.vars() assert "-std=c++17" in env["CXXFLAGS"] # With visual conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "Visual Studio", "compiler.version": "14", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) env = be.vars() assert "/std:c++latest" in env["CXXFLAGS"] # With MSVC conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "msvc", "compiler.version": "193", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) env = be.vars() assert "/std:c++17" in env["CXXFLAGS"]
def test_ndebug(): conanfile = ConanFileMock() for bt in ['Release', 'RelWithDebInfo', 'MinSizeRel']: conanfile.settings = MockSettings({"build_type": bt}) be = AutotoolsToolchain(conanfile) assert be.ndebug == "NDEBUG" env = be.vars() assert "-DNDEBUG" in env["CPPFLAGS"] for bt in ['Debug', 'DebWithDebInfo']: conanfile.settings = MockSettings({"build_type": bt}) be = AutotoolsToolchain(conanfile) assert be.ndebug is None env = be.vars() assert "-DNDEBUG" not in env["CPPFLAGS"]
def test_target_triple(self): conan_file = ConanFileMock() conan_file.deps_cpp_info = self._creat_deps_cpp_info() conan_file.settings = MockSettings({"os_target":"Linux", "arch_target":"x86_64"}) be = AutoToolsBuildEnvironment(conan_file) expected = "x86_64-linux-gnu" self.assertEqual(be.target, expected)
def test_framework_flags_only_for_apple_os(os_): """ Testing GnuDepsFlags attributes exclusively for Apple OS, frameworks and framework_paths """ # Issue: https://github.com/conan-io/conan/issues/10651 # Issue: https://github.com/conan-io/conan/issues/10640 settings = MockSettings({ "build_type": "Release", "compiler": "gcc", "compiler.version": "10.2", "os": os_, "arch": "x86_64" }) conanfile = ConanFileMock() conanfile.settings = settings cpp_info = MagicMock() cpp_info.frameworks = ["Foundation"] cpp_info.frameworkdirs = ["Framework"] gnudepsflags = GnuDepsFlags(conanfile, cpp_info) expected_framework = [] expected_framework_path = [] if is_apple_os(os_): expected_framework = ["-framework Foundation"] expected_framework_path = ["-F Framework"] assert gnudepsflags.frameworks == expected_framework assert gnudepsflags.framework_paths == expected_framework_path
def test_warn_when_no_triplet(self): conan_file = ConanFileMock() conan_file.deps_cpp_info = self._creat_deps_cpp_info() conan_file.settings = MockSettings({"arch": "UNKNOWN_ARCH", "os": "Linux"}) AutoToolsBuildEnvironment(conan_file) self.assertIn("Unknown 'UNKNOWN_ARCH' machine, Conan doesn't know " "how to translate it to the GNU triplet", conan_file.output)
def _get_conanfile(settings, frameworks=False, system_libs=False): conan_file = ConanFileMock() conan_file.settings = settings conan_file.source_folder = "my_cache_source_folder" conan_file.build_folder = "my_cache_build_folder" conan_file.deps_env_info = DepsEnvInfo() conan_file.deps_user_info = DepsUserInfo() conan_file.deps_cpp_info = DepsCppInfo() cpp_info = CppInfo("zlib", "/root") cpp_info.includedirs.append("path/to/include1") cpp_info.libdirs.append("path/to/lib1") cpp_info.libs.append("mylib") cpp_info.bindirs = "path/to/bin1" cpp_info.cflags.append("c_flag1") cpp_info.cxxflags.append("cxx_flag1") cpp_info.defines.append("mydefine1") if system_libs: cpp_info.system_libs.append("system_lib1") if frameworks: cpp_info.frameworks = ["AVFoundation", "VideoToolbox"] cpp_info.frameworkdirs.extend( ['path/to/Frameworks1', 'path/to/Frameworks2']) cpp_info.filter_empty = False conan_file.deps_cpp_info.add("zlib", cpp_info) conan_file.env_info = EnvInfo() return conan_file
def test_conan_run_tests(self): conan_file = ConanFileMock() conan_file.settings = Settings() conan_file.should_test = True meson = Meson(conan_file) with environment_append({"CONAN_RUN_TESTS": "0"}): meson.test() self.assertIsNone(conan_file.command)
def test_check_ms_toolsets(mode, expected): conanfile = ConanFileMock() conanfile.settings = MockSettings({ "compiler.version": "2021.3", "compiler.mode": mode, "os": "Windows" }) assert IntelCC(conanfile).ms_toolset == expected
def test_invalid_target_triple(): conanfile = ConanFileMock() conanfile.settings = MockSettings({"os": "Linux", "arch": "UNKNOWN_ARCH"}) conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"}) with pytest.raises(ConanException) as excinfo: AutotoolsToolchain(conanfile) assert "Unknown 'UNKNOWN_ARCH' machine, Conan doesn't know how " \ "to translate it to the GNU triplet," in str(excinfo)
def test_classic_compiler_supports_every_os(os_): conanfile = ConanFileMock() conanfile.settings = MockSettings({ "compiler.version": "2021.3", "compiler.mode": "classic", "os": os_, "arch": "x86_64" }) assert IntelCC(conanfile).arch == "x86_64"
def test_sdk_path(): conanfile = ConanFileMock() conf = ConfDefinition() conf.loads("tools.apple:sdk_path=mypath") conanfile.conf = conf conanfile.settings = MockSettings({}) xcodebuild = XcodeBuild(conanfile) xcodebuild.build("app.xcodeproj") assert "SDKROOT=mypath " in conanfile.command
def test_nmake_no_parallel(self): conan_file = ConanFileMock() conan_file.deps_cpp_info = self._creat_deps_cpp_info() conan_file.settings = Settings() be = AutoToolsBuildEnvironment(conan_file) be.make(make_program="nmake") assert "-j" not in conan_file.command be.make(make_program="make") assert "-j" in conan_file.command
def test_conf_skip_test(self): conf = ConfDefinition() conf.loads("tools.build:skip_test=1") conanfile = ConanFileMock() conanfile.settings = Settings() conanfile.conf = conf.get_conanfile_conf(None) meson = Meson(conanfile) meson.test() self.assertIsNone(conanfile.command)
def setUpClass(cls): conanfile = ConanFileMock() conanfile.settings = MockSettings({ "compiler": "gcc", "build_type": "Release" }) cls.generator = VirtualBuildEnvGenerator(conanfile) cls.generator.output_path = "not-used" cls.result = cls.generator.content
def test_package_manager_distro(distro, tool): with mock.patch("platform.system", return_value="Linux"): with mock.patch("distro.id", return_value=distro): with mock.patch('conans.ConanFile.context', new_callable=PropertyMock) as context_mock: context_mock.return_value = "host" conanfile = ConanFileMock() conanfile.settings = Settings() manager = _SystemPackageManagerTool(conanfile) assert tool == manager.get_default_tool()
def test_vs_generator(self): settings = MockSettings({"os": "Windows", "arch": "x86_64", "compiler": "Visual Studio"}) conanfile = ConanFileMock() conanfile.settings = settings settings.values['compiler.version'] = '15' assert get_generator(conanfile) == 'Visual Studio 15 2017' settings.values['compiler.version'] = '15.9' assert get_generator(conanfile) == 'Visual Studio 15 2017'
def test_error_if_detected_intel_legacy_version(os_): conanfile = ConanFileMock() conanfile.settings = MockSettings({ "compiler.version": "19.1", "compiler.mode": "classic", "os": os_ }) with pytest.raises(ConanException) as excinfo: IntelCC(conanfile) assert "You have to use 'intel' compiler which is meant for legacy" in str( excinfo.value)
def test_msys2(): with mock.patch("platform.system", return_value="Windows"): with mock.patch('conans.ConanFile.context', new_callable=PropertyMock) as context_mock: context_mock.return_value = "host" conanfile = ConanFileMock() conanfile.conf = Conf() conanfile.settings = Settings() conanfile.conf["tools.microsoft.bash:subsystem"] = "msys2" manager = _SystemPackageManagerTool(conanfile) assert manager.get_default_tool() == "pacman"
def test_tools_check(tool_class, result): conanfile = ConanFileMock() conanfile.conf = Conf() conanfile.settings = Settings() conanfile.conf["tools.system.package_manager:tool"] = tool_class.tool_name with mock.patch('conans.ConanFile.context', new_callable=PropertyMock) as context_mock: context_mock.return_value = "host" tool = tool_class(conanfile) tool.check(["package"]) assert tool._conanfile.command == result
def test_no_prefix(self): conan_file = ConanFileMock() conan_file.deps_cpp_info = MockDepsCppInfo() conan_file.settings = Settings() meson = Meson(conan_file) meson.configure() self.assertNotIn('-Dprefix', conan_file.command) meson.build() self.assertIn("ninja -C", conan_file.command) with self.assertRaises(TypeError): meson.install()
def test_sudo_str(sudo, sudo_askpass, expected_str): conanfile = ConanFileMock() conanfile.conf = Conf() conanfile.settings = Settings() conanfile.conf["tools.system.package_manager:sudo"] = sudo conanfile.conf["tools.system.package_manager:sudo_askpass"] = sudo_askpass with mock.patch('conans.ConanFile.context', new_callable=PropertyMock) as context_mock: context_mock.return_value = "host" apt = Apt(conanfile) assert apt.sudo_str == expected_str
def test_vs_generator(compiler, version, expected): settings = MockSettings({ "os": "Windows", "arch": "x86_64", "compiler": compiler }) conanfile = ConanFileMock() conanfile.settings = settings settings.values['compiler.version'] = version assert get_generator(conanfile) == expected
def test_macos_not_supported_for_new_compilers(mode): conanfile = ConanFileMock() conanfile.settings = MockSettings({ "compiler.version": "2021.3", "compiler.mode": mode, "os": "Darwin" }) with pytest.raises(ConanException) as excinfo: IntelCC(conanfile) assert "macOS* is not supported for the icx/icpx or dpcpp compilers." in str( excinfo.value)
def test_partial_build(self): conan_file = ConanFileMock() conan_file.deps_cpp_info = self._creat_deps_cpp_info() conan_file.settings = Settings() be = AutoToolsBuildEnvironment(conan_file) conan_file.should_configure = False conan_file.should_build = False conan_file.should_install = False be.configure() self.assertIsNone(conan_file.command) be.make() self.assertIsNone(conan_file.command)
def prefix_test(self): conan_file = ConanFileMock() conan_file.deps_cpp_info = MockDepsCppInfo() conan_file.settings = Settings() conan_file.package_folder = os.getcwd() expected_prefix = '-Dprefix="%s"' % os.getcwd() meson = Meson(conan_file) meson.configure() self.assertIn(expected_prefix, conan_file.command) meson.build() self.assertIn("ninja -C", conan_file.command) meson.install() self.assertIn("ninja -C", conan_file.command)
def test_build_folder_vars(self, conan_os, expected_os): settings = MockSettings({ "os": conan_os, "compiler": "apple-clang", "compiler.version": "11.0", "arch": "ios_fat" }) conanfile = ConanFileMock() conanfile.settings = settings cmake = CMake(conanfile) self.assertNotIn("CMAKE_OSX_ARCHITECTURES", cmake.definitions) self.assertIn(expected_os, cmake.definitions["CMAKE_OSX_SYSROOT"])