Salome Thirot | 0ea1daf | 2021-04-23 13:16:16 +0100 | [diff] [blame] | 1 | ############ |
| 2 | clang-format |
| 3 | ############ |
| 4 | |
| 5 | This tool uses clang-format and the script clang-format-diff.py provided |
| 6 | in the clang tools to apply style checking on all staged files. You can |
| 7 | use it before committing to check for any style that does not comply |
| 8 | with the TF-M coding guidelines. |
| 9 | |
| 10 | ************* |
| 11 | How to use it |
| 12 | ************* |
| 13 | |
| 14 | Using the configuration script |
| 15 | ============================== |
| 16 | |
| 17 | - Install clang-format on your system, the tool is available as part of the |
| 18 | clang suite, but can also be installed standalone from a packet manager. |
| 19 | - After that the only thing the user needs to do is run the |
| 20 | run-clang-format.sh script while in the TF-M root folder. If any |
| 21 | dependency is missing, it will call the setup script to install it. |
| 22 | |
| 23 | Without using the configuration script |
| 24 | ====================================== |
| 25 | |
| 26 | - Make sure clang-format is installed in your system |
| 27 | - Copy the .clang-format file to the root of the tf-m directory - |
| 28 | - Download clang-format-diff from the llvm `github repository`_ |
| 29 | - Run |
| 30 | |
| 31 | .. code-block:: bash |
| 32 | |
| 33 | git diff -U0 --no-color HEAD^ | <path/to/clang-format-diff.py> -p1 -style file> <out_file> |
| 34 | |
Salome Thirot | 9a50023 | 2021-05-13 17:02:27 +0100 | [diff] [blame] | 35 | If clang-format makes any correction, a diff file will be created in the tfm |
| 36 | root directory, simply run ``git apply -p0 <diff_file>`` to apply them. The |
| 37 | generated diff is a unified diff, whose format is slightly different that the |
| 38 | git diff format, hence the -p0 option so that git can correctly interpret the |
| 39 | file. |
Salome Thirot | 0ea1daf | 2021-04-23 13:16:16 +0100 | [diff] [blame] | 40 | |
| 41 | .. _github repository: https://github.com/llvm/llvm-project/blob/main/clang/tools/clang-format/clang-format-diff.py |
| 42 | |
| 43 | *Copyright (c) 2021, Arm Limited. All rights reserved.* |
| 44 | *SPDX-License-Identifier: BSD-3-Clause* |