-
Notifications
You must be signed in to change notification settings - Fork 235
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
Add clang-format support #913
Add clang-format support #913
Conversation
90ae51d
to
fcdf9e0
Compare
.git-blame-ignore-revs
Outdated
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Apply initial formatting | ||
4ceab17e94e73c918130a49ad1b21d5e4c14e7ec |
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.
Isn't this ignoring just this single commit? What about future reformatting that takes place when commit(s) are pushed?
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.
Thanks for reminding me, this commit hash needs update after rebases I done.
Ideally no further commits need to be added here, because now the entire repo is formatted and all formatting violations will trip CI, hence no pure formatting-related commits need to be made. Contributors are highly encouraged to configure their development environment to format on save. (eg. VS Code has editor.formatOnSave
option and multiple C/C++ formatting extensions available, most notably ms-vscode.cpptools or llvm-vs-code-extensions.vscode-clangd)
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.
Please document how to configure the development environment to configure on save. I have a personal interest in how to do it with Xcode and Vim.
Actually before you do that, let's discuss which is preferable and why: format on save from an editor or format on commit via a Git clean filter?
Did you update the commit hash?
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.
It's been updated with the latest rebase.
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.
Sorry. I edited my original comment that said "please resolve" to add the request about documentation which you probably missed. Probably BUILDING.md
is the best place for the documentation.
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.
Documented VS Code. I looked into (Neo)vim, but the phase space is too large.
6cda98c
to
44bb74a
Compare
I think this work is complete. The current CI failure doesn't seem to be related to the changes made here. |
--- | ||
# Disable clang-format in this directory | ||
DisableFormat: true | ||
SortIncludes: false |
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.
Why is this needed when formatting is disabled?
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.
It's probably not strictly necessary.
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 is the convention used in other Khronos repositories, but it should have no effects (at least on clang-format versions I've used).
if (transcoder_format == transcoder_texture_format::cTFPVRTC1_4_RGB || | ||
transcoder_format == transcoder_texture_format::cTFPVRTC1_4_RGBA) { | ||
// For PVRTC1, Basis only writes (or requires) total_blocks * bytes_per_block. But GL | ||
// requires extra padding for very small textures: | ||
// https://www.khronos.org/registry/OpenGL/extensions/IMG/IMG_texture_compression_pvrtc.txt | ||
// The transcoder will clear the extra bytes followed the used blocks to 0. |
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.
Unrelated to this PR but given the overhead of running a PR please fix the typo. s/followed/following/.
lib/astc_encode.cpp
Outdated
#define WIN32_LEAN_AND_MEAN | ||
#include <Windows.h> | ||
#define WIN32_LEAN_AND_MEAN | ||
#include <Windows.h> | ||
|
||
typedef HANDLE pthread_t; |
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.
Can you get it to indent this code up to the #endif?
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.
You can exclude lines of code from being formatted by surrounding them with:
// clang-format off
...
// clang-format on
There are examples of this in the generated files.
tests/loadtests/geom/cube.h
Outdated
@@ -3,70 +3,47 @@ | |||
* SPDX-License-Identifier: Apache-2.0 |
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.
Either don't format this file or fix the formatting for it so the vertices remain separated in the cube face - the formatting has made the comments nonsensical plus it is much harder to see the vertices when they are all run together.
The extra spaces elsewhere are also very helpful for human parsing of the various elements.
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.
There is no way to exclude individual files from formatting. That's why we had to move everything external that is not expected to be formatted by us into a separate subdirectory where we disabled formatting.
You can exclude lines of code from being formatted (or entire files) by surrounding them with:
// clang-format off
...
// clang-format on
There are examples of this in the generated files.
tests/loadtests/geom/cube_data.h
Outdated
@@ -10,146 +10,92 @@ | |||
// Mesh and VertexFormat Data |
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.
Also don't format this.
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.
See above.
tests/loadtests/geom/frame.h
Outdated
@@ -6,18 +6,6 @@ | |||
/* |
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.
Or this.
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.
See above.
tests/loadtests/geom/quad.h
Outdated
@@ -9,26 +9,10 @@ | |||
/* |
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.
Or this.
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.
See above.
tests/unittests/unittests.cc
Outdated
ktx_uint8_t CheckHeader1Test::ktxId[12] = { | ||
0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A | ||
}; | ||
ktx_uint8_t CheckHeader1Test::ktxId[12] = {0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, |
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.
Is there a way to fix the format of a few lines in a file? This represents the signature of a KTX v1 file so it much easier for humans to follow as originally written.
If there is, please make the same fix to CheckHeader2Test wherever it is.
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.
You can exclude lines of code from being formatted by surrounding them with:
// clang-format off
...
// clang-format on
There are examples of this in the generated files.
You need to rebase or merge |
@MathiasMagnus please address the outstanding issues and complete this work. |
Also remove .clang-format from self-hosted external dep fmt, because it overrides the global disable under external/
The location and the name of the added file is GitHub-friendly, GitHub's blame annotation will also refer to the original author
44bb74a
to
bc6a8af
Compare
@MarkCallow We created this PR out of courtesy, because this task did not fit in the original project timeline, so we are unable to address all the specific personal styling and tooling requests. I added documentation on the minimal requirement to reduce CI friction and noted how to configure VS Code to not trip CI. Vim is too deep a rabbit a hole and I don't have the time to give anything I document in XCode a test drive. As for the rest of the outstanding formatting related inquiries: instead of whack-a-mole-ing the formatting issues one-by-one and aligning them to the desired format, I reverted the "Initial formatting" commit and just commit the machinery enabling the enforced formatting.
Because clang-format can't run on an entire source tree, all the tools drive it file-by-file. Should you want to tweak the # list folders excluding build and .venv | recurse into all | filter files matching regex | for each of the matches { run clang-format inplace using style files and full path to file }
gci -exc build,.venv | gci -rec | where -prop Name -match '^.*\.((((c|C)(c|pp|xx|\+\+)?$)|((h|H)h?(pp|xx|\+\+)?$))|(ino|pde|proto|cu))$' | % { clang-format.exe -i --style=file $_.FullName } I leave implementing similar logic in the shell of their choice to the end-user. (The regex I borrowed from the script run by the CI action.) In summary, all the infrastructure for clang-format is there, please tweak it for your needs as you see fit. |
Were these "additional requests" related or unrelated to clang-format? If the former what where they?
These statements conflict. What am I missing? |
What about .clang-format-ignore which I've just discovered at https://clang.llvm.org/docs/ClangFormat.html. |
Edit: accidentally pressed the wrong button. They do not conflict. clang-format, the CLI tool does run file-by-file (unless you run it with a script or indirectly through git clang-format, which is ran for all changed files), but the style sheets (the The only way to disable clang-format for a single file to either move it to a separate directory for which you disable the styling in the |
This work if the continuation of #889.
Notes for the reviewers
Some comments from the original work addressed here, most notably:
Aside from explicit comments:
Should other formatting changes need refining, discussions may continue here.