def test_windows(self): self._uname = None self._version = None with mock.patch("platform.system", mock.MagicMock(return_value='Windows')): with mock.patch.object(OSInfo, "get_win_version_name", return_value="Windows 98"): with mock.patch.object(OSInfo, "get_win_os_version", return_value="4.0"): with remove_from_path("uname"): with remove_from_path("bash"): # FIXME: bug in environment_append removing variables which aren't exist (another PR) new_env = dict() if 'CONAN_BASH_PATH' in os.environ: new_env['CONAN_BASH_PATH'] = None with environment_append(new_env): self.assertTrue(OSInfo().is_windows) self.assertFalse(OSInfo().is_cygwin) self.assertFalse(OSInfo().is_msys) self.assertFalse(OSInfo().is_linux) self.assertFalse(OSInfo().is_freebsd) self.assertFalse(OSInfo().is_macos) self.assertFalse(OSInfo().is_solaris) with self.assertRaises(ConanException): OSInfo.uname() self.assertIsNone( OSInfo.detect_windows_subsystem())
def configure(self, source_folder=None): # TODO: environment? if not self._conanfile.should_configure: return source = self._conanfile.source_folder if source_folder: source = os.path.join(self._conanfile.source_folder, source_folder) build_folder = self._conanfile.build_folder if self._build_folder: build_folder = os.path.join(self._conanfile.build_folder, self._build_folder) defs = {"CMAKE_TOOLCHAIN_FILE": CMakeToolchainBase.filename} mkdir(build_folder) arg_list = join_arguments([ defs_to_string(defs), args_to_string([source]) ]) generator = '-G "{}" '.format(self._generator) if self._generator else "" command = "%s %s%s" % (self._cmake_program, generator, arg_list) is_windows_mingw = platform.system() == "Windows" and self._generator == "MinGW Makefiles" self._conanfile.output.info("CMake command: %s" % command) with chdir(build_folder): if is_windows_mingw: with tools.remove_from_path("sh"): self._conanfile.run(command) else: self._conanfile.run(command)
def configure(self, source_folder=None): # TODO: environment? if not self._conanfile.should_configure: return source = self._conanfile.source_folder if source_folder: source = os.path.join(self._conanfile.source_folder, source_folder) build_folder = self._conanfile.build_folder if self._build_folder: build_folder = os.path.join(self._conanfile.build_folder, self._build_folder) mkdir(build_folder) arg_list = '-DCMAKE_TOOLCHAIN_FILE="{}" -DCMAKE_INSTALL_PREFIX="{}" "{}"'.format( CMakeToolchainBase.filename, self._conanfile.package_folder.replace("\\", "/"), source) generator = '-G "{}" '.format( self._generator) if self._generator else "" command = "%s %s%s" % (self._cmake_program, generator, arg_list) is_windows_mingw = platform.system( ) == "Windows" and self._generator == "MinGW Makefiles" self._conanfile.output.info("CMake command: %s" % command) with chdir(build_folder): if is_windows_mingw: with tools.remove_from_path("sh"): self._conanfile.run(command) else: self._conanfile.run(command)
def test_cmake_multi_find(self): if platform.system() not in ["Windows", "Linux"]: return client = TestClient() conanfile = """from conans import ConanFile, CMake class HelloConan(ConanFile): name = "Hello" version = "0.1" settings = "build_type" exports = '*' def package(self): self.copy(pattern="*", src="%s" % self.settings.build_type) """ client.save({"conanfile.py": conanfile, "Debug/FindHello.cmake": 'message(STATUS "FIND HELLO DEBUG!")', "Release/FindHello.cmake": 'message(STATUS "FIND HELLO RELEASE!")', "RelWithDebInfo/FindHello.cmake": 'message(STATUS "FIND HELLO RELWITHDEBINFO!")', "MinSizeRel/FindHello.cmake": 'message(STATUS "FIND HELLO MINSIZEREL!")' }) client.run("export . lasote/testing") cmake = """set(CMAKE_CXX_COMPILER_WORKS 1) project(MyHello CXX) cmake_minimum_required(VERSION 2.8) include(conanbuildinfo_multi.cmake) conan_basic_setup() find_package(Hello) """ conanfile = """from conans import ConanFile, CMake class HelloConan(ConanFile): requires = "Hello/0.1@lasote/testing" settings = "build_type" generators = "cmake_multi" """ client.save({"conanfile.py": conanfile, "CMakeLists.txt": cmake}, clean_first=True) client.run("install . --build=missing ") client.run("install . -s build_type=Debug --build=missing ") client.run("install . -s build_type=RelWithDebInfo --build=missing ") client.run("install . -s build_type=MinSizeRel --build=missing ") # in Linux it can remove /usr/bin from the path invalidating "cmake" and everything with remove_from_path("sh") if platform.system() == "Windows" else no_op(): generator = "MinGW Makefiles" if platform.system() == "Windows" else "Unix Makefiles" client.run_command('cmake . -G "%s" -DCMAKE_BUILD_TYPE=Debug' % generator) self.assertIn("FIND HELLO DEBUG!", client.out) self.assertNotIn("FIND HELLO RELEASE!", client.out) client.run_command('cmake . -G "%s" -DCMAKE_BUILD_TYPE=Release' % generator) self.assertIn("FIND HELLO RELEASE!", client.out) self.assertNotIn("FIND HELLO DEBUG!", client.out) client.run_command('cmake . -G "%s" -DCMAKE_BUILD_TYPE=RelWithDebInfo' % generator) self.assertIn("FIND HELLO RELWITHDEBINFO!", client.out) client.run_command('cmake . -G "%s" -DCMAKE_BUILD_TYPE=MinSizeRel' % generator) self.assertIn("FIND HELLO MINSIZEREL!", client.out)
def test_windows(self): self._uname = None self._version = None with mock.patch("platform.system", mock.MagicMock(return_value='Windows')): with remove_from_path("uname"): with remove_from_path("bash"): with environment_append({'CONAN_BASH_PATH': None}): self.assertTrue(OSInfo().is_windows) self.assertFalse(OSInfo().is_cygwin) self.assertFalse(OSInfo().is_msys) self.assertFalse(OSInfo().is_linux) self.assertFalse(OSInfo().is_freebsd) self.assertFalse(OSInfo().is_macos) self.assertFalse(OSInfo().is_solaris) with self.assertRaises(ConanException): OSInfo.uname() self.assertIsNone(OSInfo.detect_windows_subsystem())
def configure(self, args=None, defs=None, source_dir=None, build_dir=None, source_folder=None, build_folder=None, cache_build_folder=None, pkg_config_paths=None): # TODO: Deprecate source_dir and build_dir in favor of xxx_folder if not self._conanfile.should_configure: return args = args or [] defs = defs or {} source_dir, self.build_dir = self._get_dirs(source_folder, build_folder, source_dir, build_dir, cache_build_folder) mkdir(self.build_dir) arg_list = join_arguments([ self.command_line, args_to_string(args), defs_to_string(defs), args_to_string([source_dir]) ]) if pkg_config_paths: pkg_env = { "PKG_CONFIG_PATH": os.pathsep.join( get_abs_path(f, self._conanfile.install_folder) for f in pkg_config_paths) } else: # If we are using pkg_config generator automate the pcs location, otherwise it could # read wrong files set_env = "pkg_config" in self._conanfile.generators \ and "PKG_CONFIG_PATH" not in os.environ pkg_env = { "PKG_CONFIG_PATH": self._conanfile.install_folder } if set_env else None with environment_append(pkg_env): command = "cd %s && %s %s" % (args_to_string( [self.build_dir]), self._cmake_program, arg_list) if platform.system( ) == "Windows" and self.generator == "MinGW Makefiles": with tools.remove_from_path("sh"): self._run(command) else: self._run(command)
def cmake_multi_find_test(self): if platform.system() not in ["Windows", "Linux"]: return client = TestClient() conanfile = """from conans import ConanFile, CMake class HelloConan(ConanFile): name = "Hello" version = "0.1" settings = "build_type" exports = '*' def package(self): self.copy(pattern="*", src="%s" % self.settings.build_type) """ client.save({ "conanfile.py": conanfile, "Debug/FindHello.cmake": 'message(STATUS "FIND HELLO DEBUG!")', "Release/FindHello.cmake": 'message(STATUS "FIND HELLO RELEASE!")' }) client.run("export . lasote/testing") cmake = """set(CMAKE_CXX_COMPILER_WORKS 1) project(MyHello CXX) cmake_minimum_required(VERSION 2.8) include(conanbuildinfo_multi.cmake) conan_basic_setup() find_package(Hello) """ conanfile = """from conans import ConanFile, CMake class HelloConan(ConanFile): requires = "Hello/0.1@lasote/testing" settings = "build_type" generators = "cmake_multi" """ client.save({ "conanfile.py": conanfile, "CMakeLists.txt": cmake }, clean_first=True) client.run("install . --build=missing ") client.run("install . -s build_type=Debug --build=missing ") with tools.remove_from_path("sh"): generator = "MinGW Makefiles" if platform.system( ) == "Windows" else "Unix Makefiles" client.runner('cmake . -G "%s" -DCMAKE_BUILD_TYPE=Debug' % generator, cwd=client.current_folder) self.assertIn("FIND HELLO DEBUG!", client.user_io.out) self.assertNotIn("FIND HELLO RELEASE!", client.user_io.out) client.init_dynamic_vars() # to reset output client.runner('cmake . -G "%s" -DCMAKE_BUILD_TYPE=Release' % generator, cwd=client.current_folder) self.assertIn("FIND HELLO RELEASE!", client.user_io.out) self.assertNotIn("FIND HELLO DEBUG!", client.user_io.out)