git: dd55767b86bc - main - Test various header files to ensure they can be included by themselves.

From: Warner Losh <imp_at_FreeBSD.org>
Date: Wed, 15 Dec 2021 03:26:09 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=dd55767b86bc40700d11cf0325744a4ec0a774fd

commit dd55767b86bc40700d11cf0325744a4ec0a774fd
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2021-12-14 23:55:20 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2021-12-15 03:25:37 +0000

    Test various header files to ensure they can be included by themselves.
    
    A number of header files in sys/* have, going back to 7th Edition Unix
    in 1979, reqiured other files (like sys/types.h) to compile. Likewise
    the 4BSD networking code has had prerequisites. However, going back to
    around the turn of the 21st century, other systems have made them be
    independently include-able (wide-spread header include protection
    post-dates 7th edition Unix by maybe 3 or so years judging from USENET
    source postings). Start down the path of making them all independently
    include-able by creating this test that fails buildworld when they are
    not.
    
    The file 'badfiles.inc' contains a list of the currently broken files
    that cannot be included w/o any prerequisites. As files are fixed, 'make
    badfiles.inc' should be re-run to remove them from the list. Note: All
    files that start with an underscore are considered internal and not
    tested.
    
    Please note: once a file is removed from badfiles.inc, it must pass on
    all architectures. Buildworld through at least the _includes target is
    needed to ensure its working (though a buildkernel should also be done
    on all architectures as well).
    
    Sponsored by:           Netflix
    Reviewed by:            brooks, markj
    Differential Revision:  https://reviews.freebsd.org/D32498
---
 Makefile                               |   7 +-
 Makefile.inc1                          |   6 +
 UPDATING                               |   4 +
 tools/build/test-includes/Makefile     |  52 +++++
 tools/build/test-includes/badfiles.inc | 343 +++++++++++++++++++++++++++++++++
 5 files changed, 409 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 0ee8f8ed0f7f..19452e0c0ad0 100644
--- a/Makefile
+++ b/Makefile
@@ -164,7 +164,8 @@ TGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
 	stage-packages stage-packages-kernel stage-packages-world \
 	create-packages-world create-packages-kernel create-packages \
 	update-packages packages installconfig real-packages real-update-packages \
-	sign-packages package-pkg print-dir test-system-compiler test-system-linker
+	sign-packages package-pkg print-dir test-system-compiler test-system-linker \
+	test-includes
 
 # These targets require a TARGET and TARGET_ARCH be defined.
 XTGTS=	native-xtools native-xtools-install xdev xdev-build xdev-install \
@@ -188,8 +189,8 @@ TGTS+=	${BITGTS}
 META_TGT_WHITELIST+= \
 	_* build32 buildfiles buildincludes buildkernel buildsoft \
 	buildworld everything kernel-toolchain kernel-toolchains kernel \
-	kernels libraries native-xtools showconfig test-system-compiler \
-	test-system-linker tinderbox toolchain \
+	kernels libraries native-xtools showconfig test-includes \
+	test-system-compiler test-system-linker tinderbox toolchain \
 	toolchains universe universe-toolchain world worlds xdev xdev-build
 
 .ORDER: buildworld installworld
diff --git a/Makefile.inc1 b/Makefile.inc1
index 81a3ae15c3a2..963ffac7d09b 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -1128,6 +1128,7 @@ _includes:
 .if !empty(SUBDIR_OVERRIDE) && make(buildworld)
 	${_+_}cd ${.CURDIR}; ${WMAKE} MK_INCLUDES=yes SHARED=symlinks includes
 .endif
+	${_+_}cd ${.CURDIR};  ${WMAKE} test-includes
 _libraries:
 	@echo
 	@echo "--------------------------------------------------------------"
@@ -1503,6 +1504,11 @@ makeman: .PHONY
 	${_+_}cd ${.CURDIR}/tools/build/options; sh makeman > \
 	    ${.CURDIR}/share/man/man5/src.conf.5
 
+# Ensure no regressions in self-includeability of sys/*.h and net*/*.h
+test-includes: .PHONY
+	${_+_}cd ${.CURDIR}/tools/build/test-includes; \
+	    ${WMAKEENV} ${MAKE} ${WORLD_FLAGS} DESTDIR=${WORLDTMP} test-includes
+
 # We can't assume here that ${TMPPATH} will include ${PATH} or /usr/libexec
 # because we may be building with a STRICTTMPPATH, so we explicitly include
 # /usr/libexec here for flua.  ${TMPPATH} still usefully includes anything else
diff --git a/UPDATING b/UPDATING
index df3e35056ff3..707787cd8860 100644
--- a/UPDATING
+++ b/UPDATING
@@ -27,6 +27,10 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 14.x IS SLOW:
 	world, or to merely disable the most expensive debugging functionality
 	at runtime, run "ln -s 'abort:false,junk:false' /etc/malloc.conf".)
 
+20211214:
+	A number of the kernel include files are able to be included by
+	themselves.  A test has been added to buildworld to enforce this.
+
 20211209:
 	Remove mips as a recognized target. This starts the decommissioning of
 	mips support in FreeBSD. mips related items will be removed wholesale in
diff --git a/tools/build/test-includes/Makefile b/tools/build/test-includes/Makefile
new file mode 100644
index 000000000000..b42497e0397d
--- /dev/null
+++ b/tools/build/test-includes/Makefile
@@ -0,0 +1,52 @@
+#
+# A number of header files in sys/* have, going back to 7th Edition Unix in
+# 1979, reqiured other files (like sys/types.h) to compile. Likewise the 4BSD
+# networking code has had prerequisites. However, going back to around the turn
+# of the century, other systems have made them be independently includable
+# (wide-spread header include protection post-dates 7th edition Unix by maybe 4
+# or 5 years judging from netnews sources). Start down the path of making them
+# all independently includable by creating this test that fails buildworld when
+# they are not.
+#
+# The _foo.h files are excluded as they are internal-only headers and/or have
+# special requirements. Since the purpose of this is to allow autoconfig
+# programs to detect FreeBSD has different headers, omitting internal
+# headers cuts down on the noise w/o causing problems for the goal.
+#
+PROG=	test-includes
+SRCS=	test-includes.c
+INTERNALPROG=	This is a compile-only test
+MAN=
+HDRS!=	(cd ${SRCTOP}/sys; ls sys/[^_]*.h net*/[^_]*.h)
+
+# Some files have to be clean for extra defines too...
+CFLAGS.event.c=	-D_WANT_KEVENT32 -D_WANT_FREEBSD11_KEVENT
+
+.include "badfiles.inc"
+
+.for h in ${HDRS}
+.if !${BADHDRS:M${h}}
+SRCS+=	${h:R}.c
+CLEANFILES+=${h:R}.c
+${h:R}.c:
+	echo "#include <$h>" > ${.TARGET}
+.endif
+.endfor
+
+#
+# Target to make the current known bad list. In general, this list should only
+# ever shrink and never grow.
+#
+.PHONY:	badfiles.inc
+badfiles.inc:
+	@(cd ${SRCTOP}/sys;							\
+	echo "# DO NOT EDIT-- this file is automatically @""generated.";	\
+	echo "BADHDRS= \\";							\
+	for i in sys/*.h net*/*.h; do						\
+		echo "#include <$$i>" |						\
+			${CC} ${CFLAGS} -xc - -c -o /dev/null 2> /dev/null ||	\
+			echo "	$$i \\";					\
+	done;									\
+	echo) > ${.CURDIR}/badfiles.inc
+
+.include <bsd.prog.mk>
diff --git a/tools/build/test-includes/badfiles.inc b/tools/build/test-includes/badfiles.inc
new file mode 100644
index 000000000000..afc0c1c5394d
--- /dev/null
+++ b/tools/build/test-includes/badfiles.inc
@@ -0,0 +1,343 @@
+# DO NOT EDIT-- this file is automatically @generated.
+BADHDRS= \
+	sys/aac_ioctl.h \
+	sys/agpio.h \
+	sys/atomic_common.h \
+	sys/atomic_san.h \
+	sys/bio.h \
+	sys/bitstring.h \
+	sys/blist.h \
+	sys/buf.h \
+	sys/buf_ring.h \
+	sys/bus.h \
+	sys/bus_dma.h \
+	sys/bus_dma_internal.h \
+	sys/bus_san.h \
+	sys/busdma_bufalloc.h \
+	sys/callout.h \
+	sys/caprights.h \
+	sys/cdrio.h \
+	sys/cfictl.h \
+	sys/conf.h \
+	sys/cons.h \
+	sys/copyright.h \
+	sys/counter.h \
+	sys/coverage.h \
+	sys/cpu.h \
+	sys/cpuctl.h \
+	sys/cpuset.h \
+	sys/devmap.h \
+	sys/disk_zone.h \
+	sys/domain.h \
+	sys/domainset.h \
+	sys/dtrace_bsd.h \
+	sys/dvdio.h \
+	sys/efi.h \
+	sys/efiio.h \
+	sys/elf32.h \
+	sys/elf64.h \
+	sys/elf_common.h \
+	sys/elf_generic.h \
+	sys/epoch.h \
+	sys/eui64.h \
+	sys/eventhandler.h \
+	sys/eventvar.h \
+	sys/exec.h \
+	sys/extattr.h \
+	sys/fail.h \
+	sys/filedesc.h \
+	sys/firmware.h \
+	sys/fnv_hash.h \
+	sys/font.h \
+	sys/gmon.h \
+	sys/gpio.h \
+	sys/gtaskqueue.h \
+	sys/hhook.h \
+	sys/iconv.h \
+	sys/imgact.h \
+	sys/imgact_aout.h \
+	sys/imgact_elf.h \
+	sys/interrupt.h \
+	sys/intr.h \
+	sys/ioctl_compat.h \
+	sys/iov.h \
+	sys/iov_schema.h \
+	sys/ipmi.h \
+	sys/jail.h \
+	sys/kdb.h \
+	sys/kernel.h \
+	sys/khelp.h \
+	sys/kobj.h \
+	sys/ksem.h \
+	sys/ktls.h \
+	sys/ktrace.h \
+	sys/libkern.h \
+	sys/link_aout.h \
+	sys/linker.h \
+	sys/linker_set.h \
+	sys/lock.h \
+	sys/lock_profile.h \
+	sys/lockf.h \
+	sys/lockmgr.h \
+	sys/loginclass.h \
+	sys/mac.h \
+	sys/mbuf.h \
+	sys/md4.h \
+	sys/md5.h \
+	sys/mdioctl.h \
+	sys/memdesc.h \
+	sys/memrange.h \
+	sys/module.h \
+	sys/module_khelp.h \
+	sys/mpt_ioctl.h \
+	sys/msgbuf.h \
+	sys/mutex.h \
+	sys/namei.h \
+	sys/osd.h \
+	sys/pciio.h \
+	sys/pctrie.h \
+	sys/physmem.h \
+	sys/pipe.h \
+	sys/pmc.h \
+	sys/pmckern.h \
+	sys/pmclog.h \
+	sys/posix4.h \
+	sys/power.h \
+	sys/priority.h \
+	sys/prng.h \
+	sys/proc.h \
+	sys/qmath.h \
+	sys/racct.h \
+	sys/refcount.h \
+	sys/resourcevar.h \
+	sys/rman.h \
+	sys/rmlock.h \
+	sys/rtprio.h \
+	sys/runq.h \
+	sys/rwlock.h \
+	sys/sbuf.h \
+	sys/sema.h \
+	sys/sf_buf.h \
+	sys/sglist.h \
+	sys/sigio.h \
+	sys/signalvar.h \
+	sys/smr.h \
+	sys/smr_types.h \
+	sys/socketvar.h \
+	sys/sockopt.h \
+	sys/stack.h \
+	sys/stats.h \
+	sys/sx.h \
+	sys/syscallsubr.h \
+	sys/syslimits.h \
+	sys/systm.h \
+	sys/taskqueue.h \
+	sys/terminal.h \
+	sys/termios.h \
+	sys/tiio.h \
+	sys/timeb.h \
+	sys/timeet.h \
+	sys/timeffc.h \
+	sys/timepps.h \
+	sys/timetc.h \
+	sys/ttydevsw.h \
+	sys/ttydisc.h \
+	sys/ttyhook.h \
+	sys/ttyqueue.h \
+	sys/umtx.h \
+	sys/unpcb.h \
+	sys/user.h \
+	sys/vdso.h \
+	sys/vmmeter.h \
+	sys/vnode.h \
+	net/bpf.h \
+	net/bpf_buffer.h \
+	net/bpf_jitter.h \
+	net/bpf_zerocopy.h \
+	net/bpfdesc.h \
+	net/bridgestp.h \
+	net/debugnet_int.h \
+	net/ethernet.h \
+	net/firewire.h \
+	net/if_arp.h \
+	net/if_bridgevar.h \
+	net/if_dl.h \
+	net/if_enc.h \
+	net/if_lagg.h \
+	net/if_llatbl.h \
+	net/if_llc.h \
+	net/if_media.h \
+	net/if_mib.h \
+	net/if_pflog.h \
+	net/if_pfsync.h \
+	net/if_sppp.h \
+	net/if_stf.h \
+	net/if_tap.h \
+	net/if_tun.h \
+	net/if_var.h \
+	net/if_vlan_var.h \
+	net/iflib.h \
+	net/iflib_private.h \
+	net/ifq.h \
+	net/mp_ring.h \
+	net/mppc.h \
+	net/netisr.h \
+	net/netisr_internal.h \
+	net/netmap.h \
+	net/netmap_legacy.h \
+	net/paravirt.h \
+	net/pfil.h \
+	net/pfkeyv2.h \
+	net/pfvar.h \
+	net/radix.h \
+	net/raw_cb.h \
+	net/rndis.h \
+	net/route.h \
+	net/rss_config.h \
+	net/slcompress.h \
+	net/toeplitz.h \
+	net80211/ieee80211.h \
+	net80211/ieee80211_action.h \
+	net80211/ieee80211_adhoc.h \
+	net80211/ieee80211_ageq.h \
+	net80211/ieee80211_alq.h \
+	net80211/ieee80211_amrr.h \
+	net80211/ieee80211_crypto.h \
+	net80211/ieee80211_dfs.h \
+	net80211/ieee80211_freebsd.h \
+	net80211/ieee80211_hostap.h \
+	net80211/ieee80211_ht.h \
+	net80211/ieee80211_input.h \
+	net80211/ieee80211_ioctl.h \
+	net80211/ieee80211_mesh.h \
+	net80211/ieee80211_monitor.h \
+	net80211/ieee80211_node.h \
+	net80211/ieee80211_power.h \
+	net80211/ieee80211_proto.h \
+	net80211/ieee80211_radiotap.h \
+	net80211/ieee80211_ratectl.h \
+	net80211/ieee80211_rssadapt.h \
+	net80211/ieee80211_scan.h \
+	net80211/ieee80211_scan_sw.h \
+	net80211/ieee80211_sta.h \
+	net80211/ieee80211_superg.h \
+	net80211/ieee80211_tdma.h \
+	net80211/ieee80211_var.h \
+	net80211/ieee80211_vht.h \
+	net80211/ieee80211_wds.h \
+	netgraph/netgraph.h \
+	netgraph/ng_async.h \
+	netgraph/ng_bpf.h \
+	netgraph/ng_bridge.h \
+	netgraph/ng_car.h \
+	netgraph/ng_checksum.h \
+	netgraph/ng_cisco.h \
+	netgraph/ng_deflate.h \
+	netgraph/ng_etf.h \
+	netgraph/ng_hole.h \
+	netgraph/ng_ksocket.h \
+	netgraph/ng_l2tp.h \
+	netgraph/ng_lmi.h \
+	netgraph/ng_macfilter.h \
+	netgraph/ng_message.h \
+	netgraph/ng_mppc.h \
+	netgraph/ng_nat.h \
+	netgraph/ng_one2many.h \
+	netgraph/ng_parse.h \
+	netgraph/ng_patch.h \
+	netgraph/ng_pipe.h \
+	netgraph/ng_ppp.h \
+	netgraph/ng_pppoe.h \
+	netgraph/ng_pptpgre.h \
+	netgraph/ng_pred1.h \
+	netgraph/ng_sample.h \
+	netgraph/ng_socket.h \
+	netgraph/ng_socketvar.h \
+	netgraph/ng_source.h \
+	netgraph/ng_tag.h \
+	netgraph/ng_tcpmss.h \
+	netgraph/ng_tee.h \
+	netgraph/ng_vjc.h \
+	netgraph/ng_vlan.h \
+	netgraph/ng_vlan_rotate.h \
+	netgraph/qos.h \
+	netinet/dccp.h \
+	netinet/icmp6.h \
+	netinet/icmp_var.h \
+	netinet/if_ether.h \
+	netinet/igmp.h \
+	netinet/igmp_var.h \
+	netinet/in_fib.h \
+	netinet/in_kdtrace.h \
+	netinet/in_pcb.h \
+	netinet/in_pcb_var.h \
+	netinet/in_rss.h \
+	netinet/in_systm.h \
+	netinet/in_var.h \
+	netinet/ip.h \
+	netinet/ip6.h \
+	netinet/ip_carp.h \
+	netinet/ip_dummynet.h \
+	netinet/ip_fw.h \
+	netinet/ip_icmp.h \
+	netinet/ip_mroute.h \
+	netinet/ip_options.h \
+	netinet/ip_var.h \
+	netinet/pim_var.h \
+	netinet/sctp_auth.h \
+	netinet/sctp_bsd_addr.h \
+	netinet/sctp_kdtrace.h \
+	netinet/sctp_os.h \
+	netinet/sctp_os_bsd.h \
+	netinet/sctp_pcb.h \
+	netinet/sctp_structs.h \
+	netinet/sctp_sysctl.h \
+	netinet/tcp_debug.h \
+	netinet/tcp_hpts.h \
+	netinet/tcp_log_buf.h \
+	netinet/tcp_lro.h \
+	netinet/tcp_offload.h \
+	netinet/tcp_pcap.h \
+	netinet/tcp_ratelimit.h \
+	netinet/tcp_var.h \
+	netinet/tcpip.h \
+	netinet/toecore.h \
+	netinet/udp.h \
+	netinet/udp_var.h \
+	netinet/udplite.h \
+	netinet6/icmp6.h \
+	netinet6/in6.h \
+	netinet6/in6_fib.h \
+	netinet6/in6_rss.h \
+	netinet6/in6_var.h \
+	netinet6/ip6.h \
+	netinet6/ip6_mroute.h \
+	netinet6/ip6_var.h \
+	netinet6/ip6protosw.h \
+	netinet6/ip_fw_nat64.h \
+	netinet6/ip_fw_nptv6.h \
+	netinet6/mld6.h \
+	netinet6/mld6_var.h \
+	netinet6/nd6.h \
+	netinet6/pim6.h \
+	netinet6/pim6_var.h \
+	netinet6/raw_ip6.h \
+	netinet6/send.h \
+	netipsec/ah.h \
+	netipsec/ah_var.h \
+	netipsec/esp.h \
+	netipsec/esp_var.h \
+	netipsec/ipcomp.h \
+	netipsec/ipcomp_var.h \
+	netipsec/ipsec.h \
+	netipsec/ipsec6.h \
+	netipsec/key_debug.h \
+	netipsec/keysock.h \
+	netipsec/xform.h \
+	netsmb/netbios.h \
+	netsmb/smb.h \
+	netsmb/smb_conn.h \
+	netsmb/smb_rq.h \
+	netsmb/smb_subr.h \
+	netsmb/smb_tran.h \
+