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)