From f3cd2c9aca3811a29a05872e616bd8995bbfd950 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Mon, 22 Aug 2022 13:35:56 +0200 Subject: [PATCH] Remove astyle --- ci-scripts/Jenkinsfile-gitlab | 15 +- ci-scripts/astyle-options.txt | 26 ---- ci-scripts/checkCodingFormattingRules.sh | 26 +--- ci-scripts/cls_static_code_analysis.py | 14 -- .../docker/Dockerfile.formatting.bionic | 4 - ci-scripts/reportBuildLocally.sh | 137 +++++++----------- cmake_targets/tools/indent_source_code | 68 --------- pre-commit | 31 ---- 8 files changed, 58 insertions(+), 263 deletions(-) delete mode 100644 ci-scripts/astyle-options.txt delete mode 100755 cmake_targets/tools/indent_source_code delete mode 100644 pre-commit diff --git a/ci-scripts/Jenkinsfile-gitlab b/ci-scripts/Jenkinsfile-gitlab index 784588357d..10b7034199 100644 --- a/ci-scripts/Jenkinsfile-gitlab +++ b/ci-scripts/Jenkinsfile-gitlab @@ -111,17 +111,7 @@ pipeline { sh "./ci-scripts/doGitLabMerge.sh --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}" sh "zip -r -qq localZip.zip ." - // Running astyle options on the list of modified files by the merge request - // For the moment, there is no fail criteria. Just a notification of number of files that do not follow - sh "./ci-scripts/checkCodingFormattingRules.sh --src-branch ${env.gitlabSourceBranch} --target-branch ${env.gitlabTargetBranch}" - def res=readFile('./oai_rules_result.txt').trim(); - if ("0".equals(res)) { - def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): All Changed files in Merge Request follow OAI Formatting Rules" - addGitLabMRComment comment: message - } else { - def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Some Changed files in Merge Request DO NOT follow OAI Formatting Rules" - addGitLabMRComment comment: message - } + // here was an astyle formatting check, with corresponding messages. The same could be done with clang-format } else { echo "Git Branch is ${GIT_BRANCH}" echo "Git Commit is ${GIT_COMMIT}" @@ -132,9 +122,6 @@ pipeline { sh "git log -n1 --pretty=format:\"%s\" > .git/CI_COMMIT_MSG" sh "zip -r -qq localZip.zip ." - // Running astyle options on all C/H files in the repository - // For the moment, there is no fail criteria. Just a notification of number of files that do not follow - sh "./ci-scripts/checkCodingFormattingRules.sh" } } } diff --git a/ci-scripts/astyle-options.txt b/ci-scripts/astyle-options.txt deleted file mode 100644 index 81c4d68ace..0000000000 --- a/ci-scripts/astyle-options.txt +++ /dev/null @@ -1,26 +0,0 @@ -# OAI is using a style that is similar to the Google style ---style=google -# long options can be written without the preceding '--' -# Convert tabs to spaces -convert-tabs -# Indentation is 2 spaces -indent=spaces=2 -# Indent 'switch' blocks so that the 'case X:' statements are indented in the switch block. -indent-switches -# Indent preprocessor blocks at bracket level 0. -indent-preproc-block -# Indent multi-line preprocessor #define statements. -indent-preproc-define -# Indent C++ comments beginning in column one. -indent-col1-comments -# Pad empty lines around header blocks -break-blocks -delete-empty-lines -# Attach a pointer or reference operator (*, &, or ^) to the variable name (right) -align-pointer=name -# The code line length is 200 characters/columns (this is the maximum allowed by astyle) -max-code-length=200 -# If the line contains logical conditionals they will be placed first on the new line. -break-after-logical -# Force use of the linux end of line -lineend=linux diff --git a/ci-scripts/checkCodingFormattingRules.sh b/ci-scripts/checkCodingFormattingRules.sh index c29941cade..38447674df 100755 --- a/ci-scripts/checkCodingFormattingRules.sh +++ b/ci-scripts/checkCodingFormattingRules.sh @@ -24,8 +24,6 @@ function usage { echo "OAI Coding / Formatting Guideline Check script" echo " Original Author: Raphael Defosseux" echo "" - echo " Requirement: astyle shall be installed" - echo "" echo " By default (no options) the complete repository will be checked" echo " In case of merge request, provided source and target branch," echo " the script will check only the modified files" @@ -57,11 +55,10 @@ fi if [ $# -eq 0 ] then - echo " ---- Checking the whole repository ----" - echo "" - NB_FILES_TO_FORMAT=`astyle --dry-run --options=ci-scripts/astyle-options.txt --recursive --exclude=ci-scripts --exclude=cmake_targets *.c *.h | grep -c Formatted || true` - echo "Nb Files that do NOT follow OAI rules: $NB_FILES_TO_FORMAT" - echo $NB_FILES_TO_FORMAT > ./oai_rules_result.txt + # in this file we previously had a list of files that were not properly + # formatted. At the time of this MR, the Jenkinsfile expects this file, so + # we simply produce an empty one + touch ./oai_rules_result.txt # Testing Circular Dependencies protection awk '/#[ \t]*ifndef/ { gsub("^.*ifndef *",""); if (names[$1]!="") print "files with same {define ", FILENAME, names[$1]; names[$1]=FILENAME } /#[ \t]*define/ { gsub("^.*define *",""); if(names[$1]!=FILENAME) print "error in declaration", FILENAME, $1, names[$1]; nextfile }' `find openair* common targets executables -name *.h |grep -v LFDS` > header-files-w-incorrect-define.txt @@ -151,10 +148,6 @@ echo "" # Retrieve the list of modified files since the latest develop commit MODIFIED_FILES=`git log $TARGET_INIT_COMMIT..$MERGE_COMMMIT --oneline --name-status | egrep "^M|^A" | sed -e "s@^M\t*@@" -e "s@^A\t*@@" | sort | uniq` NB_TO_FORMAT=0 -if [ -f oai_rules_result_list.txt ] -then - rm -f oai_rules_result_list.txt -fi if [ -f header-files-w-incorrect-define.txt ] then rm -f header-files-w-incorrect-define.txt @@ -178,13 +171,6 @@ do EXT="${filename##*.}" if [ $EXT = "c" ] || [ $EXT = "h" ] || [ $EXT = "cpp" ] || [ $EXT = "hpp" ] then - TO_FORMAT=`astyle --dry-run --options=ci-scripts/astyle-options.txt $FULLFILE | grep -c Formatted || true` - NB_TO_FORMAT=$((NB_TO_FORMAT + TO_FORMAT)) - if [ $TO_FORMAT -ne 0 ] - then - echo $FULLFILE - echo $FULLFILE >> ./oai_rules_result_list.txt - fi # Testing if explicit GNU GPL license banner GNU_EXCEPTION=`echo $FULLFILE | egrep -c "openair3/NAS/COMMON/milenage.h" || true` if [ $GNU_EXCEPTION -eq 0 ] @@ -215,9 +201,5 @@ do fi done rm -f header-files-w-incorrect-define-tmp.txt -echo "" -echo " ----------------------------------------------------------" -echo "Nb Files that do NOT follow OAI rules: $NB_TO_FORMAT" -echo $NB_TO_FORMAT > ./oai_rules_result.txt exit 0 diff --git a/ci-scripts/cls_static_code_analysis.py b/ci-scripts/cls_static_code_analysis.py index 5b45b48ba6..131f2d72bc 100644 --- a/ci-scripts/cls_static_code_analysis.py +++ b/ci-scripts/cls_static_code_analysis.py @@ -321,20 +321,6 @@ class StaticCodeAnalysis(): if ret is not None: analyzed = True if analyzed: - ret = re.search('Nb Files that do NOT follow OAI rules: (?P[0-9\.]+)', str(line)) - if ret is not None: - nbFilesNotFormatted = int(ret.group('nb_errors')) - - if re.search('=== Files not properly formatted ===', str(line)) is not None: - listFiles = True - if listFiles: - if re.search('Removing intermediate container', str(line)) is not None: - listFiles = False - elif re.search('Running in|Files not properly formatted', str(line)) is not None: - pass - else: - listFilesNotFormatted.append(str(line).strip()) - if re.search('=== Files with incorrect define protection ===', str(line)) is not None: circularHeaderDependency = True if circularHeaderDependency: diff --git a/ci-scripts/docker/Dockerfile.formatting.bionic b/ci-scripts/docker/Dockerfile.formatting.bionic index 01417a3bdb..47fd2a08d0 100644 --- a/ci-scripts/docker/Dockerfile.formatting.bionic +++ b/ci-scripts/docker/Dockerfile.formatting.bionic @@ -8,7 +8,6 @@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get upgrade --yes && \ DEBIAN_FRONTEND=noninteractive apt-get install --yes \ - astyle \ gawk \ git @@ -18,9 +17,6 @@ COPY . . RUN /bin/bash -c "if [[ -v MERGE_REQUEST ]]; then echo 'Source Branch = $SRC_BRANCH'; echo 'Target Branch = $TARGET_BRANCH'; else echo 'Push to develop'; fi" RUN /bin/bash -c "if [[ -v MERGE_REQUEST ]]; then ./ci-scripts/checkCodingFormattingRules.sh --src-branch $SRC_BRANCH --target-branch $TARGET_BRANCH; else ./ci-scripts/checkCodingFormattingRules.sh; fi" -RUN echo "=== Files not properly formatted ===" && \ - /bin/bash -c "if [[ -f oai_rules_result_list.txt ]]; then cat oai_rules_result_list.txt; fi" - RUN echo "=== Files with incorrect define protection ===" && \ /bin/bash -c "if [[ -f header-files-w-incorrect-define.txt ]]; then cat header-files-w-incorrect-define.txt; fi" diff --git a/ci-scripts/reportBuildLocally.sh b/ci-scripts/reportBuildLocally.sh index bcd3e2f7fe..894eb85be1 100755 --- a/ci-scripts/reportBuildLocally.sh +++ b/ci-scripts/reportBuildLocally.sh @@ -463,106 +463,75 @@ function report_build { echo " " >> ./build_results.html echo "

Build Summary

" >> ./build_results.html - if [ -f ./oai_rules_result.txt ] + echo "

OAI Coding / Formatting Guidelines Check

" >> ./build_results.html + if [ -f ./header-files-w-incorrect-define.txt ] then - echo "

OAI Coding / Formatting Guidelines Check

" >> ./build_results.html - NB_FILES=`cat ./oai_rules_result.txt` - if [ $NB_FILES = "0" ] - then + NB_FILES_IN_ERROR=`wc -l ./header-files-w-incorrect-define.txt | sed -e "s@ .*@@"` + if [ $NB_FILES_IN_ERROR -eq 0 ] + then echo "
" >> ./build_results.html - if [ $PU_TRIG -eq 1 ]; then echo " All files in repository follow OAI rules. " >> ./build_results.html; fi - if [ $MR_TRIG -eq 1 ]; then echo " All modified files in Merge-Request follow OAI rules. " >> ./build_results.html; fi + if [ $MR_TRIG -eq 1 ]; then echo " No Issue for CIRCULAR DEPENDENCY PROTECTION in modified files" >> ./build_results.html; fi + if [ $PU_TRIG -eq 1 ]; then echo " No Issue for CIRCULAR DEPENDENCY PROTECTION in the whole repository" >> ./build_results.html; fi echo "
" >> ./build_results.html else echo "
" >> ./build_results.html - if [ $PU_TRIG -eq 1 ]; then echo " $NB_FILES files in repository DO NOT follow OAI rules. " >> ./build_results.html; fi - if [ $MR_TRIG -eq 1 ]; then echo " $NB_FILES modified files in Merge-Request DO NOT follow OAI rules. " >> ./build_results.html; fi + if [ $MR_TRIG -eq 1 ]; then echo " ${NB_FILES_IN_ERROR} modified files MAY NOT HAVE CIRCULAR DEPENDENCY PROTECTION" >> ./build_results.html; fi + if [ $PU_TRIG -eq 1 ]; then echo " ${NB_FILES_IN_ERROR} files in repository MAY NOT HAVE CIRCULAR DEPENDENCY PROTECTION in the whole repository" >> ./build_results.html; fi echo "
" >> ./build_results.html - fi - if [ -f ./oai_rules_result_list.txt ] - then - echo " " >> ./build_results.html - echo "
" >> ./build_results.html - echo "

Please apply the following command to this(ese) file(s):

" >> ./build_results.html - echo "

astyle --options=ci-scripts/astyle-options.txt filename(s)

" >> ./build_results.html + echo " " >> ./build_results.html + echo "
" >> ./build_results.html echo " " >> ./build_results.html echo " " >> ./build_results.html - echo " " >> ./build_results.html + echo " " >> ./build_results.html + echo " " >> ./build_results.html + echo " " >> ./build_results.html echo " " >> ./build_results.html - awk '{print " "}' ./oai_rules_result_list.txt >> ./build_results.html + awk '{if($0 ~/error in/){print " "};if($0 ~/files with same/){print " "}}' ./header-files-w-incorrect-define.txt >> ./build_results.html echo "
FilenamePotential IssueImpacted FileIncorrect Macro
"$1"
error in declaration"$4""$5"
files with same #define"$5""$6"
" >> ./build_results.html echo "
" >> ./build_results.html echo "
" >> ./build_results.html fi - if [ -f ./header-files-w-incorrect-define.txt ] + fi + if [ -f ./files-w-gnu-gpl-license-banner.txt ] + then + NB_FILES_IN_ERROR=`wc -l ./files-w-gnu-gpl-license-banner.txt | sed -e "s@ .*@@"` + if [ $NB_FILES_IN_ERROR -ne 0 ] then - NB_FILES_IN_ERROR=`wc -l ./header-files-w-incorrect-define.txt | sed -e "s@ .*@@"` - if [ $NB_FILES_IN_ERROR -eq 0 ] - then - echo "
" >> ./build_results.html - if [ $MR_TRIG -eq 1 ]; then echo " No Issue for CIRCULAR DEPENDENCY PROTECTION in modified files" >> ./build_results.html; fi - if [ $PU_TRIG -eq 1 ]; then echo " No Issue for CIRCULAR DEPENDENCY PROTECTION in the whole repository" >> ./build_results.html; fi - echo "
" >> ./build_results.html - else - echo "
" >> ./build_results.html - if [ $MR_TRIG -eq 1 ]; then echo " ${NB_FILES_IN_ERROR} modified files MAY NOT HAVE CIRCULAR DEPENDENCY PROTECTION" >> ./build_results.html; fi - if [ $PU_TRIG -eq 1 ]; then echo " ${NB_FILES_IN_ERROR} files in repository MAY NOT HAVE CIRCULAR DEPENDENCY PROTECTION in the whole repository" >> ./build_results.html; fi - echo "
" >> ./build_results.html - echo " " >> ./build_results.html - echo "
" >> ./build_results.html - echo " " >> ./build_results.html - echo " " >> ./build_results.html - echo " " >> ./build_results.html - echo " " >> ./build_results.html - echo " " >> ./build_results.html - echo " " >> ./build_results.html - awk '{if($0 ~/error in/){print " "};if($0 ~/files with same/){print " "}}' ./header-files-w-incorrect-define.txt >> ./build_results.html - echo "
Potential IssueImpacted FileIncorrect Macro
error in declaration"$4""$5"
files with same #define"$5""$6"
" >> ./build_results.html - echo "
" >> ./build_results.html - echo "
" >> ./build_results.html - fi + echo "
" >> ./build_results.html + if [ $MR_TRIG -eq 1 ]; then echo " ${NB_FILES_IN_ERROR} modified files HAVE a GNU GPL license banner" >> ./build_results.html; fi + if [ $PU_TRIG -eq 1 ]; then echo " ${NB_FILES_IN_ERROR} files in repository HAVE a GNU GPL license banner" >> ./build_results.html; fi + echo "
" >> ./build_results.html + echo " " >> ./build_results.html + echo "
" >> ./build_results.html + echo " " >> ./build_results.html + echo " " >> ./build_results.html + echo " " >> ./build_results.html + echo " " >> ./build_results.html + awk '{print " "}' ./files-w-gnu-gpl-license-banner.txt >> ./build_results.html + echo "
Filename
"$1"
" >> ./build_results.html + echo "
" >> ./build_results.html + echo "
" >> ./build_results.html fi - if [ -f ./files-w-gnu-gpl-license-banner.txt ] + fi + if [ -f ./files-w-suspect-banner.txt ] + then + NB_FILES_IN_ERROR=`wc -l ./files-w-suspect-banner.txt | sed -e "s@ .*@@"` + if [ $NB_FILES_IN_ERROR -ne 0 ] then - NB_FILES_IN_ERROR=`wc -l ./files-w-gnu-gpl-license-banner.txt | sed -e "s@ .*@@"` - if [ $NB_FILES_IN_ERROR -ne 0 ] - then - echo "
" >> ./build_results.html - if [ $MR_TRIG -eq 1 ]; then echo " ${NB_FILES_IN_ERROR} modified files HAVE a GNU GPL license banner" >> ./build_results.html; fi - if [ $PU_TRIG -eq 1 ]; then echo " ${NB_FILES_IN_ERROR} files in repository HAVE a GNU GPL license banner" >> ./build_results.html; fi - echo "
" >> ./build_results.html - echo " " >> ./build_results.html - echo "
" >> ./build_results.html - echo " " >> ./build_results.html - echo " " >> ./build_results.html - echo " " >> ./build_results.html - echo " " >> ./build_results.html - awk '{print " "}' ./files-w-gnu-gpl-license-banner.txt >> ./build_results.html - echo "
Filename
"$1"
" >> ./build_results.html - echo "
" >> ./build_results.html - echo "
" >> ./build_results.html - fi - fi - if [ -f ./files-w-suspect-banner.txt ] - then - NB_FILES_IN_ERROR=`wc -l ./files-w-suspect-banner.txt | sed -e "s@ .*@@"` - if [ $NB_FILES_IN_ERROR -ne 0 ] - then - echo "
" >> ./build_results.html - if [ $MR_TRIG -eq 1 ]; then echo " ${NB_FILES_IN_ERROR} modified files HAVE a suspect license banner" >> ./build_results.html; fi - if [ $PU_TRIG -eq 1 ]; then echo " ${NB_FILES_IN_ERROR} files in repository HAVE a suspect license banner" >> ./build_results.html; fi - echo "
" >> ./build_results.html - echo " " >> ./build_results.html - echo "
" >> ./build_results.html - echo " " >> ./build_results.html - echo " " >> ./build_results.html - echo " " >> ./build_results.html - echo " " >> ./build_results.html - awk '{print " "}' ././files-w-suspect-banner.txt >> ./build_results.html - echo "
Filename
"$1"
" >> ./build_results.html - echo "
" >> ./build_results.html - echo "
" >> ./build_results.html - fi + echo "
" >> ./build_results.html + if [ $MR_TRIG -eq 1 ]; then echo " ${NB_FILES_IN_ERROR} modified files HAVE a suspect license banner" >> ./build_results.html; fi + if [ $PU_TRIG -eq 1 ]; then echo " ${NB_FILES_IN_ERROR} files in repository HAVE a suspect license banner" >> ./build_results.html; fi + echo "
" >> ./build_results.html + echo " " >> ./build_results.html + echo "
" >> ./build_results.html + echo " " >> ./build_results.html + echo " " >> ./build_results.html + echo " " >> ./build_results.html + echo " " >> ./build_results.html + awk '{print " "}' ././files-w-suspect-banner.txt >> ./build_results.html + echo "
Filename
"$1"
" >> ./build_results.html + echo "
" >> ./build_results.html + echo "
" >> ./build_results.html fi fi diff --git a/cmake_targets/tools/indent_source_code b/cmake_targets/tools/indent_source_code deleted file mode 100755 index a16914a91d..0000000000 --- a/cmake_targets/tools/indent_source_code +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash -#/* -# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more -# * contributor license agreements. See the NOTICE file distributed with -# * this work for additional information regarding copyright ownership. -# * The OpenAirInterface Software Alliance licenses this file to You under -# * the OAI Public License, Version 1.1 (the "License"); you may not use this file -# * except in compliance with the License. -# * You may obtain a copy of the License at -# * -# * http://www.openairinterface.org/?page_id=698 -# * -# * Unless required by applicable law or agreed to in writing, software -# * distributed under the License is distributed on an "AS IS" BASIS, -# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# * See the License for the specific language governing permissions and -# * limitations under the License. -# *------------------------------------------------------------------------------- -# * For more information about the OpenAirInterface (OAI) Software Alliance: -# * contact@openairinterface.org -# */ - -# file indent_source_code -# brief -# author Lionel Gauthier -# company Eurecom -# email: lionel.gauthier@eurecom.fr -# -################################ -# include helper functions -################################ -THIS_SCRIPT_PATH=$(dirname $(readlink -f $0)) -source $THIS_SCRIPT_PATH/build_helper - -function main() -{ - local MAX_CODE_LENGTH=200 - local INDENT_SPACES=2 -set_openair_env - - - # remove trailing white spaces - #find $OPENAIR_DIR/openair1 -type f \( -name '*.c' -o -name '*.h' \) -exec sed --in-place 's/[[:space:]]\+$//' {} \+ - #find $OPENAIR_DIR/openair2 -type f \( -name '*.c' -o -name '*.h' \) -exec sed --in-place 's/[[:space:]]\+$//' {} \+ - #find $OPENAIR_DIR/openair3 -type f \( -name '*.c' -o -name '*.h' \) -exec sed --in-place 's/[[:space:]]\+$//' {} \+ - #find $OPENAIR_DIR/openair3 -type f \( -name '*.c' -o -name '*.h' \) -exec sed --in-place 's/[[:space:]]\+$//' {} \+ - #find $OPENAIR_DIR/targets -type f \( -name '*.c' -o -name '*.h' \) -exec sed --in-place 's/[[:space:]]\+$//' {} \+ - -# Style google not available on 14.04 - - exit 0 - # will use indent - command -v astyle >/dev/null 2>&1 || { echo >&2 "astyle required but it's not installed."; sudo apt-get install astyle; } - astyle --recursive --convert-tabs --indent=spaces=$INDENT_SPACES --style=kr --indent-col1-comments --max-code-length=$MAX_CODE_LENGTH \ - $OPENAIR_DIR/openair1/*.h \ - $OPENAIR_DIR/openair1/*.c \ - $OPENAIR_DIR/openair2/*.h \ - $OPENAIR_DIR/openair2/*.c \ - $OPENAIR_DIR/openair3/*.h \ - $OPENAIR_DIR/openair3/*.c \ - $OPENAIR_DIR/openair3/*.h \ - $OPENAIR_DIR/openair3/*.c \ - $OPENAIR_DIR/targets/*.h \ - $OPENAIR_DIR/targets/*.c -} - - -main "$@" diff --git a/pre-commit b/pre-commit deleted file mode 100644 index ab54a821a5..0000000000 --- a/pre-commit +++ /dev/null @@ -1,31 +0,0 @@ - -#!/bin/bash -# Installation: -# cp pre-commit .git/hooks -# chmod +x .git/hooks/pre-commit - -OPTIONS="--options=ci-scripts/astyle-options.txt" - -RETURN=0 -ASTYLE=$(which astyle) -if [ $? -ne 0 ]; then - echo "[!] astyle not installed. Unable to check source file format policy." >&2 - exit 1 -fi - -FILES=`git diff --cached --name-only --diff-filter=ACMR | grep -E "\.(c|cpp|h)$"` -for FILE in $FILES; do - $ASTYLE $OPTIONS < $FILE | cmp -s $FILE - - if [ $? -ne 0 ]; then - echo "[!] $FILE does not respect the agreed coding style." >&2 - RETURN=1 - fi -done - -if [ $RETURN -eq 1 ]; then - echo "" >&2 - echo "Make sure you have run astyle with the following options:" >&2 - echo $OPTIONS >&2 -fi - -exit $RETURN