diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2017-10-02 19:09:08 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-02 19:09:08 +0300 |
commit | 9483875798bb6842769a0b3d52635ff950ea11a7 (patch) | |
tree | ac6927aacd5e1e4c0aeb0fb4ffb01734201c5262 /run_unittests.py | |
parent | 35313c2a850020dc2d98c1aa5b2f4340e49f01d6 (diff) | |
parent | ec45c29c9ddd5d848eb1555cdc09246d8900afec (diff) | |
download | meson-9483875798bb6842769a0b3d52635ff950ea11a7.zip meson-9483875798bb6842769a0b3d52635ff950ea11a7.tar.gz meson-9483875798bb6842769a0b3d52635ff950ea11a7.tar.bz2 |
Merge pull request #2397 from mesonbuild/prebuilt
Better support for prebuilt shared libs
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-x | run_unittests.py | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/run_unittests.py b/run_unittests.py index 7ae9947..fa8f049 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -1341,6 +1341,100 @@ int main(int argc, char **argv) { for i in targets: self.assertPathExists(os.path.join(testdir, i)) + def detect_prebuild_env(self): + if mesonbuild.mesonlib.is_windows(): + object_suffix = 'obj' + else: + object_suffix = 'o' + static_suffix = 'a' + shared_suffix = 'so' + if shutil.which('cl'): + compiler = 'cl' + static_suffix = 'lib' + shared_suffix = 'dll' + elif shutil.which('cc'): + compiler = 'cc' + elif shutil.which('gcc'): + compiler = 'gcc' + else: + raise RuntimeError("Could not find C compiler.") + return (compiler, object_suffix, static_suffix, shared_suffix) + + def pbcompile(self, compiler, source, objectfile, extra_args=[]): + if compiler == 'cl': + cmd = [compiler, '/nologo', '/Fo' + objectfile, '/c', source] + extra_args + else: + cmd = [compiler, '-c', source, '-o', objectfile] + extra_args + subprocess.check_call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + + def test_prebuilt_object(self): + (compiler, object_suffix, _, _) = self.detect_prebuild_env() + tdir = os.path.join(self.unit_test_dir, '14 prebuilt object') + source = os.path.join(tdir, 'source.c') + objectfile = os.path.join(tdir, 'prebuilt.' + object_suffix) + self.pbcompile(compiler, source, objectfile) + try: + self.init(tdir) + self.build() + self.run_tests() + finally: + os.unlink(objectfile) + + def test_prebuilt_static_lib(self): + (compiler, object_suffix, static_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.' + static_suffix) + if compiler == 'cl': + link_cmd = ['lib', '/NOLOGO', '/OUT:' + stlibfile, objectfile] + else: + link_cmd = ['ar', 'csr', stlibfile, objectfile] + self.pbcompile(compiler, source, objectfile) + try: + subprocess.check_call(link_cmd) + finally: + os.unlink(objectfile) + try: + self.init(tdir) + self.build() + self.run_tests() + finally: + os.unlink(stlibfile) + + def test_prebuilt_shared_lib(self): + (compiler, 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) + if compiler == 'cl': + extra_args = [] + shlibfile = os.path.join(tdir, 'alexandria.' + shared_suffix) + link_cmd = ['link', '/NOLOGO','/DLL', '/DEBUG', '/IMPLIB:' + os.path.join(tdir, 'alexandria.lib'), '/OUT:' + shlibfile, objectfile] + else: + extra_args = ['-fPIC'] + shlibfile = os.path.join(tdir, 'libalexandria.' + shared_suffix) + link_cmd = [compiler, '-shared', '-o', shlibfile, objectfile] + if not mesonbuild.mesonlib.is_osx(): + link_cmd += ['-Wl,-soname=libalexandria.so'] + self.pbcompile(compiler, source, objectfile, extra_args=extra_args) + try: + subprocess.check_call(link_cmd) + finally: + os.unlink(objectfile) + try: + self.init(tdir) + self.build() + self.run_tests() + finally: + 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(tdir, 'alexandria.*')): + if os.path.splitext(fname)[1] not in ['.c', '.h']: + os.unlink(fname) class FailureTests(BasePlatformTests): ''' |