Skip to content

Include guard rules (if mandated) should be documented and handled by software #80781

@ajf58

Description

@ajf58

Is your enhancement proposal related to a problem? Please describe.

At review-time, a disproportionate amount of time is spent by contributors and reviewers discussing include guards. There are a number of problems with this:

  1. This is not documented in the Contribution Guidelines.
    The guidelines defer to the Linux kernel coding style, which does not define or enforce the style. Contributors can't know this expectation in advance of doing their work. This is a problem because it is demotivating for Contributors, and a problem for the project because it slows development down.
  2. The codebase is inconsistent.
    This in itself would not be a problem if (1) was in effect, but there's also no way for a Contributor to look at prior-art and determine what they've done is wrong.

Describe the solution you'd like

  1. Defer to the kernel coding style.
    Perhaps the easiest solution. Unless there's a technical reason that the Contributor's choice of include guard is a problem, leave it alone.
  2. If there's a mandated requirement,
    1. Define and Document it.
      Allow Contributors to know what they're expected to do before they invest their own time and effort in the codebase. They may decide, based on this, whether they want to contribute at all.
    2. Provide hooks for checking it:
      1. A client side pre-commit (or pre-push) hook could determine whether a changed file is a header, and if the include guard matches the defined style.
      2. Extend the Compliance Checks to also check this.
        Contributors may not be willing or able to run the client-side hooks, so check this.
    3. Provide scripts for fixing it:
      1. This is akin to the code-formatting hints already provided by CI. Hint at a solution, and provide a script to do the work.
    4. Define and implement a plan for the existing codebase.
      Are existing files going to remain incosistent, or will they be fixed in a treewide tidy up, or as-and-when they are touched?

Describe alternatives you've considered

Continue the status-quo, (existing codebase remains inconsistent, add-hoc review-time requests to change files occur).

Additional context

A good example of the self-inconsistent codebase can be seen in a single directory:

$ grep -hr -m1 '#ifndef' include/zephyr/dt-bindings/pinctrl/ | sort

which presents ~8 different conventions.

Metadata

Metadata

Labels

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions