|
|
@ -24,9 +24,10 @@ from mesonbuild.dependencies import PkgConfigDependency, Qt5Dependency |
|
|
|
|
|
|
|
|
|
|
|
def get_soname(fname): |
|
|
|
def get_soname(fname): |
|
|
|
# HACK, fix to not use shell. |
|
|
|
# HACK, fix to not use shell. |
|
|
|
raw_out = subprocess.check_output(['readelf', '-a', fname]) |
|
|
|
raw_out = subprocess.check_output(['readelf', '-a', fname], |
|
|
|
pattern = re.compile(b'soname: \[(.*?)\]') |
|
|
|
universal_newlines=True) |
|
|
|
for line in raw_out.split(b'\n'): |
|
|
|
pattern = re.compile('soname: \[(.*?)\]') |
|
|
|
|
|
|
|
for line in raw_out.split('\n'): |
|
|
|
m = pattern.search(line) |
|
|
|
m = pattern.search(line) |
|
|
|
if m is not None: |
|
|
|
if m is not None: |
|
|
|
return m.group(1) |
|
|
|
return m.group(1) |
|
|
@ -94,27 +95,55 @@ class LinuxlikeTests(unittest.TestCase): |
|
|
|
with open(os.path.join(self.builddir, 'meson-logs', 'meson-log.txt')) as f: |
|
|
|
with open(os.path.join(self.builddir, 'meson-logs', 'meson-log.txt')) as f: |
|
|
|
return f.readlines() |
|
|
|
return f.readlines() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_meson_log_compiler_checks(self): |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
Fetch a list command-lines run by meson for compiler checks. |
|
|
|
|
|
|
|
Each command-line is returned as a list of arguments. |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
log = self.get_meson_log() |
|
|
|
|
|
|
|
prefix = 'Command line:' |
|
|
|
|
|
|
|
cmds = [l[len(prefix):].split() for l in log if l.startswith(prefix)] |
|
|
|
|
|
|
|
return cmds |
|
|
|
|
|
|
|
|
|
|
|
def introspect(self, arg): |
|
|
|
def introspect(self, arg): |
|
|
|
out = subprocess.check_output(self.mintro_command + [arg, self.builddir]) |
|
|
|
out = subprocess.check_output(self.mintro_command + [arg, self.builddir], |
|
|
|
return json.loads(out.decode('utf-8')) |
|
|
|
universal_newlines=True) |
|
|
|
|
|
|
|
return json.loads(out) |
|
|
|
|
|
|
|
|
|
|
|
def test_basic_soname(self): |
|
|
|
def test_basic_soname(self): |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
Test that the soname is set correctly for shared libraries. This can't |
|
|
|
|
|
|
|
be an ordinary test case because we need to run `readelf` and actually |
|
|
|
|
|
|
|
check the soname. |
|
|
|
|
|
|
|
https://github.com/mesonbuild/meson/issues/785 |
|
|
|
|
|
|
|
''' |
|
|
|
testdir = os.path.join(self.common_test_dir, '4 shared') |
|
|
|
testdir = os.path.join(self.common_test_dir, '4 shared') |
|
|
|
self.init(testdir) |
|
|
|
self.init(testdir) |
|
|
|
self.build() |
|
|
|
self.build() |
|
|
|
lib1 = os.path.join(self.builddir, 'libmylib.so') |
|
|
|
lib1 = os.path.join(self.builddir, 'libmylib.so') |
|
|
|
soname = get_soname(lib1) |
|
|
|
soname = get_soname(lib1) |
|
|
|
self.assertEqual(soname, b'libmylib.so') |
|
|
|
self.assertEqual(soname, 'libmylib.so') |
|
|
|
|
|
|
|
|
|
|
|
def test_custom_soname(self): |
|
|
|
def test_custom_soname(self): |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
Test that the soname is set correctly for shared libraries when |
|
|
|
|
|
|
|
a custom prefix and/or suffix is used. This can't be an ordinary test |
|
|
|
|
|
|
|
case because we need to run `readelf` and actually check the soname. |
|
|
|
|
|
|
|
https://github.com/mesonbuild/meson/issues/785 |
|
|
|
|
|
|
|
''' |
|
|
|
testdir = os.path.join(self.common_test_dir, '27 library versions') |
|
|
|
testdir = os.path.join(self.common_test_dir, '27 library versions') |
|
|
|
self.init(testdir) |
|
|
|
self.init(testdir) |
|
|
|
self.build() |
|
|
|
self.build() |
|
|
|
lib1 = os.path.join(self.builddir, 'prefixsomelib.suffix') |
|
|
|
lib1 = os.path.join(self.builddir, 'prefixsomelib.suffix') |
|
|
|
soname = get_soname(lib1) |
|
|
|
soname = get_soname(lib1) |
|
|
|
self.assertEqual(soname, b'prefixsomelib.suffix') |
|
|
|
self.assertEqual(soname, 'prefixsomelib.suffix') |
|
|
|
|
|
|
|
|
|
|
|
def test_pic(self): |
|
|
|
def test_pic(self): |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
Test that -fPIC is correctly added to static libraries when b_staticpic |
|
|
|
|
|
|
|
is true and not when it is false. This can't be an ordinary test case |
|
|
|
|
|
|
|
because we need to inspect the compiler database. |
|
|
|
|
|
|
|
''' |
|
|
|
testdir = os.path.join(self.common_test_dir, '3 static') |
|
|
|
testdir = os.path.join(self.common_test_dir, '3 static') |
|
|
|
self.init(testdir) |
|
|
|
self.init(testdir) |
|
|
|
compdb = self.get_compdb() |
|
|
|
compdb = self.get_compdb() |
|
|
@ -130,6 +159,12 @@ class LinuxlikeTests(unittest.TestCase): |
|
|
|
self.assertTrue('-fPIC' not in compdb[0]['command']) |
|
|
|
self.assertTrue('-fPIC' not in compdb[0]['command']) |
|
|
|
|
|
|
|
|
|
|
|
def test_pkgconfig_gen(self): |
|
|
|
def test_pkgconfig_gen(self): |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
Test that generated pkg-config files can be found and have the correct |
|
|
|
|
|
|
|
version and link args. This can't be an ordinary test case because we |
|
|
|
|
|
|
|
need to run pkg-config outside of a Meson build file. |
|
|
|
|
|
|
|
https://github.com/mesonbuild/meson/issues/889 |
|
|
|
|
|
|
|
''' |
|
|
|
testdir = os.path.join(self.common_test_dir, '51 pkgconfig-gen') |
|
|
|
testdir = os.path.join(self.common_test_dir, '51 pkgconfig-gen') |
|
|
|
self.init(testdir) |
|
|
|
self.init(testdir) |
|
|
|
env = FakeEnvironment() |
|
|
|
env = FakeEnvironment() |
|
|
@ -141,6 +176,12 @@ class LinuxlikeTests(unittest.TestCase): |
|
|
|
self.assertTrue('-lfoo' in simple_dep.get_link_args()) |
|
|
|
self.assertTrue('-lfoo' in simple_dep.get_link_args()) |
|
|
|
|
|
|
|
|
|
|
|
def test_vala_c_warnings(self): |
|
|
|
def test_vala_c_warnings(self): |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
Test that no warnings are emitted for C code generated by Vala. This |
|
|
|
|
|
|
|
can't be an ordinary test case because we need to inspect the compiler |
|
|
|
|
|
|
|
database. |
|
|
|
|
|
|
|
https://github.com/mesonbuild/meson/issues/864 |
|
|
|
|
|
|
|
''' |
|
|
|
testdir = os.path.join(self.vala_test_dir, '5 target glib') |
|
|
|
testdir = os.path.join(self.vala_test_dir, '5 target glib') |
|
|
|
self.init(testdir) |
|
|
|
self.init(testdir) |
|
|
|
compdb = self.get_compdb() |
|
|
|
compdb = self.get_compdb() |
|
|
@ -168,6 +209,12 @@ class LinuxlikeTests(unittest.TestCase): |
|
|
|
self.assertTrue('-Werror' in c_command) |
|
|
|
self.assertTrue('-Werror' in c_command) |
|
|
|
|
|
|
|
|
|
|
|
def test_static_compile_order(self): |
|
|
|
def test_static_compile_order(self): |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
Test that the order of files in a compiler command-line while compiling |
|
|
|
|
|
|
|
and linking statically is deterministic. This can't be an ordinary test |
|
|
|
|
|
|
|
case because we need to inspect the compiler database. |
|
|
|
|
|
|
|
https://github.com/mesonbuild/meson/pull/951 |
|
|
|
|
|
|
|
''' |
|
|
|
testdir = os.path.join(self.common_test_dir, '5 linkstatic') |
|
|
|
testdir = os.path.join(self.common_test_dir, '5 linkstatic') |
|
|
|
self.init(testdir) |
|
|
|
self.init(testdir) |
|
|
|
compdb = self.get_compdb() |
|
|
|
compdb = self.get_compdb() |
|
|
@ -179,6 +226,10 @@ class LinuxlikeTests(unittest.TestCase): |
|
|
|
# FIXME: We don't have access to the linker command |
|
|
|
# FIXME: We don't have access to the linker command |
|
|
|
|
|
|
|
|
|
|
|
def test_install_introspection(self): |
|
|
|
def test_install_introspection(self): |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
Tests that the Meson introspection API exposes install filenames correctly |
|
|
|
|
|
|
|
https://github.com/mesonbuild/meson/issues/829 |
|
|
|
|
|
|
|
''' |
|
|
|
testdir = os.path.join(self.common_test_dir, '8 install') |
|
|
|
testdir = os.path.join(self.common_test_dir, '8 install') |
|
|
|
self.init(testdir) |
|
|
|
self.init(testdir) |
|
|
|
intro = self.introspect('--targets') |
|
|
|
intro = self.introspect('--targets') |
|
|
@ -188,11 +239,19 @@ class LinuxlikeTests(unittest.TestCase): |
|
|
|
self.assertEqual(intro[1]['install_filename'], '/usr/local/bin/prog') |
|
|
|
self.assertEqual(intro[1]['install_filename'], '/usr/local/bin/prog') |
|
|
|
|
|
|
|
|
|
|
|
def test_run_target_files_path(self): |
|
|
|
def test_run_target_files_path(self): |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
Test that run_targets are run from the correct directory |
|
|
|
|
|
|
|
https://github.com/mesonbuild/meson/issues/957 |
|
|
|
|
|
|
|
''' |
|
|
|
testdir = os.path.join(self.common_test_dir, '58 run target') |
|
|
|
testdir = os.path.join(self.common_test_dir, '58 run target') |
|
|
|
self.init(testdir) |
|
|
|
self.init(testdir) |
|
|
|
self.run_target('check_exists') |
|
|
|
self.run_target('check_exists') |
|
|
|
|
|
|
|
|
|
|
|
def test_qt5dependency_qmake_detection(self): |
|
|
|
def test_qt5dependency_qmake_detection(self): |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
Test that qt5 detection with qmake works. This can't be an ordinary |
|
|
|
|
|
|
|
test case because it involves setting the environment. |
|
|
|
|
|
|
|
''' |
|
|
|
# Verify that qmake is for Qt5 |
|
|
|
# Verify that qmake is for Qt5 |
|
|
|
if not shutil.which('qmake-qt5'): |
|
|
|
if not shutil.which('qmake-qt5'): |
|
|
|
if not shutil.which('qmake'): |
|
|
|
if not shutil.which('qmake'): |
|
|
@ -215,8 +274,9 @@ class LinuxlikeTests(unittest.TestCase): |
|
|
|
self.assertTrue(msg in mesonlog or msg2 in mesonlog) |
|
|
|
self.assertTrue(msg in mesonlog or msg2 in mesonlog) |
|
|
|
|
|
|
|
|
|
|
|
def get_soname(self, fname): |
|
|
|
def get_soname(self, fname): |
|
|
|
output = subprocess.check_output(['readelf', '-a', fname]) |
|
|
|
output = subprocess.check_output(['readelf', '-a', fname], |
|
|
|
for line in output.decode('utf-8', errors='ignore').split('\n'): |
|
|
|
universal_newlines=True) |
|
|
|
|
|
|
|
for line in output.split('\n'): |
|
|
|
if 'SONAME' in line: |
|
|
|
if 'SONAME' in line: |
|
|
|
return line.split('[')[1].split(']')[0] |
|
|
|
return line.split('[')[1].split(']')[0] |
|
|
|
raise RuntimeError('Readelf gave no SONAME.') |
|
|
|
raise RuntimeError('Readelf gave no SONAME.') |
|
|
@ -262,5 +322,23 @@ class LinuxlikeTests(unittest.TestCase): |
|
|
|
self.assertEqual(self.get_soname(bothset), 'libbothset.so.1.2.3') |
|
|
|
self.assertEqual(self.get_soname(bothset), 'libbothset.so.1.2.3') |
|
|
|
self.assertEqual(len(glob(bothset[:-3] + '*')), 3) |
|
|
|
self.assertEqual(len(glob(bothset[:-3] + '*')), 3) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_compiler_check_flags_order(self): |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
Test that compiler check flags override all other flags. This can't be |
|
|
|
|
|
|
|
an ordinary test case because it needs the environment to be set. |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
Oflag = '-O3' |
|
|
|
|
|
|
|
os.environ['CFLAGS'] = os.environ['CXXFLAGS'] = Oflag |
|
|
|
|
|
|
|
testdir = os.path.join(self.common_test_dir, '43 has function') |
|
|
|
|
|
|
|
self.init(testdir) |
|
|
|
|
|
|
|
cmds = self.get_meson_log_compiler_checks() |
|
|
|
|
|
|
|
for cmd in cmds: |
|
|
|
|
|
|
|
# Verify that -I flags from the `args` kwarg are first |
|
|
|
|
|
|
|
# This is set in the '43 has function' test case |
|
|
|
|
|
|
|
self.assertEqual(cmd[2], '-I/tmp') |
|
|
|
|
|
|
|
# Verify that -O3 set via the environment is overriden by -O0 |
|
|
|
|
|
|
|
Oargs = [arg for arg in cmd if arg.startswith('-O')] |
|
|
|
|
|
|
|
self.assertEqual(Oargs, [Oflag, '-O0']) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
if __name__ == '__main__': |
|
|
|
unittest.main() |
|
|
|
unittest.main() |
|
|
|