Skip to content

Commit

Permalink
Use specified output when using ConanFile.run() with bash
Browse files Browse the repository at this point in the history
Fix #5670
  • Loading branch information
taoyouh committed May 19, 2022
1 parent 0a27518 commit 9065f43
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
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
5 changes: 3 additions & 2 deletions conans/client/tools/win.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import pdb
import platform
import re
import subprocess
Expand Down Expand Up @@ -639,7 +640,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 +718,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

0 comments on commit 9065f43

Please sign in to comment.