[PATCH] devtools: add .clang-format file
Ferruh Yigit
ferruh.yigit at amd.com
Mon Apr 29 15:32:43 CEST 2024
On 4/29/2024 2:04 PM, Abdullah Ömer Yamaç wrote:
> clang-format is a tool to format C/C++/Objective-C code. It can be used
> to reformat code to match a given coding style, or to ensure that code
> adheres to a specific coding style. It helps to maintain a consistent
> coding style across the DPDK codebase.
>
> .clang-format file overrides the default style options provided by
> clang-format and large set of IDEs and text editors support it.
>
> Signed-off-by: Abdullah Ömer Yamaç <aomeryamac at gmail.com>
>
Overall +1 to have a format file, specially to help non-frequent
contributors.
1. Some options are failing for me [1], I don't know if it requires a
specific version of clang-format
2. Current options are not fully aligned with coding convention, it is
easier to see what is not compatible by running the tool on an existing
file [2].
we need to fix them.
[1]
`clang-format -i ./lib/ethdev/rte_ethdev.c`
a.
/home/amd/development/dpdk-next-net/./.clang-format:28:1: error: unknown
key 'Whitespace'
Whitespace:
^~~~~~~~~~
Error reading /home/amd/development/dpdk-next-net/./.clang-format:
Invalid argument
b.
/home/amd/development/dpdk-next-net/./.clang-format:12:1: error: unknown
key 'EndOfLine'
EndOfLine: lf
^~~~~~~~~
Error reading /home/amd/development/dpdk-next-net/./.clang-format:
Invalid argument
c.
/home/amd/development/dpdk-next-net/./.clang-format:15:1: error: unknown
key 'File'
File:
^~~~
Error reading /home/amd/development/dpdk-next-net/./.clang-format:
Invalid argument
[2]
`clang-format -i ./lib/ethdev/rte_ethdev.c` (with failing part commented
out)
`git diff`
A few diff samples to fix at first glance:
```
static const struct rte_eth_xstats_name_off eth_dev_txq_stats_strings[] = {
- {"packets", offsetof(struct rte_eth_stats, q_opackets)},
- {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
+ {"packets", offsetof(struct rte_eth_stats, q_opackets)},
+ {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
};
```
```
-enum {
- STAT_QMAP_TX = 0,
- STAT_QMAP_RX
-};
+enum { STAT_QMAP_TX = 0, STAT_QMAP_RX };
```
```
-int
-rte_eth_iterator_init(struct rte_dev_iterator *iter, const char
*devargs_str)
+int rte_eth_iterator_init(struct rte_dev_iterator *iter, const char
*devargs_str)
```
```
RTE_ETH_FOREACH_DEV(p)
- count++;
+ count++;
```
```
rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
- RTE_ETH_FOREACH_VALID_DEV(pid) {
+ RTE_ETH_FOREACH_VALID_DEV(pid)
+ {
```
More information about the dev
mailing list