aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2019-02-12 15:51:46 -0800
committerDylan Baker <dylan@pnwbakers.com>2019-04-05 15:08:17 -0700
commit569e646e1e3556fb5fdb7c4fb012a30145c7145d (patch)
tree1e42b0750bb3e0f0cce0cb1857916c0b2d7d97b6
parent25eb86382b4b081c1d3992b9bfd9ebc4ab9b3d10 (diff)
downloadmeson-569e646e1e3556fb5fdb7c4fb012a30145c7145d.zip
meson-569e646e1e3556fb5fdb7c4fb012a30145c7145d.tar.gz
meson-569e646e1e3556fb5fdb7c4fb012a30145c7145d.tar.bz2
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.
-rw-r--r--mesonbuild/coredata.py8
-rw-r--r--mesonbuild/dependencies/base.py11
-rw-r--r--mesonbuild/msetup.py8
-rwxr-xr-xrun_unittests.py7
-rw-r--r--test cases/unit/55 pkg_config_path option/extra_path/totally_made_up_dep.pc7
-rw-r--r--test cases/unit/55 pkg_config_path option/meson.build3
6 files changed, 31 insertions, 13 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 2666bb9..034f86a 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -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
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index af4b13f..94a6a6b 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -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:
diff --git a/mesonbuild/msetup.py b/mesonbuild/msetup.py
index 6e8ca83..ef0511d 100644
--- a/mesonbuild/msetup.py
+++ b/mesonbuild/msetup.py
@@ -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))
diff --git a/run_unittests.py b/run_unittests.py
index bc28eea..34307f6 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -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')
diff --git a/test cases/unit/55 pkg_config_path option/extra_path/totally_made_up_dep.pc b/test cases/unit/55 pkg_config_path option/extra_path/totally_made_up_dep.pc
new file mode 100644
index 0000000..6d08687
--- /dev/null
+++ b/test cases/unit/55 pkg_config_path option/extra_path/totally_made_up_dep.pc
@@ -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 \ No newline at end of file
diff --git a/test cases/unit/55 pkg_config_path option/meson.build b/test cases/unit/55 pkg_config_path option/meson.build
new file mode 100644
index 0000000..623c3a2
--- /dev/null
+++ b/test cases/unit/55 pkg_config_path option/meson.build
@@ -0,0 +1,3 @@
+project('pkg_config_path option')
+
+dependency('totally_made_up_dep', method : 'pkg-config')