dependencies: Add command line option for pkg_config_path

This creates a new command line option to store pkg_config_path into,
and store the environment variable into that option. Currently this
works like the environment variable, for both cross and native targets.
pull/4931/head
Dylan Baker 6 years ago
parent 25eb86382b
commit 569e646e1e
  1. 8
      mesonbuild/coredata.py
  2. 11
      mesonbuild/dependencies/base.py
  3. 8
      mesonbuild/msetup.py
  4. 7
      run_unittests.py
  5. 7
      test cases/unit/55 pkg_config_path option/extra_path/totally_made_up_dep.pc
  6. 3
      test cases/unit/55 pkg_config_path option/meson.build

@ -270,7 +270,6 @@ class CoreData:
self.cross_compilers = OrderedDict()
self.deps = OrderedDict()
# Only to print a warning if it changes between Meson invocations.
self.pkgconf_envvar = os.environ.get('PKG_CONFIG_PATH', '')
self.config_files = self.__load_config_files(options.native_file)
self.libdir_cross_fixup()
@ -504,6 +503,12 @@ class CoreData:
# languages and setting the backend (builtin options must be set first
# to know which backend we'll use).
options = {}
# Some options default to environment variables if they are
# unset, set those now. These will either be overwritten
# below, or they won't.
options['pkg_config_path'] = os.environ.get('PKG_CONFIG_PATH', '').split(':')
for k, v in env.cmd_line_options.items():
if subproject:
if not k.startswith(subproject + ':'):
@ -789,6 +794,7 @@ builtin_options = {
'optimization': BuiltinOption(UserComboOption, 'Optimization level', '0', choices=['0', 'g', '1', '2', '3', 's']),
'debug': BuiltinOption(UserBooleanOption, 'Debug', True),
'wrap_mode': BuiltinOption(UserComboOption, 'Wrap mode', 'default', choices=['default', 'nofallback', 'nodownload', 'forcefallback']),
'pkg_config_path': BuiltinOption(UserArrayOption, 'List of additional paths for pkg-config to search', []),
}
# Special prefix-dependent defaults for installation directories that reside in

@ -609,11 +609,16 @@ class PkgConfigDependency(ExternalDependency):
return rc, out
def _call_pkgbin(self, args, env=None):
# Always copy the environment since we're going to modify it
# with pkg-config variables
if env is None:
fenv = env
env = os.environ
env = os.environ.copy()
else:
fenv = frozenset(env.items())
env = env.copy()
extra_paths = self.env.coredata.get_builtin_option('pkg_config_path')
env['PKG_CONFIG_PATH'] = ':'.join([p for p in extra_paths])
fenv = frozenset(env.items())
targs = tuple(args)
cache = PkgConfigDependency.pkgbin_cache
if (self.pkgbin, targs, fenv) not in cache:

@ -149,13 +149,6 @@ class MesonApp:
sys.exit(1)
return src_dir, build_dir
def check_pkgconfig_envvar(self, env):
curvar = os.environ.get('PKG_CONFIG_PATH', '')
if curvar != env.coredata.pkgconf_envvar:
mlog.warning('PKG_CONFIG_PATH has changed between invocations from "%s" to "%s".' %
(env.coredata.pkgconf_envvar, curvar))
env.coredata.pkgconf_envvar = curvar
def generate(self):
env = environment.Environment(self.source_dir, self.build_dir, self.options)
mlog.initialize(env.get_log_dir(), self.options.fatal_warnings)
@ -169,7 +162,6 @@ class MesonApp:
mlog.debug('Main binary:', sys.executable)
mlog.debug('Python system:', platform.system())
mlog.log(mlog.bold('The Meson build system'))
self.check_pkgconfig_envvar(env)
mlog.log('Version:', coredata.version)
mlog.log('Source dir:', mlog.bold(self.source_dir))
mlog.log('Build dir:', mlog.bold(self.build_dir))

@ -4837,9 +4837,9 @@ endian = 'little'
testdir = os.path.join(self.unit_test_dir, '58 pkgconfig relative paths')
pkg_dir = os.path.join(testdir, 'pkgconfig')
self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'librelativepath.pc')))
os.environ['PKG_CONFIG_PATH'] = pkg_dir
env = get_fake_env(testdir, self.builddir, self.prefix)
env.coredata.set_options({'pkg_config_path': pkg_dir}, '')
kwargs = {'required': True, 'silent': True}
relative_path_dep = PkgConfigDependency('librelativepath', env, kwargs)
self.assertTrue(relative_path_dep.found())
@ -5068,6 +5068,11 @@ endian = 'little'
# Assert that
self.assertEqual(len(line.split(lib)), 2, msg=(lib, line))
@skipIfNoPkgconfig
def test_pkg_config_option(self):
testdir = os.path.join(self.unit_test_dir, '55 pkg_config_path option')
self.init(testdir, extra_args=['-Dpkg_config_path=' + os.path.join(testdir, 'extra_path')])
def should_run_cross_arm_tests():
return shutil.which('arm-linux-gnueabihf-gcc') and not platform.machine().lower().startswith('arm')

@ -0,0 +1,7 @@
prefix=/
libdir=${prefix}/lib
includedir=${prefix}/include
Name: totally_made_up_dep
Description: completely and totally made up for a test case
Version: 1.2.3

@ -0,0 +1,3 @@
project('pkg_config_path option')
dependency('totally_made_up_dep', method : 'pkg-config')
Loading…
Cancel
Save