This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch clang-format
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit f11c6c717dc4aa4ddd5850edf36744b99d652593
Author: Alan M. Carroll <[email protected]>
AuthorDate: Wed Nov 8 14:02:13 2023 -0600

    Update clang-format to ATS 10.
---
 .clang-format         | 152 +++++++++++++++++++++++++++++++++++++++++---------
 tools/clang-format.sh |  68 +++++++++++++++-------
 2 files changed, 175 insertions(+), 45 deletions(-)

diff --git a/.clang-format b/.clang-format
index 68a4641..b04bf05 100644
--- a/.clang-format
+++ b/.clang-format
@@ -2,62 +2,99 @@
 Language:        Cpp
 AccessModifierOffset: -2
 AlignAfterOpenBracket: Align
-AlignConsecutiveMacros: false
-AlignConsecutiveAssignments: true
-AlignConsecutiveDeclarations: false
+AlignArrayOfStructures: Left
+AlignConsecutiveAssignments:
+  Enabled:         true
+  AcrossEmptyLines: false
+  AcrossComments:  false
+  AlignCompound:   true
+  PadOperators:    true
+AlignConsecutiveBitFields:
+  Enabled:         true
+  AcrossEmptyLines: false
+  AcrossComments:  false
+  AlignCompound:   false
+  PadOperators:    false
+AlignConsecutiveDeclarations:
+  Enabled:         false
+  AcrossEmptyLines: false
+  AcrossComments:  false
+  AlignCompound:   false
+  PadOperators:    true
+AlignConsecutiveMacros:
+  Enabled:         true
+  AcrossEmptyLines: false
+  AcrossComments:  false
+  AlignCompound:   false
+  PadOperators:    true
+AlignConsecutiveShortCaseStatements:
+  Enabled:         false
+  AcrossEmptyLines: false
+  AcrossComments:  false
+  AlignCaseColons: false
 AlignEscapedNewlines: Left
-AlignOperands:   true
-AlignTrailingComments: true
-AllowAllArgumentsOnNextLine: true
-AllowAllConstructorInitializersOnNextLine: true
+AlignOperands:   Align
+AlignTrailingComments:
+  Kind:            Always
+  OverEmptyLines:  0
+AllowAllArgumentsOnNextLine: false
 AllowAllParametersOfDeclarationOnNextLine: false
 AllowShortBlocksOnASingleLine: Never
 AllowShortCaseLabelsOnASingleLine: false
+AllowShortEnumsOnASingleLine: true
 AllowShortFunctionsOnASingleLine: Inline
-AllowShortLambdasOnASingleLine: All
 AllowShortIfStatementsOnASingleLine: Never
+AllowShortLambdasOnASingleLine: All
 AllowShortLoopsOnASingleLine: false
 AlwaysBreakAfterDefinitionReturnType: All
 AlwaysBreakAfterReturnType: AllDefinitions
 AlwaysBreakBeforeMultilineStrings: false
 AlwaysBreakTemplateDeclarations: MultiLine
+AttributeMacros:
+  - __capability
 BinPackArguments: true
 BinPackParameters: true
+BitFieldColonSpacing: Both
 BraceWrapping:
   AfterCaseLabel:  false
   AfterClass:      true
-  AfterControlStatement: false
+  AfterControlStatement: Never
   AfterEnum:       false
+  AfterExternBlock: false
   AfterFunction:   true
-  AfterNamespace:  true
+  AfterNamespace:  false
   AfterObjCDeclaration: false
   AfterStruct:     false
   AfterUnion:      false
-  AfterExternBlock: false
   BeforeCatch:     false
   BeforeElse:      false
+  BeforeLambdaBody: false
+  BeforeWhile:     false
   IndentBraces:    false
   SplitEmptyFunction: true
   SplitEmptyRecord: true
   SplitEmptyNamespace: true
+BreakAfterAttributes: Never
+BreakAfterJavaFieldAnnotations: false
+BreakArrays:     true
 BreakBeforeBinaryOperators: None
-BreakBeforeInheritanceComma: false
-BreakInheritanceList: BeforeColon
+BreakBeforeConceptDeclarations: Always
+#BreakBeforeBraces: Linux
+BreakBeforeInlineASMColon: OnlyMultiline
 BreakBeforeTernaryOperators: false
-BreakConstructorInitializersBeforeComma: false
 BreakConstructorInitializers: BeforeColon
-BreakAfterJavaFieldAnnotations: false
+BreakInheritanceList: BeforeColon
 BreakStringLiterals: true
 ColumnLimit:     132
 CommentPragmas:  '^ IWYU pragma:'
 CompactNamespaces: true
-ConstructorInitializerAllOnOneLineOrOnePerLine: true
 ConstructorInitializerIndentWidth: 2
 ContinuationIndentWidth: 2
 Cpp11BracedListStyle: true
-DeriveLineEnding: true
 DerivePointerAlignment: false
 DisableFormat:   false
+EmptyLineAfterAccessModifier: Never
+EmptyLineBeforeAccessModifier: LogicalBlock
 ExperimentalAutoDetectBinPacking: false
 FixNamespaceComments: true
 ForEachMacros:
@@ -67,72 +104,135 @@ ForEachMacros:
   - foreach
   - Q_FOREACH
   - BOOST_FOREACH
+IfMacros:
+  - KJ_IF_MAYBE
 IncludeBlocks:   Preserve
 IncludeCategories:
   - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
     Priority:        2
     SortPriority:    0
+    CaseSensitive:   false
   - Regex:           '^(<|"(gtest|isl|json)/)'
     Priority:        3
     SortPriority:    0
+    CaseSensitive:   false
   - Regex:           '.*'
     Priority:        1
     SortPriority:    0
+    CaseSensitive:   false
 IncludeIsMainRegex: '$'
 IncludeIsMainSourceRegex: ''
+IndentAccessModifiers: false
+IndentCaseBlocks: false
 IndentCaseLabels: false
+IndentExternBlock: AfterExternBlock
 IndentGotoLabels: true
 IndentPPDirectives: None
+IndentRequiresClause: true
 IndentWidth:     2
 IndentWrappedFunctionNames: false
+InsertBraces:    false
+InsertNewlineAtEOF: true
+InsertTrailingCommas: None
+IntegerLiteralSeparator:
+  Binary:          0
+  BinaryMinDigits: 0
+  Decimal:         0
+  DecimalMinDigits: 0
+  Hex:             0
+  HexMinDigits:    0
 JavaScriptQuotes: Leave
 JavaScriptWrapImports: true
 KeepEmptyLinesAtTheStartOfBlocks: false
+KeepEmptyLinesAtEOF: false
+LambdaBodyIndentation: Signature
+LineEnding:      DeriveLF
 MacroBlockBegin: ''
 MacroBlockEnd:   ''
 MaxEmptyLinesToKeep: 1
 NamespaceIndentation: None
 ObjCBinPackProtocolList: Auto
 ObjCBlockIndentWidth: 2
+ObjCBreakBeforeNestedBlockParam: true
 ObjCSpaceAfterProperty: true
 ObjCSpaceBeforeProtocolList: false
+PackConstructorInitializers: NextLine
 PenaltyBreakAssignment: 2
 PenaltyBreakBeforeFirstCallParameter: 19
 PenaltyBreakComment: 30000
 PenaltyBreakFirstLessLess: 120
+PenaltyBreakOpenParenthesis: 0
 PenaltyBreakString: 1000
 PenaltyBreakTemplateDeclaration: 10
 PenaltyExcessCharacter: 1000000
+PenaltyIndentedWhitespace: 0
 PenaltyReturnTypeOnItsOwnLine: 200
 PointerAlignment: Right
+PPIndentWidth:   -1
+QualifierAlignment: Leave
+ReferenceAlignment: Pointer
 ReflowComments:  true
-SortIncludes:    false
-SortUsingDeclarations: false
+RemoveBracesLLVM: false
+RemoveParentheses: Leave
+RemoveSemicolon: false
+RequiresClausePosition: OwnLine
+RequiresExpressionIndentation: OuterScope
+SeparateDefinitionBlocks: Leave
+ShortNamespaceLines: 1
+SortIncludes:    Never
+SortJavaStaticImport: Before
+SortUsingDeclarations: Never
 SpaceAfterCStyleCast: false
 SpaceAfterLogicalNot: false
 SpaceAfterTemplateKeyword: true
+SpaceAroundPointerQualifiers: Default
 SpaceBeforeAssignmentOperators: true
+SpaceBeforeCaseColon: false
 SpaceBeforeCpp11BracedList: false
 SpaceBeforeCtorInitializerColon: true
 SpaceBeforeInheritanceColon: true
+SpaceBeforeJsonColon: false
 SpaceBeforeParens: ControlStatements
+SpaceBeforeParensOptions:
+  AfterControlStatements: true
+  AfterForeachMacros: true
+  AfterFunctionDefinitionName: false
+  AfterFunctionDeclarationName: false
+  AfterIfMacros:   true
+  AfterOverloadedOperator: false
+  AfterRequiresInClause: false
+  AfterRequiresInExpression: false
+  BeforeNonEmptyParentheses: false
 SpaceBeforeRangeBasedForLoopColon: true
+SpaceBeforeSquareBrackets: false
 SpaceInEmptyBlock: false
-SpaceInEmptyParentheses: false
 SpacesBeforeTrailingComments: 1
-SpacesInAngles:  false
-SpacesInConditionalStatement: false
+SpacesInAngles:  Never
 SpacesInContainerLiterals: true
-SpacesInCStyleCastParentheses: false
-SpacesInParentheses: false
+SpacesInLineCommentPrefix:
+  Minimum:         1
+  Maximum:         -1
+SpacesInParens:  Never
+SpacesInParensOptions:
+  InCStyleCasts:   false
+  InConditionalStatements: false
+  InEmptyParentheses: false
+  Other:           false
 SpacesInSquareBrackets: false
-SpaceBeforeSquareBrackets: false
 Standard:        Latest
+StatementAttributeLikeMacros:
+  - Q_EMIT
 StatementMacros:
   - Q_UNUSED
   - QT_REQUIRE_VERSION
 TabWidth:        8
-UseCRLF:         false
 UseTab:          Never
+VerilogBreakBetweenInstancePorts: true
+WhitespaceSensitiveMacros:
+  - STRINGIZE
+  - PP_STRINGIZE
+  - BOOST_PP_STRINGIZE
+  - NS_SWIFT_NAME
+  - CF_SWIFT_NAME
 ...
 
diff --git a/tools/clang-format.sh b/tools/clang-format.sh
index fe4a193..86bb698 100755
--- a/tools/clang-format.sh
+++ b/tools/clang-format.sh
@@ -19,36 +19,47 @@
 #  limitations under the License.
 
 # Update the PKGDATE with the new version date when making a new clang-format 
binary package.
-PKGDATE="20200514"
+PKGDATE="20230928"
 
 function main() {
   set -e # exit on error
   ROOT=${ROOT:-$(cd $(dirname $0) && git rev-parse 
--show-toplevel)/.git/fmt/${PKGDATE}}
+  # The presence of this file indicates clang-format was successfully 
installed.
+  INSTALLED_SENTINEL=${ROOT}/.clang-format-installed
 
-  DIR=${@:-code}
+  # Check for the option to just install clang-format without running it.
+  just_install=0
+  if [ "$1" = "--install" ] ; then
+    just_install=1
+    if [ $# -ne 1 ] ; then
+      echo "No other arguments should be used with --install."
+      exit 2
+    fi
+  fi
+  DIR=${@:-.}
   PACKAGE="clang-format-${PKGDATE}.tar.bz2"
-  VERSION="clang-format version 10.0.0 
(https://github.com/llvm/llvm-project.git 
d32170dbd5b0d54436537b6b75beaf44324e0c28)"
+  VERSION="clang-format version 17.0.1 
(https://github.com/llvm/llvm-project.git 
e19b7dc36bc047b9eb72078d034596be766da350)"
 
   URL=${URL:-https://ci.trafficserver.apache.org/bintray/${PACKAGE}}
 
   TAR=${TAR:-tar}
   CURL=${CURL:-curl}
 
-  # default to using native sha1sum command when available
-  if [ $(which sha1sum) ] ; then
-    SHASUM=${SHASUM:-sha1sum}
+  # Default to sha256sum, but honor the env variable just in case
+  if [ $(which sha256sum) ] ; then
+    SHASUM=${SHASUM:-sha256sum}
   else
-    SHASUM=${SHASUM:-shasum}
+    SHASUM=${SHASUM:-shasum -a 256}
   fi
 
   ARCHIVE=$ROOT/$(basename ${URL})
 
   case $(uname -s) in
   Darwin)
-    FORMAT=${FORMAT:-${ROOT}/clang-format/clang-format.osx}
+    FORMAT=${FORMAT:-${ROOT}/clang-format/clang-format.macos.$(uname -m)}
     ;;
   Linux)
-    FORMAT=${FORMAT:-${ROOT}/clang-format/clang-format.linux}
+    FORMAT=${FORMAT:-${ROOT}/clang-format/clang-format.linux.$(uname -m)}
     ;;
   *)
     echo "Leif needs to build a clang-format for $(uname -s)"
@@ -61,10 +72,10 @@ function main() {
   if [ ! -e ${FORMAT} -o ! -e ${ROOT}/${PACKAGE} ] ; then
     ${CURL} -L --progress-bar -o ${ARCHIVE} ${URL}
     ${TAR} -x -C ${ROOT} -f ${ARCHIVE}
-    cat > ${ROOT}/sha1 << EOF
-5eec43e5c7f3010d6e6f37639491cabe51de0ab2  ${ARCHIVE}
+    cat > ${ROOT}/sha256 << EOF
+deb056a30ad968c5b7c8768ffecb382408ad2669dd61f2cc126d267069f0c197  ${ARCHIVE}
 EOF
-    ${SHASUM} -c ${ROOT}/sha1
+    ${SHASUM} -c ${ROOT}/sha256
     chmod +x ${FORMAT}
   fi
 
@@ -73,15 +84,34 @@ EOF
   ver=$(${FORMAT} --version)
   if [ "$ver" != "$VERSION" ]; then
       echo "Wrong version of clang-format!"
-      echo "See 
https://bintray.com/apache/trafficserver/clang-format-tools/view for a newer 
version,"
-      echo "or alternatively, undefine the FORMAT environment variable"
+      echo "Contact the ATS community for help and details about clang-format 
versions."
       exit 1
-  else
-      for file in $(find $DIR -iname \*.[ch] -o -iname \*.cc -o -iname 
\*.h.in); do
-    echo $file
-    ${FORMAT} -i $file
-      done
   fi
+  touch ${INSTALLED_SENTINEL}
+  [ ${just_install} -eq 1 ] && return
+
+  # Efficiently retrieving modification timestamps in a platform
+  # independent way is challenging. We use find's -newer argument, which
+  # seems to be broadly supported. The following file is created and has a
+  # timestamp just before running clang-format. Any file with a timestamp
+  # after this we assume was modified by clang-format.
+  start_time_file=$(mktemp -t clang-format-start-time.XXXXXXXXXX)
+  touch ${start_time_file}
+
+  target_files=$(find $DIR -iname \*.[ch] -o -iname \*.cc -o -iname \*.h.in)
+  for file in ${target_files}; do
+    # The ink_autoconf.h and ink_autoconf.h.in files are generated files,
+    # so they do not need to be re-formatted by clang-format. Doing so
+    # results in make rebuilding all our files, so we skip formatting them
+    # here.
+    base_name=$(basename ${file})
+    [ ${base_name} = 'ink_autoconf.h.in' -o ${base_name} = 'ink_autoconf.h' ] 
&& continue
+
+    ${FORMAT} -i $file
+  done
+
+  find ${target_files} -newer ${start_time_file}
+  rm ${start_time_file}
 }
 
 if [[ "$(basename -- "$0")" == 'clang-format.sh' ]]; then

Reply via email to