Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10:44

0001 #!/bin/bash
0002 set -e
0003 
0004 # Welcome message
0005 echo "This script will check all staged files for clang-format compliance"
0006 echo "It will also fix the files inplace and readd them to the staging area"
0007 echo "ATTENTION: This script does not work well with partially added files"
0008 
0009 # Store the CI folder
0010 CI_FILE_FOLDER="$(dirname "${BASH_SOURCE[0]}")"
0011 ACTS_ROOT_FOLDER="$(realpath ${CI_FILE_FOLDER}/../)"
0012 
0013 # Store the user variables for later
0014 USER_ID=`id -u`
0015 GROUP_ID=`id -g`
0016 
0017 # Move to the ACTS top level directory
0018 cd "${ACTS_ROOT_FOLDER}"
0019 
0020 # Check for all staged files
0021 STAGED_FILES=`git diff --cached --name-only`
0022 STAGING_FILES_TO_CHECK=""
0023 
0024 # Make sure to only check C++ source/header files
0025 for file in ${STAGED_FILES}; do
0026     FILE_ENDING_CHECK=`find ${file} \( -iname '*.cpp' -or -iname '*.hpp' -or -iname '*.ipp' \)`
0027     if [[ ! -z "${FILE_ENDING_CHECK}" ]]; then
0028         STAGING_FILES_TO_CHECK="${file} ${STAGING_FILES_TO_CHECK}"
0029     fi
0030 done
0031 
0032 if [[ -z "${STAGING_FILES_TO_CHECK}" ]]; then
0033     echo "No files to check"
0034     exit
0035 fi
0036 
0037 # Use docker for clang-format checking
0038 echo "Checking files: ${STAGING_FILES_TO_CHECK}"
0039 
0040 docker run --rm -ti \
0041            -v ${ACTS_ROOT_FOLDER}:"/working_dir":rw -w "/working_dir" \
0042            --user "$USER_ID:$GROUP_ID" \
0043            gitlab-registry.cern.ch/acts/machines/check:latest \
0044            clang-format -i -style=file ${STAGING_FILES_TO_CHECK}