Merge pull request #613 from lzutao/fix_meson_tests

meson: Fix build and test problems
This commit is contained in:
Yann Collet 2018-12-09 11:29:03 -08:00 committed by GitHub
commit 077caefae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 108 additions and 94 deletions

View File

@ -168,10 +168,14 @@ script:
&& curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
&& python3 get-pip.py --user && rm get-pip.py
&& pip3 install --user meson ninja
&& meson --buildtype=debug -Dauto_features=enabled -Ddefault_library=both
-Dbuild_{programs,contrib,tests,examples}=true contrib/meson build
&& export CC=clang CXX=clang++
&& meson --buildtype=debug
-Db_lundef=false
-Dauto_features=enabled
-Ddefault_library=both
-Dbuild_{programs,contrib,tests,examples}=true
contrib/meson build
&& cd "$_"
&& ninja
&& DESTDIR=./staging ninja install
&& tree ./staging;
travis_terminate "$?";

View File

@ -11,11 +11,6 @@ import re
import sys
def usage():
print('usage: python3 GetLz4LibraryVersion.py <path/to/lz4.h>')
sys.exit(1)
def find_version(filepath):
version_file_data = None
with open(filepath) as fd:
@ -33,10 +28,11 @@ def find_version(filepath):
def main():
if len(sys.argv) < 2:
usage()
filepath = sys.argv[1]
import argparse
parser = argparse.ArgumentParser(description='Print lz4 version from lib/lz4.h')
parser.add_argument('file', help='path to lib/lz4.h')
args = parser.parse_args()
filepath = args.file
version_tup = find_version(filepath)
print('.'.join(version_tup))

View File

@ -7,42 +7,31 @@
# LICENSE file in the root directory of this source tree) and the GPLv2 (found
# in the COPYING file in the root directory of this source tree).
# #############################################################################
import errno
import os
import pathlib # since Python 3.4
def mkdir_p(path, dir_mode=0o777):
try:
os.makedirs(path, mode=dir_mode)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
def install_symlink(src, dst, install_dir, dst_is_dir=False, dir_mode=0o777):
if not install_dir.exists():
install_dir.mkdir(mode=dir_mode, parents=True, exist_ok=True)
if not install_dir.is_dir():
raise NotADirectoryError(install_dir)
def InstallSymlink(src, dst, install_dir, dst_is_dir=False, dir_mode=0o777):
if not os.path.exists(install_dir):
mkdir_p(install_dir, dir_mode)
if not os.path.isdir(install_dir):
raise NotADirectoryError(install_dir)
new_dst = os.path.join(install_dir, dst)
if os.path.islink(new_dst) and os.readlink(new_dst) == src:
print('File exists: %r -> %r' % (dst, src))
new_dst = install_dir.joinpath(dst)
if new_dst.is_symlink() and os.readlink(new_dst) == src:
print('File exists: {!r} -> {!r}'.format(new_dst, src))
return
print('Installing symlink %r -> %r' % (new_dst, src))
os.symlink(src, new_dst, dst_is_dir)
print('Installing symlink {!r} -> {!r}'.format(new_dst, src))
new_dst.symlink_to(src, target_is_directory=dst_is_dir)
def main():
import argparse
parser = argparse.ArgumentParser(description='Install a symlink.\n',
usage='usage: InstallSymlink.py [-h] [-d] [-m MODE] src dst '
'install_dir\n\n'
parser = argparse.ArgumentParser(description='Install a symlink',
usage='InstallSymlink.py [-h] [-d] [-m MODE] src dst install_dir\n\n'
'example:\n'
'\tInstallSymlink.py libcrypto.so.1.0.0 libcrypt.so '
'/usr/lib/x86_64-linux-gnu False')
'\tInstallSymlink.py dash sh /bin')
parser.add_argument('src', help='target to link')
parser.add_argument('dst', help='link name')
parser.add_argument('install_dir', help='installation directory')
@ -56,16 +45,14 @@ def main():
src = args.src
dst = args.dst
install_dir = args.install_dir
dst_is_dir = args.isdir
dir_mode = int(args.mode, 8)
install_dir = pathlib.Path(args.install_dir)
DESTDIR = os.environ.get('DESTDIR')
if DESTDIR:
install_dir = DESTDIR + install_dir if os.path.isabs(install_dir) \
else os.path.join(DESTDIR, install_dir)
InstallSymlink(src, dst, install_dir, dst_is_dir, dir_mode)
meson_destdir = os.environ.get('MESON_INSTALL_DESTDIR_PREFIX')
if meson_destdir:
install_dir = pathlib.Path(meson_destdir).joinpath(install_dir)
install_symlink(src, dst, install_dir, dst_is_dir, dir_mode)
if __name__ == '__main__':

34
contrib/meson/README.md Normal file
View File

@ -0,0 +1,34 @@
Meson build system for lz4
==========================
Meson is a build system designed to optimize programmer productivity.
It aims to do this by providing simple, out-of-the-box support for
modern software development tools and practices, such as unit tests,
coverage reports, Valgrind, CCache and the like.
This Meson build system is provided with no guarantee.
## How to build
`cd` to this meson directory (`contrib/meson`)
```sh
meson --buildtype=release -Ddefault_library=shared -Dbuild_programs=true builddir
cd builddir
ninja # to build
ninja install # to install
```
You might want to install it in staging directory:
```sh
DESTDIR=./staging ninja install
```
To configure build options, use:
```sh
meson configure
```
See [man meson(1)](https://manpages.debian.org/testing/meson/meson.1.en.html).

View File

@ -32,13 +32,13 @@ liblz4 = library('lz4',
include_directories: liblz4_includes,
c_args: liblz4_c_args,
install: true,
soversion: lz4_libversion)
version: lz4_libversion)
liblz4_dep = declare_dependency(link_with: liblz4,
include_directories: liblz4_includes)
pkgconfig.generate(name: 'lz4',
filebase: 'lz4',
filebase: 'liblz4',
libraries: [liblz4],
description: 'extremely fast lossless compression algorithm library',
version: lz4_libversion,

View File

@ -17,6 +17,7 @@ project('lz4', ['c'],
cc = meson.get_compiler('c')
pkgconfig = import('pkgconfig')
python3 = import('python').find_installation()
c_std = get_option('c_std')
host_machine_os = host_machine.system()
os_windows = 'windows'
@ -31,26 +32,30 @@ compiler_clang = 'clang'
compiler_msvc = 'msvc'
lz4_version = meson.project_version()
lz4_libversion = ''
c_std = get_option('c_std')
lz4_h_file = join_paths(meson.current_source_dir(), '../../lib/lz4.h')
GetLz4LibraryVersion_py = files('GetLz4LibraryVersion.py')
r = run_command(python3, GetLz4LibraryVersion_py, lz4_h_file)
if r.returncode() == 0
output = r.stdout().strip()
if output.version_compare('>@0@'.format(lz4_version))
lz4_version = output
message('Project version is now: @0@'.format(lz4_version))
endif
else
message('Cannot find project version in @0@'.format(lz4_h_file))
endif
lz4_libversion = lz4_version
# =============================================================================
# Installation directories
# =============================================================================
if host_machine_os == os_windows
lz4_prefix = '.'
lz4_bindir = 'bin'
lz4_datadir = 'share'
lz4_mandir = join_paths(lz4_datadir, 'man')
else
lz4_prefix = get_option('prefix')
lz4_bindir = join_paths(lz4_prefix, get_option('bindir'))
lz4_datadir = join_paths(lz4_prefix, get_option('datadir'))
lz4_mandir = join_paths(lz4_prefix, get_option('mandir'))
endif
lz4_prefix = get_option('prefix')
lz4_bindir = get_option('bindir')
lz4_datadir = get_option('datadir')
lz4_mandir = get_option('mandir')
lz4_docdir = join_paths(lz4_datadir, 'doc', meson.project_name())
# =============================================================================
@ -72,30 +77,6 @@ build_tests = get_option('build_tests')
build_examples = get_option('build_examples')
#feature_multi_thread = get_option('multi_thread')
# =============================================================================
# Helper scripts for Meson
# =============================================================================
GetLz4LibraryVersion_py = files('GetLz4LibraryVersion.py')
# =============================================================================
# Getting project version from lz4.h
# =============================================================================
lz4_h_file = join_paths(meson.current_source_dir(), 'lib/lz4.h')
r = run_command(python3, GetLz4LibraryVersion_py, lz4_h_file)
if r.returncode() == 0
output = r.stdout().strip()
if output.version_compare('>@0@'.format(lz4_version))
lz4_version = output
message('Project version is now: @0@'.format(lz4_version))
endif
endif
if host_machine_os != os_windows
lz4_libversion = lz4_version
endif
# =============================================================================
# Dependencies
# =============================================================================
@ -112,9 +93,8 @@ add_project_arguments(['-DXXH_NAMESPACE=LZ4_'], language: 'c')
if [compiler_gcc, compiler_clang].contains(cc_id)
common_warning_flags = []
if buildtype == 'release'
common_warning_flags = ['-Werror']
endif
# Should use Meson's own --werror build option
#common_warning_flags += ['-Werror']
if c_std == 'c89' or c_std == 'gnu89'
common_warning_flags += ['-pedantic', '-Wno-long-long', '-Wno-variadic-macros']
elif c_std == 'c99' or c_std == 'gnu99'

View File

@ -43,9 +43,10 @@ install_man(join_paths(lz4_root_dir, 'programs/lz4.1'))
InstallSymlink_py = '../InstallSymlink.py'
lz4_man1_dir = join_paths(lz4_mandir, 'man1')
man1_EXT = host_machine_os != os_windows ? '.1.gz' : '.1'
bin_EXT = host_machine_os == os_windows ? '.exe' : ''
man1_EXT = '.1.gz' # Meson automatically compresses manpages
foreach f : ['lz4c', 'lz4cat', 'unlz4']
meson.add_install_script(InstallSymlink_py, 'lz4', f, lz4_bindir)
meson.add_install_script(InstallSymlink_py, 'lz4' + bin_EXT, f + bin_EXT, lz4_bindir)
meson.add_install_script(InstallSymlink_py, 'lz4' + man1_EXT, f + man1_EXT, lz4_man1_dir)
endforeach

View File

@ -15,7 +15,7 @@ lib_dir_inc = include_directories(join_paths(lz4_root_dir, 'lib'))
# Test flags
# =============================================================================
TEST_FILES = join_paths(lz4_root_dir, 'tests/COPYING')
TEST_FILES = join_paths(meson.current_source_dir(), lz4_root_dir, 'tests/COPYING')
FUZZER_TIME = '-T90s'
NB_LOOPS = '-i1'
@ -76,6 +76,18 @@ checkTag = executable('checkTag',
# Tests (Use "meson test --list" to list all tests)
# =============================================================================
test('test-fullbench', fullbench, args: ['--no-prompt', NB_LOOPS, TEST_FILES])
test('test-fuzzer', fuzzer, args: [FUZZER_TIME])
test('test-frametest', frametest, args: [FUZZER_TIME])
# XXX: (Need TEST) These timeouts (in seconds) when running on a HDD should be
# at least six times bigger than on a SSD
test('test-fullbench',
fullbench,
args: ['--no-prompt', NB_LOOPS, TEST_FILES],
timeout: 420) # Should enough when running on HDD
test('test-fuzzer',
fuzzer,
args: [FUZZER_TIME],
timeout: 100)
test('test-frametest',
frametest,
args: [FUZZER_TIME],
timeout: 100)