-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Format native code using clang-format (#2101)
- Loading branch information
Showing
31 changed files
with
2,809 additions
and
2,287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,81 @@ | ||
--- | ||
# We'll use defaults from the LLVM style, but with 4 columns indentation. | ||
BasedOnStyle: Google | ||
# copied from: https://github.com/dotnet/runtime/blob/main/src/coreclr/jit/.clang-format | ||
Language: Cpp | ||
AccessModifierOffset: -4 | ||
AlignAfterOpenBracket: Align | ||
AlignConsecutiveAssignments: true | ||
AlignConsecutiveDeclarations: true | ||
AlignEscapedNewlinesLeft: false | ||
AlignOperands: true | ||
AlignTrailingComments: true | ||
AllowAllParametersOfDeclarationOnNextLine: true | ||
AllowShortBlocksOnASingleLine: false | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: Empty | ||
AllowShortIfStatementsOnASingleLine: false | ||
AllowShortLoopsOnASingleLine: false | ||
AlwaysBreakAfterDefinitionReturnType: None | ||
AlwaysBreakBeforeMultilineStrings: false | ||
AlwaysBreakTemplateDeclarations: true | ||
BinPackArguments: true | ||
BinPackParameters: false | ||
BraceWrapping: | ||
AfterClass: true | ||
AfterControlStatement: true | ||
AfterEnum: false | ||
AfterFunction: true | ||
AfterNamespace: false | ||
AfterObjCDeclaration: false | ||
AfterStruct: true | ||
AfterUnion: true | ||
BeforeCatch: true | ||
BeforeElse: true | ||
IndentBraces: false | ||
BreakBeforeBinaryOperators: None | ||
BreakBeforeBraces: Allman | ||
BreakBeforeTernaryOperators: true | ||
BreakConstructorInitializersBeforeComma: true | ||
ColumnLimit: 120 | ||
CommentPragmas: '^ IWYU pragma:' | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: true | ||
ConstructorInitializerIndentWidth: 4 | ||
ContinuationIndentWidth: 4 | ||
Cpp11BracedListStyle: true | ||
DerivePointerAlignment: false | ||
DisableFormat: false | ||
ExperimentalAutoDetectBinPacking: false | ||
ForEachMacros: [ ] | ||
IndentCaseLabels: true | ||
IndentWidth: 4 | ||
IndentWrappedFunctionNames: false | ||
KeepEmptyLinesAtTheStartOfBlocks: true | ||
MacroBlockBegin: '' | ||
MacroBlockEnd: '' | ||
MaxEmptyLinesToKeep: 1 | ||
NamespaceIndentation: None | ||
ObjCBlockIndentWidth: 2 | ||
ObjCSpaceAfterProperty: false | ||
ObjCSpaceBeforeProtocolList: true | ||
PenaltyBreakBeforeFirstCallParameter: 400 | ||
PenaltyBreakComment: 50 | ||
PenaltyBreakFirstLessLess: 500 | ||
PenaltyBreakString: 1000 | ||
PenaltyExcessCharacter: 1000000 | ||
PenaltyReturnTypeOnItsOwnLine: 100000 | ||
PointerAlignment: Left | ||
ReflowComments: true | ||
SortIncludes: false | ||
SpaceAfterCStyleCast: false | ||
SpaceBeforeAssignmentOperators: true | ||
SpaceBeforeParens: ControlStatements | ||
SpaceInEmptyParentheses: false | ||
SpacesBeforeTrailingComments: 1 | ||
SpacesInAngles: false | ||
SpacesInContainerLiterals: true | ||
SpacesInCStyleCastParentheses: false | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false | ||
Standard: Cpp11 | ||
TabWidth: 4 | ||
UseTab: Never | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ on: | |
paths: | ||
- '**.cs' | ||
- '.editorconfig' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
check-format: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: format native | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
check-native-format: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
machine: [ windows-2022, ubuntu-20.04, macos-11 ] | ||
runs-on: ${{ matrix.machine }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3.3.0 | ||
|
||
- name: Install Clang tools | ||
shell: bash | ||
run: ./scripts/download-clang-tools.sh | ||
|
||
- name: Format native code | ||
shell: bash | ||
run: ./scripts/format-native.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/bash | ||
|
||
set -eo pipefail | ||
|
||
SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) | ||
|
||
# guess OS_TYPE if not provided | ||
if [ -z "$OS_TYPE" ]; then | ||
case "$(uname -s | tr '[:upper:]' '[:lower:]')" in | ||
cygwin_nt*|mingw*|msys_nt*) | ||
OS_TYPE="windows" | ||
;; | ||
linux*) | ||
if [ "$(ldd /bin/ls | grep -m1 'musl')" ]; then | ||
OS_TYPE="linux-musl" | ||
else | ||
OS_TYPE="linux-glibc" | ||
fi | ||
;; | ||
darwin*) | ||
OS_TYPE="macos" | ||
;; | ||
esac | ||
fi | ||
|
||
function DownloadClangTool { | ||
if [ "$OS_TYPE" == "windows" ]; then | ||
FILENAME=$1.exe | ||
else | ||
FILENAME=$1 | ||
fi | ||
|
||
case "$OS_TYPE" in | ||
"linux-glibc") | ||
TOOLS_URL=https://clrjit.blob.core.windows.net/clang-tools/ubuntu.18.04-x64/$FILENAME | ||
;; | ||
"macos") | ||
TOOLS_URL=https://clrjit.blob.core.windows.net/clang-tools/osx.10.15-x64/$FILENAME | ||
;; | ||
"windows") | ||
TOOLS_URL=https://clrjit.blob.core.windows.net/clang-tools/windows/$FILENAME | ||
;; | ||
*) | ||
echo "Set the operating system type using the OS_TYPE environment variable. Supported values: linux-glibc, macos, windows." >&2 | ||
exit 1 | ||
;; | ||
esac | ||
|
||
cd $SCRIPT_DIR/.. | ||
mkdir -p bin/artifacts | ||
cd bin/artifacts | ||
|
||
curl --retry 5 -o "${FILENAME}" "$TOOLS_URL" | ||
chmod +x $FILENAME | ||
} | ||
|
||
DownloadClangTool "clang-format" | ||
# DownloadClangTool "clang-tidy" # unused |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/sh | ||
|
||
SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) | ||
cd $SCRIPT_DIR/.. | ||
|
||
LC_ALL=C | ||
|
||
# guess OS_TYPE if not provided | ||
if [ -z "$OS_TYPE" ]; then | ||
case "$(uname -s | tr '[:upper:]' '[:lower:]')" in | ||
cygwin_nt*|mingw*|msys_nt*) | ||
OS_TYPE="windows" | ||
;; | ||
linux*) | ||
if [ "$(ldd /bin/ls | grep -m1 'musl')" ]; then | ||
OS_TYPE="linux-musl" | ||
else | ||
OS_TYPE="linux-glibc" | ||
fi | ||
;; | ||
darwin*) | ||
OS_TYPE="macos" | ||
;; | ||
esac | ||
fi | ||
|
||
if [ "$OS_TYPE" == "windows" ]; then | ||
EXT=.exe | ||
else | ||
EXT= | ||
fi | ||
|
||
# files to format | ||
NATIVE_FILES=$(find . -iname *.cpp -o -iname *.hpp -iname *.h -iname *.inc | grep -v ./packages | grep -v ./src/OpenTelemetry.AutoInstrumentation.Native/lib) | ||
|
||
# clang-format | ||
echo "$NATIVE_FILES" | xargs "./bin/artifacts/clang-format$EXT" -style=file -i | ||
|
||
## check if anything changed | ||
git status | ||
git diff | ||
test -z "$(git status --porcelain)" |
Oops, something went wrong.