mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Script for finding unneeded headers
The script does the following: All .cpp and .h files in the current directory and subdirectories are checked to see which include statements could be omitted without causing a build error. Many of these omissions would not be desired. For example, currently if you don't include Undo.h in Undo.cpp, there is no error because Undo.h is included in Cursor.h which is included in Undo.cpp. But clearly we do want to include Undo.h in Undo.cpp. See #6305.
This commit is contained in:
parent
4997d66f38
commit
6adae69810
57
development/tools/header_check.sh
Normal file
57
development/tools/header_check.sh
Normal file
@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# file header_check.sh
|
||||
# This file is part of LyX, the document processor.
|
||||
# Licence details can be found in the file COPYING.
|
||||
|
||||
# author Scott Kostyshak
|
||||
|
||||
# Full author contact details are available in file CREDITS
|
||||
|
||||
# Description:
|
||||
|
||||
# All .cpp and .h files in the current directory and subdirectories
|
||||
# are checked to see which include statements could be omitted without
|
||||
# causing a build error. Many of these omissions would not be desired.
|
||||
# For example, currently if you don't include Undo.h in Undo.cpp, there
|
||||
# is no error because Undo.h is included in Cursor.h which is included
|
||||
# in Undo.cpp. But clearly we do want to include Undo.h in Undo.cpp.
|
||||
|
||||
# The results are stored in header_check.sh.log
|
||||
|
||||
set -u
|
||||
|
||||
LOG_FILE="$(basename $0).log"
|
||||
|
||||
# For only standard headers:
|
||||
PATTERN='^#include <'
|
||||
# For all headers:
|
||||
# PATTERN='^#include'
|
||||
|
||||
function BUILD_FN ()
|
||||
{
|
||||
# This is not a clean make.
|
||||
make -j$(grep "CPU" /proc/cpuinfo | wc -l)
|
||||
}
|
||||
|
||||
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\)$" | \
|
||||
while read FILE_
|
||||
do
|
||||
FILE_COPY=$( tempfile )
|
||||
cp "${FILE_}" "${FILE_COPY}" \
|
||||
|| { echo "ERROR: bu copy failed" >&2; exit 1; }
|
||||
echo "processing ${FILE_}..."
|
||||
grep "${PATTERN}" "${FILE_}" | \
|
||||
while read INCLUDE
|
||||
do
|
||||
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}"
|
||||
done
|
||||
cp "${FILE_COPY}" "${FILE_}"
|
||||
done
|
Loading…
Reference in New Issue
Block a user