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