Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use specified output when using ConanFile.run() with bash #11306

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conans/client/subsystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions conans/client/tools/win.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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)
6 changes: 3 additions & 3 deletions conans/model/conan_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions conans/test/unittests/util/tools_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand Down