Tighten header pre-inclusions in headerscheck and cpluspluscheck.
authorTom Lane <[email protected]>
Sat, 4 Mar 2023 17:11:50 +0000 (12:11 -0500)
committerTom Lane <[email protected]>
Sat, 4 Mar 2023 17:11:50 +0000 (12:11 -0500)
commitf62975b2af6ace276a1d564a070b0aef479025af
tree659fa5bf2ab91da3e259faa36b3312a1faddba73
parentebd551f586a801dee426e49ba72fb213e8013890
Tighten header pre-inclusions in headerscheck and cpluspluscheck.

We allow our header files to depend on the appropriate one of
postgres.h, postgres_fe.h, or c.h having already been included.
However, there are a few headers such as libpq-fe.h that are
meant to be used by client applications and therefore must
compile without any assumptions about previous inclusions.
These test scripts failed to consider that, which seems quite
hazardous since we might not immediately notice such a problem
otherwise.  Hence, adjust these scripts to test relevant libpq
and ecpg headers with no prior inclusion.

While at it, we can also make an effort to actually use the
relevant one of postgres.h, postgres_fe.h, or c.h.  I added
some rules that guess which one to use based on the first-level
src subdirectory, e.g. use postgres_fe.h under src/bin/.
These rules are hardly water-tight but they seem to work today,
and we can always refine them in the future.

These changes don't reveal any live problems today, which is good,
but they should make these scripts more able to catch future bugs.

Discussion: https://postgr.es/m/2488193.1677863247@sss.pgh.pa.us
src/tools/pginclude/cpluspluscheck
src/tools/pginclude/headerscheck