blob: e469ce44c1ad9a573c3eb2950d3513e293a7a874 [file] [log] [blame]
Salome Thirot0ea1daf2021-04-23 13:16:16 +01001############
2clang-format
3############
4
5This tool uses clang-format and the script clang-format-diff.py provided
6in the clang tools to apply style checking on all staged files. You can
7use it before committing to check for any style that does not comply
8with the TF-M coding guidelines.
9
10*************
11How to use it
12*************
13
14Using 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
23Without 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 Thirot9a500232021-05-13 17:02:27 +010035If clang-format makes any correction, a diff file will be created in the tfm
36root directory, simply run ``git apply -p0 <diff_file>`` to apply them. The
37generated diff is a unified diff, whose format is slightly different that the
38git diff format, hence the -p0 option so that git can correctly interpret the
39file.
Salome Thirot0ea1daf2021-04-23 13:16:16 +010040
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*