diff --git a/conans/client/subsystems.py b/conans/client/subsystems.py index 1ad48867795..f152dac0061 100644 --- a/conans/client/subsystems.py +++ b/conans/client/subsystems.py @@ -13,7 +13,7 @@ SFU = 'sfu' # Windows Services for UNIX -def run_in_windows_bash(conanfile, command, cwd=None, env="conanbuild"): +def run_in_windows_bash(conanfile, command, cwd=None, env="conanbuild", output=True): from conan.tools.env import Environment from conan.tools.env.environment import environment_wrap_command """ Will run a unix command inside a bash terminal It requires to have MSYS2, CYGWIN, or WSL""" @@ -74,7 +74,7 @@ def run_in_windows_bash(conanfile, command, cwd=None, env="conanbuild"): wrapped_shell=wrapped_shell, inside_command=inside_command) conanfile.output.info('Running in windows bash: %s' % final_command) - return conanfile._conan_runner(final_command, output=conanfile.output, subprocess=True) + return conanfile._conan_runner(final_command, output=output, subprocess=True) def escape_windows_cmd(command): diff --git a/conans/client/tools/win.py b/conans/client/tools/win.py index 618cd8a842b..0ccbaee9dd3 100644 --- a/conans/client/tools/win.py +++ b/conans/client/tools/win.py @@ -639,7 +639,7 @@ def unix_path(path, path_flavor=None): def run_in_windows_bash(conanfile, bashcmd, cwd=None, subsystem=None, msys_mingw=True, env=None, - with_login=True): + with_login=True, output=True): """ Will run a unix command inside a bash terminal It requires to have MSYS2, CYGWIN, or WSL """ @@ -717,4 +717,4 @@ def get_path_value(container, subsystem_name): # https://github.com/conan-io/conan/issues/2839 (subprocess=True) with environment_append(normalized_env): - return conanfile._conan_runner(wincmd, output=conanfile.output, subprocess=True) + return conanfile._conan_runner(wincmd, output=output, subprocess=True) diff --git a/conans/model/conan_file.py b/conans/model/conan_file.py index ab60a3c14b6..c731790405f 100644 --- a/conans/model/conan_file.py +++ b/conans/model/conan_file.py @@ -382,14 +382,14 @@ def run(self, command, output=True, cwd=None, win_bash=False, subsystem=None, ms # NOTE: "self.win_bash" is the new parameter "win_bash" for Conan 2.0 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) + msys_mingw=msys_mingw, with_login=with_login, + output=output) elif self.win_bash: # New, Conan 2.0 from conans.client.subsystems import run_in_windows_bash - return run_in_windows_bash(self, command=cmd, cwd=cwd, env=_env) + return run_in_windows_bash(self, command=cmd, cwd=cwd, env=_env, output=output) from conan.tools.env.environment import environment_wrap_command if env: wrapped_cmd = environment_wrap_command(_env, cmd, cwd=self.generators_folder) diff --git a/conans/test/unittests/util/tools_test.py b/conans/test/unittests/util/tools_test.py index 2be7e00e8e2..24f7e2ba317 100644 --- a/conans/test/unittests/util/tools_test.py +++ b/conans/test/unittests/util/tools_test.py @@ -365,6 +365,7 @@ class MyRun(object): def __call__(self, command, output, log_filepath=None, cwd=None, subprocess=False): # @UnusedVariable self.command = command + self.output = output self._conan_runner = MyRun() conanfile = MockConanfile() @@ -373,6 +374,11 @@ def __call__(self, command, output, log_filepath=None, self.assertIn("bash", conanfile._conan_runner.command) self.assertIn("--login -c", conanfile._conan_runner.command) self.assertIn("^&^& a_command.bat ^", conanfile._conan_runner.command) + self.assertTrue(conanfile._conan_runner.output) + + output = sys.stdout + tools.run_in_windows_bash(conanfile, "a_command.bat", subsystem="cygwin", output=output) + self.assertEqual(output, conanfile._conan_runner.output) with tools.environment_append({"CONAN_BASH_PATH": "path\\to\\mybash.exe"}): tools.run_in_windows_bash(conanfile, "a_command.bat", subsystem="cygwin")