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

failed to call external command due to encoding issue when meson setup #14069

Open
trim21 opened this issue Jan 4, 2025 · 1 comment
Open
Labels
compilers OS:windows Winodows OS specific issues

Comments

@trim21
Copy link

trim21 commented Jan 4, 2025

Describe the bug
A clear and concise description of what the bug is.

I'm on windows and using chcp 65001, $Env:PYTHONUTF8 = '1' and $Env:PYTHONIOENCODING = 'UTF-8' in powershell, which will make meson failed to setup.

I have clang and msvc both installed, and when running meson setup build it failed with this error:

task: [meson] meson setup build
The Meson build system
Version: 1.6.1
Source dir: C:\Users\Trim21\proj\asio-loop
Build dir: C:\Users\Trim21\proj\asio-loop\build
Build type: native build
Project name: asioloop
Project version: dev
Exception in thread Thread-5 (_readerthread):
Traceback (most recent call last):
  File "C:\Users\Trim21\AppData\Roaming\uv\python\cpython-3.10.16-windows-x86_64-none\lib\threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "C:\Users\Trim21\AppData\Roaming\uv\python\cpython-3.10.16-windows-x86_64-none\lib\threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Trim21\AppData\Roaming\uv\python\cpython-3.10.16-windows-x86_64-none\lib\subprocess.py", line 1515, in _readerthread
    buffer.append(fh.read())
  File "C:\Users\Trim21\AppData\Roaming\uv\python\cpython-3.10.16-windows-x86_64-none\lib\codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xce in position 142: invalid continuation byte
Traceback (most recent call last):
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\mesonmain.py", line 193, in run
    return options.run_func(options)
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\msetup.py", line 365, in run
    app.generate()
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\msetup.py", line 188, in generate
    return self._generate(env, capture, vslite_ctx)
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\msetup.py", line 210, in _generate
    intr = interpreter.Interpreter(b, user_defined_options=user_defined_options)
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\interpreter\interpreter.py", line 322, in __init__
    self.parse_project()
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\interpreterbase\interpreterbase.py", line 129, in parse_project
    self.evaluate_codeblock(self.ast, end=1)
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\interpreterbase\interpreterbase.py", line 195, in evaluate_codeblock
    raise e
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\interpreterbase\interpreterbase.py", line 187, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\interpreterbase\interpreterbase.py", line 201, in evaluate_statement
    return self.function_call(cur)
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\interpreterbase\interpreterbase.py", line 528, in function_call
    res = func(node, func_args, kwargs)
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\interpreterbase\decorators.py", line 237, in wrapper
    return f(*nargs, **wrapped_kwargs)
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\interpreterbase\decorators.py", line 556, in wrapper
    return f(*wrapped_args, **wrapped_kwargs)
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\interpreter\interpreter.py", line 1321, in func_project
    self.add_languages(proj_langs, True, MachineChoice.HOST)
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\interpreter\interpreter.py", line 1490, in add_languages
    success = self.add_languages_for(args, required, for_machine)
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\interpreter\interpreter.py", line 1533, in add_languages_for
    comp = compilers.detect_compiler_for(self.environment, lang, for_machine, skip_sanity_check, self.subproject)
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\compilers\detect.py", line 105, in detect_compiler_for
    comp = compiler_from_language(env, lang, for_machine)
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\compilers\detect.py", line 102, in compiler_from_language
    return lang_map[lang](env, for_machine) if lang in lang_map else None
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\compilers\detect.py", line 616, in detect_cpp_compiler
    return _detect_c_or_cpp_compiler(env, 'cpp', for_machine)
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\compilers\detect.py", line 468, in _detect_c_or_cpp_compiler
    linker = guess_win_linker(env, compiler, cls, version, for_machine, invoked_directly=False)
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\linkers\detect.py", line 72, in guess_win_linker
    if 'LLD' in o.split('\n', maxsplit=1)[0]:
AttributeError: 'NoneType' object has no attribute 'split'

meson.build:1:0: ERROR: Unhandled python exception

    This is a Meson bug and should be reported!
task: Failed to run task "meson": exit status 2

this can be avoided by unset PYTHONUTF8 but it will be default in py315 so there maybe a issue in the future

To Reproduce
Please include your meson.build files, preferably as a minimal toy example showing the issue.
You may need to create simple source code files (don't include private/proprietary code).

I'm really not sure what cause this, and I can't re-produce it in CI.

my meson file is empty with only project meta:

project(
    'asioloop',
    'cpp',
    default_options: [
        'c_std=c11',
        'cpp_std=c++20',
        'buildtype=release',
        'debug=false',
        'default_library=static',
    ],
    meson_version: '>= 1.5.0',
    version: 'dev',
)

Expected behavior
A clear and concise description of what you expected to happen.

it should setup or report meson file missing target or something.

system parameters

  • Is this a cross build or just a plain native build (for the same computer)? no
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.) windows 10
  • what Python version are you using: Python 3.10.16
  • what meson --version 1.6.1
  • what ninja --version if it's a Ninja build: 1.11.1.git.kitware.jobserver-1
@trim21 trim21 changed the title failed to call external command due to encoding issue in meson setup failed to call external command due to encoding issue when meson setup Jan 4, 2025
@eli-schwartz
Copy link
Member

File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\compilers\detect.py", line 468, in _detect_c_or_cpp_compiler
    linker = guess_win_linker(env, compiler, cls, version, for_machine, invoked_directly=False)
  File "C:\Users\Trim21\proj\asio-loop\.venv\lib\site-packages\mesonbuild\linkers\detect.py", line 72, in guess_win_linker
    if 'LLD' in o.split('\n', maxsplit=1)[0]:
AttributeError: 'NoneType' object has no attribute 'split'

meson.build:1:0: ERROR: Unhandled python exception

So, we attempt to figure out what the linker is by running: subprocess.Popen(compiler + check_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) and then .communicate(None)ing to get stdout/stderr, which apparently left us with stdout == None in your case. I'm not sure how that particular result came about. Given that avoiding UTF-8 mode in python worked, we can assume that your compiler/linker wanted to send a result that made python basically freak out when trying to interpret it.

@eli-schwartz eli-schwartz added compilers OS:windows Winodows OS specific issues labels Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compilers OS:windows Winodows OS specific issues
Projects
None yet
Development

No branches or pull requests

2 participants