* header_check.sh: more tweaks

This commit is contained in:
Pavel Sanda 2013-05-15 00:02:16 -07:00
parent b1d8bdf670
commit 5ea35e2d62

View File

@ -1,5 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Typical usage: cd src; ../development/tools/header_check.sh
# file header_check.sh # file header_check.sh
# This file is part of LyX, the document processor. # This file is part of LyX, the document processor.
# Licence details can be found in the file COPYING. # Licence details can be found in the file COPYING.
@ -32,9 +34,9 @@ LOG_FILE="$(basename $0).log"
# (e.g. 'debug.h' will exclude 'support/debug.h') # (e.g. 'debug.h' will exclude 'support/debug.h')
# LyX was compiled on exotic environments and these sometimes # LyX was compiled on exotic environments and these sometimes
# require headers not needed on win/linux. So check the logs before # require headers not needed on win/linux. So check the logs before
# deleting "redundant" standard libraries or includes around various # deleting "redundant" standard libraries, Qt headers or includes around
# ifdefs... # various ifdefs...
EXCLUDE='\(debug.h\|cstdio\)' EXCLUDE='\(debug.h\|cstdio\|config\)'
NCORES=$(grep "CPU" /proc/cpuinfo | wc -l) NCORES=$(grep "CPU" /proc/cpuinfo | wc -l)
@ -43,12 +45,12 @@ function BUILD_FN ()
PREFIX='' PREFIX=''
# This is not a clean make. # This is not a clean make.
IFS='' ERROR_OUTPUT=$(make -j${NCORES} 2>&1 >/dev/null) IFS='' ERROR_OUTPUT=$(make -j${NCORES} 2>&1)
ERROR_CODE=$? ERROR_CODE=$?
# Without the grep, ERROR_OUTPUT might contain messages such as: # Without the grep, ERROR_OUTPUT might contain messages such as:
# 2885 translated messages, 2169 fuzzy translations, 1356 untranslated messages. # 2885 translated messages, 2169 fuzzy translations, 1356 untranslated messages.
ERROR_OUTPUT=$(echo "${ERROR_OUTPUT}" | grep -i "error") ERROR_OUTPUT=$(echo "${ERROR_OUTPUT}" | grep -i "error: ")
# The sed regex is more strict than it needs to be. # The sed regex is more strict than it needs to be.
if (( ERROR_CODE != 0 )); then if (( ERROR_CODE != 0 )); then
@ -60,13 +62,17 @@ function BUILD_FN ()
echo -e "Warning: the error was not parsed correctly."\ echo -e "Warning: the error was not parsed correctly."\
"\nThe following string was expected to be"\ "\nThe following string was expected to be"\
"'.cpp' or '.h': \n ${cppORh}" >&2 "'.cpp' or '.h': \n ${cppORh}" >&2
echo ERROR_OUTPUT: "${ERROR_OUTPUT}"
echo cppORh: "${cppORh}"
fi fi
fi fi
return "${ERROR_CODE}" return "${ERROR_CODE}"
} }
echo "BUILD_FN exited without error after removing echo Making the tree first...
the following include statements invididually:" > "${LOG_FILE}" \ 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; } || { echo "ERROR: could not create log file, ${LOG_FILE}"; exit 1; }
find -regex ".*\(cpp\|h\)$" | \ find -regex ".*\(cpp\|h\)$" | \
@ -75,10 +81,11 @@ do
FILE_COPY=$( tempfile ) FILE_COPY=$( tempfile )
cp "${FILE_}" "${FILE_COPY}" \ cp "${FILE_}" "${FILE_COPY}" \
|| { echo "ERROR: bu copy failed" >&2; exit 1; } || { echo "ERROR: bu copy failed" >&2; exit 1; }
echo "processing ${FILE_}..." echo -n "processing ${FILE_}..."
grep "${PATTERN}" "${FILE_}" | \ grep "${PATTERN}" "${FILE_}" | \
while read INCLUDE while read INCLUDE
do do
echo -n ${INCLUDE},
if echo "${INCLUDE}" | grep -q -v "${EXCLUDE}"; then if echo "${INCLUDE}" | grep -q -v "${EXCLUDE}"; then
cp "${FILE_COPY}" "${FILE_}" \ cp "${FILE_COPY}" "${FILE_}" \
|| { echo "ERROR: restore copy failed" >&2; exit 1; } || { echo "ERROR: restore copy failed" >&2; exit 1; }
@ -93,5 +100,6 @@ do
fi fi
fi fi
done done
echo
cp "${FILE_COPY}" "${FILE_}" cp "${FILE_COPY}" "${FILE_}"
done done