Machine file pkg_config_path overrides environment

This is consistent with c_args in machine file overriding CFLAGS from
env. This also spotted an issue where in a native build this resulted
in pkg_config_path being /bar instead of /foo:
`-Dpkg_config_path=/foo -Dbuild.pkg_config_path=/bar`

Fixes: #7573
pull/5071/merge
Xavier Claessens 5 years ago committed by Xavier Claessens
parent 254b836bd4
commit 7271b1e942
  1. 4
      mesonbuild/coredata.py
  2. 10
      mesonbuild/environment.py
  3. 14
      run_unittests.py

@ -735,7 +735,9 @@ class CoreData:
for k, v in options.items():
if k.startswith('build.'):
k = k.split('.', 1)[1]
res[k] = v
res.setdefault(k, v)
else:
res[k] = v
return res
def copy_build_options_from_regular_ones(self):

@ -629,12 +629,12 @@ class Environment:
self.properties = properties.default_missing()
self.cmakevars = cmakevars.default_missing()
# Environment options override those from cross/native files
self.set_options_from_env()
# Command line options override those from cross/native files
self.raw_options.update(options.cmd_line_options)
# Take default value from env if not set in cross/native files or command line.
self.set_default_options_from_env()
# Warn if the user is using two different ways of setting build-type
# options that override each other
if 'buildtype' in self.raw_options and \
@ -727,7 +727,7 @@ class Environment:
per_machine_options[build_optname] = value
self.raw_options = per_machine_options
def set_options_from_env(self):
def set_default_options_from_env(self):
for for_machine in MachineChoice:
p_env_pair = get_env_var_pair(for_machine, self.is_cross_build(), 'PKG_CONFIG_PATH')
if p_env_pair is not None:
@ -746,7 +746,7 @@ class Environment:
# FIXME: We should remember if we took the value from env to warn
# if it changes on future invocations.
if self.first_invocation:
self.raw_options[key] = p_list
self.raw_options.setdefault(key, p_list)
def create_new_coredata(self, options: 'argparse.Namespace') -> None:
# WARNING: Don't use any values from coredata in __init__. It gets

@ -8373,7 +8373,7 @@ class NativeFileTests(BasePlatformTests):
else:
self.fail('Did not find werror in build options?')
def test_builtin_options_env_overrides_conf(self):
def test_builtin_options_conf_overrides_env(self):
testcase = os.path.join(self.common_test_dir, '2 cpp')
config = self.helper_create_native_file({'built-in options': {'pkg_config_path': '/foo'}})
@ -8381,7 +8381,7 @@ class NativeFileTests(BasePlatformTests):
configuration = self.introspect('--buildoptions')
for each in configuration:
if each['name'] == 'pkg_config_path':
self.assertEqual(each['value'], ['/bar'])
self.assertEqual(each['value'], ['/foo'])
break
else:
self.fail('Did not find pkg_config_path in build options?')
@ -8786,10 +8786,10 @@ class CrossFileTests(BasePlatformTests):
break
self.assertEqual(found, 4, 'Did not find all sections.')
def test_builtin_options_env_overrides_conf(self):
def test_builtin_options_conf_overrides_env(self):
testcase = os.path.join(self.common_test_dir, '2 cpp')
config = self.helper_create_cross_file({'built-in options': {'pkg_config_path': '/foo'}})
cross = self.helper_create_cross_file({'built-in options': {'pkg_config_path': '/foo'}})
config = self.helper_create_cross_file({'built-in options': {'pkg_config_path': '/native'}})
cross = self.helper_create_cross_file({'built-in options': {'pkg_config_path': '/cross'}})
self.init(testcase, extra_args=['--native-file', config, '--cross-file', cross],
override_envvars={'PKG_CONFIG_PATH': '/bar', 'PKG_CONFIG_PATH_FOR_BUILD': '/dir'})
@ -8797,10 +8797,10 @@ class CrossFileTests(BasePlatformTests):
found = 0
for each in configuration:
if each['name'] == 'pkg_config_path':
self.assertEqual(each['value'], ['/bar'])
self.assertEqual(each['value'], ['/cross'])
found += 1
elif each['name'] == 'build.pkg_config_path':
self.assertEqual(each['value'], ['/dir'])
self.assertEqual(each['value'], ['/native'])
found += 1
if found == 2:
break

Loading…
Cancel
Save