envconfig: Make compiler and linker environment variables match

pull/6789/head
Dylan Baker 5 years ago
parent 0fa70325ed
commit 9074c7f8a4
  1. 6
      docs/markdown/howtox.md
  2. 7
      docs/markdown/snippets/linker_environment_variables_match_docs.md
  3. 30
      mesonbuild/envconfig.py
  4. 46
      run_unittests.py

@ -26,6 +26,9 @@ build. Because of this Meson needs to know both the native and the
cross compiler. The former is set via the environment variables or
native-files and the latter via the cross file only.
There is a table of all environment variables supported [Here](Reference-tables.md#compiler-and-linker-selection-variables)
## Set dynamic linker
*New in 0.53.0*
@ -61,6 +64,9 @@ c = 'clang'
c_ld = 'lld'
```
There is a table of all environment variables supported [Here](Reference-tables.md#compiler-and-linker-selection-variables)
## Set default C/C++ language version
```meson

@ -0,0 +1,7 @@
## Dynamic Linker environment variables actually match docs
The docs have always claimed that the Dynamic Linker environment variable
should be `${COMPILER_VAR}_LD`, but that's only the case for about half of
the variables. The other half are different. In 0.54.0 the variables match.
The old variables are still supported, but are deprecated and raise a
deprecation warning.

@ -317,11 +317,11 @@ class BinaryTable(HasEnvVarFallback):
# Linkers
'c_ld': 'CC_LD',
'cpp_ld': 'CXX_LD',
'd_ld': 'D_LD',
'fortran_ld': 'F_LD',
'd_ld': 'DC_LD',
'fortran_ld': 'FC_LD',
'objc_ld': 'OBJC_LD',
'objcpp_ld': 'OBJCPP_LD',
'rust_ld': 'RUST_LD',
'objcpp_ld': 'OBJCXX_LD',
'rust_ld': 'RUSTC_LD',
# Binutils
'strip': 'STRIP',
@ -334,6 +334,15 @@ class BinaryTable(HasEnvVarFallback):
'pkgconfig': 'PKG_CONFIG',
} # type: T.Dict[str, str]
# Deprecated environment variables mapped from the new variable to the old one
# Deprecated in 0.54.0
DEPRECATION_MAP = {
'DC_LD': 'D_LD',
'FC_LD': 'F_LD',
'RUSTC_LD': 'RUST_LD',
'OBJCXX_LD': 'OBJCPP_LD',
} # type: T.Dict[str, str]
@staticmethod
def detect_ccache() -> T.List[str]:
try:
@ -362,12 +371,10 @@ This is probably wrong, it should always point to the native compiler.''' % evar
return compiler, ccache
def lookup_entry(self, name: str) -> T.Optional[T.List[str]]:
"""Lookup binaryk
"""Lookup binary in cross/native file and fallback to environment.
Returns command with args as list if found, Returns `None` if nothing is
found.
First tries looking in explicit map, then tries environment variable.
"""
# Try explicit map, don't fall back on env var
command = self.binaries.get(name)
@ -380,9 +387,18 @@ This is probably wrong, it should always point to the native compiler.''' % evar
# Relies on there being no "" env var
evar = self.evarMap.get(name, "")
command = os.environ.get(evar)
if command is None:
deprecated = self.DEPRECATION_MAP.get(evar)
if deprecated:
command = os.environ.get(deprecated)
if command:
mlog.deprecation(
'The', deprecated, 'environment variable is deprecated in favor of',
evar, once=True)
if command is not None:
command = split_args(command)
# Do not return empty or blank string entries
if command is not None and (len(command) == 0 or len(command[0].strip()) == 0):
return None

@ -4972,14 +4972,21 @@ class WindowsTests(BasePlatformTests):
def _check_ld(self, name: str, lang: str, expected: str) -> None:
if not shutil.which(name):
raise unittest.SkipTest('Could not find {}.'.format(name))
envvar = mesonbuild.envconfig.BinaryTable.evarMap['{}_ld'.format(lang)]
with mock.patch.dict(os.environ, {envvar: name}):
env = get_fake_env()
try:
comp = getattr(env, 'detect_{}_compiler'.format(lang))(MachineChoice.HOST)
except EnvironmentException:
raise unittest.SkipTest('Could not find a compiler for {}'.format(lang))
self.assertEqual(comp.linker.id, expected)
envvars = [mesonbuild.envconfig.BinaryTable.evarMap['{}_ld'.format(lang)]]
# Also test a deprecated variable if there is one.
if envvars[0] in mesonbuild.envconfig.BinaryTable.DEPRECATION_MAP:
envvars.append(
mesonbuild.envconfig.BinaryTable.DEPRECATION_MAP[envvars[0]])
for envvar in envvars:
with mock.patch.dict(os.environ, {envvar: name}):
env = get_fake_env()
try:
comp = getattr(env, 'detect_{}_compiler'.format(lang))(MachineChoice.HOST)
except EnvironmentException:
raise unittest.SkipTest('Could not find a compiler for {}'.format(lang))
self.assertEqual(comp.linker.id, expected)
def test_link_environment_variable_lld_link(self):
self._check_ld('lld-link', 'c', 'lld-link')
@ -6333,14 +6340,21 @@ c = ['{0}']
raise unittest.SkipTest('Solaris currently cannot override the linker.')
if not shutil.which(check):
raise unittest.SkipTest('Could not find {}.'.format(check))
envvar = mesonbuild.envconfig.BinaryTable.evarMap['{}_ld'.format(lang)]
with mock.patch.dict(os.environ, {envvar: name}):
env = get_fake_env()
comp = getattr(env, 'detect_{}_compiler'.format(lang))(MachineChoice.HOST)
if lang != 'rust' and comp.use_linker_args('foo') == []:
raise unittest.SkipTest(
'Compiler {} does not support using alternative linkers'.format(comp.id))
self.assertEqual(comp.linker.id, expected)
envvars = [mesonbuild.envconfig.BinaryTable.evarMap['{}_ld'.format(lang)]]
# Also test a deprecated variable if there is one.
if envvars[0] in mesonbuild.envconfig.BinaryTable.DEPRECATION_MAP:
envvars.append(
mesonbuild.envconfig.BinaryTable.DEPRECATION_MAP[envvars[0]])
for envvar in envvars:
with mock.patch.dict(os.environ, {envvar: name}):
env = get_fake_env()
comp = getattr(env, 'detect_{}_compiler'.format(lang))(MachineChoice.HOST)
if lang != 'rust' and comp.use_linker_args('bfd') == []:
raise unittest.SkipTest(
'Compiler {} does not support using alternative linkers'.format(comp.id))
self.assertEqual(comp.linker.id, expected)
def test_ld_environment_variable_bfd(self):
self._check_ld('ld.bfd', 'bfd', 'c', 'ld.bfd')

Loading…
Cancel
Save