From 9b725a1eb843944d53887814777f8ca5b1ab55ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Mon, 20 Jan 2025 21:44:03 +0000 Subject: [PATCH] python: add python_build_config property (for cross files) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe LaĆ­ns --- docs/markdown/Machine-files.md | 2 ++ mesonbuild/envconfig.py | 5 +++++ mesonbuild/modules/python.py | 10 ++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/markdown/Machine-files.md b/docs/markdown/Machine-files.md index 42f288f17951..7734b87115e1 100644 --- a/docs/markdown/Machine-files.md +++ b/docs/markdown/Machine-files.md @@ -251,6 +251,8 @@ section. - `java_home` is an absolute path pointing to the root of a Java installation. - `bindgen_clang_arguments` an array of extra arguments to pass to clang when calling bindgen +- `python_build_config` is a path to the Python build configuration file (PEP 739). + (*new in 1.7.0*) ### CMake variables diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py index 4055b21761c5..7cae57ceb8b1 100644 --- a/mesonbuild/envconfig.py +++ b/mesonbuild/envconfig.py @@ -191,6 +191,11 @@ def get_pkg_config_libdir(self) -> T.Optional[T.List[str]]: assert isinstance(i, str) return res + def get_python_build_config(self) -> T.Optional[str]: + python_build_config = self.properties.get('python_build_config', None) + assert python_build_config is None or isinstance(python_build_config, str) + return python_build_config + def get_cmake_defaults(self) -> bool: if 'cmake_defaults' not in self.properties: return True diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index 53145ab9ee37..78b8b2863c24 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -266,7 +266,10 @@ def _dependency_method_impl(self, kwargs: TYPE_kwargs) -> Dependency: if dep is not None: return dep - build_config = self.interpreter.environment.coredata.get_option(OptionKey('python.build_config')) + build_config = ( + self.interpreter.environment.properties[for_machine].get_python_build_config() + or self.interpreter.environment.coredata.get_option(OptionKey('python.build_config')) + ) new_kwargs = kwargs.copy() new_kwargs['required'] = False @@ -455,7 +458,10 @@ def _get_win_pythonpath(name_or_path: str) -> T.Optional[str]: return None def _find_installation_impl(self, state: 'ModuleState', display_name: str, name_or_path: str, required: bool) -> MaybePythonProg: - build_config = self.interpreter.environment.coredata.get_option(OptionKey('python.build_config')) + build_config = ( + self.interpreter.environment.properties[MachineChoice.BUILD].get_python_build_config() + or self.interpreter.environment.coredata.get_option(OptionKey('python.build_config')) + ) if not name_or_path: python = PythonExternalProgram('python3', mesonlib.python_command, build_config_path=build_config)