Skip to content

Commit

Permalink
python: add python_build_config property (for cross files)
Browse files Browse the repository at this point in the history
Signed-off-by: Filipe Laíns <[email protected]>
  • Loading branch information
FFY00 committed Jan 20, 2025
1 parent d98836b commit 9b725a1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/markdown/Machine-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions mesonbuild/envconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions mesonbuild/modules/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9b725a1

Please sign in to comment.