Repository: mesonbuild/meson

Issue:
Missing _bootlocale in Windows MSI in meson 0.60.1
When trying to configure any project with meson 0.60.1 on Windows installed from the provided Release MSI, I receive the following error:

```
The Meson build system
Version: 0.60.1
Source dir: C:\src\etx\src
Build dir: C:\src\etx\vbuild2
Build type: native build
Project name: project
Project version: undefined
Traceback (most recent call last):
  File "mesonbuild\mesonmain.py", line 138, in run
  File "mesonbuild\msetup.py", line 294, in run
  File "mesonbuild\msetup.py", line 185, in generate
  File "mesonbuild\msetup.py", line 207, in _generate
  File "mesonbuild\interpreter\interpreter.py", line 297, in __init__
  File "mesonbuild\interpreterbase\interpreterbase.py", line 118, in parse_project
  File "mesonbuild\interpreterbase\interpreterbase.py", line 173, in evaluate_codeblock
  File "mesonbuild\interpreterbase\interpreterbase.py", line 166, in evaluate_codeblock
  File "mesonbuild\interpreterbase\interpreterbase.py", line 179, in evaluate_statement
  File "mesonbuild\interpreterbase\interpreterbase.py", line 454, in function_call
  File "mesonbuild\interpreterbase\decorators.py", line 115, in wrapped
  File "mesonbuild\interpreterbase\decorators.py", line 276, in wrapper
  File "mesonbuild\interpreter\interpreter.py", line 1130, in func_project
  File "mesonbuild\interpreter\interpreter.py", line 1257, in add_languages
  File "mesonbuild\interpreter\interpreter.py", line 1295, in add_languages_for
  File "mesonbuild\compilers\detect.py", line 215, in detect_compiler_for
  File "mesonbuild\compilers\detect.py", line 212, in compiler_from_language
  File "mesonbuild\compilers\detect.py", line 623, in detect_c_compiler
  File "mesonbuild\compilers\detect.py", line 403, in _detect_c_or_cpp_compiler
  File "mesonbuild\mesonlib\universal.py", line 1385, in Popen_safe
  File "locale.py", line 628, in getpreferredencoding
ModuleNotFoundError: No module named '_bootlocale'
```

This happens both with and without --backend=vs. Discovered while testing vs2022, but I don't think the VS version matters as meson does not reach that part of the configuration (and vs2022 works fine with ninja in 0.60.0).

This is a regression from the 0.60.0 Release MSI.


Discussion:
Same for me:
When trying out the basic example found on the meson tutorial page, when running the meson builddir command. I get the following error: ModuleNotFoundError: No module named '_bootlocale'.

The output:

The Meson build system
Version: 0.60.1
Source dir: C:\LEFTOUT\meson_local_target_test_build
Build dir: C:\LEFTOUT\meson_local_target_test_build\builddir
Build type: native build
Project name: meson_local_target_test
Project version: 1.0
Traceback (most recent call last):
  File "mesonbuild\mesonmain.py", line 138, in run
  File "mesonbuild\msetup.py", line 294, in run
  File "mesonbuild\msetup.py", line 185, in generate
  File "mesonbuild\msetup.py", line 207, in _generate
  File "mesonbuild\interpreter\interpreter.py", line 297, in __init__
  File "mesonbuild\interpreterbase\interpreterbase.py", line 118, in parse_project
  File "mesonbuild\interpreterbase\interpreterbase.py", line 173, in evaluate_codeblock
  File "mesonbuild\interpreterbase\interpreterbase.py", line 166, in evaluate_codeblock
  File "mesonbuild\interpreterbase\interpreterbase.py", line 179, in evaluate_statement
  File "mesonbuild\interpreterbase\interpreterbase.py", line 454, in function_call
  File "mesonbuild\interpreterbase\decorators.py", line 115, in wrapped
  File "mesonbuild\interpreterbase\decorators.py", line 276, in wrapper
  File "mesonbuild\interpreter\interpreter.py", line 1130, in func_project
  File "mesonbuild\interpreter\interpreter.py", line 1257, in add_languages
  File "mesonbuild\interpreter\interpreter.py", line 1295, in add_languages_for
  File "mesonbuild\compilers\detect.py", line 215, in detect_compiler_for
  File "mesonbuild\compilers\detect.py", line 212, in compiler_from_language
  File "mesonbuild\compilers\detect.py", line 623, in detect_c_compiler
  File "mesonbuild\compilers\detect.py", line 403, in _detect_c_or_cpp_compiler
  File "mesonbuild\mesonlib\universal.py", line 1385, in Popen_safe
  File "locale.py", line 628, in getpreferredencoding
ModuleNotFoundError: No module named '_bootlocale'
Python version: Python 3.10.0
OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.19041 N/A Build 19041
Have the same problem
'+'
I created a test version with a fix. Could someone try if [this](https://www.dropbox.com/s/ptghny2cjzgyzru/meson-0.60.1.1-64.msi?dl=0) works for them?
Thanks for creating a fix!
I am fine with testing, however I am uncomfortable with downloading an .exe from a dropbox link. If you create a pull request and point me to it I am happy to test it from there.
@jpakkane - _bootlocale issue fixed for me, thank you!


Resolving patch:
diff --git a/packaging/createmsi.py b/packaging/createmsi.py
--- a/packaging/createmsi.py
+++ b/packaging/createmsi.py
@@ -124,11 +124,19 @@ def __init__(self):
         self.final_output = f'meson-{self.version}-64.msi'
         self.staging_dirs = ['dist', 'dist2']
         self.progfile_dir = 'ProgramFiles64Folder'
-        redist_glob = 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Redist\\MSVC\\v*\\MergeModules\\Microsoft_VC142_CRT_x64.msm'
-        trials = glob(redist_glob)
-        if len(trials) != 1:
-            sys.exit('Could not find unique MSM setup:' + '\n'.join(trials))
-        self.redist_path = trials[0]
+        redist_globs = ['C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Redist\\MSVC\\v*\\MergeModules\\Microsoft_VC142_CRT_x64.msm',
+                        'C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Redist\\MSVC\\v*\\MergeModules\\Microsoft_VC143_CRT_x64.msm']
+        redist_path = None
+        for g in redist_globs:
+            trials = glob(g)
+            if len(trials) > 1:
+                sys.exit('MSM glob matched multiple entries:' + '\n'.join(trials))
+            if len(trials) == 1:
+                redist_path = trials[0]
+                break
+        if redist_path is None:
+            sys.exit('No MSMs found.')
+        self.redist_path = redist_path
         self.component_num = 0
         self.feature_properties = {
             self.staging_dirs[0]: {
@@ -173,8 +181,6 @@ def build_dist(self):
                       pyinstaller_tmpdir]
         for m in modules:
             pyinst_cmd += ['--hidden-import', m]
-        # https://github.com/pyinstaller/pyinstaller/issues/5693
-        pyinst_cmd += ['--exclude-module', '_bootlocale']
         pyinst_cmd += ['meson.py']
         subprocess.check_call(pyinst_cmd)
         shutil.move(pyinstaller_tmpdir + '/meson', main_stage)


Test patch: