aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-02-11 14:48:30 -0500
committerEli Schwartz <eschwartz@archlinux.org>2022-02-15 16:50:41 -0500
commit6240920c213fb76b4e4be8b6b59ae3346cbbcf77 (patch)
tree33ea225046c625f5942cf1972df9e52a17992482 /mesonbuild
parent2d56ff135e6e0f3cdf455797a6561796a8c1b7b4 (diff)
downloadmeson-6240920c213fb76b4e4be8b6b59ae3346cbbcf77.zip
meson-6240920c213fb76b4e4be8b6b59ae3346cbbcf77.tar.gz
meson-6240920c213fb76b4e4be8b6b59ae3346cbbcf77.tar.bz2
pkgconfig module: allow custom variables to reference builtin directories
Automatically generate additional variables and write them into the generated pkg-config file. This means projects no longer need to manually define the ones they use, which is annoying for dataonly usages (it used to forbid setting the base library-relevant "reserved" ones, and now allows it only for dataonly. But it's bloat to manualy list them anyway). It also fixes a regression in commit 248e6cf4736ef9ec636228da66c28f9be03aa74f which caused libdir to not be set, and to be unsettable, if the pkg-config file has no libraries but uses the ${libdir} expansion in a custom variable. This could be considered likely a case for dataonly, but it's not guaranteed.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/modules/pkgconfig.py57
1 files changed, 46 insertions, 11 deletions
diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py
index 2e985cf..f67e6eb 100644
--- a/mesonbuild/modules/pkgconfig.py
+++ b/mesonbuild/modules/pkgconfig.py
@@ -22,8 +22,9 @@ from .. import build
from .. import dependencies
from .. import mesonlib
from .. import mlog
+from ..coredata import BUILTIN_DIR_OPTIONS
from ..dependencies import ThreadDependency
-from ..interpreterbase import permittedKwargs, FeatureNew, FeatureNewKwargs
+from ..interpreterbase import permittedKwargs, FeatureNew, FeatureDeprecated, FeatureNewKwargs
if T.TYPE_CHECKING:
from . import ModuleState
@@ -329,6 +330,41 @@ class PkgConfigModule(ExtensionModule):
url, version, pcfile, conflicts, variables,
unescaped_variables, uninstalled=False, dataonly=False):
coredata = state.environment.get_coredata()
+ referenced_vars = set()
+ optnames = [x.name for x in BUILTIN_DIR_OPTIONS.keys()]
+
+ if not dataonly:
+ # includedir is always implied, although libdir may not be
+ # needed for header-only libraries
+ referenced_vars |= {'prefix', 'includedir'}
+ if deps.pub_libs or deps.priv_libs:
+ referenced_vars |= {'libdir'}
+ # also automatically infer variables referenced in other variables
+ implicit_vars_warning = False
+ redundant_vars_warning = False
+ varnames = set()
+ varstrings = set()
+ for k, v in variables + unescaped_variables:
+ varnames |= {k}
+ varstrings |= {v}
+ for optname in optnames:
+ optvar = f'${{{optname}}}'
+ if any(x.startswith(optvar) for x in varstrings):
+ if optname in varnames:
+ redundant_vars_warning = True
+ else:
+ # these 3 vars were always "implicit"
+ if dataonly or optname not in {'prefix', 'includedir', 'libdir'}:
+ implicit_vars_warning = True
+ referenced_vars |= {'prefix', optname}
+ if redundant_vars_warning:
+ FeatureDeprecated.single_use('pkgconfig.generate variable for builtin directories', '0.62.0',
+ state.subproject, 'They will be automatically included when referenced',
+ state.current_node)
+ if implicit_vars_warning:
+ FeatureNew.single_use('pkgconfig.generate implicit variable for builtin directories', '0.62.0',
+ state.subproject, location=state.current_node)
+
if uninstalled:
outdir = os.path.join(state.environment.build_dir, 'meson-uninstalled')
if not os.path.exists(outdir):
@@ -338,18 +374,17 @@ class PkgConfigModule(ExtensionModule):
else:
outdir = state.environment.scratch_dir
prefix = PurePath(coredata.get_option(mesonlib.OptionKey('prefix')))
- # These always return paths relative to prefix
- libdir = PurePath(coredata.get_option(mesonlib.OptionKey('libdir')))
- incdir = PurePath(coredata.get_option(mesonlib.OptionKey('includedir')))
fname = os.path.join(outdir, pcfile)
with open(fname, 'w', encoding='utf-8') as ofile:
- if not dataonly:
- ofile.write('prefix={}\n'.format(self._escape(prefix)))
- if uninstalled:
- ofile.write('srcdir={}\n'.format(self._escape(srcdir)))
- if deps.pub_libs or deps.priv_libs:
- ofile.write('libdir={}\n'.format(self._escape('${prefix}' / libdir)))
- ofile.write('includedir={}\n'.format(self._escape('${prefix}' / incdir)))
+ for optname in optnames:
+ if optname in referenced_vars - varnames:
+ if optname == 'prefix':
+ ofile.write('prefix={}\n'.format(self._escape(prefix)))
+ else:
+ dirpath = PurePath(coredata.get_option(mesonlib.OptionKey(optname)))
+ ofile.write('{}={}\n'.format(optname, self._escape('${prefix}' / dirpath)))
+ if uninstalled and not dataonly:
+ ofile.write('srcdir={}\n'.format(self._escape(srcdir)))
if variables or unescaped_variables:
ofile.write('\n')
for k, v in variables: