diff --git a/docker/code-analysis/Dockerfile b/docker/code-analysis/Dockerfile index 3eb95bd635bff8ea1d053c00812c7d82b7a0c95b..ef87679d4b44e4fc44b4f96f9f876e583bd2476f 100644 --- a/docker/code-analysis/Dockerfile +++ b/docker/code-analysis/Dockerfile @@ -259,9 +259,8 @@ COPY supervisord.conf /etc/supervisor/ RUN mkdir -p /usr/share/rpcd/schemas && \ mkdir -p /usr/share/rpcd/definitions - -# Copy more_test script -COPY more_test.sh /usr/local/bin/more_test.sh +# Copy static_code_analysis script +COPY static_code_analysis.sh /usr/local/bin/static_code_analysis.sh # Start entrypoint COPY entrypoint.sh /usr/local/bin/entrypoint.sh diff --git a/docker/code-analysis/more_test.sh b/docker/code-analysis/static_code_analysis.sh similarity index 67% rename from docker/code-analysis/more_test.sh rename to docker/code-analysis/static_code_analysis.sh index 4ca71d016fa849dc108edbc328b9d2ed91af2b24..2c9766f3d7f9c267a3818796b8cc0e48b3f72680 100755 --- a/docker/code-analysis/more_test.sh +++ b/docker/code-analysis/static_code_analysis.sh @@ -11,7 +11,12 @@ exec_cmd() $@ if [ "$?" -ne 0 ]; then log "Failed to run [$@]..." - exit 1 + if [ -n "${CI}" ]; then + exit 1 + else + # Ignore errors for development environment + log "Ignoring the last error ..." + fi fi } @@ -51,19 +56,45 @@ run_infer_analysis() exec_cmd infer --fail-on-issue --compilation-database compile_commands.json } +run_flawfinder_checks() +{ + exec_cmd flawfinder --minlevel 4 --error-level=4 ${FLAWFINDER_OPTIONS} ${SOURCE_FOLDER} +} + +run_cpd_check() +{ + exec_cmd /usr/local/pmd/bin/run.sh cpd --language c --exclude ./test/ ${CPD_OPTIONS} --files ${SOURCE_FOLDER} +} + main() { log "SOURCE_FOLDER: ${SOURCE_FOLDER}" log "COMPILATION_FIXUP: ${COMPILATION_FIXUP}" log "CPPCHECK_OPTIONS: ${CPPCHECK_OPTIONS}" + log "FLAWFINDER_OPTIONS: ${FLAWFINDER_OPTIONS}" + log "CPD_OPTIONS: ${CPD_OPTIONS:=--minimum-tokens 200}" log "" + if [ -z "${SOURCE_FOLDER}" ]; then + log "SOURCE_FOLDER not defined" + if [ -n "${CI}" ]; then + log "Can't proceed without SOURCE_FOLDER in pipeline" + exit 5 + else + log "Assuming current path '.' as SOURCE_FOLDER" + export SOURCE_FOLDER="." + fi + fi + # Install pre-req if present/defined if [ -f "./gitlab-ci/install-dependencies.sh" ]; then log "Installing prerequisites for compilation" exec_cmd ./gitlab-ci/install-dependencies.sh fi + # Run flawfinder + run_flawfinder_checks + # Generate compilation db generate_compilation_db @@ -72,11 +103,14 @@ main() # Run cppcheck with compilation-db run_cppcheck_validation - # Run clag analysis + # Run clang analysis run_cppcheck_clang_validation # Run infer analysis run_infer_analysis + + # Run CPD checks + run_cpd_check } main "$@" diff --git a/static-code-analysis.yml b/static-code-analysis.yml index 0d21c62e48ecb2c668d80b7f522b5b592729668d..809a896a9db27c50c6b47695c2a0aaef13054947 100644 --- a/static-code-analysis.yml +++ b/static-code-analysis.yml @@ -1,7 +1,7 @@ variables: COMMON_IMAGE: "dev.iopsys.eu:5050/iopsys/gitlab-ci-pipeline/code-analysis:0.33" FLAWFINDER_OPTIONS: "" - CPD_OPTIONS: "--minimum-tokens 200 --language c --exclude ./test/ --files" + CPD_OPTIONS: "--minimum-tokens 200" CPPCHECK_OPTIONS: "" COMPILATION_FIXUP: "" SHELL_SRC: "" @@ -13,17 +13,12 @@ run_static_code_analysis: stage: static_code_analysis allow_failure: false script: - - echo "flawfinder --minlevel 4 --error-level=4 ${FLAWFINDER_OPTIONS} ${SOURCE_FOLDER}" - - "flawfinder --minlevel 4 --error-level=4 ${FLAWFINDER_OPTIONS} ${SOURCE_FOLDER}" - - echo "/usr/local/pmd/bin/run.sh cpd ${CPD_OPTIONS} ${SOURCE_FOLDER}" - - "/usr/local/pmd/bin/run.sh cpd ${CPD_OPTIONS} ${SOURCE_FOLDER}" - - echo "Run cppcheck/infer/clag/gcc to scan for more issues" - - "more_test.sh" - only: - variables: - - $SOURCE_FOLDER + - "static_code_analysis.sh" + rules: + - if: ${SOURCE_FOLDER} + when: always artifacts: - when: always + when: on_failure paths: - infer-out/report.txt @@ -36,6 +31,6 @@ run_shell_checks: - echo "Running optional tests" - echo "Running shellcheck ${SHELLCHECK_OPTIONS} ${SHELL_SRC}" - "shellcheck ${SHELLCHECK_OPTIONS} ${SHELL_SRC}" - only: - variables: - - $SHELL_SRC + rules: + - if: ${SHELL_SRC} + when: always