diff options
author | Martin Hostettler <textshell@uchuujin.de> | 2018-02-18 18:33:35 +0100 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2018-04-15 07:29:21 +0000 |
commit | aff597fb99a77b8c1211e30f712f223d6d99587c (patch) | |
tree | 1267ab643f11f1fef70b19cc27efeef654d7283a /run_unittests.py | |
parent | 642e17aa6be5b6736b856961563377d10faa57aa (diff) | |
download | meson-aff597fb99a77b8c1211e30f712f223d6d99587c.zip meson-aff597fb99a77b8c1211e30f712f223d6d99587c.tar.gz meson-aff597fb99a77b8c1211e30f712f223d6d99587c.tar.bz2 |
ninjabackend: Try to guess library dependencies for linker invocation.
The linkers currently do not support ninja compatible output of
dependencies used while linking. Try to guess which files will be used
while linking in python code and generate conservative dependencies to
ensure changes in linked libraries are detected.
This generates dependencies on the best match for static and shared
linking, but this should not be a problem, except for spurious
rebuilding when only one of them changes, which should not be a problem.
Also makes sure to ignore any libraries generated inside the build, to
keep the optimisation working where changes in a shared library only
cause relink if the symbols have changed as well.
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-x | run_unittests.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/run_unittests.py b/run_unittests.py index 0f9a50b..0f9abcb 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -1949,6 +1949,55 @@ recommended as it can lead to undefined behaviour on some platforms''') exe = os.path.join(self.builddir, 'main') self.assertEqual(b'NDEBUG=0', subprocess.check_output(exe).strip()) + def test_guessed_linker_dependencies(self): + ''' + Test that meson adds dependencies for libraries based on the final + linker command line. + ''' + # build library + testdirbase = os.path.join(self.unit_test_dir, '26 guessed linker dependencies') + testdirlib = os.path.join(testdirbase, 'lib') + extra_args = None + env = Environment(testdirlib, self.builddir, self.meson_command, + get_fake_options(self.prefix), []) + if env.detect_c_compiler(False).get_id() != 'msvc': + # 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 + os.environ["LDFLAGS"] = '-L{}'.format(libdir.replace('\\', '/')) + self.init(os.path.join(testdirbase, 'exe')) + del os.environ["LDFLAGS"] + 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') + class FailureTests(BasePlatformTests): ''' |