aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/howtox.md6
-rw-r--r--docs/markdown/snippets/linker_environment_variables_match_docs.md7
-rw-r--r--mesonbuild/envconfig.py30
-rwxr-xr-xrun_unittests.py46
4 files changed, 66 insertions, 23 deletions
diff --git a/docs/markdown/howtox.md b/docs/markdown/howtox.md
index f70ff47..1a2add0 100644
--- a/docs/markdown/howtox.md
+++ b/docs/markdown/howtox.md
@@ -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
diff --git a/docs/markdown/snippets/linker_environment_variables_match_docs.md b/docs/markdown/snippets/linker_environment_variables_match_docs.md
new file mode 100644
index 0000000..233547c
--- /dev/null
+++ b/docs/markdown/snippets/linker_environment_variables_match_docs.md
@@ -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.
diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py
index 3e5e44b..8587842 100644
--- a/mesonbuild/envconfig.py
+++ b/mesonbuild/envconfig.py
@@ -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
diff --git a/run_unittests.py b/run_unittests.py
index ee6ec7e..2f7ad43 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -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')