From 4997017be281b06f8dc83d03e0e66dbfedf6c634 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 12 Sep 2017 16:26:15 +0200 Subject: [PATCH] Run meson test when possible. To run unit-test (meson) on cross-compilation, we need a wrapper to run the binary (wine, qemu, ...), but: - We have no emulator for android (we have one for the system, but we can't simply run a binary) - With dynamic compilation, it seems pretty complex to configure them correctly. - For mingw32 compilation, `wine` need to be correctly configured to find dll from the system mingw32 installation. --- dependency_utils.py | 11 +++++++++ kiwix-build.py | 34 +++++++++++++++++++++++--- templates/meson_android_cross_file.txt | 19 ++++++++++++++ templates/meson_cross_file.txt | 1 + 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 templates/meson_android_cross_file.txt diff --git a/dependency_utils.py b/dependency_utils.py index e1b3b0d..b423597 100644 --- a/dependency_utils.py +++ b/dependency_utils.py @@ -210,6 +210,8 @@ class Builder: self.command('pre_build_script', self._pre_build_script) self.command('configure', self._configure) self.command('compile', self._compile) + if hasattr(self, '_test'): + self.command('test', self._test) self.command('install', self._install) if hasattr(self, '_post_build_script'): self.command('post_build_script', self._post_build_script) @@ -340,6 +342,15 @@ class MesonBuilder(Builder): command = "{} -v".format(self.buildEnv.ninja_command) self.buildEnv.run_command(command, self.build_path, context) + def _test(self, context): + if ( self.buildEnv.platform_info.build == 'android' + or (self.buildEnv.platform_info.build != 'native' + and not self.buildEnv.platform_info.static) + ): + raise SkipCommand() + command = "{} --verbose".format(self.buildEnv.mesontest_command) + self.buildEnv.run_command(command, self.build_path, context) + def _install(self, context): command = "{} -v install".format(self.buildEnv.ninja_command) self.buildEnv.run_command(command, self.build_path, context) diff --git a/kiwix-build.py b/kiwix-build.py index a2b8428..be7d907 100755 --- a/kiwix-build.py +++ b/kiwix-build.py @@ -254,6 +254,7 @@ class BuildEnv: self.meson_command = self._detect_meson() if not self.meson_command: sys.exit("ERROR: meson command not fount") + self.mesontest_command = "mesontest" self.setup_build(options.target_platform) self.setup_toolchains() self.options = options @@ -328,7 +329,7 @@ class BuildEnv: def setup_android(self): self.cmake_crossfile = self._gen_crossfile('cmake_android_cross_file.txt') - self.meson_crossfile = self._gen_crossfile('meson_cross_file.txt') + self.meson_crossfile = self._gen_crossfile('meson_android_cross_file.txt') def setup_armhf(self): self.cmake_crossfile = self._gen_crossfile('cmake_cross_file.txt') @@ -428,12 +429,12 @@ class BuildEnv: env['LD_LIBRARY_PATH'] = ':'.join([env['LD_LIBRARY_PATH'], pj(self.install_dir, 'lib'), - pj(self.install_dir, 'lib64') + pj(self.install_dir, self.libprefix) ]) env['CPPFLAGS'] = " ".join(['-I'+pj(self.install_dir, 'include'), env['CPPFLAGS']]) env['LDFLAGS'] = " ".join(['-L'+pj(self.install_dir, 'lib'), - '-L'+pj(self.install_dir, 'lib64'), + '-L'+pj(self.install_dir, self.libprefix), env['LDFLAGS']]) return env @@ -547,6 +548,7 @@ class Toolchain(metaclass=_MetaToolchain): all_toolchains = {} configure_option = "" cmake_option = "" + exec_wrapper_def = "" Builder = None Source = None @@ -618,6 +620,16 @@ class mingw32_toolchain(Toolchain): ('RANLIB', 'ranlib')) } + @property + def exec_wrapper_def(self): + try: + which('wine') + except subprocess.CalledProcessError: + return "" + else: + return "exec_wrapper = 'wine'" + + @property def configure_option(self): return '--host={}'.format(self.arch_full) @@ -836,6 +848,15 @@ class armhf_toolchain(Toolchain): return {k:pj(self.root_path, 'bin', v) for k,v in binaries} + @property + def exec_wrapper_def(self): + try: + which('qemu-arm') + except subprocess.CalledProcessError: + return "" + else: + return "exec_wrapper = 'qemu-arm'" + @property def configure_option(self): return '--host={}'.format(self.arch_full) @@ -848,6 +869,13 @@ class armhf_toolchain(Toolchain): env['CFLAGS'] = " -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 "+env['CFLAGS'] env['CXXFLAGS'] = " -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 "+env['CXXFLAGS'] env['LIBS'] = " ".join(self.buildEnv.cross_config['extra_libs']) + " " +env['LIBS'] + env['QEMU_LD_PREFIX'] = pj(self.root_path, "arm-linux-gnueabihf", "libc") + env['QEMU_SET_ENV'] = "LD_LIBRARY_PATH={}".format( + ':'.join([ + pj(self.root_path, "arm-linux-gnueabihf", "lib"), + pj(self.buildEnv.install_dir, 'lib'), + pj(self.buildEnv.install_dir, self.buildEnv.libprefix) + ])) def set_compiler(self, env): env['CC'] = self.binaries['CC'] diff --git a/templates/meson_android_cross_file.txt b/templates/meson_android_cross_file.txt new file mode 100644 index 0000000..d0710b4 --- /dev/null +++ b/templates/meson_android_cross_file.txt @@ -0,0 +1,19 @@ +[binaries] +pkgconfig = 'pkg-config' +c = '{toolchain.binaries[CC]}' +ar = '{toolchain.binaries[AR]}' +cpp = '{toolchain.binaries[CXX]}' +strip = '{toolchain.binaries[STRIP]}' + +[properties] +c_link_args = {extra_libs!r} +cpp_link_args = {extra_libs!r} +c_args = {extra_cflags!r} +cpp_args = {extra_cflags!r} +android_abi = '{host_machine[abi]}' + +[host_machine] +cpu_family = '{host_machine[cpu_family]}' +cpu = '{host_machine[cpu]}' +system = '{host_machine[lsystem]}' +endian = '{host_machine[endian]}' diff --git a/templates/meson_cross_file.txt b/templates/meson_cross_file.txt index d0710b4..069b2ee 100644 --- a/templates/meson_cross_file.txt +++ b/templates/meson_cross_file.txt @@ -4,6 +4,7 @@ c = '{toolchain.binaries[CC]}' ar = '{toolchain.binaries[AR]}' cpp = '{toolchain.binaries[CXX]}' strip = '{toolchain.binaries[STRIP]}' +{toolchain.exec_wrapper_def} [properties] c_link_args = {extra_libs!r}