From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: vignesh C <vignesh21@gmail.com>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Subject: Re: Unused header file inclusion
Date: Sun, 18 Aug 2019 20:50:51 -0400
Message-ID: <14803.1566175851@sss.pgh.pa.us> (raw)
In-Reply-To: <17463.1566153454@sss.pgh.pa.us>
References: <20190731203607.GA5260@alvherre.pgsql>
<22389.1564606531@sss.pgh.pa.us>
<20190731215314.tdlrqdgnd73do2ht@alap3.anarazel.de>
<29534.1564615501@sss.pgh.pa.us>
<20190803193733.g3l3x3o42uv4qj7l@alap3.anarazel.de>
<20190816230716.jndus364yfcz4sr6@alap3.anarazel.de>
<17463.1566153454@sss.pgh.pa.us>
I wrote:
> (My headerscheck script is missing that header; I need to update it to
> match the latest version of cpluspluscheck.)
I did that, and ended up with the attached. I'm rather tempted to stick
this into src/tools/ alongside cpluspluscheck, because it seems to find
rather different trouble spots than cpluspluscheck does. Thoughts?
As of HEAD (927f34ce8), I get clean passes from both this and
cpluspluscheck, except for the FmgrInfo references in selfuncs.h.
I tried it on RHEL/Fedora, FreeBSD 12, and current macOS.
regards, tom lane
Attachments:headerscheck (text/x-shellscript, 5.8K) download
#!/bin/sh
# Check (almost) all PostgreSQL include files for standalone build.
#
# Argument 1 is the top-level source directory, argument 2 the
# top-level build directory (they might be the same). If not set, they
# default to the current directory.
#
# Needs to be run after configuring and creating all generated headers.
# It's advisable to configure --with-perl --with-python, or you're
# likely to get errors from associated headers.
#
# No output if everything is OK, else compiler errors.
if [ -z "$1" ]; then
srcdir="."
else
srcdir="$1"
fi
if [ -z "$2" ]; then
builddir="."
else
builddir="$2"
fi
me=`basename $0`
# Pull some info from configure's results.
MGLOB="$builddir/src/Makefile.global"
CFLAGS=`sed -n 's/^CFLAGS[ ]*=[ ]*//p' "$MGLOB"`
CPPFLAGS=`sed -n 's/^CPPFLAGS[ ]*=[ ]*//p' "$MGLOB"`
PG_SYSROOT=`sed -n 's/^PG_SYSROOT[ ]*=[ ]*//p' "$MGLOB"`
CC=`sed -n 's/^CC[ ]*=[ ]*//p' "$MGLOB"`
perl_includespec=`sed -n 's/^perl_includespec[ ]*=[ ]*//p' "$MGLOB"`
python_includespec=`sed -n 's/^python_includespec[ ]*=[ ]*//p' "$MGLOB"`
# needed on Darwin
CPPFLAGS=`echo "$CPPFLAGS" | sed "s|\\$(PG_SYSROOT)|$PG_SYSROOT|g"`
# (EXTRAFLAGS is not set here, but user can pass it in if need be.)
# Create temp directory.
tmp=`mktemp -d /tmp/$me.XXXXXX`
trap 'rm -rf $tmp' 0 1 2 3 15
# Scan all of src/ and contrib/ for header files.
for f in `cd "$srcdir" && find src contrib -name '*.h' -print`
do
# Ignore files that are unportable or intentionally not standalone.
# These files are platform-specific, and c.h will include the
# one that's relevant for our current platform anyway.
test "$f" = src/include/port/aix.h && continue
test "$f" = src/include/port/cygwin.h && continue
test "$f" = src/include/port/darwin.h && continue
test "$f" = src/include/port/freebsd.h && continue
test "$f" = src/include/port/hpux.h && continue
test "$f" = src/include/port/linux.h && continue
test "$f" = src/include/port/netbsd.h && continue
test "$f" = src/include/port/openbsd.h && continue
test "$f" = src/include/port/solaris.h && continue
test "$f" = src/include/port/win32.h && continue
# Additional Windows-specific headers.
test "$f" = src/include/port/win32_port.h && continue
test "$f" = src/include/port/win32/sys/socket.h && continue
test "$f" = src/include/port/win32_msvc/dirent.h && continue
test "$f" = src/port/pthread-win32.h && continue
# Likewise, these files are platform-specific, and the one
# relevant to our platform will be included by atomics.h.
test "$f" = src/include/port/atomics/arch-arm.h && continue
test "$f" = src/include/port/atomics/arch-hppa.h && continue
test "$f" = src/include/port/atomics/arch-ia64.h && continue
test "$f" = src/include/port/atomics/arch-ppc.h && continue
test "$f" = src/include/port/atomics/arch-x86.h && continue
test "$f" = src/include/port/atomics/fallback.h && continue
test "$f" = src/include/port/atomics/generic.h && continue
test "$f" = src/include/port/atomics/generic-acc.h && continue
test "$f" = src/include/port/atomics/generic-gcc.h && continue
test "$f" = src/include/port/atomics/generic-msvc.h && continue
test "$f" = src/include/port/atomics/generic-sunpro.h && continue
test "$f" = src/include/port/atomics/generic-xlc.h && continue
# rusagestub.h is also platform-specific, and will be included
# by utils/pg_rusage.h if necessary.
test "$f" = src/include/rusagestub.h && continue
# sepgsql.h depends on headers that aren't there on most platforms.
test "$f" = contrib/sepgsql/sepgsql.h && continue
# These files are not meant to be included standalone, because
# they contain lists that might have multiple use-cases.
test "$f" = src/include/access/rmgrlist.h && continue
test "$f" = src/include/parser/kwlist.h && continue
test "$f" = src/pl/plpgsql/src/pl_reserved_kwlist.h && continue
test "$f" = src/pl/plpgsql/src/pl_unreserved_kwlist.h && continue
test "$f" = src/interfaces/ecpg/preproc/c_kwlist.h && continue
test "$f" = src/interfaces/ecpg/preproc/ecpg_kwlist.h && continue
test "$f" = src/include/regex/regerrs.h && continue
test "$f" = src/pl/plpgsql/src/plerrcodes.h && continue
test "$f" = src/pl/plpython/spiexceptions.h && continue
test "$f" = src/pl/tcl/pltclerrcodes.h && continue
# We can't make these Bison output files compilable standalone
# without using "%code require", which old Bison versions lack.
# parser/gram.h will be included by parser/gramparse.h anyway.
test "$f" = src/include/parser/gram.h && continue
test "$f" = src/backend/parser/gram.h && continue
test "$f" = src/pl/plpgsql/src/pl_gram.h && continue
test "$f" = src/interfaces/ecpg/preproc/preproc.h && continue
# This produces a "no previous prototype" warning.
test "$f" = src/include/storage/checksum_impl.h && continue
# ppport.h is not under our control, so we can't make it standalone.
test "$f" = src/pl/plperl/ppport.h && continue
# regression.h is not actually C, but ECPG code.
test "$f" = src/interfaces/ecpg/test/regression.h && continue
# printf_hack.h produces "unused function" warnings.
test "$f" = src/interfaces/ecpg/test/printf_hack.h && continue
# OK, create .c file to include this .h file.
{
test "$f" != src/include/postgres_fe.h && echo '#include "postgres.h"'
echo "#include \"$f\""
} >$tmp/test.c
# Some subdirectories need extra -I switches.
case "$f" in
src/pl/plperl/*)
EXTRAINCLUDES="$perl_includespec" ;;
src/pl/plpython/*)
EXTRAINCLUDES="$python_includespec" ;;
src/interfaces/ecpg/*)
EXTRAINCLUDES="-I $builddir/src/interfaces/ecpg/include -I $srcdir/src/interfaces/ecpg/include" ;;
*)
EXTRAINCLUDES="" ;;
esac
# Run the test.
${CC:-gcc} $CPPFLAGS $CFLAGS -I $builddir -I $srcdir \
-I $builddir/src/include -I $srcdir/src/include \
-I $builddir/src/interfaces/libpq -I $srcdir/src/interfaces/libpq \
$EXTRAINCLUDES $EXTRAFLAGS -c $tmp/test.c -o $tmp/test.o
done
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, andres@anarazel.de, alvherre@2ndquadrant.com, vignesh21@gmail.com
Subject: Re: Unused header file inclusion
In-Reply-To: <14803.1566175851@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox