diff options
author | Eugene Kliuchnikov <eustas@google.com> | 2016-07-28 10:18:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-28 10:18:20 +0200 |
commit | bd3a5ada1a76841555411c597731a144f1a4eed4 (patch) | |
tree | 581af67c0c79c85685f0805c4189cc3350532631 | |
parent | 882f41850b679c1ff4a3804d5515d142a5807376 (diff) | |
parent | 97b846f2fe0b1490e15ff6be8cedec1661ebf6e1 (diff) | |
download | brotli-bd3a5ada1a76841555411c597731a144f1a4eed4.zip brotli-bd3a5ada1a76841555411c597731a144f1a4eed4.tar.gz brotli-bd3a5ada1a76841555411c597731a144f1a4eed4.tar.bz2 |
Merge pull request #397 from nemequ/master
Add CMake, lots of Travis configurations
-rwxr-xr-x | .travis.sh | 46 | ||||
-rw-r--r-- | .travis.yml | 242 | ||||
-rw-r--r-- | CMakeLists.txt | 152 | ||||
-rw-r--r-- | tests/run-compatibility-test.cmake | 28 | ||||
-rw-r--r-- | tests/run-roundtrip-test.cmake | 35 |
5 files changed, 483 insertions, 20 deletions
diff --git a/.travis.sh b/.travis.sh new file mode 100755 index 0000000..2e8c2af --- /dev/null +++ b/.travis.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +case "$1" in + "install") + case "${TRAVIS_OS_NAME}" in + "osx") + brew update + brew install binutils + + case "${CC}" in + "gcc-"*) + which ${CC} || brew install homebrew/versions/gcc$(echo "${CC#*-}" | sed 's/\.//') + ;; + esac + + case "${BUILD_SYSTEM}" in + "python") + source terryfy/travis_tools.sh + get_python_environment $INSTALL_TYPE $PYTHON_VERSION venv + pip install --upgrade wheel + ;; + esac + ;; + esac + ;; + "script") + case "${BUILD_SYSTEM}" in + "cmake") + mkdir builddir && cd builddir + cmake -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DENABLE_SANITIZER="${SANITIZER}" -DCMAKE_C_FLAGS="${CFLAGS}" .. + make VERBOSE=1 + ctest -V + ;; + "python") + python setup.py build_ext test + ;; + esac + ;; + "after_success") + case "${BUILD_SYSTEM}" in + "python") + pip wheel -w dist . + ;; + esac + ;; +esac diff --git a/.travis.yml b/.travis.yml index c6fd74d..563e368 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,32 +1,234 @@ -language: -- objective-c -env: - matrix: - - INSTALL_TYPE='system' VERSION=2.7 - - INSTALL_TYPE='macpython' VERSION=2.7.10 CC=clang CXX=clang++ - - INSTALL_TYPE='macpython' VERSION=3.4.3 CC=clang CXX=clang++ - - INSTALL_TYPE='macpython' VERSION=3.5.0 CC=clang CXX=clang++ - - INSTALL_TYPE='homebrew' VERSION=2.7.10 - - INSTALL_TYPE='homebrew' VERSION=3.4.3 - - INSTALL_TYPE='homebrew' VERSION=3.5.0 +language: c +dist: trusty +matrix: + include: + ### + ## Linux builds using various versions of GCC. + ### + - os: linux + env: BUILD_SYSTEM=cmake C_COMPILER=gcc-6 CXX_COMPILER=g++-6 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-6 + - g++-6 + - os: linux + env: BUILD_SYSTEM=cmake C_COMPILER=gcc-5 CXX_COMPILER=g++-5 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-5 + - g++-5 + - os: linux + env: BUILD_SYSTEM=cmake C_COMPILER=gcc-4.9 CXX_COMPILER=g++-4.9 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.9 + - g++-4.9 + - os: linux + env: BUILD_SYSTEM=cmake C_COMPILER=gcc-4.8 CXX_COMPILER=g++-4.8 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.8 + - g++-4.8 + - os: linux + env: BUILD_SYSTEM=cmake C_COMPILER=gcc-4.7 CXX_COMPILER=g++-4.7 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.7 + - g++-4.7 + - os: linux + env: BUILD_SYSTEM=cmake C_COMPILER=gcc-4.6 CXX_COMPILER=g++-4.6 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.6 + - g++-4.6 + # - os: linux + # env: BUILD_SYSTEM=cmake C_COMPILER=gcc-4.5 CXX_COMPILER=g++-4.5 + # addons: + # apt: + # sources: + # - ubuntu-toolchain-r-test + # packages: + # - gcc-4.5 + # - g++-4.5 + - os: linux + env: BUILD_SYSTEM=cmake C_COMPILER=gcc-4.4 CXX_COMPILER=g++-4.4 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.4 + - g++-4.4 + + ### + ## clang on Linux + ### + - os: linux + env: BUILD_SYSTEM=cmake C_COMPILER=clang-3.8 CXX_COMPILER=clang++-3.8 + addons: + apt: + sources: + - llvm-toolchain-precise-3.8 + - ubuntu-toolchain-r-test + packages: + - clang-3.8 + - os: linux + env: BUILD_SYSTEM=cmake C_COMPILER=clang-3.7 CXX_COMPILER=clang++-3.7 + addons: + apt: + sources: + - llvm-toolchain-precise-3.7 + - ubuntu-toolchain-r-test + packages: + - clang-3.7 + - os: linux + env: BUILD_SYSTEM=cmake C_COMPILER=clang-3.6 CXX_COMPILER=clang++-3.6 + addons: + apt: + sources: + - llvm-toolchain-precise-3.6 + - ubuntu-toolchain-r-test + packages: + - clang-3.6 + - os: linux + env: BUILD_SYSTEM=cmake C_COMPILER=clang-3.5 CXX_COMPILER=clang++-3.5 + addons: + apt: + sources: + - llvm-toolchain-precise-3.5 + - ubuntu-toolchain-r-test + packages: + - clang-3.5 + + ### + ## Python build on Linux + ### + - os: linux + env: BUILD_SYSTEM=python C_COMPILER=gcc-6 CXX_COMPILER=g++-6 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-6 + - g++-6 + + ### + ## CMake on OS X + ## + ## These all work, but it seems unnecessary to actually build them + ## all since we already test all these versions of GCC on Linux. + ## We'll just test 4.4 and the most recent version. + ### + - os: osx + env: BUILD_SYSTEM=cmake C_COMPILER=gcc-6 CXX_COMPILER=g++-6 + # - os: osx + # env: BUILD_SYSTEM=cmake C_COMPILER=gcc-5 CXX_COMPILER=g++-5 + # - os: osx + # env: BUILD_SYSTEM=cmake C_COMPILER=gcc-4.9 CXX_COMPILER=g++-4.9 + # - os: osx + # env: BUILD_SYSTEM=cmake C_COMPILER=gcc-4.8 CXX_COMPILER=g++-4.8 + # - os: osx + # env: BUILD_SYSTEM=cmake C_COMPILER=gcc-4.7 CXX_COMPILER=g++-4.7 + # - os: osx + # env: BUILD_SYSTEM=cmake C_COMPILER=gcc-4.6 CXX_COMPILER=g++-4.6 + # - os: osx + # env: BUILD_SYSTEM=cmake C_COMPILER=gcc-4.5 CXX_COMPILER=g++-4.5 + - os: osx + env: BUILD_SYSTEM=cmake C_COMPILER=gcc-4.4 CXX_COMPILER=g++-4.4 + + ### + ## Python OS X builds + ### + - os: osx + env: BUILD_SYSTEM=python INSTALL_TYPE=system PYTHON_VERSION=2.7 + - os: osx + env: BUILD_SYSTEM=python INSTALL_TYPE=macpython PYTHON_VERSION=2.7.10 + - os: osx + env: BUILD_SYSTEM=python INSTALL_TYPE=homebrew PYTHON_VERSION=2.7.10 + - os: osx + env: BUILD_SYSTEM=python INSTALL_TYPE=macpython PYTHON_VERSION=3.4.3 + - os: osx + env: BUILD_SYSTEM=python INSTALL_TYPE=homebrew PYTHON_VERSION=3.4.3 + - os: osx + env: BUILD_SYSTEM=python INSTALL_TYPE=macpython PYTHON_VERSION=3.5.0 + - os: osx + env: BUILD_SYSTEM=python INSTALL_TYPE=homebrew PYTHON_VERSION=3.5.0 + + ### + ## Sanitizers + ### + - os: linux + env: BUILD_SYSTEM=cmake C_COMPILER=clang-3.8 CXX_COMPILER=clang++-3.8 SANITIZER=address + addons: + apt: + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.8 + packages: + - clang-3.8 + - os: linux + env: BUILD_SYSTEM=cmake C_COMPILER=clang-3.8 CXX_COMPILER=clang++-3.8 SANITIZER=thread + addons: + apt: + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.8 + packages: + - clang-3.8 + - os: linux + env: BUILD_SYSTEM=cmake C_COMPILER=clang-3.8 CXX_COMPILER=clang++-3.8 SANITIZER=undefined CFLAGS="-fno-sanitize-recover=undefined,integer" + addons: + apt: + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.8 + packages: + - clang-3.8 + +before_install: +### +## If we use the matrix to set CC/CXX Travis, overwrites the values, +## so instead we use C/CXX_COMPILER, then copy the values to CC/CXX +## here (after Travis has set CC/CXX). +### +- if [ -n "${C_COMPILER}" ]; then export CC="${C_COMPILER}"; fi +- if [ -n "${CXX_COMPILER}" ]; then export CXX="${CXX_COMPILER}"; fi install: -- source terryfy/travis_tools.sh -- get_python_environment $INSTALL_TYPE $VERSION venv -- pip install --upgrade wheel +- ./.travis.sh install script: -- python setup.py build_ext test +- ./.travis.sh script after_success: -- pip wheel -w dist . +- ./.travis.sh after_success + before_deploy: -- export WHEELS=$(ls ./dist/*.whl) +- if [ "${BUILD_SYSTEM}" = "python" ]; then export WHEELS=$(ls ./dist/*.whl); fi deploy: provider: releases api_key: secure: YcCBi6W/w4dtKCa59Wfm8L5lGWvK7KxaFNDr3yh1Hz5aStXXf758pEMHGewnlbfbwuj5a3SjBb1nLp1M69OQJfxm442uXBaBKo52PM9PPbD7NjvbNIso73pqcSODXQXKuZxDFpEhfuDTVq3hUkUqiwhChWhrFucJsSL51i7qSss= - file: - - "${WHEELS}" + file: "${WHEELS}" skip_cleanup: true on: - repo: google/brotli + repo: "google/brotli" tags: true + condition: "${BUILD_SYSTEM} = python" diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9d55711 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,152 @@ +# Ubuntu 12.04 LTS has CMake 2.8.7, and is an important target since +# several CI services, such as Travis and Drone, use it. Solaris 11 +# has 2.8.6, and it's not difficult to support if you already have to +# support 2.8.7. +cmake_minimum_required(VERSION 2.8.6) + +project(brotli) + +# If Brotli is being bundled in another project, we don't want to +# install anything. However, we want to let people override this, so +# we'll use the BROTLI_BUNDLED_MODE variable to let them do that; just +# set it to OFF in your project before you add_subdirectory(brotli). +get_directory_property(BROTLI_PARENT_DIRECTORY PARENT_DIRECTORY) +if(BROTLI_BUNDLED_MODE STREQUAL "") + # Bundled mode hasn't been set one way or the other, set the default + # depending on whether or not we are the top-level project. + if(BROTLI_PARENT_DIRECTORY) + set(BROTLI_BUNDLED_MODE OFF) + else() + set(BROTLI_BUNDLED_MODE ON) + endif() +endif() +mark_as_advanced(BROTLI_BUNDLED_MODE) + +# Parse version information from tools/version.h. Normally we would +# define these values here and write them out to configuration file(s) +# (i.e., config.h), but in this case we parse them from +# tools/version.h to be less intrusive. +file(STRINGS "tools/version.h" BROTLI_VERSION REGEX "^#define BROTLI_VERSION \"+([0-9]+)\\.([0-9]+)\\.([0-9]+)\"") +string(REGEX REPLACE "^#define BROTLI_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+)\"$" "\\1" BROTLI_VERSION_MAJOR "${BROTLI_VERSION}") +string(REGEX REPLACE "^#define BROTLI_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+)\"$" "\\2" BROTLI_VERSION_MINOR "${BROTLI_VERSION}") +string(REGEX REPLACE "^#define BROTLI_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+)\"$" "\\3" BROTLI_VERSION_REVISION "${BROTLI_VERSION}") +mark_as_advanced(BROTLI_VERSION_MAJOR BROTLI_VERSION_MINOR BROTLI_VERSION_REVISION) + +if (ENABLE_SANITIZER) + set(CMAKE_C_FLAGS " ${CMAKE_C_FLAGS} -fsanitize=${ENABLE_SANITIZER}") + set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -fsanitize=${ENABLE_SANITIZER}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${ENABLE_SANITIZER}") + + # By default, brotli depends on undefined behavior, but setting + # BROTLI_BUILD_PORTABLE should result in a build which does not. + if(ENABLE_SANITIZER STREQUAL "undefined") + add_definitions(-DBROTLI_BUILD_PORTABLE) + endif() +endif () + +set(BROTLI_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") +set(BROTLI_LIBRARIES brotli_enc brotli_dec brotli_common m) +mark_as_advanced(BROTLI_INCLUDE_DIRS BROTLI_LIBRARIES) + +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + add_definitions(-DOS_LINUX) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + add_definitions(-DOS_FREEBSD) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + add_definitions(-DOS_MACOSX) +endif() + +add_library(brotli_common STATIC + common/dictionary.c) +add_library(brotli_dec STATIC + dec/bit_reader.c + dec/decode.c + dec/huffman.c + dec/state.c) +add_library(brotli_enc STATIC + enc/backward_references.c + enc/bit_cost.c + enc/block_splitter.c + enc/brotli_bit_stream.c + enc/cluster.c + enc/compress_fragment.c + enc/compress_fragment_two_pass.c + enc/encode.c + enc/entropy_encode.c + enc/histogram.c + enc/literal_cost.c + enc/memory.c + enc/metablock.c + enc/static_dict.c + enc/utf8_util.c) + +foreach(lib brotli_common brotli_dec brotli_enc) + target_link_libraries(${lib} m) + set_property(TARGET ${lib} APPEND PROPERTY INCLUDE_DIRECTORIES ${BROTLI_INCLUDE_DIRS}) + set_target_properties(${lib} PROPERTIES + VERSION ${BROTLI_VERSION_MAJOR}.${BROTLI_VERSION_MINOR}.${BROTLI_VERSION_REVISION} + POSITION_INDEPENDENT_CODE TRUE) + + set_property(TARGET ${lib} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${BROTLI_INCLUDE_DIRS}") +endforeach() + +# For projects stuck on older versions of CMake, this will set the +# BROTLI_INCLUDE_DIRS and BROTLI_LIBRARIES variables so they still +# have a relatively easy way to use Brotli: +# +# include_directories(${BROTLI_INCLUDE_DIRS}) +# target_link_libraries(foo ${BROTLI_LIBRARIES}) +if(BROTLI_PARENT_DIRECTORY) + set(BROTLI_INCLUDE_DIRS "${BROTLI_INCLUDE_DIRS}" PARENT_SCOPE) + set(BROTLI_LIBRARIES "${BROTLI_LIBRARIES}" PARENT_SCOPE) +endif() + +# Build the bro executable +add_executable(bro tools/bro.c) +target_link_libraries(bro ${BROTLI_LIBRARIES}) + +# Installation +if(NOT BROTLI_BUNDLE_MODE) + include(GNUInstallDirs) + + install (TARGETS bro RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +endif() + +# Tests +if(NOT BROTLI_DISABLE_TESTS) + include(CTest) + enable_testing() + + set(ROUNDTRIP_INPUTS + tests/testdata/alice29.txt + tests/testdata/asyoulik.txt + tests/testdata/lcet10.txt + tests/testdata/plrabn12.txt + enc/encode.c + common/dictionary.h + dec/decode.c) + + foreach(INPUT ${ROUNDTRIP_INPUTS}) + foreach(quality 1 6 9 11) + add_test(NAME "${BROTLI_TEST_PREFIX}roundtrip/${INPUT}/${quality}" + COMMAND "${CMAKE_COMMAND}" + -DBROTLI_CLI=$<TARGET_FILE:bro> + -DQUALITY=${quality} + -DINPUT=${CMAKE_CURRENT_SOURCE_DIR}/${INPUT} + -P ${CMAKE_CURRENT_SOURCE_DIR}/tests/run-roundtrip-test.cmake) + endforeach() + endforeach() + + file(GLOB_RECURSE + COMPATIBILITY_INPUTS + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + tests/testdata/*.compressed*) + + foreach(INPUT ${COMPATIBILITY_INPUTS}) + add_test(NAME "${BROTLI_TEST_PREFIX}compatibility/${INPUT}" + COMMAND "${CMAKE_COMMAND}" + -DBROTLI_CLI=$<TARGET_FILE:bro> + -DINPUT=${CMAKE_CURRENT_SOURCE_DIR}/${INPUT} + -P ${CMAKE_CURRENT_SOURCE_DIR}/tests/run-compatibility-test.cmake) + endforeach() +endif() diff --git a/tests/run-compatibility-test.cmake b/tests/run-compatibility-test.cmake new file mode 100644 index 0000000..9e7461b --- /dev/null +++ b/tests/run-compatibility-test.cmake @@ -0,0 +1,28 @@ +string(REGEX REPLACE "([a-zA-Z0-9\\.]+)\\.compressed(\\.[0-9]+)?$" "\\1" REFERENCE_DATA "${INPUT}") +get_filename_component(OUTPUT_NAME "${REFERENCE_DATA}" NAME) + +execute_process( + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMAND ${BROTLI_CLI} -f -d -i "${INPUT}" -o "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}.unbro" + RESULT_VARIABLE result) +if(result) + message(FATAL_ERROR "Decompression failed") +endif() + +function(test_file_equality f1 f2) + if(NOT CMAKE_VERSION VERSION_LESS 2.8.7) + file(SHA512 "${f1}" f1_cs) + file(SHA512 "${f2}" f2_cs) + if(NOT "${f1_cs}" STREQUAL "${f2_cs}") + message(FATAL_ERROR "Files do not match") + endif() + else() + file(READ "${f1}" f1_contents) + file(READ "${f2}" f2_contents) + if(NOT "${f1_contents}" STREQUAL "${f2_contents}") + message(FATAL_ERROR "Files do not match") + endif() + endif() +endfunction() + +test_file_equality("${REFERENCE_DATA}" "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}.unbro") diff --git a/tests/run-roundtrip-test.cmake b/tests/run-roundtrip-test.cmake new file mode 100644 index 0000000..6cbd906 --- /dev/null +++ b/tests/run-roundtrip-test.cmake @@ -0,0 +1,35 @@ +get_filename_component(OUTPUT_NAME "${INPUT}" NAME) + +execute_process( + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMAND ${BROTLI_CLI} -f -q ${QUALITY} -i "${INPUT}" -o "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}.bro" + RESULT_VARIABLE result) +if(result) + message(FATAL_ERROR "Compression failed") +endif() + +execute_process( + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMAND ${BROTLI_CLI} -f -d -i "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}.bro" -o "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}.unbro" + RESULT_VARIABLE result) +if(result) + message(FATAL_ERROR "Decompression failed") +endif() + +function(test_file_equality f1 f2) + if(NOT CMAKE_VERSION VERSION_LESS 2.8.7) + file(SHA512 "${f1}" f1_cs) + file(SHA512 "${f2}" f2_cs) + if(NOT "${f1_cs}" STREQUAL "${f2_cs}") + message(FATAL_ERROR "Files do not match") + endif() + else() + file(READ "${f1}" f1_contents) + file(READ "${f2}" f2_contents) + if(NOT "${f1_contents}" STREQUAL "${f2_contents}") + message(FATAL_ERROR "Files do not match") + endif() + endif() +endfunction() + +test_file_equality("${INPUT}" "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}.unbro") |