def test_run_in_bash(self): class MockConanfile(object): def __init__(self): self.output = namedtuple("output", "info")( lambda x: None) # @UnusedVariable self.env = {"PATH": "/path/to/somewhere"} class MyRun(object): def __call__(self, command, output, log_filepath=None, cwd=None, subprocess=False): # @UnusedVariable self.command = command self._conan_runner = MyRun() conanfile = MockConanfile() with patch.object(OSInfo, "bash_path", return_value='bash'): tools.run_in_windows_bash(conanfile, "a_command.bat", subsystem="cygwin") self.assertIn("bash", conanfile._conan_runner.command) self.assertIn("--login -c", conanfile._conan_runner.command) self.assertIn("^&^& a_command.bat ^", conanfile._conan_runner.command) with tools.environment_append( {"CONAN_BASH_PATH": "path\\to\\mybash.exe"}): tools.run_in_windows_bash(conanfile, "a_command.bat", subsystem="cygwin") self.assertIn('path\\to\\mybash.exe --login -c', conanfile._conan_runner.command) with tools.environment_append( {"CONAN_BASH_PATH": "path with spaces\\to\\mybash.exe"}): tools.run_in_windows_bash(conanfile, "a_command.bat", subsystem="cygwin", with_login=False) self.assertIn('"path with spaces\\to\\mybash.exe" -c', conanfile._conan_runner.command) # try to append more env vars conanfile = MockConanfile() with patch.object(OSInfo, "bash_path", return_value='bash'): tools.run_in_windows_bash(conanfile, "a_command.bat", subsystem="cygwin", env={ "PATH": "/other/path", "MYVAR": "34" }) self.assertIn( '^&^& PATH=\\^"/cygdrive/other/path:/cygdrive/path/to/somewhere:$PATH\\^" ' '^&^& MYVAR=34 ^&^& a_command.bat ^', conanfile._conan_runner.command)
def _run(): if not win_bash: return self._conan_runner(command, output, os.path.abspath(RUN_LOG_NAME), cwd) # FIXME: run in windows bash is not using output return tools.run_in_windows_bash(self, bashcmd=command, cwd=cwd, subsystem=subsystem, msys_mingw=msys_mingw)
def _run(cmd, _env): # FIXME: run in windows bash is not using output if platform.system() == "Windows": if win_bash: return tools.run_in_windows_bash(self, bashcmd=cmd, cwd=cwd, subsystem=subsystem, msys_mingw=msys_mingw, with_login=with_login) elif self.win_bash: # New, Conan 2.0 from conan.tools.microsoft.subsystems import run_in_windows_bash return run_in_windows_bash(self, command=cmd, cwd=cwd, env=_env) if _env is None: _env = "conanbuild" from conan.tools.env.environment import environment_wrap_command wrapped_cmd = environment_wrap_command(_env, cmd, cwd=self.generators_folder) return self._conan_runner(wrapped_cmd, output, os.path.abspath(RUN_LOG_NAME), cwd)
def _run(cmd, _env): # FIXME: run in windows bash is not using output if platform.system() == "Windows": if win_bash: return tools.run_in_windows_bash(self, bashcmd=cmd, cwd=cwd, subsystem=subsystem, msys_mingw=msys_mingw, with_login=with_login) envfiles_folder = self.generators_folder or os.getcwd() _env = [_env] if _env and isinstance(_env, str) else [] wrapped_cmd = command_env_wrapper(self, cmd, _env, envfiles_folder=envfiles_folder) return self._conan_runner(wrapped_cmd, output, os.path.abspath(RUN_LOG_NAME), cwd)