From 9bf718fcee0d9e30b5de2d6a2f154aa417aa8d4c Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 13 Feb 2023 22:56:48 -0500 Subject: [PATCH] python dependency: simplify compile args handling We can set it once instead of tangling it inside the guts of the overly specialized library lookups. It is mostly identical anyway. --- mesonbuild/dependencies/python.py | 32 +++++++++++++------------------ 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/mesonbuild/dependencies/python.py b/mesonbuild/dependencies/python.py index 11691e5ab..1bbcdfedf 100644 --- a/mesonbuild/dependencies/python.py +++ b/mesonbuild/dependencies/python.py @@ -170,11 +170,24 @@ class PythonSystemDependency(SystemDependency, _PythonDependencyBase): 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: @@ -197,13 +210,6 @@ class PythonSystemDependency(SystemDependency, _PythonDependencyBase): 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') @@ -287,18 +293,6 @@ class PythonSystemDependency(SystemDependency, _PythonDependencyBase): 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