Skip to content

Commit 7b8e2ae

Browse files
committed
Combine headerscheck and cpluspluscheck scripts
They are mostly the same, and it is tedious to maintain two copies of essentially the same exclude list. headerscheck now has a new option --cplusplus to select the cpluspluscheck functionality. The top-level make targets are still the same. Reviewed-by: Thomas Munro <thomas.munro@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://www.postgresql.org/message-id/flat/4754a5b0-a32b-4036-a99a-6de14cf9fd72@eisentraut.org
1 parent f696c0c commit 7b8e2ae

File tree

3 files changed

+55
-231
lines changed

3 files changed

+55
-231
lines changed

GNUmakefile.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,6 @@ headerscheck: submake-generated-headers
133133
$(top_srcdir)/src/tools/pginclude/headerscheck $(top_srcdir) $(abs_top_builddir)
134134

135135
cpluspluscheck: submake-generated-headers
136-
$(top_srcdir)/src/tools/pginclude/cpluspluscheck $(top_srcdir) $(abs_top_builddir)
136+
$(top_srcdir)/src/tools/pginclude/headerscheck --cplusplus $(top_srcdir) $(abs_top_builddir)
137137

138138
.PHONY: dist distdir distcheck docs install-docs world check-world install-world installcheck-world headerscheck cpluspluscheck

src/tools/pginclude/cpluspluscheck

-226
This file was deleted.

src/tools/pginclude/headerscheck

+54-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
# src/tools/pginclude/headerscheck
1616
# Copyright (c) 2009-2024, PostgreSQL Global Development Group
1717

18+
# option to check for C++ compatibility
19+
if [ "$1" = "--cplusplus" ]; then
20+
cplusplus=true
21+
shift
22+
else
23+
cplusplus=false
24+
fi
25+
1826
if [ -z "$1" ]; then
1927
srcdir="."
2028
else
@@ -29,11 +37,15 @@ fi
2937

3038
me=`basename $0`
3139

40+
# These switches are g++ specific, you may override if necessary.
41+
CXXFLAGS=${CXXFLAGS:- -fsyntax-only -Wall}
42+
3243
# Pull some info from configure's results.
3344
MGLOB="$builddir/src/Makefile.global"
3445
CPPFLAGS=`sed -n 's/^CPPFLAGS[ ]*=[ ]*//p' "$MGLOB"`
3546
CFLAGS=`sed -n 's/^CFLAGS[ ]*=[ ]*//p' "$MGLOB"`
3647
CC=`sed -n 's/^CC[ ]*=[ ]*//p' "$MGLOB"`
48+
CXX=`sed -n 's/^CXX[ ]*=[ ]*//p' "$MGLOB"`
3749
PG_SYSROOT=`sed -n 's/^PG_SYSROOT[ ]*=[ ]*//p' "$MGLOB"`
3850
perl_includespec=`sed -n 's/^perl_includespec[ ]*=[ ]*//p' "$MGLOB"`
3951
python_includespec=`sed -n 's/^python_includespec[ ]*=[ ]*//p' "$MGLOB"`
@@ -43,6 +55,22 @@ CPPFLAGS=`echo "$CPPFLAGS" | sed "s|\\\$(PG_SYSROOT)|$PG_SYSROOT|g"`
4355

4456
# (EXTRAFLAGS is not set here, but user can pass it in if need be.)
4557

58+
if $cplusplus; then
59+
ext=cpp
60+
COMPILER=${CXX:-g++}
61+
# Extract any -I and -D switches from CPPFLAGS.
62+
for flag in $CPPFLAGS; do
63+
case $flag in
64+
-I*|-D*) CXXPPFLAGS="$CXXPPFLAGS $flag";;
65+
esac
66+
done
67+
COMPILER_FLAGS="$CXXPPFLAGS $CXXFLAGS"
68+
else
69+
ext=c
70+
COMPILER=${CC:-gcc}
71+
COMPILER_FLAGS="$CPPFLAGS $CFLAGS"
72+
fi
73+
4674
# Create temp directory.
4775
tmp=`mktemp -d /tmp/$me.XXXXXX`
4876

@@ -69,6 +97,7 @@ do
6997
# Additional Windows-specific headers.
7098
test "$f" = src/include/port/win32_port.h && continue
7199
test "$f" = src/include/port/win32/netdb.h && continue
100+
$cplusplus && test "$f" = src/include/port/win32/sys/resource.h && continue
72101
test "$f" = src/include/port/win32/sys/socket.h && continue
73102
test "$f" = src/include/port/win32_msvc/dirent.h && continue
74103
test "$f" = src/include/port/win32_msvc/utime.h && continue
@@ -134,7 +163,7 @@ do
134163
test "$f" = src/test/isolation/specparse.h && continue
135164

136165
# This produces a "no previous prototype" warning.
137-
test "$f" = src/include/storage/checksum_impl.h && continue
166+
! $cplusplus && test "$f" = src/include/storage/checksum_impl.h && continue
138167

139168
# ppport.h is not under our control, so we can't make it standalone.
140169
test "$f" = src/pl/plperl/ppport.h && continue
@@ -144,8 +173,28 @@ do
144173
# printf_hack.h produces "unused function" warnings.
145174
test "$f" = src/interfaces/ecpg/test/printf_hack.h && continue
146175

176+
if $cplusplus; then
177+
# pg_trace.h and utils/probes.h can include sys/sdt.h from SystemTap,
178+
# which itself contains C++ code and so won't compile with a C++
179+
# compiler under extern "C" linkage.
180+
test "$f" = src/include/pg_trace.h && continue
181+
test "$f" = src/include/utils/probes.h && continue
182+
183+
# pg_dump is not C++-clean because it uses "public" and "namespace"
184+
# as field names, which is unfortunate but we won't change it now.
185+
test "$f" = src/bin/pg_dump/compress_gzip.h && continue
186+
test "$f" = src/bin/pg_dump/compress_io.h && continue
187+
test "$f" = src/bin/pg_dump/compress_lz4.h && continue
188+
test "$f" = src/bin/pg_dump/compress_none.h && continue
189+
test "$f" = src/bin/pg_dump/compress_zstd.h && continue
190+
test "$f" = src/bin/pg_dump/parallel.h && continue
191+
test "$f" = src/bin/pg_dump/pg_backup_archiver.h && continue
192+
test "$f" = src/bin/pg_dump/pg_dump.h && continue
193+
fi
194+
147195
# OK, create .c file to include this .h file.
148196
{
197+
$cplusplus && echo 'extern "C" {'
149198
# Ideally we'd pre-include only the appropriate one of
150199
# postgres.h, postgres_fe.h, or c.h. We don't always have enough
151200
# info to guess which, but in some subdirectories there's a
@@ -174,7 +223,8 @@ do
174223
echo '#include "postgres.h"' ;;
175224
esac
176225
echo "#include \"$f\""
177-
} >$tmp/test.c
226+
$cplusplus && echo '};'
227+
} >$tmp/test.$ext
178228

179229
# Some subdirectories need extra -I switches.
180230
case "$f" in
@@ -193,10 +243,10 @@ do
193243
esac
194244

195245
# Run the test.
196-
if ! ${CC:-gcc} $CPPFLAGS $CFLAGS -I $builddir -I $srcdir \
246+
if ! $COMPILER $COMPILER_FLAGS -I $builddir -I $srcdir \
197247
-I $builddir/src/include -I $srcdir/src/include \
198248
-I $builddir/src/interfaces/libpq -I $srcdir/src/interfaces/libpq \
199-
$EXTRAINCLUDES $EXTRAFLAGS -c $tmp/test.c -o $tmp/test.o
249+
$EXTRAINCLUDES $EXTRAFLAGS -c $tmp/test.$ext -o $tmp/test.o
200250
then
201251
exit_status=1
202252
fi

0 commit comments

Comments
 (0)