Skip to content

Commit 94db666

Browse files
committed
Modify pgrminclude -v to report include files that can't be compiled on
their own. Avoid compile problems with defines being redefined after the removal of the #if blocks. Change script to use shell functions for simplicity.
1 parent a49fbaa commit 94db666

File tree

1 file changed

+98
-65
lines changed

1 file changed

+98
-65
lines changed

src/tools/pginclude/pgrminclude

Lines changed: 98 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -7,87 +7,120 @@ then echo "pgdefine must be in your PATH" 1>&2
77
fi
88

99
trap "rm -f /tmp/$$.c /tmp/$$.o /tmp/$$ /tmp/$$a /tmp/$$b" 0 1 2 3 15
10-
# do include files first
11-
(find . \( -name .git -a -prune \) -o -type f -name '*.h' -print;
12-
find . \( -name .git -a -prune \) -o -type f -name '*.c' -print ) |
13-
grep -v '\./postgres.h' |
14-
grep -v '\./postgres_fe.h' |
15-
grep -v '\./pg_config.h' |
16-
grep -v '\./c.h' |
17-
while read FILE
18-
do
19-
if [ `expr $FILE : '.*\.h$'` -ne 0 ]
20-
then IS_INCLUDE="Y"
21-
else IS_INCLUDE="N"
10+
11+
if [ "$1" = "-v" ]
12+
then VERBOSE="Y"
13+
else VERBOSE=""
14+
fi
15+
16+
verbose_output() {
17+
if [ "$VERBOSE" ]
18+
then cat /tmp/$$
19+
cat /tmp/$$b
20+
nl /tmp/$$.c
2221
fi
22+
}
2323

24-
# loop through all includes
24+
process_includes_in_file() {
25+
# loop through all includes mentioned in the file
2526
cat "$FILE" |
2627
grep "^#include\>" |
2728
grep -v '/\* *pgrminclude *ignore *\*/' |
2829
sed 's/^#include[ ]*[<"]\([^>"]*\).*$/\1/g' |
2930
grep -v 'parser/kwlist\.h' |
3031
grep -v '\.c$' |
3132
while read INCLUDE
32-
do
33-
if [ "$1" = "-v" ]
33+
do if [ "$VERBOSE" ]
3434
then echo "checking $FILE $INCLUDE"
3535
fi
36+
compile_file
37+
done
38+
}
3639

37-
[ -s /usr/include/$INCLUDE ] && continue
38-
[ "$INCLUDE" = postgres.h ] && continue
39-
[ "$INCLUDE" = postgres_fe.h ] && continue
40-
[ "$INCLUDE" = pg_config.h ] && continue
41-
[ "$INCLUDE" = c.h ] && continue
40+
compile_file() {
41+
[ "$INCLUDE" -a -s /usr/include/"$INCLUDE" ] && continue
42+
[ "$INCLUDE" = "postgres.h" ] && continue
43+
[ "$INCLUDE" = "postgres_fe.h" ] && continue
44+
[ "$INCLUDE" = "pg_config.h" ] && continue
45+
[ "$INCLUDE" = "c.h" ] && continue
4246

43-
# preserve configure-specific includes
44-
# these includes are surrounded by #ifdef's
45-
grep -B1 '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' "$FILE" |
46-
egrep -q '^#if|^#else|^#elif' && continue
47-
grep -A1 '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' "$FILE" |
48-
egrep -q '^#else|^#elif|^#endif' && continue
47+
# preserve configure-specific includes
48+
# these includes are surrounded by #ifdef's
49+
grep -B1 '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' "$FILE" |
50+
egrep -q '^#if|^#else|^#elif' && continue
51+
grep -A1 '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' "$FILE" |
52+
egrep -q '^#else|^#elif|^#endif' && continue
4953

50-
# Remove all #if and #ifdef blocks because the blocks
51-
# might contain code that is not compiled on this platform.
52-
cat "$FILE" |
53-
grep -v "^#if" |
54-
grep -v "^#else" |
55-
grep -v "^#elif" |
56-
grep -v "^#endif" >/tmp/$$a
54+
# Remove all #if and #ifdef blocks because the blocks
55+
# might contain code that is not compiled on this platform.
56+
cat "$FILE" |
57+
grep -v "^#if" |
58+
grep -v "^#else" |
59+
grep -v "^#elif" |
60+
grep -v "^#endif" |
61+
# with #if blocks gone, now undef #defines to avoid redefine
62+
# warning and failure
63+
sed 's/#define[ ][ ]*\([A-Za-z0-9_]*\).*$/#undef \1\n&/' >/tmp/$$a
5764

58-
# set up initial file contents
59-
grep -v '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' \
60-
/tmp/$$a >/tmp/$$b
65+
# set up initial file contents
66+
grep -v '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' \
67+
/tmp/$$a >/tmp/$$b
6168

62-
if [ "$IS_INCLUDE" = "Y" ]
63-
then echo "#include \"postgres.h\"" >/tmp/$$.c
64-
else >/tmp/$$.c
65-
fi
69+
if [ "$IS_INCLUDE" = "Y" ]
70+
then echo "#include \"postgres.h\"" >/tmp/$$.c
71+
else >/tmp/$$.c
72+
fi
6673

67-
echo "#include \"/tmp/$$b\"" >>/tmp/$$.c
68-
echo "void include_test(void);" >>/tmp/$$.c
69-
echo "void include_test() {" >>/tmp/$$.c
70-
if [ "$IS_INCLUDE" = "Y" ]
71-
then pgdefine "$FILE" >>/tmp/$$.c
72-
fi
73-
echo "}" >>/tmp/$$.c
74+
echo "#include \"/tmp/$$b\"" >>/tmp/$$.c
75+
# supress fcinfo errors
76+
echo "#undef PG_GETARG_DATUM" >>/tmp/$$.c
77+
echo "#define PG_GETARG_DATUM(n)" >>/tmp/$$.c
78+
echo "void include_test(void);" >>/tmp/$$.c
79+
echo "void include_test() {" >>/tmp/$$.c
80+
if [ "$IS_INCLUDE" = "Y" ]
81+
then pgdefine "$FILE" >>/tmp/$$.c
82+
fi
83+
echo "}" >>/tmp/$$.c
7484

75-
# Use -O1 to get warnings only generated by optimization,
76-
# but -O2 is too slow.
77-
cc -fsyntax-only -Werror -Wall -Wmissing-prototypes \
78-
-Wmissing-declarations -I/pg/include -I/pg/backend \
79-
-I/pg/interfaces/libpq -I`dirname $FILE` $CFLAGS -O1 -c /tmp/$$.c \
80-
-o /tmp/$$.o >/tmp/$$ 2>&1
81-
if [ "$?" -eq 0 ]
82-
then echo "$FILE $INCLUDE"
83-
if [ "$1" = "-v" ]
84-
then cat /tmp/$$
85-
cat /tmp/$$b
86-
cat /tmp/$$.c
87-
fi
88-
grep -v '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' \
89-
"$FILE" >/tmp/$$b
90-
mv /tmp/$$b "$FILE"
91-
fi
92-
done
85+
# Use -O1 to get warnings only generated by optimization,
86+
# but -O2 is too slow.
87+
cc -fsyntax-only -Werror -Wall -Wmissing-prototypes \
88+
-Wmissing-declarations -I/pg/include -I/pg/backend \
89+
-I/pg/interfaces/libpq -I`dirname $FILE` $CFLAGS -O1 -c /tmp/$$.c \
90+
-o /tmp/$$.o >/tmp/$$ 2>&1
91+
if [ "$?" -eq 0 ]
92+
then [ "$INCLUDE" -o "$VERBOSE" ] && echo "$FILE $INCLUDE"
93+
grep -v '^#include[ ][ ]*[<"]'"$INCLUDE"'[>"]' \
94+
"$FILE" >/tmp/$$b
95+
mv /tmp/$$b "$FILE"
96+
return 0
97+
else return 1
98+
fi
99+
}
100+
101+
# Process include files first because they can affect the compilation
102+
# of *.c files.
103+
(find . \( -name .git -a -prune \) -o -type f -name '*.h' -print;
104+
find . \( -name .git -a -prune \) -o -type f -name '*.c' -print ) |
105+
grep -v '/postgres.h$' |
106+
grep -v '/postgres_fe.h$' |
107+
grep -v '/pg_config.h$' |
108+
grep -v '\./c.h$' |
109+
while read FILE
110+
do
111+
if [ `expr $FILE : '.*\.h$'` -ne 0 ]
112+
then IS_INCLUDE="Y"
113+
else IS_INCLUDE="N"
114+
fi
115+
116+
# Can we compile the file with all existing includes?
117+
INCLUDE=""
118+
compile_file
119+
# If the file can't be compiled on its own, there is no sense
120+
# trying to remove the include files.
121+
if [ "$?" -ne 0 ]
122+
then echo "cannot compile $FILE with existing includes"
123+
verbose_output
124+
else process_includes_in_file
125+
fi
93126
done

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy