From 9f1bd2176fa23386e34dc0c7d489cd0bafa54e41 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 20 Apr 2018 01:08:24 +0200 Subject: [PATCH] Jenkinsfile: Run colobot-lint --- Jenkinsfile | 160 ++++++++++++++++++++++++++++++++++++++- src/level/scoreboard.cpp | 2 +- src/level/scoreboard.h | 2 +- 3 files changed, 159 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7b999eba..9acf5add 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -64,8 +64,6 @@ pipeline { } } } - - // TODO: Run colobot-lint } } @@ -77,7 +75,7 @@ pipeline { } post { success { - publishHTML target: [$class: 'HtmlPublisherTarget', reportName: 'Doxygen', reportDir: 'build/linux/doc/html', reportFiles: 'index.html'] + publishHTML([reportName: 'Doxygen', reportDir: 'build/linux/doc/html', reportFiles: 'index.html', reportTitles: '', allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false]) } } } @@ -91,5 +89,161 @@ pipeline { } // TODO: Maybe run Windows tests using wine as well? } + + stage('Run colobot-lint') { + steps { + copyArtifacts filter: 'build/colobot-lint,build/html_report.tar.gz,Tools/count_errors.py', fingerprintArtifacts: true, projectName: 'colobot/colobot-lint/master', selector: lastSuccessful(), target: 'colobot-lint' + sh 'chmod +x colobot-lint/Tools/count_errors.py' // TODO: ??? + sh 'mkdir -p build/lint' + dir('build/lint') { + sh 'cmake -DCOLOBOT_LINT_BUILD=1 -DTESTS=1 -DTOOLS=1 -DCMAKE_EXPORT_COMPILE_COMMANDS=1 $WORKSPACE' + sh '''#!/bin/bash +set -e +x + +# Run colobot-lint + +COLOBOT_DIR="$WORKSPACE" +COLOBOT_BUILD_DIR="$WORKSPACE/build/lint" + +COLOBOT_LINT_BUILD_DIR="$WORKSPACE/colobot-lint/build" + +COLOBOT_LINT_REPORT_FILE="$WORKSPACE/build/lint/colobot_lint_report.xml" + +CLANG_PREFIX="/usr/lib/llvm-3.6" + +cd "$COLOBOT_LINT_BUILD_DIR" +chmod +x ./colobot-lint + +# Workaround for Clang not finding system headers +rm -rf bin/ +mkdir -p bin +mv ./colobot-lint ./bin/ +rm -f ./lib +ln -s ${CLANG_PREFIX}/lib ./lib + +echo "Running colobot-lint" +find "$WORKSPACE" \\( -wholename "$COLOBOT_DIR/src/*.cpp" \ + -or -wholename "$COLOBOT_DIR/test/unit/*.cpp" \ + -or -wholename "$COLOBOT_BUILD_DIR/fake_header_sources/src/*.cpp" \ + -or -wholename "$COLOBOT_BUILD_DIR/fake_header_sources/test/unit/*.cpp" \\) \ + -exec ./bin/colobot-lint \ + -verbose \ + -output-format xml \ + -output-file "$COLOBOT_LINT_REPORT_FILE" \ + -p "$COLOBOT_BUILD_DIR" \ + -project-local-include-path "$COLOBOT_DIR/src" -project-local-include-path "$COLOBOT_BUILD_DIR/src" \ + -license-template-file "$COLOBOT_DIR/LICENSE-HEADER.txt" \ + {} + + ''' + sh '''#!/bin/bash +set -e +x + +# Generate HTML report + +COLOBOT_LINT_BUILD_DIR="$WORKSPACE/colobot-lint/build" +COLBOT_LINT_REPORT_FILE="$WORKSPACE/build/lint/colobot_lint_report.xml" +HTML_REPORT_DIR="$WORKSPACE/build/lint/html_report" + +echo "Generating HTML report" +cd "$COLOBOT_LINT_BUILD_DIR" +rm -rf HtmlReport/ +tar -zxf html_report.tar.gz +HtmlReport/generate.py --xml-report "$COLBOT_LINT_REPORT_FILE" --output-dir "$HTML_REPORT_DIR" + ''' + script { + retcode = sh script: '''#!/bin/bash +set -e +x + +# Update stable/unstable build status + +ret=0 + +COLOBOT_LINT_REPORT_FILE="$WORKSPACE/build/lint/colobot_lint_report.xml" +COLOBOT_LINT_DIR="$WORKSPACE/colobot-lint" + +OVERALL_STABLE_RULES=( + "class naming" + "code block placement" + "compile error" +# "compile warning" +# "enum naming" +# "function naming" + "header file not self-contained" +# "implicit bool cast" +# "include style" +# "inconsistent declaration parameter name" + "license header" +# "naked delete" +# "naked new" +# "old style function" + "old-style null pointer" +# "possible forward declaration" + "undefined function" +# "uninitialized field" +# "uninitialized local variable" +# "unused forward declaration" +# "variable naming" + "whitespace" +) + +echo "Checking rule stability (overall)" +for ((i = 0; i < ${#OVERALL_STABLE_RULES[@]}; i++)); do + rule="${OVERALL_STABLE_RULES[$i]}" + count="$("$COLOBOT_LINT_DIR/Tools/count_errors.py" --rule-filter="$rule" --xml-report-file "$COLOBOT_LINT_REPORT_FILE")" + if [ "$count" != "0" ]; then + echo "UNSTABLE RULE: $rule ($count occurences)" + ret=1 + fi +done + +STABLE_RULES_WITHOUT_CBOT=( + "class naming" + "code block placement" + "compile error" + "compile warning" +# "enum naming" +# "function naming" + "header file not self-contained" +# "implicit bool cast" + "include style" + "inconsistent declaration parameter name" + "license header" + "naked delete" + "naked new" +# "old style function" + "old-style null pointer" +# "possible forward declaration" + "undefined function" + "uninitialized field" +# "uninitialized local variable" + "unused forward declaration" +# "variable naming" + "whitespace" +) + +echo "Checking rule stability (without CBOT)" +for ((i = 0; i < ${#STABLE_RULES_WITHOUT_CBOT[@]}; i++)); do + rule="${STABLE_RULES_WITHOUT_CBOT[$i]}" + count="$("$COLOBOT_LINT_DIR/Tools/count_errors.py" --rule-filter="$rule" --file-filter="-.*CBot.*" --xml-report-file "$COLOBOT_LINT_REPORT_FILE")" + if [ "$count" != "0" ]; then + echo "UNSTABLE RULE: $rule (without CBOT, $count occurences)" + ret=1 + fi +done + +exit $ret + ''', returnStatus: true + if (retcode != 0) { + currentBuild.result = 'UNSTABLE' + } + } + } + + // TODO: cppcheck publisher STILL doesn't have pipeline support + // There is an open pull request though, merged but no release yet... https://github.com/jenkinsci/cppcheck-plugin/pull/36 + + publishHTML([reportName: 'Colobot-lint HTML report', reportDir: 'build/lint/html_report', reportFiles: 'index.html', reportTitles: '', allowMissing: false, alwaysLinkToLastBuild: true, keepAll: true]) + } + } } } diff --git a/src/level/scoreboard.cpp b/src/level/scoreboard.cpp index 7e4b5b04..95bcc397 100644 --- a/src/level/scoreboard.cpp +++ b/src/level/scoreboard.cpp @@ -1,6 +1,6 @@ /* * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2017, Daniel Roux, EPSITEC SA & TerranovaTeam + * Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam * http://epsitec.ch; http://colobot.info; http://github.com/colobot * * This program is free software: you can redistribute it and/or modify diff --git a/src/level/scoreboard.h b/src/level/scoreboard.h index 58a5acb5..cb8b83b2 100644 --- a/src/level/scoreboard.h +++ b/src/level/scoreboard.h @@ -1,6 +1,6 @@ /* * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2017, Daniel Roux, EPSITEC SA & TerranovaTeam + * Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam * http://epsitec.ch; http://colobot.info; http://github.com/colobot * * This program is free software: you can redistribute it and/or modify