C++ Format Code
C++ code formatting
Doris uses clang-format for code formatting, and provides a package script in the build-support directory:
clang-format.sh
.Format the C/C++ code in the
be/src
andbe/test
directories.check-format.sh
.Check the C/C++ code format in the
be/src
andbe/test
directories, and output diff, but the content of the file will not be modified.
Code style customizationβ
The code style of Doris is slightly modified on the basis of Google Style and is customized as a .clang-format
file located in the root directory of Doris.
Currently, the .clang-format
configuration file is adapted to versions above clang-format-16.0.0.
The code that you do not want to be formatted is recorded in the .clang-format-ignore
file. These codes usually come from third-party code bases, and it is recommended to keep the original code style.
Environmental preparationβ
You need to download and install clang-format, or you can use the clang-format plug-in provided by IDE or Editor, as described below.
Download and install clang-formatβ
The current doris uses clang-format 16 for code formatting (different versions of clang-format may produce different code formats).
Linux: You can use the LDB toolchain directly, which already comes with a corresponding version of clang-format. Or install or compile the binary by yourself in other ways.
Mac: brew install clang-format@16
LDB toolchain:
If you are using LDB toolchain, the latest version (>= v0.18) of LDB toolchain has already included clang-format with 16.0.0 version.
clang-format pluginβ
Clion IDE can use the plug-in "ClangFormat", search and download in File->Setting->Plugins
. However, you need to confirm whether the clang-format version is 16.
How to useβ
Command line operationβ
cd to the root directory of Doris, and then execute the following command:
build-support/clang-format.sh
Note: The
clang-format.sh
script requires python 3 to be installed on your machine
Use clang-format in IDE or Editorβ
Clionβ
If Clion uses a plug-in, just click Reformat Code
.
VS Codeβ
VS Code needs to install the extension Clang-Format, but you need to provide the location of the clang-format execution program.
Open the VS Code configuration page, directly search for "clang_format", and fill in
"clang_format_path": "$clang-format path$",
"clang_format_style": "file"
Then, right-click on Format Document
.