|
|
@ -1389,34 +1389,34 @@ int main(int argc, char **argv) { |
|
|
|
self.assertPathExists(os.path.join(testdir, i)) |
|
|
|
self.assertPathExists(os.path.join(testdir, i)) |
|
|
|
|
|
|
|
|
|
|
|
def detect_prebuild_env(self): |
|
|
|
def detect_prebuild_env(self): |
|
|
|
|
|
|
|
env = Environment('', self.builddir, self.meson_command, |
|
|
|
|
|
|
|
get_fake_options(self.prefix), []) |
|
|
|
|
|
|
|
cc = env.detect_c_compiler(False) |
|
|
|
if mesonbuild.mesonlib.is_windows(): |
|
|
|
if mesonbuild.mesonlib.is_windows(): |
|
|
|
object_suffix = 'obj' |
|
|
|
object_suffix = 'obj' |
|
|
|
else: |
|
|
|
shared_suffix = 'dll' |
|
|
|
|
|
|
|
elif mesonbuild.mesonlib.is_cygwin(): |
|
|
|
object_suffix = 'o' |
|
|
|
object_suffix = 'o' |
|
|
|
static_suffix = 'a' |
|
|
|
|
|
|
|
shared_suffix = 'so' |
|
|
|
|
|
|
|
if shutil.which('cl'): |
|
|
|
|
|
|
|
compiler = 'cl' |
|
|
|
|
|
|
|
static_suffix = 'lib' |
|
|
|
|
|
|
|
shared_suffix = 'dll' |
|
|
|
shared_suffix = 'dll' |
|
|
|
elif shutil.which('cc'): |
|
|
|
elif mesonbuild.mesonlib.is_osx(): |
|
|
|
compiler = 'cc' |
|
|
|
object_suffix = 'o' |
|
|
|
elif shutil.which('gcc'): |
|
|
|
shared_suffix = 'dylib' |
|
|
|
compiler = 'gcc' |
|
|
|
|
|
|
|
else: |
|
|
|
else: |
|
|
|
raise RuntimeError("Could not find C compiler.") |
|
|
|
object_suffix = 'o' |
|
|
|
return (compiler, object_suffix, static_suffix, shared_suffix) |
|
|
|
shared_suffix = 'so' |
|
|
|
|
|
|
|
return (cc, object_suffix, shared_suffix) |
|
|
|
|
|
|
|
|
|
|
|
def pbcompile(self, compiler, source, objectfile, extra_args=[]): |
|
|
|
def pbcompile(self, compiler, source, objectfile, extra_args=[]): |
|
|
|
if compiler == 'cl': |
|
|
|
cmd = compiler.get_exelist() |
|
|
|
cmd = [compiler, '/nologo', '/Fo' + objectfile, '/c', source] + extra_args |
|
|
|
if compiler.id == 'msvc': |
|
|
|
|
|
|
|
cmd += ['/nologo', '/Fo' + objectfile, '/c', source] + extra_args |
|
|
|
else: |
|
|
|
else: |
|
|
|
cmd = [compiler, '-c', source, '-o', objectfile] + extra_args |
|
|
|
cmd += ['-c', source, '-o', objectfile] + extra_args |
|
|
|
subprocess.check_call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
|
|
|
subprocess.check_call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prebuilt_object(self): |
|
|
|
def test_prebuilt_object(self): |
|
|
|
(compiler, object_suffix, _, _) = self.detect_prebuild_env() |
|
|
|
(compiler, object_suffix, _) = self.detect_prebuild_env() |
|
|
|
tdir = os.path.join(self.unit_test_dir, '14 prebuilt object') |
|
|
|
tdir = os.path.join(self.unit_test_dir, '14 prebuilt object') |
|
|
|
source = os.path.join(tdir, 'source.c') |
|
|
|
source = os.path.join(tdir, 'source.c') |
|
|
|
objectfile = os.path.join(tdir, 'prebuilt.' + object_suffix) |
|
|
|
objectfile = os.path.join(tdir, 'prebuilt.' + object_suffix) |
|
|
@ -1428,21 +1428,27 @@ int main(int argc, char **argv) { |
|
|
|
finally: |
|
|
|
finally: |
|
|
|
os.unlink(objectfile) |
|
|
|
os.unlink(objectfile) |
|
|
|
|
|
|
|
|
|
|
|
def test_prebuilt_static_lib(self): |
|
|
|
def build_static_lib(self, compiler, source, objectfile, outfile, extra_args=None): |
|
|
|
(compiler, object_suffix, static_suffix, _) = self.detect_prebuild_env() |
|
|
|
if extra_args is None: |
|
|
|
tdir = os.path.join(self.unit_test_dir, '15 prebuilt static') |
|
|
|
extra_args = [] |
|
|
|
source = os.path.join(tdir, 'libdir/best.c') |
|
|
|
if compiler.id == 'msvc': |
|
|
|
objectfile = os.path.join(tdir, 'libdir/best.' + object_suffix) |
|
|
|
link_cmd = ['lib', '/NOLOGO', '/OUT:' + outfile, objectfile] |
|
|
|
stlibfile = os.path.join(tdir, 'libdir/libbest.' + static_suffix) |
|
|
|
|
|
|
|
if compiler == 'cl': |
|
|
|
|
|
|
|
link_cmd = ['lib', '/NOLOGO', '/OUT:' + stlibfile, objectfile] |
|
|
|
|
|
|
|
else: |
|
|
|
else: |
|
|
|
link_cmd = ['ar', 'csr', stlibfile, objectfile] |
|
|
|
link_cmd = ['ar', 'csr', outfile, objectfile] |
|
|
|
self.pbcompile(compiler, source, objectfile) |
|
|
|
self.pbcompile(compiler, source, objectfile, extra_args=extra_args) |
|
|
|
try: |
|
|
|
try: |
|
|
|
subprocess.check_call(link_cmd) |
|
|
|
subprocess.check_call(link_cmd) |
|
|
|
finally: |
|
|
|
finally: |
|
|
|
os.unlink(objectfile) |
|
|
|
os.unlink(objectfile) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prebuilt_static_lib(self): |
|
|
|
|
|
|
|
(cc, object_suffix, _) = self.detect_prebuild_env() |
|
|
|
|
|
|
|
tdir = os.path.join(self.unit_test_dir, '15 prebuilt static') |
|
|
|
|
|
|
|
source = os.path.join(tdir, 'libdir/best.c') |
|
|
|
|
|
|
|
objectfile = os.path.join(tdir, 'libdir/best.' + object_suffix) |
|
|
|
|
|
|
|
stlibfile = os.path.join(tdir, 'libdir/libbest.a') |
|
|
|
|
|
|
|
self.build_static_lib(cc, source, objectfile, stlibfile) |
|
|
|
|
|
|
|
# Run the test |
|
|
|
try: |
|
|
|
try: |
|
|
|
self.init(tdir) |
|
|
|
self.init(tdir) |
|
|
|
self.build() |
|
|
|
self.build() |
|
|
@ -1450,26 +1456,37 @@ int main(int argc, char **argv) { |
|
|
|
finally: |
|
|
|
finally: |
|
|
|
os.unlink(stlibfile) |
|
|
|
os.unlink(stlibfile) |
|
|
|
|
|
|
|
|
|
|
|
def test_prebuilt_shared_lib(self): |
|
|
|
def build_shared_lib(self, compiler, source, objectfile, outfile, impfile, extra_args=None): |
|
|
|
(compiler, object_suffix, _, shared_suffix) = self.detect_prebuild_env() |
|
|
|
if extra_args is None: |
|
|
|
tdir = os.path.join(self.unit_test_dir, '16 prebuilt shared') |
|
|
|
|
|
|
|
source = os.path.join(tdir, 'alexandria.c') |
|
|
|
|
|
|
|
objectfile = os.path.join(tdir, 'alexandria.' + object_suffix) |
|
|
|
|
|
|
|
if compiler == 'cl': |
|
|
|
|
|
|
|
extra_args = [] |
|
|
|
extra_args = [] |
|
|
|
shlibfile = os.path.join(tdir, 'alexandria.' + shared_suffix) |
|
|
|
if compiler.id == 'msvc': |
|
|
|
link_cmd = ['link', '/NOLOGO','/DLL', '/DEBUG', '/IMPLIB:' + os.path.join(tdir, 'alexandria.lib'), '/OUT:' + shlibfile, objectfile] |
|
|
|
link_cmd = ['link', '/NOLOGO', '/DLL', '/DEBUG', |
|
|
|
|
|
|
|
'/IMPLIB:' + impfile, '/OUT:' + outfile, objectfile] |
|
|
|
else: |
|
|
|
else: |
|
|
|
extra_args = ['-fPIC'] |
|
|
|
extra_args += ['-fPIC'] |
|
|
|
shlibfile = os.path.join(tdir, 'libalexandria.' + shared_suffix) |
|
|
|
link_cmd = compiler.get_exelist() + ['-shared', '-o', outfile, objectfile] |
|
|
|
link_cmd = [compiler, '-shared', '-o', shlibfile, objectfile] |
|
|
|
|
|
|
|
if not mesonbuild.mesonlib.is_osx(): |
|
|
|
if not mesonbuild.mesonlib.is_osx(): |
|
|
|
link_cmd += ['-Wl,-soname=libalexandria.so'] |
|
|
|
link_cmd += ['-Wl,-soname=' + os.path.basename(outfile)] |
|
|
|
self.pbcompile(compiler, source, objectfile, extra_args=extra_args) |
|
|
|
self.pbcompile(compiler, source, objectfile, extra_args=extra_args) |
|
|
|
try: |
|
|
|
try: |
|
|
|
subprocess.check_call(link_cmd) |
|
|
|
subprocess.check_call(link_cmd) |
|
|
|
finally: |
|
|
|
finally: |
|
|
|
os.unlink(objectfile) |
|
|
|
os.unlink(objectfile) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prebuilt_shared_lib(self): |
|
|
|
|
|
|
|
(cc, object_suffix, shared_suffix) = self.detect_prebuild_env() |
|
|
|
|
|
|
|
tdir = os.path.join(self.unit_test_dir, '16 prebuilt shared') |
|
|
|
|
|
|
|
source = os.path.join(tdir, 'alexandria.c') |
|
|
|
|
|
|
|
objectfile = os.path.join(tdir, 'alexandria.' + object_suffix) |
|
|
|
|
|
|
|
impfile = os.path.join(tdir, 'alexandria.lib') |
|
|
|
|
|
|
|
if cc.id == 'msvc': |
|
|
|
|
|
|
|
shlibfile = os.path.join(tdir, 'alexandria.' + shared_suffix) |
|
|
|
|
|
|
|
elif is_cygwin(): |
|
|
|
|
|
|
|
shlibfile = os.path.join(tdir, 'cygalexandria.' + shared_suffix) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
shlibfile = os.path.join(tdir, 'libalexandria.' + shared_suffix) |
|
|
|
|
|
|
|
self.build_shared_lib(cc, source, objectfile, shlibfile, impfile) |
|
|
|
|
|
|
|
# Run the test |
|
|
|
try: |
|
|
|
try: |
|
|
|
self.init(tdir) |
|
|
|
self.init(tdir) |
|
|
|
self.build() |
|
|
|
self.build() |
|
|
@ -1483,6 +1500,68 @@ int main(int argc, char **argv) { |
|
|
|
if os.path.splitext(fname)[1] not in ['.c', '.h']: |
|
|
|
if os.path.splitext(fname)[1] not in ['.c', '.h']: |
|
|
|
os.unlink(fname) |
|
|
|
os.unlink(fname) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_pkgconfig_static(self): |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
Test that the we only use static libraries when `static: true` is |
|
|
|
|
|
|
|
passed to dependency() with pkg-config. Can't be an ordinary test |
|
|
|
|
|
|
|
because we need to build libs and try to find them from meson.build |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
if not shutil.which('pkg-config'): |
|
|
|
|
|
|
|
raise unittest.SkipTest('pkg-config not found') |
|
|
|
|
|
|
|
(cc, objext, shext) = self.detect_prebuild_env() |
|
|
|
|
|
|
|
testdir = os.path.join(self.unit_test_dir, '17 pkgconfig static') |
|
|
|
|
|
|
|
source = os.path.join(testdir, 'foo.c') |
|
|
|
|
|
|
|
objectfile = os.path.join(testdir, 'foo.' + objext) |
|
|
|
|
|
|
|
stlibfile = os.path.join(testdir, 'libfoo.a') |
|
|
|
|
|
|
|
impfile = os.path.join(testdir, 'foo.lib') |
|
|
|
|
|
|
|
if cc.id == 'msvc': |
|
|
|
|
|
|
|
shlibfile = os.path.join(testdir, 'foo.' + shext) |
|
|
|
|
|
|
|
elif is_cygwin(): |
|
|
|
|
|
|
|
shlibfile = os.path.join(testdir, 'cygfoo.' + shext) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
shlibfile = os.path.join(testdir, 'libfoo.' + shext) |
|
|
|
|
|
|
|
# Build libs |
|
|
|
|
|
|
|
self.build_static_lib(cc, source, objectfile, stlibfile, extra_args=['-DFOO_STATIC']) |
|
|
|
|
|
|
|
self.build_shared_lib(cc, source, objectfile, shlibfile, impfile) |
|
|
|
|
|
|
|
# Run test |
|
|
|
|
|
|
|
os.environ['PKG_CONFIG_LIBDIR'] = self.builddir |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
self.init(testdir) |
|
|
|
|
|
|
|
self.build() |
|
|
|
|
|
|
|
self.run_tests() |
|
|
|
|
|
|
|
finally: |
|
|
|
|
|
|
|
os.unlink(stlibfile) |
|
|
|
|
|
|
|
os.unlink(shlibfile) |
|
|
|
|
|
|
|
if mesonbuild.mesonlib.is_windows(): |
|
|
|
|
|
|
|
# Clean up all the garbage MSVC writes in the |
|
|
|
|
|
|
|
# source tree. |
|
|
|
|
|
|
|
for fname in glob(os.path.join(testdir, 'foo.*')): |
|
|
|
|
|
|
|
if os.path.splitext(fname)[1] not in ['.c', '.h', '.in']: |
|
|
|
|
|
|
|
os.unlink(fname) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_pkgconfig_gen_escaping(self): |
|
|
|
|
|
|
|
if not shutil.which('pkg-config'): |
|
|
|
|
|
|
|
raise unittest.SkipTest('pkg-config not found') |
|
|
|
|
|
|
|
testdir = os.path.join(self.common_test_dir, '51 pkgconfig-gen') |
|
|
|
|
|
|
|
prefix = '/usr/with spaces' |
|
|
|
|
|
|
|
libdir = 'lib' |
|
|
|
|
|
|
|
self.init(testdir, extra_args=['--prefix=' + prefix, |
|
|
|
|
|
|
|
'--libdir=' + libdir]) |
|
|
|
|
|
|
|
# Find foo dependency |
|
|
|
|
|
|
|
os.environ['PKG_CONFIG_LIBDIR'] = self.privatedir |
|
|
|
|
|
|
|
env = FakeEnvironment() |
|
|
|
|
|
|
|
kwargs = {'required': True, 'silent': True} |
|
|
|
|
|
|
|
foo_dep = PkgConfigDependency('libfoo', env, kwargs) |
|
|
|
|
|
|
|
# Ensure link_args are properly quoted |
|
|
|
|
|
|
|
libdir = PurePath(prefix) / PurePath(libdir) |
|
|
|
|
|
|
|
link_args = ['-L' + libdir.as_posix(), '-lfoo'] |
|
|
|
|
|
|
|
self.assertEqual(foo_dep.get_link_args(), link_args) |
|
|
|
|
|
|
|
# Ensure include args are properly quoted |
|
|
|
|
|
|
|
incdir = PurePath(prefix) / PurePath('include') |
|
|
|
|
|
|
|
cargs = ['-I' + incdir.as_posix()] |
|
|
|
|
|
|
|
self.assertEqual(foo_dep.get_compile_args(), cargs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FailureTests(BasePlatformTests): |
|
|
|
class FailureTests(BasePlatformTests): |
|
|
|
''' |
|
|
|
''' |
|
|
|
Tests that test failure conditions. Build files here should be dynamically |
|
|
|
Tests that test failure conditions. Build files here should be dynamically |
|
|
@ -1539,6 +1618,8 @@ class FailureTests(BasePlatformTests): |
|
|
|
def test_dependency(self): |
|
|
|
def test_dependency(self): |
|
|
|
if not shutil.which('pkg-config'): |
|
|
|
if not shutil.which('pkg-config'): |
|
|
|
raise unittest.SkipTest('pkg-config not found') |
|
|
|
raise unittest.SkipTest('pkg-config not found') |
|
|
|
|
|
|
|
if subprocess.call(['pkg-config', '--exists', 'zlib']) != 0: |
|
|
|
|
|
|
|
raise unittest.SkipTest('zlib not found with pkg-config') |
|
|
|
a = (("dependency('zlib', method : 'fail')", "'fail' is invalid"), |
|
|
|
a = (("dependency('zlib', method : 'fail')", "'fail' is invalid"), |
|
|
|
("dependency('zlib', static : '1')", "[Ss]tatic.*boolean"), |
|
|
|
("dependency('zlib', static : '1')", "[Ss]tatic.*boolean"), |
|
|
|
("dependency('zlib', version : 1)", "[Vv]ersion.*string or list"), |
|
|
|
("dependency('zlib', version : 1)", "[Vv]ersion.*string or list"), |
|
|
@ -1722,12 +1803,12 @@ class LinuxlikeTests(BasePlatformTests): |
|
|
|
env = FakeEnvironment() |
|
|
|
env = FakeEnvironment() |
|
|
|
kwargs = {'required': True, 'silent': True} |
|
|
|
kwargs = {'required': True, 'silent': True} |
|
|
|
os.environ['PKG_CONFIG_LIBDIR'] = self.privatedir |
|
|
|
os.environ['PKG_CONFIG_LIBDIR'] = self.privatedir |
|
|
|
simple_dep = PkgConfigDependency('libfoo', env, kwargs) |
|
|
|
foo_dep = PkgConfigDependency('libfoo', env, kwargs) |
|
|
|
self.assertTrue(simple_dep.found()) |
|
|
|
self.assertTrue(foo_dep.found()) |
|
|
|
self.assertEqual(simple_dep.get_version(), '1.0') |
|
|
|
self.assertEqual(foo_dep.get_version(), '1.0') |
|
|
|
self.assertIn('-lfoo', simple_dep.get_link_args()) |
|
|
|
self.assertIn('-lfoo', foo_dep.get_link_args()) |
|
|
|
self.assertEqual(simple_dep.get_pkgconfig_variable('foo'), 'bar') |
|
|
|
self.assertEqual(foo_dep.get_pkgconfig_variable('foo'), 'bar') |
|
|
|
self.assertPathEqual(simple_dep.get_pkgconfig_variable('datadir'), '/usr/data') |
|
|
|
self.assertPathEqual(foo_dep.get_pkgconfig_variable('datadir'), '/usr/data') |
|
|
|
|
|
|
|
|
|
|
|
def test_vala_c_warnings(self): |
|
|
|
def test_vala_c_warnings(self): |
|
|
|
''' |
|
|
|
''' |
|
|
|