-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format native code using clang-format #2101
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
94a0fff
Download clang tools script
pellared 532770a
Fix GH workflow
pellared fe0d597
Format native code
pellared f9c674e
Fix build
pellared a8fa4bc
Add workflow_dispatch to dotnet format
pellared df10106
Fix GH job matrix
pellared 4ea1f73
chmod=+x
pellared 1816f2f
Fix typos
pellared 7e910fa
Fix check
pellared 2affbaf
Better output when not formatted
pellared 58af6f6
Add docs
pellared 1b34215
Fix for Linux and macOS
pellared 9c24a44
Fix typos
pellared 004e19c
Add a references to runtime .clang-format
pellared 7987764
Merge branch 'main' into clang-format
pellared 655b14c
Merge branch 'main' into clang-format
Kielek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is the main reason why it is not yet implemented in Nuke. I think we can create an issue to move the formatting logic to Nuke targets. Let me know what you think if we should address it ASAP or can we postpone it.