Merge pull request #6789 from dcbaker/deprecated-c-ld

Make linker selection environment variables match docs
pull/6803/head
Jussi Pakkanen 5 years ago committed by GitHub
commit 321774d715
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      docs/markdown/Reference-tables.md
  2. 6
      docs/markdown/howtox.md
  3. 7
      docs/markdown/snippets/linker_environment_variables_match_docs.md
  4. 4
      mesonbuild/compilers/mixins/gnu.py
  5. 4
      mesonbuild/compilers/mixins/visualstudio.py
  6. 30
      mesonbuild/envconfig.py
  7. 46
      run_unittests.py
  8. 4
      test cases/java/1 basic/meson.build

@ -255,3 +255,22 @@ These are the values that can be passed to `dependency` function's
| config-tool | Use a custom dep tool such as `cups-config` |
| system | System provided (e.g. OpenGL) |
| extraframework | A macOS/iOS framework |
## Compiler and Linker selection variables
| Language | Compiler | Linker | Note |
|:-------------:|----------|-----------|---------------------------------------------|
| C | CC | CC_LD | |
| C++ | CXX | CXX_LD | |
| D | DC | DC_LD | Before 0.54 D_LD* |
| Fortran | FC | FC_LD | Before 0.54 F_LD* |
| Objective-C | OBJC | OBJC_LD | |
| Objective-C++ | OBJCXX | OBJCXX_LD | Before 0.54 OBJCPP_LD* |
| Rust | RUSTC | RUSTC_LD | Before 0.54 RUST_LD* |
| Vala | VALAC | | Use CC_LD. Vala transpiles to C |
| C# | CSC | CSC | The linker is the compiler |
*The old environment variales are still supported, but are deprecated and will
be removed in a future version of meson.

@ -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.

@ -304,6 +304,10 @@ class GnuLikeCompiler(metaclass=abc.ABCMeta):
@classmethod
def use_linker_args(cls, linker: str) -> T.List[str]:
if linker not in {'gold', 'bfd', 'lld'}:
raise mesonlib.MesonException(
'Unsupported linker, only bfd, gold, and lld are supported, '
'not {}.'.format(linker))
return ['-fuse-ld={}'.format(linker)]

@ -366,10 +366,6 @@ class VisualStudioLikeCompiler(metaclass=abc.ABCMeta):
def get_argument_syntax(self) -> str:
return 'msvc'
@classmethod
def use_linker_args(cls, linker: str) -> T.List[str]:
return []
class MSVCCompiler(VisualStudioLikeCompiler):

@ -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')

@ -5,3 +5,7 @@ javaprog = jar('myprog', 'com/mesonbuild/Simple.java',
install : true,
install_dir : get_option('bindir'))
test('mytest', javaprog)
jc = meson.get_compiler('java')
message(jc.get_id())
message(jc.get_linker_id())

Loading…
Cancel
Save