VPP/CodeStyleConventions

From fd.io
< VPP
Revision as of 15:06, 6 August 2016 by Alagalah (Talk | contribs)

Jump to: navigation, search

Introduction

  • Link to mailer describing it.

DO I NEED TO APPLY STYLE ?

  • If you don't see this at the end of your [.ch] file:

/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

you need to apply style.

EMACS

  • There is an emacs skel for a set of emacs scripts that will auto-format

Essentially the idea is that the skeleton will put some comments in that EMACS script understands, apply a predefined format style, that more importantly than "GNU" or "Linux" or where "{" goes, DOESN'T MUCK UP MACROS!

Pre-processor macros are a key part of VPP and need special format attention.

C-code style for VPP is "gnu"

  • Load the emacs skel by either opening and "M-x eval-buffer" or "M-x load-file" ..
.../build-root/emacs-lisp/fix-coding-style.el
  • Now you should have a meta-function "M-x fd-io-styleify"
  • Run this against an active buffer containing the VPP code you wish to apply the style to.

You should see diffs of this sort:

+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (test_sr_debug, static) = {
    .path = "test sr debug",
    .short_help = "test sr debug on|off",
    .function = test_sr_debug_fn,
};
+/* *INDENT-ON* */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */

  • Save file and, assuming you have installed "indent" from apt/rpm, from a bash prompt:
indent <files>
  • Fix any warnings or errors
  • Here is an example of vnet/vnet/sr/sr.c.

After running the "fd-io-styleify", saving and "git diff"