add docker compilation to travis (#3433)
* add docker compilation to travis add new matrix entry in .travis.yml for compiling on 18.04 add Dockerfile in .ci to build ubuntu 18.04 inside docker remove release entry for uvuntu 16.04 to not conflict refactor .travis.yml refactor travis-comile.sh merge travis-dependencies.sh into the travis.yml remove travis-dependencies.sh * enable debugging on travis-compile.sh * set ubuntu16 buildtype to "Debug" set buildtype Debug for as requirement for "test" add --debug and --release flags to travis-compile.sh * make output prettier edit the format warning message and clangify.sh output * fix clangify.sh fix --cf-version flag fix directory argument parsing add directory parsing details to --help add examples to --help
This commit is contained in:
parent
f70699d3de
commit
72ed98e404
5 changed files with 206 additions and 105 deletions
20
.ci/Dockerfile
Normal file
20
.ci/Dockerfile
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
FROM ubuntu:bionic
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
bc \
|
||||||
|
build-essential \
|
||||||
|
clang-format \
|
||||||
|
g++ \
|
||||||
|
git \
|
||||||
|
cmake \
|
||||||
|
libprotobuf-dev \
|
||||||
|
libqt5multimedia5-plugins \
|
||||||
|
libqt5svg5-dev \
|
||||||
|
libqt5sql5-mysql \
|
||||||
|
libqt5websockets5-dev \
|
||||||
|
protobuf-compiler \
|
||||||
|
qt5-default \
|
||||||
|
qttools5-dev \
|
||||||
|
qttools5-dev-tools \
|
||||||
|
qtmultimedia5-dev \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
|
@ -1,59 +1,111 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This script is to be used in .travis.yaml from the project root directory, do not use it from somewhere else.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
./servatrice/check_schema_version.sh
|
# Read arguments
|
||||||
|
while [[ "$@" ]]; do
|
||||||
|
case "$1" in
|
||||||
|
'--format')
|
||||||
|
CHECK_FORMAT=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
'--install')
|
||||||
|
MAKE_INSTALL=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
'--package')
|
||||||
|
MAKE_PACKAGE=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
'--server')
|
||||||
|
MAKE_SERVER=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
'--test')
|
||||||
|
MAKE_TEST=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
'--debug')
|
||||||
|
BUILDTYPE="Debug"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
'--release')
|
||||||
|
BUILDTYPE="Release"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
BUILDTYPE="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Check formatting using clang-format
|
||||||
|
if [[ $CHECK_FORMAT ]]; then
|
||||||
|
echo "Checking your code using clang-format..."
|
||||||
|
if ! diff="$(./clangify.sh --color-diff --cf-version)"; then
|
||||||
|
cat <<EOM
|
||||||
|
***********************************************************
|
||||||
|
*** ***
|
||||||
|
*** Your code does not comply with our styleguide. ***
|
||||||
|
*** ***
|
||||||
|
*** Please correct it or run the "clangify.sh" script. ***
|
||||||
|
*** Then commit and push those changes to this branch. ***
|
||||||
|
*** Check our CONTRIBUTING.md file for more details. ***
|
||||||
|
*** ***
|
||||||
|
*** Thank you ♥ ***
|
||||||
|
*** ***
|
||||||
|
***********************************************************
|
||||||
|
|
||||||
|
The following changes should be made:
|
||||||
|
$diff
|
||||||
|
|
||||||
|
Exiting...
|
||||||
|
EOM
|
||||||
|
exit 2
|
||||||
|
else
|
||||||
|
echo "Thank you for complying with our code standards."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Setup
|
||||||
|
./servatrice/check_schema_version.sh
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
cd build
|
cd build
|
||||||
prefix=""
|
|
||||||
|
|
||||||
if [[ $TRAVIS_OS_NAME == "osx" ]]; then
|
# Add cmake flags
|
||||||
export PATH="/usr/local/opt/ccache/bin:$PATH"
|
if [[ $MAKE_SERVER ]]; then
|
||||||
prefix="-DCMAKE_PREFIX_PATH=$(echo /usr/local/opt/qt5/)"
|
flags+=" -DWITH_SERVER=1"
|
||||||
fi
|
fi
|
||||||
if [[ $TRAVIS_OS_NAME == "linux" ]]; then
|
if [[ $MAKE_TEST ]]; then
|
||||||
prefix="-DCMAKE_PREFIX_PATH=$(echo /opt/qt5*/lib/cmake/)"
|
flags+=" -DTEST=1"
|
||||||
|
BUILDTYPE="Debug" # test requires buildtype Debug
|
||||||
|
fi
|
||||||
|
if [[ $BUILDTYPE ]]; then
|
||||||
|
flags+=" -DCMAKE_BUILD_TYPE=$BUILDTYPE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Add qt install location when using brew
|
||||||
|
if [[ $(uname) == "Darwin" ]]; then
|
||||||
|
PATH="/usr/local/opt/ccache/bin:$PATH"
|
||||||
|
flags+=" -DCMAKE_PREFIX_PATH=/usr/local/opt/qt5/"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Compile
|
||||||
cmake --version
|
cmake --version
|
||||||
|
cmake .. $flags
|
||||||
if [[ $BUILDTYPE == "Debug" ]]; then
|
|
||||||
cmake .. -DWITH_SERVER=1 -DCMAKE_BUILD_TYPE=$BUILDTYPE $prefix -DTEST=1
|
|
||||||
make -j2
|
make -j2
|
||||||
make test
|
|
||||||
|
|
||||||
if [[ $TRAVIS_OS_NAME == "osx" ]]; then
|
if [[ $MAKE_TEST ]]; then
|
||||||
|
make test
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $MAKE_INSTALL ]]; then
|
||||||
make install
|
make install
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $TRAVIS_OS_NAME == "linux" ]]; then
|
if [[ $MAKE_PACKAGE ]]; then
|
||||||
cd ..
|
make package
|
||||||
clang-format -version
|
|
||||||
clang-format -i \
|
|
||||||
common/*.h \
|
|
||||||
common/*.cpp \
|
|
||||||
cockatrice/src/*.h \
|
|
||||||
cockatrice/src/*.cpp \
|
|
||||||
oracle/src/*.h \
|
|
||||||
oracle/src/*.cpp \
|
|
||||||
servatrice/src/*.h \
|
|
||||||
servatrice/src/*.cpp
|
|
||||||
|
|
||||||
git clean -f
|
|
||||||
git diff --quiet || (
|
|
||||||
echo "*****************************************************";
|
|
||||||
echo "*** This PR is not clean against our code style ***";
|
|
||||||
echo "*** Run clang-format and fix up any differences ***";
|
|
||||||
echo "*** Check our CONTRIBUTING.md file for details! ***";
|
|
||||||
echo "*** Thank you ♥ ***";
|
|
||||||
echo "*****************************************************";
|
|
||||||
)
|
|
||||||
git diff --exit-code
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $BUILDTYPE == "Release" ]]; then
|
|
||||||
cmake .. -DWITH_SERVER=1 -DCMAKE_BUILD_TYPE=$BUILDTYPE $prefix
|
|
||||||
make package -j2
|
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
if [[ $TRAVIS_OS_NAME == "osx" ]] ; then
|
|
||||||
brew update
|
|
||||||
brew install ccache protobuf qt
|
|
||||||
fi
|
|
||||||
if [[ $TRAVIS_OS_NAME == "linux" ]] ; then
|
|
||||||
echo Skipping... packages are installed with the Travis apt addon for sudo disabled container builds
|
|
||||||
fi
|
|
69
.travis.yml
69
.travis.yml
|
@ -4,32 +4,26 @@ cache: ccache
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
#Ubuntu
|
#Ubuntu Bionic (on docker)
|
||||||
- name: Ubuntu (Debug)
|
- name: Ubuntu Bionic (Debug)
|
||||||
if: tag IS NOT present
|
if: tag IS NOT present
|
||||||
os: linux
|
services: docker
|
||||||
dist: xenial
|
before_install: docker build -t img .ci
|
||||||
group: stable
|
script: docker run --mount "type=bind,source=$(pwd),target=/src" -w="/src" img
|
||||||
env: BUILDTYPE=Debug
|
bash .ci/travis-compile.sh --server --debug
|
||||||
- name: Ubuntu (Release)
|
- name: Ubuntu Bionic (Release)
|
||||||
if: (branch = master AND NOT type = pull_request) OR tag IS present
|
if: (branch = master AND NOT type = pull_request) OR tag IS present
|
||||||
os: linux
|
services: docker
|
||||||
dist: xenial
|
script: docker build -t img .ci &&
|
||||||
group: stable
|
docker run --mount "type=bind,source=$(pwd),target=/src" -w="/src" img
|
||||||
env: BUILDTYPE=Release
|
bash .ci/travis-compile.sh --server --package --release
|
||||||
#macOS
|
|
||||||
- name: macOS (Debug)
|
|
||||||
if: tag IS NOT present
|
|
||||||
os: osx
|
|
||||||
osx_image: xcode8
|
|
||||||
env: BUILDTYPE=Debug
|
|
||||||
- name: macOS (Release)
|
|
||||||
if: (branch = master AND NOT type = pull_request) OR tag IS present
|
|
||||||
os: osx
|
|
||||||
osx_image: xcode8
|
|
||||||
env: BUILDTYPE=Release
|
|
||||||
|
|
||||||
#install dependencies for container-based "linux" builds
|
#Ubuntu Xenial (Debug only)
|
||||||
|
- name: Ubuntu Xenial (Debug)
|
||||||
|
if: tag IS NOT present
|
||||||
|
os: linux
|
||||||
|
dist: xenial
|
||||||
|
group: stable
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
packages:
|
packages:
|
||||||
|
@ -43,11 +37,32 @@ addons:
|
||||||
- libqt5svg5-dev
|
- libqt5svg5-dev
|
||||||
- libqt5sql5-mysql
|
- libqt5sql5-mysql
|
||||||
- libqt5websockets5-dev
|
- libqt5websockets5-dev
|
||||||
|
script: bash ./.ci/travis-compile.sh --format --server --test --debug
|
||||||
|
|
||||||
|
#macOS
|
||||||
before_install: bash ./.ci/travis-dependencies.sh
|
- name: macOS (Debug)
|
||||||
|
os: osx
|
||||||
script: bash ./.ci/travis-compile.sh
|
osx_image: xcode8
|
||||||
|
before_install:
|
||||||
|
- brew update
|
||||||
|
- brew update
|
||||||
|
- brew install ccache
|
||||||
|
- brew unlink python # protobuf python2 install requires this link to be removed
|
||||||
|
- brew install protobuf
|
||||||
|
- brew install qt
|
||||||
|
script: bash ./.ci/travis-compile.sh --server --install --debug
|
||||||
|
- name: macOS (Release)
|
||||||
|
if: (branch = master AND NOT type = pull_request) OR tag IS present
|
||||||
|
os: osx
|
||||||
|
osx_image: xcode8
|
||||||
|
before_install:
|
||||||
|
- brew update
|
||||||
|
- brew update
|
||||||
|
- brew install ccache
|
||||||
|
- brew unlink python # protobuf python2 install requires this link to be removed
|
||||||
|
- brew install protobuf
|
||||||
|
- brew install qt
|
||||||
|
script: bash ./.ci/travis-compile.sh --server --package --release
|
||||||
|
|
||||||
|
|
||||||
# Builds for pull requests skip the deployment step altogether
|
# Builds for pull requests skip the deployment step altogether
|
||||||
|
|
65
clangify.sh
65
clangify.sh
|
@ -4,13 +4,8 @@
|
||||||
# Never, ever, should this recieve a path with a newline in it. Don't bother proofing it for that.
|
# Never, ever, should this recieve a path with a newline in it. Don't bother proofing it for that.
|
||||||
|
|
||||||
|
|
||||||
# use script dir and return on exit
|
# go to the project root directory, this file should be located in the project root directory
|
||||||
current=$PWD
|
cd "${BASH_SOURCE%/*}/" || exit 2 # could not find path, this could happen with special links etc.
|
||||||
function cleanup {
|
|
||||||
cd $current
|
|
||||||
}
|
|
||||||
trap cleanup EXIT
|
|
||||||
cd "${BASH_SOURCE%/*}/"
|
|
||||||
|
|
||||||
# defaults
|
# defaults
|
||||||
include=("common" \
|
include=("common" \
|
||||||
|
@ -44,14 +39,19 @@ while [[ $@ ]]; do
|
||||||
;;
|
;;
|
||||||
'-h'|'--help')
|
'-h'|'--help')
|
||||||
cat <<EOM
|
cat <<EOM
|
||||||
A bash script to format your code using clang-format.
|
A bash script to automatically format your code using clang-format.
|
||||||
If no options are given, all dirty files are edited in place.
|
|
||||||
If <dir>s are given, all source files in those directories are checked, recursively.
|
|
||||||
|
|
||||||
USAGE: $0 [option] [-b[ranch] <git branch or object>] [<dir> ...]
|
If no options are given, all dirty source files are edited in place.
|
||||||
|
If <dir>s are given, all source files in those directories of the project root
|
||||||
|
path are formatted. To only format changed files in these directories use the
|
||||||
|
--branch option in combination. <dir> has to be a path relative to the project
|
||||||
|
root path or a full path inside $PWD.
|
||||||
|
. can not be specified as a dir, if you really want to format everything use */.
|
||||||
|
|
||||||
|
USAGE: $0 [option] [--branch <git branch or object>] [<dir> ...]
|
||||||
|
|
||||||
DEFAULTS:
|
DEFAULTS:
|
||||||
Default includes are:
|
Current includes are:
|
||||||
${include[@]/%/
|
${include[@]/%/
|
||||||
}
|
}
|
||||||
Default excludes are:
|
Default excludes are:
|
||||||
|
@ -62,7 +62,8 @@ OPTIONS:
|
||||||
Compare to this git branch and format only files that differ.
|
Compare to this git branch and format only files that differ.
|
||||||
If unspecified it defaults to origin/master.
|
If unspecified it defaults to origin/master.
|
||||||
To not compare to a branch this has to be explicitly set to "".
|
To not compare to a branch this has to be explicitly set to "".
|
||||||
When not comparing to a branch git will not be used at all and all valid files will be parsed.
|
When not comparing to a branch, git will not be used at all and every
|
||||||
|
source file in the entire project will be parsed.
|
||||||
|
|
||||||
-c, --color-diff
|
-c, --color-diff
|
||||||
Display a colored diff. Implies --diff.
|
Display a colored diff. Implies --diff.
|
||||||
|
@ -80,11 +81,23 @@ OPTIONS:
|
||||||
-t, --test
|
-t, --test
|
||||||
Do not edit files in place. Set exit code to 1 if changes are required.
|
Do not edit files in place. Set exit code to 1 if changes are required.
|
||||||
|
|
||||||
|
--cf-version
|
||||||
|
Print the version of clang-format being used before continuing.
|
||||||
|
|
||||||
EXIT CODES:
|
EXIT CODES:
|
||||||
0 on a successful format or if no files require formatting.
|
0 on a successful format or if no files require formatting.
|
||||||
1 if a file requires formatting.
|
1 if a file requires formatting.
|
||||||
2 if given incorrect arguments.
|
2 if given incorrect arguments.
|
||||||
3 if clang-format could not be found.
|
3 if clang-format could not be found.
|
||||||
|
|
||||||
|
EXAMPLES:
|
||||||
|
$0 --test \$PWD || echo "code requires formatting"
|
||||||
|
Tests if the source files in the current directory are correctly
|
||||||
|
formatted and prints an error message if formatting is required.
|
||||||
|
|
||||||
|
$0 --branch $USER/patch-2 ${include[0]}
|
||||||
|
Formats all changed files compared to the git branch "$USER/patch-2"
|
||||||
|
in the directory ${include[0]}.
|
||||||
EOM
|
EOM
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
@ -96,24 +109,31 @@ EOM
|
||||||
mode=code
|
mode=code
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
'--cf-version')
|
||||||
|
print_version=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
'--')
|
'--')
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
include=() # empty includes
|
if next_dir=$(cd "$1" && pwd); then
|
||||||
while [[ $@ ]]; do
|
if [[ ${next_dir#$PWD/} == /* ]]; then
|
||||||
if [[ -d $1 ]]; then
|
echo "error in parsing arguments of $0: $next_dir is not in $PWD" >&2
|
||||||
include+=("$1")
|
exit 2 # input error
|
||||||
shift
|
elif ! [[ $set_include ]]; then
|
||||||
|
include=() # remove default includes
|
||||||
|
set_include=1
|
||||||
|
fi
|
||||||
|
include+=("${next_dir#$PWD/}")
|
||||||
else
|
else
|
||||||
echo "error in parsing arguments of $0: $1 is not a directory" >&2
|
echo "error in parsing arguments of $0: $PWD/$1 is not a directory" >&2
|
||||||
exit 2 # input error
|
exit 2 # input error
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
if ! [[ $set_branch ]]; then
|
if ! [[ $set_branch ]]; then
|
||||||
unset branch # unset branch if not set explicitly
|
unset branch # unset branch if not set explicitly
|
||||||
fi
|
fi
|
||||||
break
|
shift
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
@ -152,6 +172,9 @@ if ! [[ $names ]]; then
|
||||||
exit 0 # nothing to format means format is successful!
|
exit 0 # nothing to format means format is successful!
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# optionally print version
|
||||||
|
[[ $print_version ]] && $cf_cmd -version
|
||||||
|
|
||||||
# format
|
# format
|
||||||
case $mode in
|
case $mode in
|
||||||
diff)
|
diff)
|
||||||
|
|
Loading…
Reference in a new issue