commit 3592467d57aa548d3111a80f5e8c95f6e974a739
Author: Pavel Sanda <[email protected]>
Date: Tue Apr 8 20:49:52 2025 +0200
Next iteration over header_check.sh.
Narrow down .cpp #include candidates for removal.
Not perfect, but the list is too long for purely
manual pass.
---
.../tools/header_check-filter_candidates.sh | 78 ++++++++++++++++++++++
development/tools/header_check.sh | 6 ++
2 files changed, 84 insertions(+)
diff --git a/development/tools/header_check-filter_candidates.sh
b/development/tools/header_check-filter_candidates.sh
new file mode 100755
index 0000000000..4fbe757685
--- /dev/null
+++ b/development/tools/header_check-filter_candidates.sh
@@ -0,0 +1,78 @@
+#!/bin/bash
+
+# Narrow down possible candidates for include removal in .cpp files.
+# The main idea here is that the removal candidates in header_check.sh.log
+# are real only when included in the translation unit just once.
+# If included twice or more the removal candidacy is just effect of indirect
+# include from other header.
+
+# To detect this we just insert unconditionally unique declaration ("trap")
+# into each header file and look on the result of preprocessor, which will
+# be stored now stored in .o (instead of usual compiled binary content).
+# Output are only the cases where trap is found exactly once in a given .o.
+
+# To be run on the results of header_check.sh script.
+# Careful, the tree will be left in mess after running this
+# (changed header and (git untracked) Makefiles...).
+
+
+# we want to be in lyx/src/
+if ! [ -e LyX.cpp ]; then echo Wrong dir; exit 1; fi
+
+find . -name "*.h" -print0 | while IFS= read -r -d $'\0' file; do
+ filename=$(basename "$file" .h)
+ class_declaration="class tt${filename}_h;"
+ # Read the entire content of the file
+ content=$(cat "$file")
+# echo "$class_declaration" > "$file"
+# echo "$content" >> "$file"
+ #echo "Processed: $file"
+done
+
+# Let's have all .o file contain just preprocessed output
+#find . -name "Makefile" -print0 | xargs -0 sed -i 's/^CXX = g++ *$/CXX = g++
-E /'
+#make -k 2>/dev/null 1>/dev/null
+
+input_file="../development/tools/header_check.sh.log"
+
+if [ -z "$input_file" ]; then exit 1 ; fi
+
+cat "$input_file" | grep .cpp | grep -v filtered: |
+while IFS='::' read -r header include; do
+ if [ -n "$header" ] && [ -n "$include" ]; then
+ header_file=$(basename "$header")
+ header_file="${header_file%.*}" # Extract filename without extension
+ #trap_declaration="class tt${header_file}_h;"
+
+
+ # Remove the "#include" part and the quotes and alike
+ trap_file=$(echo "$include" | tr '<' '"' | tr '>' '"' |sed -E
's/.*#include\s+"(.*)"/\1/'|sed 's/.*#include.//'| sed 's/\/\/.*//'|sed 's/
$//' |sed 's/.h$/_h/'|sed 's/.hxx$/_h/'|sed 's/.*\///')
+ trap_declaration="tt$trap_file"
+
+ preprocessed_output="${header%.cpp}.o"
+
+ #echo "Processing header: $header"
+ #echo "Preprocess output: $preprocessed_output"
+ #echo "Include statement: $include"
+ #echo "Expected trap: $trap_declaration"
+
+ # Preprocess the header file
+ #preprocessed_output=$(g++ -E "$header" 2>/dev/null)
+
+ if [ -e "$preprocessed_output" ]; then
+ trap_count=$(cat "$preprocessed_output" | grep -F -c "$trap_declaration")
+
+ #echo "Trap declaration found $trap_count times in preprocessed output."
+
+ if [ 1 -eq "$trap_count" ]; then
+ echo filtered: $header : "${trap_declaration#tt}" # found
$trap_count==1 times in $header."
+ fi
+
+ else
+ echo filtered: miss: "$preprocessed_output" # The corresponding .cpp
will not be checked for candidates.
+ fi
+
+ else
+ echo "WARNING: Skipping invalid line."
+ fi
+done | sort | uniq
diff --git a/development/tools/header_check.sh
b/development/tools/header_check.sh
index 65d43bbdd2..c83cbacf08 100755
--- a/development/tools/header_check.sh
+++ b/development/tools/header_check.sh
@@ -132,3 +132,9 @@ do
echo
cp "${FILE_COPY}" "${FILE_}"
done
+
+if [ -e ../development/tools/header_check-filter_candidates.sh ];
+ echo Filtering suitable candidates from .cpp list...
+ ../development/tools/header_check-filter_candidates.sh >> "${LOG_FILE}"
+fi
+
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs