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