Page MenuHomeFreeBSD

Update .clang-format with style(9) header-sorting
ClosedPublic

Authored by cem on Wed, Jun 24, 4:51 PM.

Details

Summary

Thanks to work done in the NetBSD clang-format project.

Test Plan

Example 1:

--- a/sys/kern/uipc_mbuf.c
+++ b/sys/kern/uipc_mbuf.c
@@ -34,105 +34,89 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");

-#include "opt_param.h"
-#include "opt_mbuf_stress_test.h"
 #include "opt_mbuf_profiling.h"
+#include "opt_mbuf_stress_test.h"
+#include "opt_param.h"

 #include <sys/param.h>
-#include <sys/systm.h>
+#include <sys/domain.h>
 #include <sys/kernel.h>
 #include <sys/limits.h>
 #include <sys/lock.h>
 #include <sys/malloc.h>
 #include <sys/mbuf.h>
-#include <sys/sysctl.h>
-#include <sys/domain.h>
 #include <sys/protosw.h>
+#include <sys/sdt.h>
+#include <sys/sysctl.h>
+#include <sys/systm.h>
 #include <sys/uio.h>
 #include <sys/vmmeter.h>
-#include <sys/sdt.h>
+
 #include <vm/vm.h>
-#include <vm/vm_pageout.h>
 #include <vm/vm_page.h>
+#include <vm/vm_pageout.h>

Example 2:

--- a/sys/x86/x86/mp_x86.c
+++ b/sys/x86/x86/mp_x86.c
@@ -39,12 +39,12 @@ __FBSDID("$FreeBSD$");
 #include "opt_stack.h"

 #include <sys/param.h>
-#include <sys/systm.h>
 #include <sys/bus.h>
-#include <sys/cons.h>  /* cngetc() */
+#include <sys/cons.h> /* cngetc() */
 #include <sys/cpuset.h>
 #include <sys/csan.h>
-#ifdef GPROF
+#include <sys/systm.h>
+#ifdef GPROF
 #include <sys/gmon.h>
 #endif
 #include <sys/kdb.h>
@@ -61,32 +61,33 @@ __FBSDID("$FreeBSD$");
 #include <sys/sysctl.h>

 #include <vm/vm.h>
-#include <vm/vm_param.h>
 #include <vm/pmap.h>
-#include <vm/vm_kern.h>
 #include <vm/vm_extern.h>
+#include <vm/vm_kern.h>
 #include <vm/vm_map.h>
+#include <vm/vm_param.h>

-#include <x86/apicreg.h>
 #include <machine/clock.h>
 #include <machine/cpu.h>
 #include <machine/cputypes.h>
-#include <x86/mca.h>
 #include <machine/md_var.h>
 #include <machine/pcb.h>
 #include <machine/psl.h>
 #include <machine/smp.h>
 #include <machine/specialreg.h>
 #include <machine/stack.h>
+
+#include <x86/apicreg.h>
+#include <x86/mca.h>
 #include <x86/ucode.h>

Any objections to the reordering, or suggestions for other test cases?

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

cem requested review of this revision.Wed, Jun 24, 4:51 PM
cem created this revision.
cem edited the test plan for this revision. (Show Details)Wed, Jun 24, 4:52 PM
cem added a reviewer: emaste.
emaste added a subscriber: dim.Wed, Jun 24, 4:54 PM
cem edited the test plan for this revision. (Show Details)Wed, Jun 24, 4:55 PM

I'm not sure off hand of other representative test cases - most likely we can just find them from user feedback as folks start using this.

cem updated this revision to Diff 73583.Wed, Jun 24, 4:57 PM

vm/vm.h must come before vm/pmap.h (and likely all other vm/ headers).

cem edited the test plan for this revision. (Show Details)Wed, Jun 24, 4:58 PM

(This is definitely not a complete style(9) .clang-format; the working goal is "less wrong than it was before.")

emaste added a subscriber: markj.Wed, Jun 24, 5:00 PM
markj accepted this revision.Wed, Jun 24, 5:19 PM

This seems reasonable to me. Thanks for doing it.

.clang-format
105 ↗(On Diff #73583)

I think it should be just `^<(fs|nfs|nfsclient|nfsserver|ufs)/'.

This revision is now accepted and ready to land.Wed, Jun 24, 5:19 PM
cem updated this revision to Diff 73585.Wed, Jun 24, 5:36 PM
cem marked an inline comment as done.

Drop miscfs/msdosfs and add nfs{client,server} to top-level include-ordering rule.

This revision now requires review to proceed.Wed, Jun 24, 5:36 PM
markj accepted this revision.Wed, Jun 24, 5:59 PM
This revision is now accepted and ready to land.Wed, Jun 24, 5:59 PM
This revision was automatically updated to reflect the committed changes.
dim added a comment.Wed, Jun 24, 8:28 PM

This is very nice to have codified, although I personally think our header ordering requirements are atrocious. ;-)