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 and be/test directories.
check-format.sh.
Check the C/C++ code format in the be/src and be/test directories, and output diff, but the content of the file will not be modified.
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-13.0.1.
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.
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.
It is recommended to use NPM to install clang-format 14 (different versions of clang-format may produce different code formats, it is recommended to use version 14):
npm install clang-format@1.6.0
Ubuntu: apt-get install clang-format
The current version is 10.0, you can also specify the old version, for example: apt-get install clang-format-9. It is recommended to compile version 14.0 from source code.
Mac: brew install clang-format
Centos 7:
The version of clang-format installed by centos yum is too old and supports too few StyleOptions. It is recommended to compile version 14.0 from source code.
LDB toolchain:
If you are using LDB toolchain, the latest version (>= v0.11) of LDB toolchain has already included clang-format with 13.0.1 version.
Clion IDE can use the plug-in “ClangFormat”, search and download in File->Setting->Plugins. But the version can’t match The version of the clang-format program matches, judging from the supported StyleOption, it should be lower than clang-format-9.0.
cd to the root directory of Doris, and then execute the following command:
build-support/clang-format.sh
Note: The
clang-format.shscript requires python 3 to be installed on your machine
If Clion uses a plug-in, just click Reformat 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.