-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prototype support for PEP 739 #13945
Draft
FFY00
wants to merge
4
commits into
mesonbuild:master
Choose a base branch
from
FFY00:pep-739-prototype
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9bf5154
python: add a python.build_config option (PEP 739)
FFY00 624b7b1
tests: add test for the Python build config
FFY00 64e51ab
python: move pkg-config discovery introspection logic to PythonPkgCon…
FFY00 f30406d
python: validate python.build_config version and expand relative paths
FFY00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,12 +41,13 @@ def set_program_override(pkg_bin: ExternalProgram, for_machine: MachineChoice) - | |
PkgConfigInterface.pkg_bin_per_machine[for_machine] = pkg_bin | ||
|
||
@staticmethod | ||
def instance(env: Environment, for_machine: MachineChoice, silent: bool) -> T.Optional[PkgConfigInterface]: | ||
def instance(env: Environment, for_machine: MachineChoice, silent: bool, | ||
extra_paths: T.Optional[T.List[str]] = None) -> T.Optional[PkgConfigInterface]: | ||
'''Return a pkg-config implementation singleton''' | ||
for_machine = for_machine if env.is_cross_build() else MachineChoice.HOST | ||
impl = PkgConfigInterface.class_impl[for_machine] | ||
if impl is False: | ||
impl = PkgConfigCLI(env, for_machine, silent, PkgConfigInterface.pkg_bin_per_machine[for_machine]) | ||
impl = PkgConfigCLI(env, for_machine, silent, PkgConfigInterface.pkg_bin_per_machine[for_machine], extra_paths) | ||
if not impl.found(): | ||
impl = None | ||
if not impl and not silent: | ||
|
@@ -55,7 +56,9 @@ def instance(env: Environment, for_machine: MachineChoice, silent: bool) -> T.Op | |
return impl | ||
|
||
@staticmethod | ||
def _cli(env: Environment, for_machine: MachineChoice, silent: bool = False) -> T.Optional[PkgConfigCLI]: | ||
def _cli(env: Environment, for_machine: MachineChoice, | ||
extra_paths: T.Optional[T.List[str]] = None, | ||
silent: bool = False) -> T.Optional[PkgConfigCLI]: | ||
'''Return the CLI pkg-config implementation singleton | ||
Even when we use another implementation internally, external tools might | ||
still need the CLI implementation. | ||
|
@@ -66,15 +69,16 @@ def _cli(env: Environment, for_machine: MachineChoice, silent: bool = False) -> | |
if impl and not isinstance(impl, PkgConfigCLI): | ||
impl = PkgConfigInterface.class_cli_impl[for_machine] | ||
if impl is False: | ||
impl = PkgConfigCLI(env, for_machine, silent, PkgConfigInterface.pkg_bin_per_machine[for_machine]) | ||
impl = PkgConfigCLI(env, for_machine, silent, PkgConfigInterface.pkg_bin_per_machine[for_machine], extra_paths) | ||
if not impl.found(): | ||
impl = None | ||
PkgConfigInterface.class_cli_impl[for_machine] = impl | ||
return T.cast('T.Optional[PkgConfigCLI]', impl) # Trust me, mypy | ||
|
||
@staticmethod | ||
def get_env(env: Environment, for_machine: MachineChoice, uninstalled: bool = False) -> EnvironmentVariables: | ||
cli = PkgConfigInterface._cli(env, for_machine) | ||
def get_env(env: Environment, for_machine: MachineChoice, uninstalled: bool = False, | ||
extra_paths: T.Optional[T.List[str]] = None) -> EnvironmentVariables: | ||
cli = PkgConfigInterface._cli(env, for_machine, extra_paths) | ||
return cli._get_env(uninstalled) if cli else EnvironmentVariables() | ||
|
||
@staticmethod | ||
|
@@ -123,11 +127,13 @@ class PkgConfigCLI(PkgConfigInterface): | |
'''pkg-config CLI implementation''' | ||
|
||
def __init__(self, env: Environment, for_machine: MachineChoice, silent: bool, | ||
pkgbin: T.Optional[ExternalProgram] = None) -> None: | ||
pkgbin: T.Optional[ExternalProgram] = None, | ||
extra_paths: T.Optional[T.List[str]] = None) -> None: | ||
super().__init__(env, for_machine) | ||
self._detect_pkgbin(pkgbin) | ||
if self.pkgbin and not silent: | ||
mlog.log('Found pkg-config:', mlog.green('YES'), mlog.bold(f'({self.pkgbin.get_path()})'), mlog.blue(self.pkgbin_version)) | ||
self.extra_paths = extra_paths or [] | ||
|
||
def found(self) -> bool: | ||
return bool(self.pkgbin) | ||
|
@@ -256,7 +262,7 @@ def _check_pkgconfig(self, pkgbin: ExternalProgram) -> T.Optional[str]: | |
def _get_env(self, uninstalled: bool = False) -> EnvironmentVariables: | ||
env = EnvironmentVariables() | ||
key = OptionKey('pkg_config_path', machine=self.for_machine) | ||
extra_paths: T.List[str] = self.env.coredata.optstore.get_value(key)[:] | ||
extra_paths: T.List[str] = self.env.coredata.optstore.get_value(key)[:] + self.extra_paths | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need the cryptic copy of the first list anymore, right? |
||
if uninstalled: | ||
bpath = self.env.get_build_dir() | ||
if bpath is not None: | ||
|
@@ -295,11 +301,13 @@ def _call_pkgbin(self, args: T.List[str], env: T.Optional[EnvironOrDict] = None) | |
class PkgConfigDependency(ExternalDependency): | ||
|
||
def __init__(self, name: str, environment: Environment, kwargs: T.Dict[str, T.Any], | ||
language: T.Optional[str] = None) -> None: | ||
language: T.Optional[str] = None, | ||
extra_paths: T.Optional[T.List[str]] = None) -> None: | ||
super().__init__(DependencyTypeName('pkgconfig'), environment, kwargs, language=language) | ||
self.name = name | ||
self.is_libtool = False | ||
pkgconfig = PkgConfigInterface.instance(self.env, self.for_machine, self.silent) | ||
self.extra_paths = extra_paths | ||
pkgconfig = PkgConfigInterface.instance(self.env, self.for_machine, self.silent, self.extra_paths) | ||
if not pkgconfig: | ||
msg = f'Pkg-config for machine {self.for_machine} not found. Giving up.' | ||
if self.required: | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I see what you're doing here. You allow a PkgConfigDependency to take an additional PKG_CONFIG_PATH which is joined to the one in the cross file, which also means we don't need to push/pop os.environ.
On the flip side, the way we previously used it was via PKG_CONFIG_LIBDIR which was more narrowly scoped. I suspect this change means we can accidentally fall back to a different python than the one we were searching for (but still the same major.minor version at least)...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah hold on, we anyways fall back to checking for pkg-config without the internal LIBPC which means this is actually doing exactly what we want with one less check. Heh. :)