From bf9314e00dde4160b1022168cff91e09c868935c Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Tue, 17 Oct 2023 10:36:19 -0400 Subject: [PATCH] pkgconfig: Allow setting both pkgconfig and pkg-config This was previously allowed for different usage. Keep allowing it, but with non fatal deprecation notice, and ignore the value from legacy pkgconfig. --- .../pkgconfig_deprecated_machine_file.md | 10 ++++++++++ mesonbuild/envconfig.py | 19 ++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 docs/markdown/snippets/pkgconfig_deprecated_machine_file.md diff --git a/docs/markdown/snippets/pkgconfig_deprecated_machine_file.md b/docs/markdown/snippets/pkgconfig_deprecated_machine_file.md new file mode 100644 index 000000000000..36647e90e844 --- /dev/null +++ b/docs/markdown/snippets/pkgconfig_deprecated_machine_file.md @@ -0,0 +1,10 @@ +## Machine files: `pkgconfig` field deprecated and replaced by `pkg-config` + +Meson used to allow both `pkgconfig` and `pkg-config` entries in machine files, +the former was used for `dependency()` lookup and the latter was used as return +value for `find_program('pkg-config')`. + +This inconsistency is now fixed by deprecating `pkgconfig` in favor of +`pkg-config` which matches the name of the binary. For backward compatibility +it is still allowed to define both with the same value, in that case no +deprecation warning is printed. diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py index 5621b99feff8..07f1229e3065 100644 --- a/mesonbuild/envconfig.py +++ b/mesonbuild/envconfig.py @@ -404,12 +404,21 @@ def __init__( if not isinstance(command, (list, str)): raise mesonlib.MesonException( f'Invalid type {command!r} for entry {name!r} in cross file') - if name == 'pkgconfig': - if 'pkg-config' in binaries: - raise mesonlib.MesonException('Both pkgconfig and pkg-config entries in machine file.') - mlog.deprecation('"pkgconfig" entry is deprecated and should be replaced by "pkg-config"') - name = 'pkg-config' self.binaries[name] = mesonlib.listify(command) + if 'pkgconfig' in self.binaries: + if 'pkg-config' not in self.binaries: + mlog.deprecation('"pkgconfig" entry is deprecated and should be replaced by "pkg-config"', fatal=False) + self.binaries['pkg-config'] = self.binaries['pkgconfig'] + elif self.binaries['pkgconfig'] != self.binaries['pkg-config']: + raise mesonlib.MesonException('Mismatched pkgconfig and pkg-config binaries in the machine file.') + else: + # Both are defined with the same value, this is allowed + # for backward compatibility. + # FIXME: We should still print deprecation warning if the + # project targets Meson >= 1.3.0, but we have no way to know + # that here. + pass + del self.binaries['pkgconfig'] @staticmethod def detect_ccache() -> T.List[str]: