X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=development%2Ftools%2Fheader_check.sh;h=881fe1a6875a588945e87b624891eec2907b2d36;hb=6de3c19fd63f810eed90ef3bc4469faf28e949c2;hp=ebf0eab5cc2c3b3a4902e62996f48cef5e30f9cd;hpb=9d478d55872e570bd781124e5dc85a4c303d99dd;p=lyx.git diff --git a/development/tools/header_check.sh b/development/tools/header_check.sh old mode 100644 new mode 100755 index ebf0eab5cc..881fe1a687 --- a/development/tools/header_check.sh +++ b/development/tools/header_check.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +# Typical usage: cd src; ../development/tools/header_check.sh + # file header_check.sh # This file is part of LyX, the document processor. # Licence details can be found in the file COPYING. @@ -24,44 +26,85 @@ set -u LOG_FILE="$(basename $0).log" # For only standard headers: - PATTERN='^#include <' +# PATTERN='^#include <' # For all headers: -# PATTERN='^#include' + PATTERN='^#include' # Exclude common headers with regex # (e.g. 'debug.h' will exclude 'support/debug.h') # LyX was compiled on exotic environments and these sometimes # require headers not needed on win/linux. So check the logs before -# deleting "redundant" standard libraries or includes around various -# ifdefs... -EXCLUDE='\(debug.h\|cstdio\)' +# deleting "redundant" standard libraries, Qt headers or includes around +# various ifdefs... +EXCLUDE='\(debug.h\|cstdio\|config.h\)' + +NCORES=$(grep "CPU" /proc/cpuinfo | wc -l) function BUILD_FN () { + PREFIX='' + # This is not a clean make. - make -j$(grep "CPU" /proc/cpuinfo | wc -l) + make -j${NCORES} 2>/dev/null 1>/dev/null + ERROR_CODE=$? + + + # The sed regex is more strict than it needs to be. + if (( ERROR_CODE != 0 )); then + # Use just one core, so we don't mix outputs + IFS='' ERROR_OUTPUT=$(make 2>&1) + # Without the grep, ERROR_OUTPUT might contain messages such as: + # 2885 translated messages, 2169 fuzzy translations, 1356 untranslated messages. + ERROR_OUTPUT=$(echo "${ERROR_OUTPUT}" | grep -i "error: ") + + cppORh=$(echo "${ERROR_OUTPUT}" | head -n 1 | \ + sed 's/.*\.\(cpp\|h\):[0-9]\+:[0-9]\+: error: .*/\1/') + if [ "${cppORh}" = "cpp" ]; then + PREFIX='suspicious: ' + elif [ "${cppORh}" != "h" ]; then + echo -e "Warning: the error was not parsed correctly."\ + "\nThe following string was expected to be"\ + "'.cpp' or '.h': \n ${cppORh}" >&2 + echo ERROR_OUTPUT: "${ERROR_OUTPUT}" + echo cppORh: "${cppORh}" + fi + fi + return "${ERROR_CODE}" } -echo "BUILD_FN exited without error after removing -the following include statements invididually:" > "${LOG_FILE}" \ +echo Making the tree first... +make -j${NCORES} 2>&1 >/dev/null || exit + +echo "BUILD_FN exited without error after removing the following include statements invididually:" > "${LOG_FILE}" \ || { echo "ERROR: could not create log file, ${LOG_FILE}"; exit 1; } -find -regex ".*\(cpp\|h\)$" | \ +find -regex ".*\(cpp\|h\)$" | grep -vE "frontends/qt4/ui_|frontends/qt4/moc_" | sort | while read FILE_ do FILE_COPY=$( tempfile ) cp "${FILE_}" "${FILE_COPY}" \ || { echo "ERROR: bu copy failed" >&2; exit 1; } - echo "processing ${FILE_}..." + echo -n "processing ${FILE_}..." grep "${PATTERN}" "${FILE_}" | \ while read INCLUDE do + echo -n ${INCLUDE}, if echo "${INCLUDE}" | grep -q -v "${EXCLUDE}"; then cp "${FILE_COPY}" "${FILE_}" \ || { echo "ERROR: restore copy failed" >&2; exit 1; } sed -i "s@${INCLUDE}@@" "${FILE_}" - ( BUILD_FN ) &>/dev/null && echo "${FILE_}::${INCLUDE}" >> "${LOG_FILE}" + + BUILD_FN + BUILD_FN_RET=$? + if [ "${BUILD_FN_RET}" = 0 ]; then + echo "${FILE_}::${INCLUDE}" >> "${LOG_FILE}" + elif [ -n "${PREFIX}" ]; then + if [ ${FILE_:(-2):2} == .h ]; then + echo "${PREFIX}${FILE_}::${INCLUDE}" >> "${LOG_FILE}" + fi + fi fi done + echo cp "${FILE_COPY}" "${FILE_}" done