~aleteoryx/muditaos

ac4b1aacc46d7072e71544d96917e75dd927c514 — Artur Śleszyński 5 years ago e49512b
[EGD-5638] Use ignore_paths in formatting script hook mode

When used as a pre-commit hook, the formatting script should ignore
paths and files the same way as in standalone mode.
3 files changed, 46 insertions(+), 45 deletions(-)

M config/format-config.sh
M config/license_header_check.sh
M config/style_check_hook.sh
M config/format-config.sh => config/format-config.sh +40 -40
@@ 14,44 14,44 @@ VERBOSE=1
# ignore_paths for formatter - these are regex matched with filenames to be formated
# if you don't wish to format i.e one file - just pass whole path to this file from git root directory
declare ignore_paths=(
    './.*/catch.hpp'
    './.*/lib/'
    './board/'
    './build'
    './host-tools/littlefs-fuse/lfsfuse/'
    './module-audio/Audio/decoder/dr_flac.h'
    './module-bluetooth/Bluetooth/btstack_config.h'
    './module-bluetooth/Bluetooth/glucode/bluetooth_init_cc2564C_1.0.c'
    './module-bluetooth/Bluetooth/glucode/btstack_uart_block_rt1051.h'
    './module-bluetooth/Bluetooth/glucode/hal_time_ms.c'
    './module-bluetooth/lib/btstack/'
    './module-bsp/board/rt1051/bsp/eMMC/'
    './module-bsp/board/rt1051/bsp/pwr/'
    './module-bsp/board/rt1051/common/board.cpp'
    './module-bsp/board/rt1051/common/board.h'
    './module-bsp/board/rt1051/common/clock_config.h'
    './module-bsp/board/rt1051/common/cmsis/'
    './module-bsp/board/rt1051/common/fsl_drivers/'
    './module-bsp/board/rt1051/common/pin_mux.h'
    './module-bsp/board/rt1051/common/pin_mux.c'
    './module-bsp/board/rt1051/common/system_MIMXRT1051.c'
    './module-bsp/board/rt1051/common/system_MIMXRT1051.h'
    './module-bsp/bsp/'
    './module-db/[Dd]atabase/config.h'
    './module-db/[Dd]atabase/sqlite3.c'
    './module-db/[Dd]atabase/sqlite3.h'
    './module-db/[Dd]atabase/sqlite3ext.h'
    './module-lwip/includes/arch/cc.h'
    './module-lwip/includes/lwipopts.h'
    './module-lwip/lib/lwip/'
    './module-os/'
    './module-utils/json/'
    './module-utils/microtar/'
    './module-utils/segger/log/'
    './module-utils/segger/systemview/'
    './module-utils/tinyfsm/'
    './module-vfs/board/cross/freeRTOS_FAT/'
    './module-vfs/board/free_rtos_custom/include/FreeRTOSFATConfig.h'
    './module-vfs/drivers/include/thirdparty/fatfs/ffconf.h'
    './module-vfs/thirdparty/*'
    '.*/catch.hpp'
    '.*/lib/'
    'board/'
    'build'
    'host-tools/littlefs-fuse/lfsfuse/'
    'module-audio/Audio/decoder/dr_flac.h'
    'module-bluetooth/Bluetooth/btstack_config.h'
    'module-bluetooth/Bluetooth/glucode/bluetooth_init_cc2564C_1.0.c'
    'module-bluetooth/Bluetooth/glucode/btstack_uart_block_rt1051.h'
    'module-bluetooth/Bluetooth/glucode/hal_time_ms.c'
    'module-bluetooth/lib/btstack/'
    'module-bsp/board/rt1051/bsp/eMMC/'
    'module-bsp/board/rt1051/bsp/pwr/'
    'module-bsp/board/rt1051/common/board.cpp'
    'module-bsp/board/rt1051/common/board.h'
    'module-bsp/board/rt1051/common/clock_config.h'
    'module-bsp/board/rt1051/common/cmsis/'
    'module-bsp/board/rt1051/common/fsl_drivers/'
    'module-bsp/board/rt1051/common/pin_mux.h'
    'module-bsp/board/rt1051/common/pin_mux.c'
    'module-bsp/board/rt1051/common/system_MIMXRT1051.c'
    'module-bsp/board/rt1051/common/system_MIMXRT1051.h'
    'module-bsp/bsp/'
    'module-db/[Dd]atabase/config.h'
    'module-db/[Dd]atabase/sqlite3.c'
    'module-db/[Dd]atabase/sqlite3.h'
    'module-db/[Dd]atabase/sqlite3ext.h'
    'module-lwip/includes/arch/cc.h'
    'module-lwip/includes/lwipopts.h'
    'module-lwip/lib/lwip/'
    'module-os/'
    'module-utils/json/'
    'module-utils/microtar/'
    'module-utils/segger/log/'
    'module-utils/segger/systemview/'
    'module-utils/tinyfsm/'
    'module-vfs/board/cross/freeRTOS_FAT/'
    'module-vfs/board/free_rtos_custom/include/FreeRTOSFATConfig.h'
    'module-vfs/drivers/include/thirdparty/fatfs/ffconf.h'
    'module-vfs/thirdparty/*'
)

M config/license_header_check.sh => config/license_header_check.sh +5 -4
@@ 166,14 166,11 @@ function excludePathFromFind(){
        fi
        I=$(( $I + 1 ))
    done
    declare -p paths_to_ignore
    
}

function findFiles() {
    # find files except submodule directories
    echo "find . ${NOT_PATH} -iname \"*.${FILE_EXT}\" -print0 "
    readarray -d '' FILES_TO_CHECK < <(find . ${NOT_PATH} -iname "*.${FILE_EXT}" -print0)
    readarray -d '' FILES_TO_CHECK < <(find . ${NOT_PATH} -iname \"*.${FILE_EXT}\" -printf \"%P\0\")
}

function shouldnt_ignore() {


@@ 208,10 205,14 @@ function hookMain() {
    parseArgs $@
    readarray -d '' FILES_TO_CHECK < <( ${GET_FILES_CMD} )

    NOT_PATH=""
    excludePathFromFind

    for FILE_TYPE in "${!FileTypes[@]}" 
    do
        echo "=== ${FILE_TYPE} ==="
        extractValues ${FILE_TYPE}
        findFiles
        I=0
        while [[ $I -lt ${#FILES_TO_CHECK[@]} ]]
        do

M config/style_check_hook.sh => config/style_check_hook.sh +1 -1
@@ 126,7 126,7 @@ shouldnt_ignore() {
    # change full name path to path relative to root git dir
    local fname=${1/"$L_GIT_DIR"/"./"}
    for el in ${ignore_paths[@]}; do
        if [[ ./${fname}  =~ ^${el}.* ]]; then
        if [[ ${fname}  =~ ^${el}.* ]]; then
            [[ $VERBOSE ]] && echo "Ignore: ${fname} formatting due to: $el match!"
            return 1
        fi