mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.62k stars 1.63k forks source link

meson_log.txt is garbled #13592

Open ShimYama opened 2 months ago

ShimYama commented 2 months ago

Describe the bug Characters in meson_log.txt are garbled.

To Reproduce

  1. Create a hello world project.

hello.c

#include <stdio.h>
int main() {
    printf("Hello world!\n");
}

meson.build

project('helloworld', 'c')
executable('hello', 'hello.c')
  1. Run meson build --backend vs
    
    > meson build --backend vs
    The Meson build system
    Version: 1.5.1
    Source dir: E:\Develop\mesontest
    Build dir: E:\Develop\mesontest\build
    Build type: native build
    Project name: helloworld
    Project version: undefined
    Activating VS 17.9.7
    C compiler for the host machine: cl (msvc 19.39.33523 "Microsoft(R) C/C++ Optimizing Compiler Version 19.39.33523 for x64")
    C linker for the host machine: link link 14.39.33523.0
    Auto detected Visual Studio backend: vs2022
    Host machine cpu family: x86_64
    Host machine cpu: x86_64
    Build targets in project: 1

helloworld undefined

User defined options backend: vs

WARNING: Running the setup command as meson [options] instead of meson setup [options] is ambiguous and deprecated.



3. I get this log file.
[meson-log.txt](https://github.com/user-attachments/files/16719813/meson-log.txt)

**Expected behavior**
meson-log.txt with no garble characters.

**system parameters**
- OS: Windows 10
- Python version: 3.11.0
- meson version: 1.5.1
- ninja version: 1.10.2
eli-schwartz commented 2 months ago

It is reporting that the output of cl /? is garbled!

Question is, what could or should we do about making cl.exe produce output which is more useful for our logging. Given configuration succeeds I wonder whether we actually need to do anything here though. The log file does accurately describe the information it used to detect the compiler...

AHSauge commented 2 months ago

Not that I've looked at in any detail, but just from the log file, this has mixed-up character encoding all over it. My hunch is that the Windows terminal has some fun multi-byte code page that's not UTF-8 or UTF-16, and it's not correctly transcoded to whatever Python and meson is using (please let that be UTF-8, or at least UTF-something :pray:).

@ShimYama Would it be correct to assume that both your Windows and Visual Studio is in Japanese? If so, do you happen to know whether Shift JIS, ISO-2022-JP or EUC-JP is being used by default in the Windows terminal or Visual Studio?

This isn't me saying I'll go fix it (...but I might have a quick peek at it later), but I assume this will be immensely helpful for whoever tries to look at it.

@eli-schwartz I haven't looked a single line of code here, but could it be that there's no code checking the character encoding of the terminal? If so, then this might honestly not be that difficult to fix.

ShimYama commented 1 month ago

@ShimYama Would it be correct to assume that both your Windows and Visual Studio is in Japanese? If so, do you happen to know whether Shift JIS, ISO-2022-JP or EUC-JP is being used by default in the Windows terminal or Visual Studio?

I checked my command prompt and Visual Studio Developer Command Prompt and it uses Shift-JIS by default.

> chcp
現在のコード ページ: 932

I switched encoding to UTF-8 by running this command.

> chcp 65001
Active code page: 65001

Then run meson again, I got correct log text file. meson-log.txt

ref. https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers