Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 1 | Coding Style & Guidelines |
| 2 | ========================= |
| 3 | |
Julian Hall | eed5b9c | 2022-04-05 15:33:50 +0100 | [diff] [blame] | 4 | The following sections contain |TS| coding guidelines for different types of file. They are continually evolving |
| 5 | and should not be considered "set in stone". Feel free to question them and provide feedback. |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 6 | |
| 7 | To help configuring text editors the project comes with "`EditorConfig`_" file(s). (:download:`../../.editorconfig`). |
| 8 | |
Julian Hall | eed5b9c | 2022-04-05 15:33:50 +0100 | [diff] [blame] | 9 | Common Rules |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 10 | ------------ |
| 11 | |
Julian Hall | eed5b9c | 2022-04-05 15:33:50 +0100 | [diff] [blame] | 12 | The following rules are common for all types of text file, except where noted otherwise: |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 13 | |
| 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 Hall | eed5b9c | 2022-04-05 15:33:50 +0100 | [diff] [blame] | 19 | C Rules |
| 20 | ------- |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 21 | |
| 22 | C source code rules are base on the *Linux Coding Style* (See: |LCS|). The following deviations apply: |
| 23 | |
| 24 | 5. |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 Hall | eed5b9c | 2022-04-05 15:33:50 +0100 | [diff] [blame] | 33 | C source files should include a copyright and license comment block at the head of each file. Here is an example:: |
| 34 | |
| 35 | /* |
Gabor Toth | 11192a2 | 2023-04-04 12:40:16 +0200 | [diff] [blame] | 36 | * Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved. |
Julian Hall | eed5b9c | 2022-04-05 15:33:50 +0100 | [diff] [blame] | 37 | * |
| 38 | * SPDX-License-Identifier: BSD-3-Clause |
| 39 | */ |
| 40 | |
Gabor Toth | 11192a2 | 2023-04-04 12:40:16 +0200 | [diff] [blame] | 41 | Boring stuff is not for smart people and the project uses the `Clang-Format`_ code beautifier to easy formatting the |
| 42 | source. (See :download:`../../.clang-format`) |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 43 | |
Julian Hall | eed5b9c | 2022-04-05 15:33:50 +0100 | [diff] [blame] | 44 | CMake Rules |
| 45 | ----------- |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 46 | |
Julian Hall | eed5b9c | 2022-04-05 15:33:50 +0100 | [diff] [blame] | 47 | Cmake files (e.g. CMakeLists.txt and .cmake) should conform to the following rules: |
| 48 | |
| 49 | 1. CMake file names use `CamelCase`_ style. |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 50 | #. 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 Hall | eed5b9c | 2022-04-05 15:33:50 +0100 | [diff] [blame] | 63 | Each file should include a copyright and license comment block at the head of each file. Here is an example:: |
| 64 | |
| 65 | #------------------------------------------------------------------------------- |
Gabor Toth | 11192a2 | 2023-04-04 12:40:16 +0200 | [diff] [blame] | 66 | # Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved. |
Julian Hall | eed5b9c | 2022-04-05 15:33:50 +0100 | [diff] [blame] | 67 | # |
| 68 | # SPDX-License-Identifier: BSD-3-Clause |
| 69 | # |
| 70 | #------------------------------------------------------------------------------- |
| 71 | |
Julian Hall | eed5b9c | 2022-04-05 15:33:50 +0100 | [diff] [blame] | 72 | Restructured Text Rules |
| 73 | ----------------------- |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 74 | |
| 75 | Please 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 Toth | 11192a2 | 2023-04-04 12:40:16 +0200 | [diff] [blame] | 83 | .. _`Clang-Format`: https://clang.llvm.org/docs/ClangFormat.html |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 84 | |
Gabor Toth | 11192a2 | 2023-04-04 12:40:16 +0200 | [diff] [blame] | 85 | *Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.* |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 86 | |
| 87 | SPDX-License-Identifier: BSD-3-Clause |