tools: add make format-cpp to run clang-format on C++ diffs#21997
Closed
joyeecheung wants to merge 1 commit intonodejs:masterfrom
Closed
tools: add make format-cpp to run clang-format on C++ diffs#21997joyeecheung wants to merge 1 commit intonodejs:masterfrom
make format-cpp to run clang-format on C++ diffs#21997joyeecheung wants to merge 1 commit intonodejs:masterfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is a rework of #16122. I took the advice from @codebytere and make clang-format run on C++ diffs instead of the whole code base (this is also what chromium's git-cl does). This allows us to gradually format the code base while we update the C++ files in normal PRs (although it may require support from external tooling and build to make sure people run it before landing PRs).
There is currently only a shortcut in Makefile. To run it on Windows one will either need to start the command manually or refactor vcbuild.bat a bit to include/exclude the formatable C++ files in the command.
One thing to note: the clang-format npm package is maintained by the Angular team. It directly downloads executables hosted in their repository: https://github.com/angular/clang-format It seems to be reasonably safe to use. Otherwise we will have to build and host a bunch of executables for different platforms ourselves because different versions of clang-format may format the files differently so we would want to keep the version fixed.
------ patch description ----
This patch adds a
make format-cppshortcut to the Makefilethat runs clang-format on the C++ diffs, and a
make format-cpp-buildto install clang-format fromnpm.
To format staged changes:
To format HEAD~1...HEAD (latest commit):
To format diff between master and current branch head (master...HEAD):
Most of the .clang-format file comes from running
with clang-format built with llvm/trunk 328768 (npm version 1.2.3)
The clang-format version is fixed because different version of
clang-format may format the files differently.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes