-
Notifications
You must be signed in to change notification settings - Fork 297
/
format_all.sh
executable file
·192 lines (179 loc) · 8.27 KB
/
format_all.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#! /bin/bash
if [ ! -f "$CTS_CLANG_FORMAT" ]; then
echo "Set the CTS_CLANG_FORMAT environment variable to /path/to/clang-format first"
exit 1
fi
# Make automatic substitutions for removed types, etc.
#
# The following files are excluded:
#
# - CMakeLists.txt, AndroidGen.*: Build files which include deInt32.c
# - deDefs_kc_cts.h: Includes deprecated defines for the sake of kc-cts
# - format_all.sh: This script!
#
echo "Replacing standard types in all files, this will take a minute..."
git ls-files | grep -v -e framework/delibs/debase/CMakeLists.txt \
-e framework/delibs/debase/deDefs_kc_cts.h \
-e AndroidGen.bp \
-e AndroidGen.mk \
-e format_all.sh \
| xargs -P 8 -d '\n' sed -b -i 's|\<deInt8\>|int8_t|g;
s|\<deUint8\>|uint8_t|g;
s|\<deInt16\>|int16_t|g;
s|\<deUint16\>|uint16_t|g;
s|\<deInt32\>|int32_t|g;
s|\<deUint32\>|uint32_t|g;
s|\<deInt64\>|int64_t|g;
s|\<deUint64\>|uint64_t|g;
s|\<deIntptr\>|intptr_t|g;
s|\<deUintptr\>|uintptr_t|g;
s|#include "int32_t\.h"|#include "deInt32.h"|;
s|#include <int32_t\.h>|#include <deInt32.h>|;
s|\<deBool\>|bool|g;
s|\<DE_TRUE\>|true|g;
s|\<DE_FALSE\>|false|g;
s|::\<deGetFalse()|false|g;
s|::\<deGetTrue()|true|g;
s|\<deGetFalse()|false|g;
s|\<deGetTrue()|true|g;
s|\<DE_OFFSET_OF\>|offsetof|g'
sed -b -i 's|tdeUint32 id;|tuint32_t id;|g' external/vulkancts/scripts/gen_framework.py
# Fixes for compile errors found in various branches:
sed -b -i 's|parseError(false)|parseError(0)|g' framework/opengl/gluShaderLibrary.cpp
if [ -e "external/vulkancts/modules/vulkan/video/extFFmpegDemuxer.h" ]; then
sed -b -i 's|"BT470BG: also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601"|(&)|' "external/vulkancts/modules/vulkan/video/extFFmpegDemuxer.h"
fi
if [ -e "external/vulkancts/modules/vulkan/spirv_assembly/vktSpvAsmPhysicalStorageBufferPointerTests.cpp" ]; then
sed -b -i 's|m_params->method == PassMethod::PUSH_CONSTANTS_FUNCTION ? 1 : 0|m_params->method == PassMethod::PUSH_CONSTANTS_FUNCTION|g' "external/vulkancts/modules/vulkan/spirv_assembly/vktSpvAsmPhysicalStorageBufferPointerTests.cpp"
fi
# Coalesce common patterns in comments and strings (which don't get
# formatted with clang-format):
#
# ",<tabs>" => ", "
# "<tabs>=" => " ="
# ":<tabs>" => ": "
#
# Additionally, coalesce the tabs in the "// type<tabs>name;" comments
# added after struct members, changing them to "// type name;". Note
# that because sed does not have non-greedy matching, the tabs in the
# above are coalesced in multiple steps before being replaced.
#
# Finally, turn every other tab into 4 spaces.
#
function remove_tabs() {
git ls-files -z | while IFS= read -r -d '' file; do
extension="${file#*.}"
if [[ "$extension" =~ ^(cpp|hpp|c|h|m|mm|hh|inc|js|java|json|py|test|css)$ ]]; then
if [[ "$file" != external/openglcts/modules/runner/*Mustpass*.hpp ]]; then
echo "$file"
fi
fi
done | xargs -P 8 -I {} sed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)$|\1 \2|g;
s|\(//.*\)\\t\+\(.*;\)$|\1 \2|g;
s|\(//.*\)\\t\+\(.*;\)$|\1 \2|g;
s|\(//.*\)\\t\+\(.*;\)$|\1 \2|g;
s|\(//.*\)\\t\+\(.*;\)$|\1 \2|g;
s|\(//.*\)\\t\+\(.*;\)$|\1 \2|g;
s|\(//.*\)\\t\+\(.*;\)$|\1 \2|g;
s|\(//.*\)\\t\+\(.*;\)$|\1 \2|g;
s|\(//.*\)\\t\+\(.*;\)$|\1 \2|g;
s|\(//.*\)\\t\+\(.*;\)$|\1 \2|g;
s|\(//.*\)\\t\+\(.*;\)$|\1 \2|g;
s|\(//.*\)\\t\+\(.*;\)$|\1 \2|g;
s|\\t| |g" "{}"
}
function run_clang_format() {
counter=0
git ls-files -z | while IFS= read -r -d '' file; do
extension="${file#*.}"
if [[ "$extension" =~ ^(cpp|hpp|c|h|m|mm|hh|inc|js|java|json)$ ]]; then
# The following files are excluded:
#
# - external/vulkancts/scripts/src/*.h: Input to
# gen_framework*.py which parse these files with fragile regexes.
# - external/openglcts/modules/runner/*Mustpass*.hpp: Autogenerated files
# that are not given the inl extension.
#
if [[ "$file" == external/vulkancts/scripts/src/*.h ]]; then
continue
fi
if [[ "$file" == external/openglcts/modules/runner/*Mustpass*.hpp ]]; then
continue
fi
echo "$file"
counter=$((counter+1))
if [ "$counter" == 100 ]; then
>&2 printf '.'
counter=0
fi
fi
done | xargs -P 8 -I {} "$CTS_CLANG_FORMAT" -i "{}"
printf '\n'
}
# Remove tabs from the files, they are confusing clang-format and causing its output to be unstable.
echo "Removing tabs from source files, this will take another minute..."
remove_tabs
# Run clang-format in the end
echo "Running clang-format on all the files, this will take several minutes."
echo "Each dot represents 100 files processed."
run_clang_format
# Run clang-format again, a few files end up getting changed again
echo "Running clang-format on all the files, again!"
run_clang_format
# Make sure changes to scripts are reflected in the generated files
echo "Regenerating inl files"
# Reset glslang, it has a tag (main-tot) that's causing fetch to fail
rm -rf external/glslang/src/
# Some files seem to be left over in vulkan-docs when hopping between branches
git -C external/vulkan-docs/src/ clean -fd
if grep -q -e "--skip-post-checks" "scripts/check_build_sanity.py"; then
SKIP_DIFF_CHECK=" --skip-post-checks "
else
SKIP_DIFF_CHECK=""
fi
if command -v python3 &>/dev/null; then
PYTHON_CMD="python3"
elif command -v python &>/dev/null && python -c "import sys; sys.exit(sys.version_info[0] != 3)" &>/dev/null; then
PYTHON_CMD="python"
else
echo "Python 3 is not installed."
exit 1
fi
echo "Using $PYTHON_CMD"
$PYTHON_CMD scripts/check_build_sanity.py -r gen-inl-files $SKIP_DIFF_CHECK > /dev/null
if [ -z "$SKIP_DIFF_CHECK" ]; then
echo "It is acceptable if the previous lines report: Exception: Failed to execute '['git', 'diff', '--exit-code']', got 1"
fi
# This file is not being regenerated but its output will be slightly different.
# Much faster to just fix it here than to regenerate mustpass
sed -b -i '4,15s/\t/ /g' external/vulkancts/mustpass/AndroidTest.xml