Skip to content

Commit

Permalink
python dependency: simplify compile args handling
Browse files Browse the repository at this point in the history
We can set it once instead of tangling it inside the guts of the overly
specialized library lookups. It is mostly identical anyway.
  • Loading branch information
eli-schwartz authored and dcbaker committed Feb 22, 2023
1 parent aa69cf0 commit 9bf718f
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions mesonbuild/dependencies/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,24 @@ def __init__(self, name: str, environment: 'Environment',
SystemDependency.__init__(self, name, environment, kwargs)
_PythonDependencyBase.__init__(self, installation, kwargs.get('embed', False))

# link args
if mesonlib.is_windows():
self.find_libpy_windows(environment)
else:
self.find_libpy(environment)

# compile args
inc_paths = mesonlib.OrderedSet([
self.variables.get('INCLUDEPY'),
self.paths.get('include'),
self.paths.get('platinclude')])

self.compile_args += ['-I' + path for path in inc_paths if path]

# https://sourceforge.net/p/mingw-w64/mailman/message/30504611/
if mesonlib.is_windows() and self.get_windows_python_arch() == '64' and self.major_version == 2:
self.compile_args += ['-DMS_WIN64']

def find_libpy(self, environment: 'Environment') -> None:
if self.is_pypy:
if self.major_version == 3:
Expand All @@ -197,13 +210,6 @@ def find_libpy(self, environment: 'Environment') -> None:

self.is_found = largs is not None or not self.link_libpython

inc_paths = mesonlib.OrderedSet([
self.variables.get('INCLUDEPY'),
self.paths.get('include'),
self.paths.get('platinclude')])

self.compile_args += ['-I' + path for path in inc_paths if path]

def get_windows_python_arch(self) -> T.Optional[str]:
if self.platform == 'mingw':
pycc = self.variables.get('CC')
Expand Down Expand Up @@ -287,18 +293,6 @@ def find_libpy_windows(self, env: 'Environment') -> None:
self.is_found = False
return
self.link_args = largs
# Compile args
inc_paths = mesonlib.OrderedSet([
self.variables.get('INCLUDEPY'),
self.paths.get('include'),
self.paths.get('platinclude')])

self.compile_args += ['-I' + path for path in inc_paths if path]

# https://sourceforge.net/p/mingw-w64/mailman/message/30504611/
if pyarch == '64' and self.major_version == 2:
self.compile_args += ['-DMS_WIN64']

self.is_found = True

@staticmethod
Expand Down

0 comments on commit 9bf718f

Please sign in to comment.