diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000000000000000000000000000000000..6843818d6e803791f575f5abf37f3499809ad9a0 --- /dev/null +++ b/.clang-format @@ -0,0 +1,107 @@ +--- +Language: Cpp +# BasedOnStyle: Google +AccessModifierOffset: -1 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: true +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: true +BinPackArguments: false +BinPackParameters: false +BitFieldColonSpacing: After +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakStringLiterals: true +ColumnLimit: 200 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: true +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^' + Priority: 1 + - Regex: '^<.*\.h>' + Priority: 1 + - Regex: '^<.*' + Priority: 1 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '([-_](test|unittest))?$' +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 2 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Right +ReflowComments: true +SortIncludes: false +SortUsingDeclarations: false +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 2 +UseTab: Never +... + diff --git a/ci-scripts/Jenkinsfile-gitlab b/ci-scripts/Jenkinsfile-gitlab index 784588357df03867adc6cfddca52f3854640bf22..10b70341991baa71c0d7362af3c6d4368ac84f73 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 81c4d68ace94aad5332b9bafba07025c181c469a..0000000000000000000000000000000000000000 --- 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 c29941cade3d2464f591ed3a5873341bacb63a4c..16aba3b7a77c161262b98ba9b4c21c038de79631 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,10 @@ 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 + +# in this script we previously produced 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 file +touch ./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 5b45b48ba67bd0454716428cf89d29cddcf16a97..131f2d72bc7a4fffe219c99e096a61c1f491a6d8 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 01417a3bdb3c68385cac0141a971d7ab90002c21..47fd2a08d00637e9f52961c63365860d756497fa 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 bcd3e2f7fecf0ed24cc9ea921cb0bdc6fdddd8c3..894eb85be1abcd1b81c01f017f726daa2ae59519 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 + 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 - if [ -f ./oai_rules_result_list.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 - 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 + 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 " "}' ./oai_rules_result_list.txt >> ./build_results.html + awk '{print " "}' ./files-w-gnu-gpl-license-banner.txt >> ./build_results.html echo "
Filename
"$1"
"$1"
" >> ./build_results.html echo "
" >> ./build_results.html echo "
" >> ./build_results.html fi - if [ -f ./header-files-w-incorrect-define.txt ] - 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 - 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 - 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 ] + 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-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 a16914a91dde6e3f89ddf60ecc56e26a379adcad..0000000000000000000000000000000000000000 --- 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/doc/GET_SOURCES.md b/doc/GET_SOURCES.md index 854ff3b504c2aca273dfb7490408eb9cd7f8b31c..f594ba174782e0f6662077c930b38b424e94c06c 100644 --- a/doc/GET_SOURCES.md +++ b/doc/GET_SOURCES.md @@ -1,41 +1,20 @@ - - - - - -
- - - - - - The OpenAirInterface repository: the sources -
- The OpenAirInterface software can be obtained from our gitLab server. You will need a git client to get the sources. The repository is currently used for main developments. # Prerequisites -You need to install the subversion/git using the following commands: +You need to install git using the following commands: ```shell sudo apt-get update -sudo apt-get install subversion git +sudo apt-get install git ``` # Using EURECOM Gitlab The [openairinterface5g repository](https://gitlab.eurecom.fr/oai/openairinterface5g.git) -holds the source code for (eNB RAN + UE RAN). - -For legal issues (licenses), the core network (EPC) source code is now moved away from -the above openairinterface5g git repository. - -* A more recent version is available under our GitHub domain: - * [OAI GitHub openair-cn domain](https://github.com/OPENAIRINTERFACE) - * Check its wiki pages for more details +holds the source code for the RAN (4G and 5G). Configure git with your name/email address (only important if you are developer and want to contribute/push code to Git Repository): @@ -44,18 +23,6 @@ git config --global user.name "Your Name" git config --global user.email "Your email address" ``` -- Add a certificate from gitlab.eurecom.fr to your Ubuntu 14.04 installation: - -```shell -echo -n | openssl s_client -showcerts -connect gitlab.eurecom.fr:443 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt -``` - -- Disable certificate check completely if you do not have root access to /etc/ssl directory - -```shell -git config --global http.sslverify false -``` - ## In order to clone the Git repository (for OAI Users without login to gitlab server) Cloning RAN repository (eNB RAN + UE RAN): @@ -70,13 +37,6 @@ Please send email to [contact@openairinterface.org](mailto:contact@openairinterf as a developer (only important for users who want to commit code to the repository). If you do not have account on gitlab.eurecom.fr, please register yourself to gitlab.eurecom.fr and provide the identifiant in the email. -* Clone with using ssh keys: - * You will need to put your ssh keys in https://gitlab.eurecom.fr/profile/keys - to access to the git repo. Once that is done, clone the git repository using: - * `git clone git@gitlab.eurecom.fr:oai/openairinterface5g.git` -* Clone with user name/password prompt: - * `git clone https://YOUR_USERNAME@gitlab.eurecom.fr/oai/openairinterface5g.git` - # Which branch to checkout? On the RAN side: @@ -84,15 +44,15 @@ On the RAN side: * **master**: This branch is targeted for the user community. Since January 2019, it is also subject to a Continuous Integration process. The update frequency is about once every 2-3 months. We are also performing bug fixes on this branch. * **develop**: This branch contains recent commits that are tested on our CI test bench. The update frequency is about once a week. -Please see the work flow and policies page : +Please see the work flow and policies page: https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/oai-policies-home -you can find the latest stable tag release here : +you can find the latest stable tag release here: https://gitlab.eurecom.fr/oai/openairinterface5g/tags -The tag naming conventions are : +The tag naming conventions are: - On `master` branch: **v1.`x`.`y`** where * `x` is the minor release number, incremented every 2-3 months when we are merging `develop` into `master` branch. diff --git a/doc/clang-format.md b/doc/clang-format.md new file mode 100644 index 0000000000000000000000000000000000000000..fa751b303dcbf14ecc3152a905e557c57d626002 --- /dev/null +++ b/doc/clang-format.md @@ -0,0 +1,66 @@ +We use [clang-format](https://clang.llvm.org/docs/ClangFormat.html) to format our code. + +# Integration into editors + +Integration into various editors (`vim`, `emacs`, `VSCode`, `CLion`) is on the +[clang-format project page](https://clang.llvm.org/docs/ClangFormat.html). + +There is also an [eclipse plugin](https://github.com/wangzw/CppStyle). + +# Integration into git + +## Short version + +See below for a more detailed explanation. In short: Add this to `~/.gitconfig`: +``` +[clangFormat] + binary = clang-format-12 + style = file +``` +Now stage files for reformatting, then run `git clang-format`. It will reformat +only the code that is staged, and you can view reformatted code with `git +diff`. To add modified lines to your commit, stage them as well, then commit. + +There is also a pre-commit hook that you can install. To install it, copy it +`pre-commit-clang` to `.git/hooks/pre-commit`, and make it executable. + +## Long version + +In order to integrate `clang-format` into `git`, follow these steps: + +1) Copy `pre-commit-clang` to `.git/hooks/pre-commit` and make it executable. + +2) Install clang-format-12 (needs at least Ubuntu 20, remove anything else) + ```bash + $ sudo apt-get remove clang-format* + $ sudo apt-get install clang-format-12 + ``` + +3) Configure `git` (set correct executable, set mode, provide more convenient alias) + ```bash + $ git config --global clangFormat.binary clang-format-12 + $ git config --global clangFormat.style file + $ git config --global alias.clang-format clang-format-12 + ``` + +When this is done, you are set up. How to use: + +4) When committing new code, add the code to commit into the staging (`git add + -p` or `git add `) _and stash the rest_ (e.g., `git stash -p`, this is + quite important or reformatting might not work properly, or you don't know + what has been reformatted) + +5) Run git clang-format. The staged code will be reformatted. After this, you + still have your changes in the staging area, and the formatted code appears + as additional modification. Thus, your changes can be seen with + ```bash + $ git diff --staged + ``` + while the modifications of clang-format with + ```bash + $ git diff + ``` + So now, you can add all or parts of reformatted code to the staging area + +6) Commit. It won't work if code is not properly formatted due to the + pre-commit hook. Force committing with `git commit --no-verify` diff --git a/pre-commit b/pre-commit deleted file mode 100644 index ab54a821a5436e156a444ac7fc53f9c452eb786d..0000000000000000000000000000000000000000 --- 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 diff --git a/pre-commit-clang b/pre-commit-clang new file mode 100644 index 0000000000000000000000000000000000000000..f7b219a7d567d55ec0dd21903a4ba5304fb4ba2f --- /dev/null +++ b/pre-commit-clang @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# +# Runs clang-format on changed regions before commit. +# +# To install this, copy it to .git/hooks/pre-commit in your repo. +# Remaining installation checks/instructions will be printed when you commit. +# + +read -d '' help <<- EOF +This repository requires you to install the clang-format command. This hook has +been tested with clang-format-10, so remove all previous versions and reinstall: +$ sudo apt-get remove clang-format-* +$ sudo apt-get install clang-format-10 +You should now have clang-format-10 installed. Then, update the configuration +as follows: +$ git config --global clangFormat.binary clang-format-10 +$ git config --global clangFormat.style file +$ git config --global alias.clang-format clang-format-10 +EOF + +check_clang_format() { + if hash git clang-format 2>/dev/null; then + return + else + echo "SETUP ERROR: no git clang-format executable found, or it is not executable" + echo "$help" + exit 1 + fi +} + +check_git_config() { + if [[ "$(git config --get clangFormat.binary)" != "clang-format-10" ]]; then + echo "SETUP ERROR: git config clangFormat.binary should be \"clang-format-10\"." + echo "$help" + exit 1 + fi + if [[ "$(git config --get clangFormat.style)" != "file" ]]; then + echo "SETUP ERROR: git config clangFormat.style should be \"file\"." + echo "$help" + exit 1 + fi +} + +check_clang_format +check_git_config + +readonly out=$(git clang-format -v --diff) + +if [[ "$out" == *"no modified files to format"* ]]; then exit 0; fi +if [[ "$out" == *"clang-format did not modify any files"* ]]; then exit 0; fi + +echo "ERROR: the code to be committed is not formatted properly" +echo "you need to run \"git clang-format\" on your commit" +exit 1