Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6f54b80

Browse files
committed
Improve coverage of cpluspluscheck.
Formerly, cpluspluscheck was only meant to examine headers thatwe thought of as exported --- but its notion of what we exportwas well behind the times. Let's just make it check *all* .hfiles, except for a well-defined blacklist, instead.While at it, improve its ability to use a C++ compiler other than g++,by scraping the CXX setting from Makefile.global and making it possibleto override the warning options used (per suggestion from Andres Freund).Discussion:https://postgr.es/m/b517ec3918d645eb950505eac8dd434e@gaz-is.ru
1 parentb1cd7ce commit6f54b80

File tree

1 file changed

+116
-28
lines changed

1 file changed

+116
-28
lines changed

‎src/tools/pginclude/cpluspluscheck

Lines changed: 116 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,148 @@
11
#!/bin/sh
22

3-
# Checkall exported PostgreSQL include files for C++ compatibility.
3+
# Check(almost) all PostgreSQL include files for C++ compatibility.
44
#
55
# Argument 1 is the top-level source directory, argument 2 the
66
# top-level build directory (they might be the same). If not set, they
77
# default to the current directory.
88
#
9-
# Needs to be run after all generated headers are created.
9+
# Needs to be run afterconfiguring and creatingall generated headers.
1010
#
1111
# No output if everything is OK, else compiler errors.
1212

13-
if [-z"$1" ];then
13+
if [-z"$1" ];then
1414
srcdir="."
1515
else
1616
srcdir="$1"
1717
fi
1818

19-
if [-z"$2" ];then
20-
builddir="$."
19+
if [-z"$2" ];then
20+
builddir="."
2121
else
2222
builddir="$2"
2323
fi
2424

2525
me=`basename$0`
2626

27+
# Pull some info from configure's results.
28+
MGLOB="$builddir/src/Makefile.global"
29+
CXX=`sed -n's/^CXX[ ]*=[ ]*//p'"$MGLOB"`
30+
perl_includespec=`sed -n's/^perl_includespec[ ]*=[ ]*//p'"$MGLOB"`
31+
python_includespec=`sed -n's/^python_includespec[ ]*=[ ]*//p'"$MGLOB"`
32+
33+
# These switches are g++ specific, you may override if necessary.
34+
CXXFLAGS=${CXXFLAGS:- -fsyntax-only -Wall}
35+
36+
# Create temp directory.
2737
tmp=`mktemp -d /tmp/$me.XXXXXX`
2838

2939
trap'rm -rf $tmp' 0 1 2 3 15
3040

31-
# Omit src/include/port/, because it's platform specific, and c.h includes
32-
# the relevant file anyway.
33-
# rusagestub.h is also platform-specific, and will be included by
34-
# utils/pg_rusage.h if necessary.
35-
# access/rmgrlist.h is not meant to be included standalone.
36-
# regex/regerrs.h is not meant to be included standalone.
37-
# parser/gram.h will be included by parser/gramparse.h.
38-
# parser/kwlist.h is not meant to be included standalone.
39-
# pg_trace.h and utils/probes.h can include sys/sdt.h from SystemTap,
40-
# which itself contains C++ code and so won't compile with a C++
41-
# compiler under extern "C" linkage.
42-
43-
forfin`cd"$srcdir"&& find src/include src/interfaces/libpq/libpq-fe.h src/interfaces/libpq/libpq-events.h -name'*.h' -print| \
44-
grep -v -e ^src/include/port/ \
45-
-e ^src/include/rusagestub.h -e ^src/include/regex/regerrs.h \
46-
-e ^src/include/access/rmgrlist.h \
47-
-e ^src/include/parser/gram.h -e ^src/include/parser/kwlist.h \
48-
-e ^src/include/pg_trace.h -e ^src/include/utils/probes.h`
41+
# Scan all of src/ and contrib/ for header files.
42+
forfin`cd"$srcdir"&& find src contrib -name'*.h' -print`
4943
do
44+
# Ignore files that are unportable or intentionally not standalone.
45+
46+
# These files are platform-specific, and c.h will include the
47+
# one that's relevant for our current platform anyway.
48+
test"$f" = src/include/port/aix.h&&continue
49+
test"$f" = src/include/port/cygwin.h&&continue
50+
test"$f" = src/include/port/darwin.h&&continue
51+
test"$f" = src/include/port/freebsd.h&&continue
52+
test"$f" = src/include/port/hpux.h&&continue
53+
test"$f" = src/include/port/linux.h&&continue
54+
test"$f" = src/include/port/netbsd.h&&continue
55+
test"$f" = src/include/port/openbsd.h&&continue
56+
test"$f" = src/include/port/solaris.h&&continue
57+
test"$f" = src/include/port/win32.h&&continue
58+
59+
# Additional Windows-specific headers.
60+
test"$f" = src/include/port/win32_port.h&&continue
61+
test"$f" = src/include/port/win32/sys/socket.h&&continue
62+
test"$f" = src/include/port/win32_msvc/dirent.h&&continue
63+
test"$f" = src/port/pthread-win32.h&&continue
64+
65+
# Likewise, these files are platform-specific, and the one
66+
# relevant to our platform will be included by atomics.h.
67+
test"$f" = src/include/port/atomics/arch-arm.h&&continue
68+
test"$f" = src/include/port/atomics/fallback.h&&continue
69+
test"$f" = src/include/port/atomics/generic.h&&continue
70+
test"$f" = src/include/port/atomics/generic-acc.h&&continue
71+
test"$f" = src/include/port/atomics/generic-gcc.h&&continue
72+
test"$f" = src/include/port/atomics/generic-msvc.h&&continue
73+
test"$f" = src/include/port/atomics/generic-xlc.h&&continue
74+
75+
# rusagestub.h is also platform-specific, and will be included
76+
# by utils/pg_rusage.h if necessary.
77+
test"$f" = src/include/rusagestub.h&&continue
78+
79+
# sepgsql.h depends on headers that aren't there on most platforms.
80+
test"$f" = contrib/sepgsql/sepgsql.h&&continue
81+
82+
# These files are not meant to be included standalone, because
83+
# they contain lists that might have multiple use-cases.
84+
test"$f" = src/include/access/rmgrlist.h&&continue
85+
test"$f" = src/include/parser/kwlist.h&&continue
86+
test"$f" = src/pl/plpgsql/src/pl_reserved_kwlist.h&&continue
87+
test"$f" = src/pl/plpgsql/src/pl_unreserved_kwlist.h&&continue
88+
test"$f" = src/interfaces/ecpg/preproc/c_kwlist.h&&continue
89+
test"$f" = src/interfaces/ecpg/preproc/ecpg_kwlist.h&&continue
90+
test"$f" = src/include/regex/regerrs.h&&continue
91+
test"$f" = src/pl/plpgsql/src/plerrcodes.h&&continue
92+
test"$f" = src/pl/plpython/spiexceptions.h&&continue
93+
test"$f" = src/pl/tcl/pltclerrcodes.h&&continue
94+
95+
# We can't make these Bison output files compilable standalone
96+
# without using "%code require", which old Bison versions lack.
97+
# parser/gram.h will be included by parser/gramparse.h anyway.
98+
test"$f" = src/include/parser/gram.h&&continue
99+
test"$f" = src/backend/parser/gram.h&&continue
100+
test"$f" = src/pl/plpgsql/src/pl_gram.h&&continue
101+
test"$f" = src/interfaces/ecpg/preproc/preproc.h&&continue
102+
103+
# ppport.h is not under our control, so we can't make it standalone.
104+
test"$f" = src/pl/plperl/ppport.h&&continue
105+
106+
# regression.h is not actually C, but ECPG code.
107+
test"$f" = src/interfaces/ecpg/test/regression.h&&continue
108+
109+
# pg_trace.h and utils/probes.h can include sys/sdt.h from SystemTap,
110+
# which itself contains C++ code and so won't compile with a C++
111+
# compiler under extern "C" linkage.
112+
test"$f" = src/include/pg_trace.h&&continue
113+
test"$f" = src/include/utils/probes.h&&continue
114+
115+
# pg_dump is not C++-clean because it uses "public" and "namespace"
116+
# as field names, which is unfortunate but we won't change it now.
117+
test"$f" = src/bin/pg_dump/compress_io.h&&continue
118+
test"$f" = src/bin/pg_dump/parallel.h&&continue
119+
test"$f" = src/bin/pg_dump/pg_backup_archiver.h&&continue
120+
test"$f" = src/bin/pg_dump/pg_dump.h&&continue
121+
122+
# OK, create .c file to include this .h file.
50123
{
51-
echo'extern "C" {'
52-
test$f!="src/include/postgres_fe.h"&&echo'#include "postgres.h"'
124+
echo'extern "C" {'
125+
test"$f"!= src/include/postgres_fe.h&&echo'#include "postgres.h"'
53126
echo"#include\"$f\""
54127
echo'};'
55128
}>$tmp/test.cpp
56129

57-
${CXX:-g++} -I$srcdir -I$srcdir/src/interfaces/libpq -I$srcdir/src/include \
58-
-I$builddir -I$builddir/src/interfaces/libpq -I$builddir/src/include \
59-
-fsyntax-only -Wall -c$tmp/test.cpp
130+
# Some subdirectories need extra -I switches.
131+
case"$f"in
132+
src/pl/plperl/*)
133+
EXTRAINCLUDES="$perl_includespec" ;;
134+
src/pl/plpython/*)
135+
EXTRAINCLUDES="$python_includespec" ;;
136+
src/interfaces/ecpg/*)
137+
EXTRAINCLUDES="-I$builddir/src/interfaces/ecpg/include -I$srcdir/src/interfaces/ecpg/include" ;;
138+
*)
139+
EXTRAINCLUDES="" ;;
140+
esac
141+
142+
# Run the test.
143+
${CXX:-g++} -I$builddir -I$srcdir \
144+
-I$builddir/src/include -I$srcdir/src/include \
145+
-I$builddir/src/interfaces/libpq -I$srcdir/src/interfaces/libpq \
146+
$EXTRAINCLUDES$CXXFLAGS -c$tmp/test.cpp
147+
60148
done

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp