Skip to content

OIL 41, F-5: every file includes what it uses - #113

Merged
theAndreas merged 8 commits into
mainfrom
oil-41-f5-include-cleaner
Nov 16, 2026
Merged

theAndreas merged 8 commits into
mainfrom
oil-41-f5-include-cleaner

Conversation

@theAndreas

Copy link
Copy Markdown
Owner

What

Nothing changes for a sketch: it still includes MaxMatrix.h alone, and every example is the same size. Every file of the repository now includes what it uses, as F-5 of docs/CodingStyle.md asks, and misc-include-cleaner checks it, which was the last check of the template still off (OIL 41).

Why

A file that gets a name only through another header breaks when that header changes, and does not say what it depends on. The check was off because its own fix names <cstdint>, which avr-gcc lacks, and <avr/pgmspace.h>, which the host's mock did not have.

  • The C library's headers are written as <stdint.h> and <stddef.h>, as the template and Utl write them.
  • MaxMatrix.h marks the headers whose names a sketch uses as exported, so that a sketch is not asked to include parts of the library. A sketch includes what it uses of avr-libc itself; the examples now include <stdint.h>, and <avr/pgmspace.h> where they keep a table in flash.
  • The mock has avr-libc's avr/pgmspace.h, avr/io.h and avr/interrupt.h, as the core has them, so the library includes the same headers on the host and the board.
  • Where the check takes an internal header for a name's provider (avr/common.h behind <avr/io.h>, glibc's bits/, Linux's asm-generic/, the GTK port of wxWidgets), .clang-tidy leaves it out, as the template already does for avr/io*.h; decided against a NOLINT on each of some 20 lines. avr/common.h is one for the template as well, whose pattern misses it.
  • Seven includes that nothing used are gone.

How it was checked

  • make check passes, make avr included, with 100 % of lines, branches and conditions.
  • make examples on main and on this branch: flash and RAM of every example are the same in all three variants.
  • make check without a change afterwards: 100 s, as after the template's v0.11.1.
  • The transfer code only gained includes; nothing ran on hardware.

PROGMEM and the reads from flash in avr/pgmspace.h, SREG in avr/io.h and
cli() in avr/interrupt.h, which Arduino.h includes as the core's does. A
file of the library can then include what it uses (F-5) and compile on the
host and the board alike.
A sketch includes MaxMatrix.h alone, and names ModuleType, Sprite, Byte,
make_array() and the rest through it. // IWYU pragma: export says so to
misc-include-cleaner (F-5), which would otherwise ask a sketch for
Matrix/Panel.h or Utility/array.h.
<stdint.h> and <stddef.h> rather than <cstdint>, which avr-gcc lacks;
<avr/pgmspace.h> for PROGMEM and the reads from flash, <avr/io.h> and
<avr/interrupt.h> for SREG and cli(). MaxMatrixErrorReport.cpp includes
MaxMatrixError.h only where it uses it, with MAXMATRIX_DEV_ERROR_DETECT,
and keeps MaxMatrixConfig.h, whose switch the build may set with -D.
…F-5)

The rest of what a sketch names comes through MaxMatrix.h.
MaxMatrixTestSupport.h exports MaxMatrix.h, so that a test reaches the
library through it alone: one that included Font/Font.h itself would have
it sorted before #define private public. The headers of GoogleTest, the
mock and the model each test includes itself. <fcntl.h> and <arpa/inet.h>
went where nothing used them: htons() comes with <netinet/in.h>.
<arpa/inet.h>, <stdio.h> and <array> went where nothing used them. Four
headers of wxWidgets that include only the port's header, and <sys/time.h>
for timeval, which glibc declares in bits/, stay with // IWYU pragma: keep.
IgnoreHeaders leaves out what a public header includes and include-cleaner
takes for a name's provider, as the template does for avr/io*.h:
avr/common.h, glibc's bits/ and sys/poll.h, Linux's asm-generic/ and the
GTK port of wxWidgets. Decided against a NOLINT on each of some 20 lines.
@theAndreas
theAndreas merged commit 61274a8 into main Nov 16, 2026
12 checks passed
@theAndreas
theAndreas deleted the oil-41-f5-include-cleaner branch November 16, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants