From bf87a834dd13ef570df5fec6f38245a36ba9100d Mon Sep 17 00:00:00 2001 From: quicksilver Date: Wed, 6 Nov 2019 17:14:31 +0800 Subject: [PATCH] add travis CI --- .travis.yaml | 11 +++ ci/scripts/build.sh | 123 ++++++++++++++++++++++++++++++++ ci/travis/install_dependency.sh | 35 +++++++++ ci/travis/travis_build.sh | 24 +++++++ ci/travis/travis_env_common.sh | 10 +++ 5 files changed, 203 insertions(+) create mode 100644 .travis.yaml create mode 100755 ci/scripts/build.sh create mode 100755 ci/travis/install_dependency.sh create mode 100644 ci/travis/travis_build.sh create mode 100644 ci/travis/travis_env_common.sh diff --git a/.travis.yaml b/.travis.yaml new file mode 100644 index 0000000000..7b008a38e4 --- /dev/null +++ b/.travis.yaml @@ -0,0 +1,11 @@ +sudo: required +dist: bionic +addons: + apt: + update: true + packages: + - cmake-3.14 +install: + - source $TRAVIS_BUILD_DIR/ci/travis/install_dependency.sh +script: + - $TRAVIS_BUILD_DIR/ci/travis/travis_build.sh diff --git a/ci/scripts/build.sh b/ci/scripts/build.sh new file mode 100755 index 0000000000..fb6f94f670 --- /dev/null +++ b/ci/scripts/build.sh @@ -0,0 +1,123 @@ +#!/bin/bash + +set -ex + +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +SCRIPTS_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + +MILVUS_CORE_DIR="${SCRIPTS_DIR}/../../core" +CORE_BUILD_DIR="${MILVUS_CORE_DIR}/cmake_build" +BUILD_TYPE="Debug" +BUILD_UNITTEST="OFF" +INSTALL_PREFIX="/opt/milvus" +BUILD_COVERAGE="OFF" +USE_JFROG_CACHE="OFF" +RUN_CPPLINT="OFF" +CUDA_COMPILER=/usr/local/cuda/bin/nvcc + +while getopts "o:t:b:ulcjh" arg +do + case $arg in + o) + INSTALL_PREFIX=$OPTARG + ;; + t) + BUILD_TYPE=$OPTARG # BUILD_TYPE + ;; + b) + CORE_BUILD_DIR=$OPTARG # CORE_BUILD_DIR + ;; + u) + echo "Build and run unittest cases" ; + BUILD_UNITTEST="ON"; + ;; + l) + RUN_CPPLINT="ON" + ;; + c) + BUILD_COVERAGE="ON" + ;; + j) + USE_JFROG_CACHE="ON" + ;; + h) # help + echo " + +parameter: +-o: install prefix(default: /opt/milvus) +-t: build type(default: Debug) +-b: core code build directory +-u: building unit test options(default: OFF) +-l: run cpplint, clang-format and clang-tidy(default: OFF) +-c: code coverage(default: OFF) +-j: use jfrog cache build directory(default: OFF) +-h: help + +usage: +./build.sh -o \${INSTALL_PREFIX} -t \${BUILD_TYPE} -b \${CORE_BUILD_DIR} [-u] [-l] [-c] [-j] [-h] + " + exit 0 + ;; + ?) + echo "ERROR! unknown argument" + exit 1 + ;; + esac +done + +if [[ ! -d ${CORE_BUILD_DIR} ]]; then + mkdir ${CORE_BUILD_DIR} +fi + +pushd ${CORE_BUILD_DIR} + +# remove make cache since build.sh -l use default variables +# force update the variables each time +make rebuild_cache + +CMAKE_CMD="cmake \ +-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} +-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ +-DCMAKE_CUDA_COMPILER=${CUDA_COMPILER} \ +-DBUILD_UNIT_TEST=${BUILD_UNITTEST} \ +-DBUILD_COVERAGE=${BUILD_COVERAGE} \ +-DUSE_JFROG_CACHE=${USE_JFROG_CACHE} \ +${MILVUS_CORE_DIR}" +echo ${CMAKE_CMD} +${CMAKE_CMD} + +if [[ ${RUN_CPPLINT} == "ON" ]]; then + # cpplint check + make lint + if [ $? -ne 0 ]; then + echo "ERROR! cpplint check failed" + exit 1 + fi + echo "cpplint check passed!" + + # clang-format check + make check-clang-format + if [ $? -ne 0 ]; then + echo "ERROR! clang-format check failed" + exit 1 + fi + echo "clang-format check passed!" + +# # clang-tidy check +# make check-clang-tidy +# if [ $? -ne 0 ]; then +# echo "ERROR! clang-tidy check failed" +# rm -f CMakeCache.txt +# exit 1 +# fi +# echo "clang-tidy check passed!" +else + # compile and build + make -j8 || exit 1 + make install || exit 1 +fi diff --git a/ci/travis/install_dependency.sh b/ci/travis/install_dependency.sh new file mode 100755 index 0000000000..bc4a972b8f --- /dev/null +++ b/ci/travis/install_dependency.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +set -ex + +wget -P /tmp https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB + +sudo apt-key add /tmp/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB + +echo "deb https://apt.repos.intel.com/mkl all main" | \ + sudo tee /etc/apt/sources.list.d/intel-mkl.list + +sudo apt-get update -qq + +sudo apt-get install -y -q --no-install-recommends \ + flex \ + bison \ + gfortran \ + lsb-core \ + libtool \ + automake \ + pkg-config \ + libboost-filesystem-dev \ + libboost-system-dev \ + libboost-regex-dev \ + intel-mkl-gnu-2019.4-243 \ + intel-mkl-core-2019.4-243 \ + libmysqlclient-dev \ + clang-format-6.0 \ + clang-tidy-6.0 \ + lcov + +sudo ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so \ + /usr/lib/x86_64-linux-gnu/libmysqlclient_r.so + +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/opt/intel/compilers_and_libraries_2019.4.243/linux/mkl/lib/intel64 \ No newline at end of file diff --git a/ci/travis/travis_build.sh b/ci/travis/travis_build.sh new file mode 100644 index 0000000000..3cde1d5a4d --- /dev/null +++ b/ci/travis/travis_build.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -ex + +source $TRAVIS_BUILD_DIR/ci/travis/travis_env_common.sh + +only_library_mode=no + +while true; do + case "$1" in + --only-library) + only_library_mode=yes + shift ;; + *) break ;; + esac +done + +BUILD_COMMON_FLAGS="-t ${MILVUS_BUILD_TYPE} -o ${MILVUS_INSTALL_PREFIX} -b ${MILVUS_BUILD_DIR}" + +if [ $only_library_mode == "yes" ]; then + ${TRAVIS_BUILD_DIR}/ci/scripts/build.sh ${BUILD_COMMON_FLAGS} +else + ${TRAVIS_BUILD_DIR}/ci/scripts/build.sh ${BUILD_COMMON_FLAGS} -u -c +fi \ No newline at end of file diff --git a/ci/travis/travis_env_common.sh b/ci/travis/travis_env_common.sh new file mode 100644 index 0000000000..ac63d2950b --- /dev/null +++ b/ci/travis/travis_env_common.sh @@ -0,0 +1,10 @@ +export MILVUS_CORE_DIR=${TRAVIS_BUILD_DIR}/core +export MILVUS_BUILD_DIR=${TRAVIS_BUILD_DIR}/core/cmake_build +export MILVUS_INSTALL_PREFIX=/opt/milvus +export MILVUS_TRAVIS_COVERAGE=${MILVUS_TRAVIS_COVERAGE:=0} + +if ["$MILVUS_TRAVIS_COVERAGE" == "1"]; then + export MILVUS_CPP_COVERAGE_FILE=${TRAVIS_BUILD_DIR}/output_new.info +fi + +export MILVUS_BUILD_TYPE=${MILVUS_BUILD_TYPE:=Release}