30
30
#
31
31
# The script to check or format source code of OpenThread.
32
32
#
33
- # Format python and c/c++:
33
+ # Format c/c++, markdown, and python :
34
34
#
35
35
# script/make-pretty
36
36
#
37
- # Format python only:
38
- #
39
- # script/make-pretty python
40
- #
41
37
# Format c/c++ only:
42
38
#
43
39
# script/make-pretty clang
44
40
#
41
+ # Format markdown only:
42
+ #
43
+ # script/make-pretty markdown
44
+ #
45
+ # Format python only:
46
+ #
47
+ # script/make-pretty python
48
+ #
45
49
# Check only:
46
50
#
47
51
# script/make-pretty check clang
52
+ # script/make-pretty check markdown
48
53
# script/make-pretty check python
49
54
#
50
55
51
56
set -euo pipefail
52
57
53
- readonly OT_CLANG_DIRS=(examples include src tests tools)
54
- readonly OT_PYTHON_DIRS=(tests tools)
55
58
readonly OT_BUILD_JOBS=$( getconf _NPROCESSORS_ONLN)
59
+ readonly OT_EXCLUDE_DIRS=(third_party)
60
+
56
61
readonly OT_CLANG_SOURCES=(' *.c' ' *.cc' ' *.cpp' ' *.h' ' *.hpp' )
62
+ readonly OT_MARKDOWN_SOURCES=(' *.md' )
63
+ readonly OT_PYTHON_SOURCES=(' *.py' )
57
64
58
65
do_clang_format ()
59
66
{
60
67
echo -e ' ====================='
61
68
echo -e ' format c/c++'
62
69
echo -e ' ====================='
63
70
64
- git ls-files " ${OT_CLANG_SOURCES[@]} " | grep -E " ^($( echo " ${OT_CLANG_DIRS [@]} " | tr ' ' ' |' ) )" \
71
+ git ls-files " ${OT_CLANG_SOURCES[@]} " | grep -v - E " ^($( echo " ${OT_EXCLUDE_DIRS [@]} " | tr ' ' ' |' ) )" \
65
72
| xargs -n3 -P" ${OT_BUILD_JOBS} " script/clang-format -style=file -i -verbose
66
73
}
67
74
@@ -71,17 +78,37 @@ do_clang_check()
71
78
echo -e ' check c/c++'
72
79
echo -e ' ====================='
73
80
74
- git ls-files " ${OT_CLANG_SOURCES[@]} " | grep -E " ^($( echo " ${OT_CLANG_DIRS [@]} " | tr ' ' ' |' ) )" \
81
+ git ls-files " ${OT_CLANG_SOURCES[@]} " | grep -v - E " ^($( echo " ${OT_EXCLUDE_DIRS [@]} " | tr ' ' ' |' ) )" \
75
82
| xargs -n3 -P" ${OT_BUILD_JOBS} " script/clang-format-check
76
83
}
77
84
85
+ do_markdown_format ()
86
+ {
87
+ echo -e ' ======================'
88
+ echo -e ' format markdown'
89
+ echo -e ' ======================'
90
+
91
+ git ls-files " ${OT_MARKDOWN_SOURCES[@]} " | grep -v -E " ^($( echo " ${OT_EXCLUDE_DIRS[@]} " | tr ' ' ' |' ) )" \
92
+ | xargs -n10 -P" ${OT_BUILD_JOBS} " npx prettier@2.0.4 --write
93
+ }
94
+
95
+ do_markdown_check ()
96
+ {
97
+ echo -e ' ======================'
98
+ echo -e ' check markdown'
99
+ echo -e ' ======================'
100
+
101
+ git ls-files " ${OT_MARKDOWN_SOURCES[@]} " | grep -v -E " ^($( echo " ${OT_EXCLUDE_DIRS[@]} " | tr ' ' ' |' ) )" \
102
+ | xargs -n10 -P" ${OT_BUILD_JOBS} " npx prettier@2.0.4 --check
103
+ }
104
+
78
105
do_python_format ()
79
106
{
80
107
echo -e ' ======================'
81
108
echo -e ' format python'
82
109
echo -e ' ======================'
83
110
84
- git ls-files ' *.py ' | grep -E " ^($( echo " ${OT_PYTHON_DIRS [@]} " | tr ' ' ' |' ) )" \
111
+ git ls-files " ${OT_PYTHON_SOURCES[@]} " | grep -v - E " ^($( echo " ${OT_EXCLUDE_DIRS [@]} " | tr ' ' ' |' ) )" \
85
112
| xargs -n10 -P" ${OT_BUILD_JOBS} " python3 -m yapf --verbose --style google -ipr
86
113
}
87
114
@@ -91,21 +118,24 @@ do_python_check()
91
118
echo -e ' check python'
92
119
echo -e ' ====================='
93
120
94
- git ls-files ' *.py ' | grep -E " ^($( echo " ${OT_PYTHON_DIRS [@]} " | tr ' ' ' |' ) )" \
121
+ git ls-files " ${OT_PYTHON_SOURCES[@]} " | grep -v - E " ^($( echo " ${OT_EXCLUDE_DIRS [@]} " | tr ' ' ' |' ) )" \
95
122
| xargs -n10 -P" ${OT_BUILD_JOBS} " python3 -m yapf --verbose --style google -dpr
96
123
}
97
124
98
125
do_check ()
99
126
{
100
127
if [ $# == 0 ]; then
101
- do_python_check
102
128
do_clang_check
129
+ do_markdown_check
130
+ do_python_check
103
131
elif [ " $1 " == ' clang' ]; then
104
132
do_clang_check
133
+ elif [ " $1 " == ' markdown' ]; then
134
+ do_markdown_check
105
135
elif [ " $1 " == ' python' ]; then
106
136
do_python_check
107
137
else
108
- >&2 echo " Unsupported check: $1 . Supported: clang, python"
138
+ >&2 echo " Unsupported check: $1 . Supported: clang, markdown, python"
109
139
# 128 for Invalid arguments
110
140
exit 128
111
141
fi
@@ -115,16 +145,19 @@ main()
115
145
{
116
146
if [ $# == 0 ]; then
117
147
do_clang_format
118
- do_python_format
119
- elif [ " $1 " == ' python' ]; then
148
+ do_markdown_format
120
149
do_python_format
121
150
elif [ " $1 " == ' clang' ]; then
122
151
do_clang_format
152
+ elif [ " $1 " == ' markdown' ]; then
153
+ do_markdown_format
154
+ elif [ " $1 " == ' python' ]; then
155
+ do_python_format
123
156
elif [ " $1 " == ' check' ]; then
124
157
shift
125
158
do_check " $@ "
126
159
else
127
- >&2 echo " Unsupported action: $1 . Supported: clang, python"
160
+ >&2 echo " Unsupported action: $1 . Supported: clang, markdown, python"
128
161
# 128 for Invalid arguments
129
162
exit 128
130
163
fi
0 commit comments