blob: cc5c18e4c79db490c3257c3d8b3a4ea27b803856 [file] [log] [blame]
Julian Halle76ade82020-11-25 03:07:21 +01001Coding Style & Guidelines
2=========================
3
Julian Halleed5b9c2022-04-05 15:33:50 +01004The following sections contain |TS| coding guidelines for different types of file. They are continually evolving
5and should not be considered "set in stone". Feel free to question them and provide feedback.
Julian Halle76ade82020-11-25 03:07:21 +01006
7To help configuring text editors the project comes with "`EditorConfig`_" file(s). (:download:`../../.editorconfig`).
8
Julian Halleed5b9c2022-04-05 15:33:50 +01009Common Rules
Julian Halle76ade82020-11-25 03:07:21 +010010------------
11
Julian Halleed5b9c2022-04-05 15:33:50 +010012The following rules are common for all types of text file, except where noted otherwise:
Julian Halle76ade82020-11-25 03:07:21 +010013
14#. Files shall be **UTF-8** encoded.
15#. Use **Unix** style line endings (``LF`` character)
16#. The primary language of the project is English. All comments and documentation must be in this language.
17#. Trailing whitespace is not welcome, please trim these.
18
Julian Halleed5b9c2022-04-05 15:33:50 +010019C Rules
20-------
Julian Halle76ade82020-11-25 03:07:21 +010021
22C source code rules are base on the *Linux Coding Style* (See: |LCS|). The following deviations apply:
23
245. |TS| follows *ISO/IEC 9899:1999* standard with |ACLE| version *Q3 2020* extensions.
25#. Line length shall not exceed 100 characters.
26#. Use `snake_case`_ for function, variable and file names.
27#. Each file shall be "self contained" and include header files with external dependencies. No file shall depend on
28 headers included by other files.
29#. Include ordering: please include project specific headers first and then system includes. Please order the files
30 alphabetically in the above two groups.
31#. All variables must be initialized.
32
Julian Halleed5b9c2022-04-05 15:33:50 +010033C source files should include a copyright and license comment block at the head of each file. Here is an example::
34
35 /*
Gabor Toth11192a22023-04-04 12:40:16 +020036 * Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.
Julian Halleed5b9c2022-04-05 15:33:50 +010037 *
38 * SPDX-License-Identifier: BSD-3-Clause
39 */
40
Gabor Toth11192a22023-04-04 12:40:16 +020041Boring stuff is not for smart people and the project uses the `Clang-Format`_ code beautifier to easy formatting the
42source. (See :download:`../../.clang-format`)
Julian Halle76ade82020-11-25 03:07:21 +010043
Julian Halleed5b9c2022-04-05 15:33:50 +010044CMake Rules
45-----------
Julian Halle76ade82020-11-25 03:07:21 +010046
Julian Halleed5b9c2022-04-05 15:33:50 +010047Cmake files (e.g. CMakeLists.txt and .cmake) should conform to the following rules:
48
491. CMake file names use `CamelCase`_ style.
Julian Halle76ade82020-11-25 03:07:21 +010050#. Indent with tabs and otherwise use spaces. Use 4 spaces for tab size.
51#. Use LF as line end in CMake files.
52#. Remove trailing whitespace.
53#. Maximum line length is 128 characters.
54#. When complicated functionality is needed prefer CMake scripting over other languages.
55#. Prefix local variables with `_`.
56#. Use functions to prevent global name-space pollution.
57#. Use `snake_case`_ for function and variable names.
58#. Use the ``include_guard()`` CMake function when creating new modules, to prevent multiple inclusion.
59#. Use self contained modules, i.e. include direct dependencies of the module.
60#. Use the Sphinx CMake domain for in-line documentation of CMake scripts. For details please refer to the
61 `CMake Documentation`_.
62
Julian Halleed5b9c2022-04-05 15:33:50 +010063Each file should include a copyright and license comment block at the head of each file. Here is an example::
64
65 #-------------------------------------------------------------------------------
Gabor Toth11192a22023-04-04 12:40:16 +020066 # Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.
Julian Halleed5b9c2022-04-05 15:33:50 +010067 #
68 # SPDX-License-Identifier: BSD-3-Clause
69 #
70 #-------------------------------------------------------------------------------
71
Julian Halleed5b9c2022-04-05 15:33:50 +010072Restructured Text Rules
73-----------------------
Julian Halle76ade82020-11-25 03:07:21 +010074
75Please refer to :doc:`/developer/writing-documentation`.
76
77--------------
78
79.. _`CamelCase`: https://hu.wikipedia.org/wiki/CamelCase
80.. _`snake_case`: https://en.wikipedia.org/wiki/Snake_case
81.. _`CMake Documentation`: https://github.com/Kitware/CMake/blob/master/Help/dev/documentation.rst
82.. _`EditorConfig`: https://editorconfig.org/
Gabor Toth11192a22023-04-04 12:40:16 +020083.. _`Clang-Format`: https://clang.llvm.org/docs/ClangFormat.html
Julian Halle76ade82020-11-25 03:07:21 +010084
Gabor Toth11192a22023-04-04 12:40:16 +020085*Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.*
Julian Halle76ade82020-11-25 03:07:21 +010086
87SPDX-License-Identifier: BSD-3-Clause