aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorChun-wei Fan <fanchunwei@src.gnome.org>2022-04-25 12:50:13 +0800
committerJussi Pakkanen <jpakkane@gmail.com>2022-05-02 02:45:51 +0300
commit99ad11bd9c3249f548dda0b275d9f8dd1b3f6d14 (patch)
tree1e60c04575a69a902bc34ce0b82e303643494fc6 /mesonbuild
parent17f5d0cffb9c40fec292244894b909ace4ea08ed (diff)
downloadmeson-99ad11bd9c3249f548dda0b275d9f8dd1b3f6d14.zip
meson-99ad11bd9c3249f548dda0b275d9f8dd1b3f6d14.tar.gz
meson-99ad11bd9c3249f548dda0b275d9f8dd1b3f6d14.tar.bz2
Windows: Improve Python 3.8+ module check on Windows
On Python 3.8.x and later, if the imported module requires non-system DLLs that are not installed nor bundled with the module package, os.add_dll_directory() must be called on every path that contains the required DLLs, so that the module can be imported successfully by Python. Make things easier for people by calling os.add_dll_directory() on the valid directories in %PATH%, so that such module checks can be carried out successfully with much less manual intervention.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/modules/python.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
index 1147945..324dfc8 100644
--- a/mesonbuild/modules/python.py
+++ b/mesonbuild/modules/python.py
@@ -727,10 +727,22 @@ class PythonModule(ExtensionModule):
found_modules: T.List[str] = []
missing_modules: T.List[str] = []
if python.found() and want_modules:
+ # Python 3.8.x or later require add_dll_directory() to be called on Windows if
+ # the needed modules require external DLLs that are not bundled with the modules.
+ # Simplify things by calling add_dll_directory() on the paths in %PATH%
+ add_paths_cmd = ''
+ if hasattr(os, 'add_dll_directory'):
+ add_paths_cmds = []
+ paths = os.environ['PATH'].split(os.pathsep)
+ for path in paths:
+ if path != '' and os.path.isdir(path):
+ add_paths_cmds.append(f'os.add_dll_directory({path!r})')
+ add_paths_cmd = 'import os;' + ';'.join(reversed(add_paths_cmds)) + ';'
+
for mod in want_modules:
p, *_ = mesonlib.Popen_safe(
python.command +
- ['-c', f'import {mod}'])
+ ['-c', f'{add_paths_cmd}import {mod}'])
if p.returncode != 0:
missing_modules.append(mod)
else: