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

Commit55ea109

Browse files
committed
Add "headerscheck" script to test header-file compilability under C.
We already had "cpluspluscheck", which served the dual purposes ofverifying that headers compile standalone and that they compile as C++.However, C++ compilers don't have the exact same set of error conditionsas C compilers, so this doesn't really prove that a header will compilestandalone as C.Hence, add a second script that's largely similar but runs the Ccompiler not C++.Also add a bit more documentation than the none-at-all we had before.Discussion:https://postgr.es/m/14803.1566175851@sss.pgh.pa.us
1 parenta120791 commit55ea109

File tree

4 files changed

+210
-1
lines changed

4 files changed

+210
-1
lines changed

‎GNUmakefile.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ distcheck: dist
128128
rm -rf $(distdir) $(dummy)
129129
@echo "Distribution integrity checks out."
130130

131+
headerscheck: submake-generated-headers
132+
$(top_srcdir)/src/tools/pginclude/headerscheck $(top_srcdir) $(abs_top_builddir)
133+
131134
cpluspluscheck: submake-generated-headers
132135
$(top_srcdir)/src/tools/pginclude/cpluspluscheck $(top_srcdir) $(abs_top_builddir)
133136

134-
.PHONY: dist distdir distcheck docs install-docs world check-world install-world installcheck-world
137+
.PHONY: dist distdir distcheck docs install-docs world check-world install-world installcheck-world headerscheck cpluspluscheck

‎src/tools/pginclude/README

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,51 @@ Another tools that does a similar task is at:
5353
An include file visualizer script is available at:
5454

5555
http://archives.postgresql.org/pgsql-hackers/2011-09/msg00311.php
56+
57+
58+
headerscheck
59+
============
60+
61+
This script can be run to verify that all Postgres include files meet
62+
the project convention that they will compile "standalone", that is
63+
with no prerequisite headers other than postgres.h (or postgres_fe.h
64+
or c.h, as appropriate).
65+
66+
A small number of header files are exempted from this requirement,
67+
and are whitelisted in the headerscheck script.
68+
69+
The easy way to run the script is to say "make -s headerscheck" in
70+
the top-level build directory after completing a build. You should
71+
have included "--with-perl --with-python" in your configure options,
72+
else you're likely to get errors about related headers not being found.
73+
74+
A limitation of the current script is that it doesn't know which headers
75+
are for frontend or backend, so it tests everything with postgres.h
76+
as prerequisite, even if postgres_fe.h would be more appropriate. Also
77+
note that the contents of macros are not checked; this is intentional.
78+
79+
80+
cpluspluscheck
81+
==============
82+
83+
This script can be run to verify that all Postgres include files meet
84+
the project convention that they will compile as C++ code. Although
85+
the project's coding language is C, some people write extensions in C++,
86+
so it's helpful for include files to be C++-clean.
87+
88+
A small number of header files are exempted from this requirement,
89+
and are whitelisted in the cpluspluscheck script.
90+
91+
The easy way to run the script is to say "make -s cpluspluscheck" in
92+
the top-level build directory after completing a build. You should
93+
have included "--with-perl --with-python" in your configure options,
94+
else you're likely to get errors about related headers not being found.
95+
96+
If you are using a non-g++-compatible C++ compiler, you may need to
97+
override the script's CXXFLAGS setting by setting a suitable environment
98+
value.
99+
100+
A limitation of the current script is that it doesn't know which headers
101+
are for frontend or backend, so it tests everything with postgres.h
102+
as prerequisite, even if postgres_fe.h would be more appropriate. Also
103+
note that the contents of macros are not checked; this is intentional.

‎src/tools/pginclude/cpluspluscheck

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
# default to the current directory.
88
#
99
# Needs to be run after configuring and creating all generated headers.
10+
# It's advisable to configure --with-perl --with-python, else you're
11+
# likely to get errors from associated headers.
1012
#
1113
# No output if everything is OK, else compiler errors.
14+
#
15+
# src/tools/pginclude/cpluspluscheck
16+
# Copyright (c) 2009-2019, PostgreSQL Global Development Group
1217

1318
if [-z"$1" ];then
1419
srcdir="."

‎src/tools/pginclude/headerscheck

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/bin/sh
2+
3+
# Check (almost) all PostgreSQL include files for standalone build.
4+
#
5+
# Argument 1 is the top-level source directory, argument 2 the
6+
# top-level build directory (they might be the same). If not set, they
7+
# default to the current directory.
8+
#
9+
# Needs to be run after configuring and creating all generated headers.
10+
# It's advisable to configure --with-perl --with-python, else you're
11+
# likely to get errors from associated headers.
12+
#
13+
# No output if everything is OK, else compiler errors.
14+
#
15+
# src/tools/pginclude/headerscheck
16+
# Copyright (c) 2009-2019, PostgreSQL Global Development Group
17+
18+
if [-z"$1" ];then
19+
srcdir="."
20+
else
21+
srcdir="$1"
22+
fi
23+
24+
if [-z"$2" ];then
25+
builddir="."
26+
else
27+
builddir="$2"
28+
fi
29+
30+
me=`basename$0`
31+
32+
# Pull some info from configure's results.
33+
MGLOB="$builddir/src/Makefile.global"
34+
CPPFLAGS=`sed -n's/^CPPFLAGS[ ]*=[ ]*//p'"$MGLOB"`
35+
CFLAGS=`sed -n's/^CFLAGS[ ]*=[ ]*//p'"$MGLOB"`
36+
CC=`sed -n's/^CC[ ]*=[ ]*//p'"$MGLOB"`
37+
PG_SYSROOT=`sed -n's/^PG_SYSROOT[ ]*=[ ]*//p'"$MGLOB"`
38+
perl_includespec=`sed -n's/^perl_includespec[ ]*=[ ]*//p'"$MGLOB"`
39+
python_includespec=`sed -n's/^python_includespec[ ]*=[ ]*//p'"$MGLOB"`
40+
41+
# needed on Darwin
42+
CPPFLAGS=`echo"$CPPFLAGS"| sed"s|\\\$(PG_SYSROOT)|$PG_SYSROOT|g"`
43+
44+
# (EXTRAFLAGS is not set here, but user can pass it in if need be.)
45+
46+
# Create temp directory.
47+
tmp=`mktemp -d /tmp/$me.XXXXXX`
48+
49+
trap'rm -rf $tmp' 0 1 2 3 15
50+
51+
# Scan all of src/ and contrib/ for header files.
52+
forfin`cd"$srcdir"&& find src contrib -name'*.h' -print`
53+
do
54+
# Ignore files that are unportable or intentionally not standalone.
55+
56+
# These files are platform-specific, and c.h will include the
57+
# one that's relevant for our current platform anyway.
58+
test"$f" = src/include/port/aix.h&&continue
59+
test"$f" = src/include/port/cygwin.h&&continue
60+
test"$f" = src/include/port/darwin.h&&continue
61+
test"$f" = src/include/port/freebsd.h&&continue
62+
test"$f" = src/include/port/hpux.h&&continue
63+
test"$f" = src/include/port/linux.h&&continue
64+
test"$f" = src/include/port/netbsd.h&&continue
65+
test"$f" = src/include/port/openbsd.h&&continue
66+
test"$f" = src/include/port/solaris.h&&continue
67+
test"$f" = src/include/port/win32.h&&continue
68+
69+
# Additional Windows-specific headers.
70+
test"$f" = src/include/port/win32_port.h&&continue
71+
test"$f" = src/include/port/win32/sys/socket.h&&continue
72+
test"$f" = src/include/port/win32_msvc/dirent.h&&continue
73+
test"$f" = src/port/pthread-win32.h&&continue
74+
75+
# Likewise, these files are platform-specific, and the one
76+
# relevant to our platform will be included by atomics.h.
77+
test"$f" = src/include/port/atomics/arch-arm.h&&continue
78+
test"$f" = src/include/port/atomics/arch-hppa.h&&continue
79+
test"$f" = src/include/port/atomics/arch-ia64.h&&continue
80+
test"$f" = src/include/port/atomics/arch-ppc.h&&continue
81+
test"$f" = src/include/port/atomics/arch-x86.h&&continue
82+
test"$f" = src/include/port/atomics/fallback.h&&continue
83+
test"$f" = src/include/port/atomics/generic.h&&continue
84+
test"$f" = src/include/port/atomics/generic-acc.h&&continue
85+
test"$f" = src/include/port/atomics/generic-gcc.h&&continue
86+
test"$f" = src/include/port/atomics/generic-msvc.h&&continue
87+
test"$f" = src/include/port/atomics/generic-sunpro.h&&continue
88+
test"$f" = src/include/port/atomics/generic-xlc.h&&continue
89+
90+
# rusagestub.h is also platform-specific, and will be included
91+
# by utils/pg_rusage.h if necessary.
92+
test"$f" = src/include/rusagestub.h&&continue
93+
94+
# sepgsql.h depends on headers that aren't there on most platforms.
95+
test"$f" = contrib/sepgsql/sepgsql.h&&continue
96+
97+
# These files are not meant to be included standalone, because
98+
# they contain lists that might have multiple use-cases.
99+
test"$f" = src/include/access/rmgrlist.h&&continue
100+
test"$f" = src/include/parser/kwlist.h&&continue
101+
test"$f" = src/pl/plpgsql/src/pl_reserved_kwlist.h&&continue
102+
test"$f" = src/pl/plpgsql/src/pl_unreserved_kwlist.h&&continue
103+
test"$f" = src/interfaces/ecpg/preproc/c_kwlist.h&&continue
104+
test"$f" = src/interfaces/ecpg/preproc/ecpg_kwlist.h&&continue
105+
test"$f" = src/include/regex/regerrs.h&&continue
106+
test"$f" = src/pl/plpgsql/src/plerrcodes.h&&continue
107+
test"$f" = src/pl/plpython/spiexceptions.h&&continue
108+
test"$f" = src/pl/tcl/pltclerrcodes.h&&continue
109+
110+
# We can't make these Bison output files compilable standalone
111+
# without using "%code require", which old Bison versions lack.
112+
# parser/gram.h will be included by parser/gramparse.h anyway.
113+
test"$f" = src/include/parser/gram.h&&continue
114+
test"$f" = src/backend/parser/gram.h&&continue
115+
test"$f" = src/pl/plpgsql/src/pl_gram.h&&continue
116+
test"$f" = src/interfaces/ecpg/preproc/preproc.h&&continue
117+
118+
# This produces a "no previous prototype" warning.
119+
test"$f" = src/include/storage/checksum_impl.h&&continue
120+
121+
# ppport.h is not under our control, so we can't make it standalone.
122+
test"$f" = src/pl/plperl/ppport.h&&continue
123+
124+
# regression.h is not actually C, but ECPG code.
125+
test"$f" = src/interfaces/ecpg/test/regression.h&&continue
126+
# printf_hack.h produces "unused function" warnings.
127+
test"$f" = src/interfaces/ecpg/test/printf_hack.h&&continue
128+
129+
# OK, create .c file to include this .h file.
130+
{
131+
test"$f"!= src/include/postgres_fe.h&&echo'#include "postgres.h"'
132+
echo"#include\"$f\""
133+
}>$tmp/test.c
134+
135+
# Some subdirectories need extra -I switches.
136+
case"$f"in
137+
src/pl/plperl/*)
138+
EXTRAINCLUDES="$perl_includespec" ;;
139+
src/pl/plpython/*)
140+
EXTRAINCLUDES="$python_includespec" ;;
141+
src/interfaces/ecpg/*)
142+
EXTRAINCLUDES="-I$builddir/src/interfaces/ecpg/include -I$srcdir/src/interfaces/ecpg/include" ;;
143+
*)
144+
EXTRAINCLUDES="" ;;
145+
esac
146+
147+
# Run the test.
148+
${CC:-gcc}$CPPFLAGS$CFLAGS -I$builddir -I$srcdir \
149+
-I$builddir/src/include -I$srcdir/src/include \
150+
-I$builddir/src/interfaces/libpq -I$srcdir/src/interfaces/libpq \
151+
$EXTRAINCLUDES$EXTRAFLAGS -c$tmp/test.c -o$tmp/test.o
152+
153+
done

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp