From 72ed98e4042a09bcb4f7374a1f0ce33de2d68672 Mon Sep 17 00:00:00 2001 From: ebbit1q Date: Fri, 16 Nov 2018 15:44:22 +0100 Subject: [PATCH] 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 --- .ci/Dockerfile | 20 ++++++ .ci/travis-compile.sh | 136 +++++++++++++++++++++++++------------ .ci/travis-dependencies.sh | 9 --- .travis.yml | 79 ++++++++++++--------- clangify.sh | 67 ++++++++++++------ 5 files changed, 206 insertions(+), 105 deletions(-) create mode 100644 .ci/Dockerfile delete mode 100644 .ci/travis-dependencies.sh diff --git a/.ci/Dockerfile b/.ci/Dockerfile new file mode 100644 index 00000000..5fe8b4c1 --- /dev/null +++ b/.ci/Dockerfile @@ -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/* diff --git a/.ci/travis-compile.sh b/.ci/travis-compile.sh index 8dbde5c2..7adc99c3 100644 --- a/.ci/travis-compile.sh +++ b/.ci/travis-compile.sh @@ -1,59 +1,111 @@ #!/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 -./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 <s are given, all source files in those directories are checked, recursively. +A bash script to automatically format your code using clang-format. -USAGE: $0 [option] [-b[ranch] ] [ ...] +If no options are given, all dirty source files are edited in place. +If 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. 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 ] [ ...] DEFAULTS: -Default includes are: +Current includes are: ${include[@]/%/ } Default excludes are: @@ -62,7 +62,8 @@ OPTIONS: Compare to this git branch and format only files that differ. If unspecified it defaults to origin/master. 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 Display a colored diff. Implies --diff. @@ -80,11 +81,23 @@ OPTIONS: -t, --test 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: 0 on a successful format or if no files require formatting. 1 if a file requires formatting. 2 if given incorrect arguments. 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 exit 0 ;; @@ -96,24 +109,31 @@ EOM mode=code shift ;; + '--cf-version') + print_version=1 + shift + ;; '--') shift ;; *) - include=() # empty includes - while [[ $@ ]]; do - if [[ -d $1 ]]; then - include+=("$1") - shift - else - echo "error in parsing arguments of $0: $1 is not a directory" >&2 + if next_dir=$(cd "$1" && pwd); then + if [[ ${next_dir#$PWD/} == /* ]]; then + echo "error in parsing arguments of $0: $next_dir is not in $PWD" >&2 exit 2 # input error + elif ! [[ $set_include ]]; then + include=() # remove default includes + set_include=1 fi - done + include+=("${next_dir#$PWD/}") + else + echo "error in parsing arguments of $0: $PWD/$1 is not a directory" >&2 + exit 2 # input error + fi if ! [[ $set_branch ]]; then unset branch # unset branch if not set explicitly fi - break + shift ;; esac done @@ -152,6 +172,9 @@ if ! [[ $names ]]; then exit 0 # nothing to format means format is successful! fi +# optionally print version +[[ $print_version ]] && $cf_cmd -version + # format case $mode in diff)