Correctly handle platform-specific LDFLAGS options

pull/5969/head
Aleksey Gurtovoy 5 years ago committed by Jussi Pakkanen
parent 534e94ffc3
commit 7dbabdc7b6
  1. 2
      mesonbuild/backend/ninjabackend.py
  2. 5
      mesonbuild/compilers/compilers.py
  3. 12
      mesonbuild/compilers/mixins/visualstudio.py
  4. 11
      mesonbuild/linkers.py
  5. 71
      run_unittests.py

@ -2385,7 +2385,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
build_dir = self.environment.get_build_dir()
# the following loop sometimes consumes two items from command in one pass
it = iter(commands)
it = iter(linker.native_args_to_unix(commands))
for item in it:
if item in internal and not item.startswith('-'):
continue

@ -900,6 +900,11 @@ class Compiler:
"Always returns a copy that can be independently mutated"
return args[:]
@classmethod
def native_args_to_unix(cls, args: typing.List[str]) -> typing.List[str]:
"Always returns a copy that can be independently mutated"
return args[:]
def find_library(self, *args, **kwargs):
raise EnvironmentException('Language {} does not support library finding.'.format(self.get_display_language()))

@ -234,6 +234,18 @@ class VisualStudioLikeCompiler(metaclass=abc.ABCMeta):
result.append(i)
return result
@classmethod
def native_args_to_unix(cls, args: typing.List[str]) -> typing.List[str]:
result = []
for arg in args:
if arg.startswith('/LIBPATH:'):
result.append('-L' + arg[9:])
elif arg.endswith(('.a', '.lib')) and not os.path.isabs(arg):
result.append('-l' + arg)
else:
result.append(arg)
return result
def get_werror_args(self) -> typing.List[str]:
return ['/WX']

@ -69,7 +69,11 @@ class StaticLinker:
@classmethod
def unix_args_to_native(cls, args: typing.List[str]) -> typing.List[str]:
return args
return args[:]
@classmethod
def native_args_to_unix(cls, args: typing.List[str]) -> typing.List[str]:
return args[:]
def get_link_debugfile_args(self, targetfile: str) -> typing.List[str]:
# Static libraries do not have PDB files
@ -106,6 +110,11 @@ class VisualStudioLikeLinker:
from .compilers import VisualStudioCCompiler
return VisualStudioCCompiler.unix_args_to_native(args)
@classmethod
def native_args_to_unix(cls, args: typing.List[str]) -> typing.List[str]:
from .compilers import VisualStudioCCompiler
return VisualStudioCCompiler.native_args_to_unix(args)
class VisualStudioLinker(VisualStudioLikeLinker, StaticLinker):

@ -3079,47 +3079,62 @@ recommended as it is not supported on some platforms''')
Test that meson adds dependencies for libraries based on the final
linker command line.
'''
# build library
testdirbase = os.path.join(self.unit_test_dir, '29 guessed linker dependencies')
testdirlib = os.path.join(testdirbase, 'lib')
extra_args = None
libdir_flags = ['-L']
env = get_fake_env(testdirlib, self.builddir, self.prefix)
if env.detect_c_compiler(MachineChoice.HOST).get_id() not in {'msvc', 'clang-cl', 'intel-cl'}:
if env.detect_c_compiler(MachineChoice.HOST).get_id() in {'msvc', 'clang-cl', 'intel-cl'}:
# msvc-like compiler, also test it with msvc-specific flags
libdir_flags += ['/LIBPATH:']
else:
# static libraries are not linkable with -l with msvc because meson installs them
# as .a files which unix_args_to_native will not know as it expects libraries to use
# .lib as extension. For a DLL the import library is installed as .lib. Thus for msvc
# this tests needs to use shared libraries to test the path resolving logic in the
# dependency generation code path.
extra_args = ['--default-library', 'static']
self.init(testdirlib, extra_args=extra_args)
self.build()
self.install()
libbuilddir = self.builddir
installdir = self.installdir
libdir = os.path.join(self.installdir, self.prefix.lstrip('/').lstrip('\\'), 'lib')
# build user of library
self.new_builddir()
# replace is needed because meson mangles platform pathes passed via LDFLAGS
self.init(os.path.join(testdirbase, 'exe'),
override_envvars={"LDFLAGS": '-L{}'.format(libdir.replace('\\', '/'))})
self.build()
self.assertBuildIsNoop()
initial_builddir = self.builddir
initial_installdir = self.installdir
# rebuild library
exebuilddir = self.builddir
self.installdir = installdir
self.builddir = libbuilddir
# Microsoft's compiler is quite smart about touching import libs on changes,
# so ensure that there is actually a change in symbols.
self.setconf('-Dmore_exports=true')
self.build()
self.install()
# no ensure_backend_detects_changes needed because self.setconf did that already
for libdir_flag in libdir_flags:
# build library
self.init(testdirlib, extra_args=extra_args)
self.build()
self.install()
libbuilddir = self.builddir
installdir = self.installdir
libdir = os.path.join(self.installdir, self.prefix.lstrip('/').lstrip('\\'), 'lib')
# build user of library
self.new_builddir()
# replace is needed because meson mangles platform pathes passed via LDFLAGS
self.init(os.path.join(testdirbase, 'exe'),
override_envvars={"LDFLAGS": '{}{}'.format(libdir_flag, libdir.replace('\\', '/'))})
self.build()
self.assertBuildIsNoop()
# rebuild library
exebuilddir = self.builddir
self.installdir = installdir
self.builddir = libbuilddir
# Microsoft's compiler is quite smart about touching import libs on changes,
# so ensure that there is actually a change in symbols.
self.setconf('-Dmore_exports=true')
self.build()
self.install()
# no ensure_backend_detects_changes needed because self.setconf did that already
# assert user of library will be rebuild
self.builddir = exebuilddir
self.assertRebuiltTarget('app')
# restore dirs for the next test case
self.installdir = initial_builddir
self.builddir = initial_installdir
# assert user of library will be rebuild
self.builddir = exebuilddir
self.assertRebuiltTarget('app')
def test_conflicting_d_dash_option(self):
testdir = os.path.join(self.unit_test_dir, '37 mixed command line args')

Loading…
Cancel
Save