Skip to content

Commit 813785b

Browse files
authored
Merge b4e792f into 946b66e
2 parents 946b66e + b4e792f commit 813785b

File tree

6 files changed

+461
-522
lines changed

6 files changed

+461
-522
lines changed

mesonbuild/dependencies/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434
from .scalapack import scalapack_factory
3535
from .misc import (
3636
BlocksDependency, OpenMPDependency, cups_factory, curses_factory, gpgme_factory,
37-
libgcrypt_factory, libwmf_factory, netcdf_factory, pcap_factory, python3_factory,
37+
libgcrypt_factory, libwmf_factory, netcdf_factory, pcap_factory,
3838
shaderc_factory, threads_factory, ThreadDependency, iconv_factory, intl_factory,
3939
dl_factory, openssl_factory, libcrypto_factory, libssl_factory,
4040
)
4141
from .platform import AppleFrameworks
42+
from .python import python_factory as python3_factory
4243
from .qt import qt4_factory, qt5_factory, qt6_factory
4344
from .ui import GnuStepDependency, WxDependency, gl_factory, sdl2_factory, vulkan_factory
4445

@@ -250,7 +251,6 @@ def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.
250251
'curses': curses_factory,
251252
'netcdf': netcdf_factory,
252253
'openmp': OpenMPDependency,
253-
'python3': python3_factory,
254254
'threads': threads_factory,
255255
'pcap': pcap_factory,
256256
'cups': cups_factory,
@@ -268,6 +268,9 @@ def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.
268268
# From platform:
269269
'appleframeworks': AppleFrameworks,
270270

271+
# from python:
272+
'python3': python3_factory,
273+
271274
# From ui:
272275
'gl': gl_factory,
273276
'gnustep': GnuStepDependency,

mesonbuild/dependencies/misc.py

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
# This file contains the detection logic for miscellaneous external dependencies.
1616
from __future__ import annotations
1717

18-
from pathlib import Path
1918
import functools
2019
import re
21-
import sysconfig
2220
import typing as T
2321

2422
from .. import mesonlib
2523
from .. import mlog
26-
from ..environment import detect_cpu_family
2724
from .base import DependencyException, DependencyMethods
2825
from .base import BuiltinDependency, SystemDependency
2926
from .cmake import CMakeDependency
@@ -187,108 +184,6 @@ def __init__(self, environment: 'Environment', kwargs: T.Dict[str, T.Any]) -> No
187184
self.is_found = True
188185

189186

190-
class Python3DependencySystem(SystemDependency):
191-
def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.Any]) -> None:
192-
super().__init__(name, environment, kwargs)
193-
194-
if not environment.machines.matches_build_machine(self.for_machine):
195-
return
196-
if not environment.machines[self.for_machine].is_windows():
197-
return
198-
199-
self.name = 'python3'
200-
# We can only be sure that it is Python 3 at this point
201-
self.version = '3'
202-
self._find_libpy3_windows(environment)
203-
204-
@staticmethod
205-
def get_windows_python_arch() -> T.Optional[str]:
206-
pyplat = sysconfig.get_platform()
207-
if pyplat == 'mingw':
208-
pycc = sysconfig.get_config_var('CC')
209-
if pycc.startswith('x86_64'):
210-
return '64'
211-
elif pycc.startswith(('i686', 'i386')):
212-
return '32'
213-
else:
214-
mlog.log(f'MinGW Python built with unknown CC {pycc!r}, please file a bug')
215-
return None
216-
elif pyplat == 'win32':
217-
return '32'
218-
elif pyplat in {'win64', 'win-amd64'}:
219-
return '64'
220-
mlog.log(f'Unknown Windows Python platform {pyplat!r}')
221-
return None
222-
223-
def get_windows_link_args(self) -> T.Optional[T.List[str]]:
224-
pyplat = sysconfig.get_platform()
225-
if pyplat.startswith('win'):
226-
vernum = sysconfig.get_config_var('py_version_nodot')
227-
if self.static:
228-
libpath = Path('libs') / f'libpython{vernum}.a'
229-
else:
230-
comp = self.get_compiler()
231-
if comp.id == "gcc":
232-
libpath = Path(f'python{vernum}.dll')
233-
else:
234-
libpath = Path('libs') / f'python{vernum}.lib'
235-
lib = Path(sysconfig.get_config_var('base')) / libpath
236-
elif pyplat == 'mingw':
237-
if self.static:
238-
libname = sysconfig.get_config_var('LIBRARY')
239-
else:
240-
libname = sysconfig.get_config_var('LDLIBRARY')
241-
lib = Path(sysconfig.get_config_var('LIBDIR')) / libname
242-
if not lib.exists():
243-
mlog.log('Could not find Python3 library {!r}'.format(str(lib)))
244-
return None
245-
return [str(lib)]
246-
247-
def _find_libpy3_windows(self, env: 'Environment') -> None:
248-
'''
249-
Find python3 libraries on Windows and also verify that the arch matches
250-
what we are building for.
251-
'''
252-
pyarch = self.get_windows_python_arch()
253-
if pyarch is None:
254-
self.is_found = False
255-
return
256-
arch = detect_cpu_family(env.coredata.compilers.host)
257-
if arch == 'x86':
258-
arch = '32'
259-
elif arch == 'x86_64':
260-
arch = '64'
261-
else:
262-
# We can't cross-compile Python 3 dependencies on Windows yet
263-
mlog.log(f'Unknown architecture {arch!r} for',
264-
mlog.bold(self.name))
265-
self.is_found = False
266-
return
267-
# Pyarch ends in '32' or '64'
268-
if arch != pyarch:
269-
mlog.log('Need', mlog.bold(self.name), 'for {}-bit, but '
270-
'found {}-bit'.format(arch, pyarch))
271-
self.is_found = False
272-
return
273-
# This can fail if the library is not found
274-
largs = self.get_windows_link_args()
275-
if largs is None:
276-
self.is_found = False
277-
return
278-
self.link_args = largs
279-
# Compile args
280-
inc = sysconfig.get_path('include')
281-
platinc = sysconfig.get_path('platinclude')
282-
self.compile_args = ['-I' + inc]
283-
if inc != platinc:
284-
self.compile_args.append('-I' + platinc)
285-
self.version = sysconfig.get_config_var('py_version')
286-
self.is_found = True
287-
288-
@staticmethod
289-
def log_tried() -> str:
290-
return 'sysconfig'
291-
292187
class PcapDependencyConfigTool(ConfigToolDependency):
293188

294189
tools = ['pcap-config']
@@ -670,17 +565,6 @@ def shaderc_factory(env: 'Environment',
670565
pkgconfig_name='libpcap',
671566
)
672567

673-
python3_factory = DependencyFactory(
674-
'python3',
675-
[DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM, DependencyMethods.EXTRAFRAMEWORK],
676-
system_class=Python3DependencySystem,
677-
# There is no version number in the macOS version number
678-
framework_name='Python',
679-
# There is a python in /System/Library/Frameworks, but that's python 2.x,
680-
# Python 3 will always be in /Library
681-
extra_kwargs={'paths': ['/Library/Frameworks']},
682-
)
683-
684568
threads_factory = DependencyFactory(
685569
'threads',
686570
[DependencyMethods.SYSTEM, DependencyMethods.CMAKE],

0 commit comments

Comments
 (0)