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

fix stdout assumptions #12806

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion mesonbuild/mesonmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def run_script_command(script_name, script_args):
return 1

def ensure_stdout_accepts_unicode():
if sys.stdout.encoding and not sys.stdout.encoding.upper().startswith('UTF-'):
if sys.stdout is not None and sys.stdout.encoding and not sys.stdout.encoding.upper().startswith('UTF-'):
sys.stdout.reconfigure(errors='surrogateescape')

def set_meson_command(mainfile):
Expand Down
3 changes: 3 additions & 0 deletions mesonbuild/mlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def _windows_ansi() -> bool:
return bool(kernel.SetConsoleMode(stdout, mode.value | 0x4) or os.environ.get('ANSICON'))

def colorize_console() -> bool:
if sys.stdout is None:
return False

_colorize_console: bool = getattr(sys.stdout, 'colorize_console', None)
if _colorize_console is not None:
return _colorize_console
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/utils/universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ def Popen_safe(args: T.List[str], write: T.Optional[str] = None,
stdin = subprocess.PIPE

try:
if not sys.stdout.encoding or encoding.upper() != 'UTF-8':
if (sys.stdout is not None and not sys.stdout.encoding) or encoding.upper() != 'UTF-8':
p, o, e = Popen_safe_legacy(args, write=write, stdin=stdin, stdout=stdout, stderr=stderr, **kwargs)
else:
p = subprocess.Popen(args, universal_newlines=True, encoding=encoding, close_fds=False,
Expand Down Expand Up @@ -1542,7 +1542,7 @@ def Popen_safe_legacy(args: T.List[str], write: T.Optional[str] = None,
input_ = write.encode('utf-8')
o, e = p.communicate(input_)
if o is not None:
if sys.stdout.encoding is not None:
if sys.stdout is not None and sys.stdout.encoding is not None:
o = o.decode(encoding=sys.stdout.encoding, errors='replace').replace('\r\n', '\n')
else:
o = o.decode(errors='replace').replace('\r\n', '\n')
Expand Down
Loading