Skip to content

Commit fe708cd

Browse files
committed
[MOS-670] Change clang-format AlwaysBreakTemplateDeclarations to Yes
Add --all and --fix-all options to style-check-hook
1 parent 2de71a0 commit fe708cd

File tree

303 files changed

+1099
-884
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

303 files changed

+1099
-884
lines changed

.clang-format

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ AllowShortLoopsOnASingleLine: false
2020
AlwaysBreakAfterDefinitionReturnType: None
2121
AlwaysBreakAfterReturnType: None
2222
AlwaysBreakBeforeMultilineStrings: false
23-
AlwaysBreakTemplateDeclarations: MultiLine
23+
AlwaysBreakTemplateDeclarations: Yes
2424
BasedOnStyle: Chromium
2525
BinPackArguments: false
2626
BinPackParameters: false

board/linux/libiosyscalls/src/iosyscalls-internal.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#pragma once
@@ -37,7 +37,7 @@ namespace vfsn::linux::internal
3737
bool is_image_DIR(__dirstream *indir);
3838

3939
template <class Base, typename T, typename... Args>
40-
auto invoke_fs(T Base::*lfs_fun, Args &&... args)
40+
auto invoke_fs(T Base::*lfs_fun, Args &&...args)
4141
-> decltype((static_cast<Base *>(nullptr)->*lfs_fun)(std::forward<Args>(args)...))
4242
{
4343
auto vfs = purefs::subsystem::vfs_core();

board/rt1051/memwrap.c

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
//
@@ -12,51 +12,51 @@
1212

1313
#include "memory/usermem.h"
1414

15-
1615
void free(void *pv)
1716
{
1817
#if PROJECT_CONFIG_MEM_LEAKS_CHECKS == 1
19-
uint32_t caller = (uint32_t)__builtin_return_address (0);
20-
memleaks_log_free((uint32_t)pv,caller);
18+
uint32_t caller = (uint32_t)__builtin_return_address(0);
19+
memleaks_log_free((uint32_t)pv, caller);
2120
#endif
2221
return userfree(pv);
2322
}
2423

2524
void *malloc(size_t xWantedSize)
2625
{
27-
void * ptr = usermalloc(xWantedSize);
26+
void *ptr = usermalloc(xWantedSize);
2827

2928
#if PROJECT_CONFIG_MEM_LEAKS_CHECKS == 1
30-
uint32_t caller = (uint32_t)__builtin_return_address (0);
31-
memleaks_log_malloc((uint32_t)ptr,(uint32_t)caller,xWantedSize);
29+
uint32_t caller = (uint32_t)__builtin_return_address(0);
30+
memleaks_log_malloc((uint32_t)ptr, (uint32_t)caller, xWantedSize);
3231
#endif
3332

3433
return ptr;
3534
}
3635

37-
void* _malloc_r (struct _reent *r, size_t sz)
36+
void *_malloc_r(struct _reent *r, size_t sz)
3837
{
39-
void * ptr = usermalloc(sz);
38+
void *ptr = usermalloc(sz);
4039

4140
#if PROJECT_CONFIG_MEM_LEAKS_CHECKS == 1
42-
uint32_t caller = (uint32_t)__builtin_return_address (0);
43-
memleaks_log_malloc((uint32_t)ptr,(uint32_t)caller,sz);
41+
uint32_t caller = (uint32_t)__builtin_return_address(0);
42+
memleaks_log_malloc((uint32_t)ptr, (uint32_t)caller, sz);
4443
#endif
4544

4645
return ptr;
4746
}
4847

49-
void* calloc (size_t num, size_t size)
48+
void *calloc(size_t num, size_t size)
5049
{
5150
size_t total = num * size;
52-
void * p = usermalloc(total);
51+
void *p = usermalloc(total);
5352

5453
#if PROJECT_CONFIG_MEM_LEAKS_CHECKS == 1
55-
uint32_t caller = (uint32_t)__builtin_return_address (0);
56-
memleaks_log_malloc((uint32_t)p,(uint32_t)caller,total);
54+
uint32_t caller = (uint32_t)__builtin_return_address(0);
55+
memleaks_log_malloc((uint32_t)p, (uint32_t)caller, total);
5756
#endif
5857

59-
if (!p) return NULL;
58+
if (!p)
59+
return NULL;
6060

6161
return memset(p, 0, total);
6262
}
@@ -66,32 +66,32 @@ void *realloc(void *aptr, size_t nbytes)
6666
return userrealloc(aptr, nbytes);
6767
}
6868

69-
70-
void* _calloc_r (struct _reent *r, size_t a, size_t b)
69+
void *_calloc_r(struct _reent *r, size_t a, size_t b)
7170
{
7271
size_t total = a * b;
73-
void * p = usermalloc(total);
72+
void *p = usermalloc(total);
7473

7574
#if PROJECT_CONFIG_MEM_LEAKS_CHECKS == 1
76-
uint32_t caller = (uint32_t)__builtin_return_address (0);
77-
memleaks_log_malloc((uint32_t)p,(uint32_t)caller,total);
75+
uint32_t caller = (uint32_t)__builtin_return_address(0);
76+
memleaks_log_malloc((uint32_t)p, (uint32_t)caller, total);
7877
#endif
7978

80-
if (!p) return NULL;
79+
if (!p)
80+
return NULL;
8181

8282
return memset(p, 0, total);
8383
}
8484

85-
void _free_r (struct _reent *r, void* x)
85+
void _free_r(struct _reent *r, void *x)
8686
{
8787
#if PROJECT_CONFIG_MEM_LEAKS_CHECKS == 1
88-
uint32_t caller = (uint32_t)__builtin_return_address (0);
89-
memleaks_log_free((uint32_t)x,caller);
88+
uint32_t caller = (uint32_t)__builtin_return_address(0);
89+
memleaks_log_free((uint32_t)x, caller);
9090
#endif
9191
return userfree(x);
9292
}
9393

94-
void* _realloc_r (struct _reent *r, void* x, size_t sz)
94+
void *_realloc_r(struct _reent *r, void *x, size_t sz)
9595
{
9696
return realloc(x, sz);
9797
}

config/clang/clang-common.sh

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/env bash
2-
# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
2+
# Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
33
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
44

55
set -eo pipefail
@@ -48,8 +48,17 @@ get_tool() {
4848
echo "${tool}"
4949
}
5050

51-
## Search for clang-format-diff.py
51+
## Search for clang-format.py
5252
get_clang_format() {
53+
local searchpaths=(
54+
"$(which "clang-format" 2>/dev/null 1>/dev/null)" # clang-format in path
55+
"/usr/bin/clang-format-*"
56+
)
57+
get_tool "clang-format" "${searchpaths[@]}"
58+
}
59+
60+
## Search for clang-format-diff.py
61+
get_clang_format_diff() {
5362
local searchpaths=(
5463
"$(which "clang-format-diff.py" 2>/dev/null 1>/dev/null)" # clang-format-diff in path
5564
"/usr/share/clang/clang-format-*/clang-format-diff.py" # clang-format-diff location on Ubuntu/Debian
@@ -59,7 +68,7 @@ get_clang_format() {
5968
}
6069

6170
## search for clang-tidy-diff
62-
get_clang_tidy()
71+
get_clang_tidy_diff()
6372
{
6473
local searchpaths=(
6574
"$(which "clang-tidy-diff.py" 2>/dev/null 1>/dev/null)" # clang-format-diff in path

config/clang_check.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/env bash
2-
# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
2+
# Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
33
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
44

55
set -euo pipefail
@@ -54,7 +54,7 @@ main()
5454
exit 0
5555
fi
5656
local tool
57-
tool=$(get_clang_tidy)
57+
tool=$(get_clang_tidy_diff)
5858
echo "Target branch: ${CHANGE_TARGET}"
5959

6060
local files_to_check

config/format-config.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ export declare ignore_paths=(
5757
'module-vfs/board/free_rtos_custom/include/FreeRTOSFATConfig.h'
5858
'module-vfs/drivers/include/thirdparty/fatfs/ffconf.h'
5959
'module-vfs/thirdparty/*'
60+
'test/'
6061
'third-party/'
6162
)
6263

6364
# bash function using above config function
6465
shouldnt_ignore() {
6566
# change full name path to path relative to root git dir
66-
local fname=${1/"$L_GIT_DIR"/"./"}
67+
local fname=${1/"$L_GIT_DIR/"/}
6768
for el in ${ignore_paths[@]}; do
6869
if [[ ${fname} =~ ^${el}.* ]]; then
6970
[[ $VERBOSE ]] && echo "Ignore: ${fname} formatting due to: $el match!"

config/style_check_hook.sh

+37-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@ fi
3333

3434
verify_clang_format_version
3535

36-
L_CLANG_DIFF_TOOL=$(get_clang_format)
36+
L_CLANG_TOOL=$(get_clang_format)
37+
if ! [[ $L_CLANG_TOOL ]] || [[ $L_CLANG_TOOL == "" ]]; then
38+
[[ $VERBOSE ]] && echo "clang-format not found"
39+
exit 1
40+
fi
41+
42+
L_CLANG_DIFF_TOOL=$(get_clang_format_diff)
3743
if ! [[ $L_CLANG_DIFF_TOOL ]] || [[ $L_CLANG_DIFF_TOOL == "" ]]; then
38-
[[ $VERBOSE ]] && echo "clang tool not found"
44+
[[ $VERBOSE ]] && echo "clang-format-diff not found"
3945
exit 1
4046
fi
4147

@@ -79,6 +85,22 @@ check_file() {
7985
fi
8086
fi
8187
;;
88+
"All")
89+
if [[ ${FIX,,} == "true" ]]; then
90+
${L_CLANG_TOOL} -style file -i ${file}
91+
STATUS=$(git status --short -- "${file}")
92+
if [ -n "${STATUS}" ]; then
93+
git add "${file}"
94+
results["${file}"]="${FIXED}";
95+
fi
96+
else
97+
OUT=$(${L_CLANG_TOOL} -style file ${file})
98+
if [ -n "${OUT}" ]; then
99+
results["${file}"]="${ERROR}"
100+
return 1
101+
fi
102+
fi
103+
;;
82104
*)
83105
OUT=$(git diff -U0 --no-color --cached "${file}" | ${L_CLANG_DIFF_TOOL} -style file -p1 )
84106
if [[ -n ${OUT} ]]; then
@@ -100,6 +122,8 @@ function help() {
100122
--last checks current branch against origin/master - doesn't fix
101123
--branch-fix checks current branch against origin/master and fixes errors - you have to 'git add' and 'git commit' them
102124
--fix fix style in currently staged files (ignores user.fixinstage variale), this is usefull for manual style applying
125+
--all check style in all files
126+
--fix-all fix style in all files
103127
104128
If you would like to automatically fix style before commit
105129
add to your git config "user.fixinstage" variable with value "True"
@@ -129,7 +153,17 @@ case "${1}" in
129153
--fix)
130154
FILES=$(git diff-index --cached --name-only HEAD)
131155
LAST="Stage"
132-
FIX=true
156+
FIX="true"
157+
;;
158+
--all)
159+
FILES=$(find $L_GIT_DIR -type f -name '*.cpp' -o -name '*.hpp' -o -name '*.c' -o -name '*.h' -o -name '*.cxx' -o -name '*.gcc' -o -name '*.cc')
160+
LAST="All"
161+
FIX="false"
162+
;;
163+
--fix-all)
164+
FILES=$(find $L_GIT_DIR -type f -name '*.cpp' -o -name '*.hpp' -o -name '*.c' -o -name '*.h' -o -name '*.cxx' -o -name '*.gcc' -o -name '*.cc')
165+
LAST="All"
166+
FIX="true"
133167
;;
134168
*)
135169
if [[ $# -ne 0 ]]; then

host-tools/genlittlefs/lfs_ioaccess.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#include <lfs.h>
@@ -214,10 +214,10 @@ struct lfs_ioaccess_context *lfs_ioaccess_open(struct lfs_config *cfg,
214214
}
215215
ret->part_offs = start_pos;
216216
// Mount the file system
217-
cfg->read = lfs_read;
218-
cfg->prog = lfs_prog;
219-
cfg->erase = lfs_erase;
220-
cfg->sync = lfs_sync;
217+
cfg->read = lfs_read;
218+
cfg->prog = lfs_prog;
219+
cfg->erase = lfs_erase;
220+
cfg->sync = lfs_sync;
221221
#ifdef LFS_THREADSAFE
222222
cfg->lock = lfs_lock_unlock;
223223
cfg->unlock = lfs_lock_unlock;

host-tools/genlittlefs/mklfs.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#include <lfs.h>
@@ -366,7 +366,7 @@ int main(int argc, char **argv)
366366
}
367367
}
368368
const lfs_ssize_t used_blocks = lfs_fs_size(&lfs);
369-
err = lfs_unmount(&lfs);
369+
err = lfs_unmount(&lfs);
370370
if (err < 0) {
371371
fprintf(stderr, "lfs umount error: error=%d\n", err);
372372
lfs_ioaccess_close(ioctx);

module-apps/application-alarm-clock/ApplicationAlarmClock.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#pragma once
@@ -38,7 +38,8 @@ namespace app
3838
std::shared_ptr<SoundsPlayer> soundsPlayer;
3939
};
4040

41-
template <> struct ManifestTraits<ApplicationAlarmClock>
41+
template <>
42+
struct ManifestTraits<ApplicationAlarmClock>
4243
{
4344
static auto GetManifest() -> manager::ApplicationManifest
4445
{

module-apps/application-alarm-clock/data/AlarmsData.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#pragma once
@@ -29,4 +29,3 @@ class AlarmRecordData : public gui::SwitchData
2929
record = std::move(rec);
3030
}
3131
};
32-

module-apps/application-alarm-clock/models/AlarmsRepository.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#include "AlarmsRepository.hpp"
@@ -19,8 +19,8 @@ namespace app::alarmClock
1919
void AlarmsDBRepository::getLimited(std::uint32_t offset, std::uint32_t limit, const OnGetCallback &callback)
2020
{
2121
auto request = std::make_unique<alarms::AlarmsGetInRangeRequestMessage>(offset, limit);
22-
auto task = async(std::move(request), service::name::service_time); // -> std::unique_ptr<AsyncRequest>;
23-
auto cb = [callback](auto response) {
22+
auto task = async(std::move(request), service::name::service_time); // -> std::unique_ptr<AsyncRequest>;
23+
auto cb = [callback](auto response) {
2424
auto result = dynamic_cast<alarms::AlarmsGetInRangeResponseMessage *>(response);
2525
if (result == nullptr) {
2626
LOG_ERROR("BAD RESULT");

module-apps/application-alarm-clock/widgets/AlarmClockStyle.hpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ namespace style::alarmClock
2626

2727
namespace item
2828
{
29-
inline constexpr auto height = 100;
30-
inline constexpr auto botMargin = 4;
31-
inline constexpr auto imageMargin = 150;
32-
inline constexpr auto timeHeight = 60 - style::margins::small;
33-
inline constexpr auto periodHeight = 40;
29+
inline constexpr auto height = 100;
30+
inline constexpr auto botMargin = 4;
31+
inline constexpr auto imageMargin = 150;
32+
inline constexpr auto timeHeight = 60 - style::margins::small;
33+
inline constexpr auto periodHeight = 40;
3434

3535
namespace time
3636
{
37-
inline constexpr auto width = style::listview::item_width_with_without_scroll;
38-
inline constexpr auto height = 80;
39-
inline constexpr auto marginTop = 32;
40-
inline constexpr auto marginBot = 20;
41-
inline constexpr auto separator = 30;
37+
inline constexpr auto width = style::listview::item_width_with_without_scroll;
38+
inline constexpr auto height = 80;
39+
inline constexpr auto marginTop = 32;
40+
inline constexpr auto marginBot = 20;
41+
inline constexpr auto separator = 30;
4242
} // namespace time
43-
} // namespace item
43+
} // namespace item
4444

4545
} // namespace window
4646
} // namespace style::alarmClock

0 commit comments

Comments
 (0)