Skip to content

treewide: run clang-format - #2085

Merged
gmarull merged 2 commits into
coredevices:mainfrom
teslabs:clang-format
Sep 16, 2026
Merged

gmarull merged 2 commits into
coredevices:mainfrom
teslabs:clang-format

Conversation

@gmarull

@gmarull gmarull commented Sep 16, 2026

Copy link
Copy Markdown
Member

Supersedes #2035 (thanks @nschonni for doing the groundwork).

Same intent as #2035, rebased on current main and with the config reduced to BasedOnStyle: Google plus the actual deviations instead of a full --dump-config dump. The dumped config differed from the Google preset in only 12 options, 3 of which are C++/Verilog-only, so the resulting formatting is identical for C (verified by running --dry-run --Werror with the #2035 config over the reformatted tree).

Deviations from Google, per the review in #2035:

  • ColumnLimit: 100, PointerAlignment: Right, SortIncludes: Never (as before)
  • all AllowShort*OnASingleLine off: functions, enums, ifs and loops always break
  • BreakAfterOpenBracketBracedList / BreakBeforeCloseBracketBracedList: braced initializers always break after { (no {.name = ... on one line)
  • AllowAllArgumentsOnNextLine: false
  • AlignConsecutiveMacros: Consecutive: consecutive #defines stay column-aligned (register maps, colour tables)
  • BreakStringLiterals: false: long strings are left as the author wrote them, so log / i18n messages stay greppable
  • BracedInitializerIndentWidth: 2 and SpacesBeforeTrailingComments: 1: match the prevailing style of the existing sources (measured over the tree), which cuts the reformat diff by ~16%

Other changes vs #2035:

  • protos follow the same single config (100 cols) instead of a separate Google-defaults Language: Proto section
  • generated bitmap data headers (demo_images/*, fps_test_bitmaps.h, test_bitmaps.h) are excluded via .clang-format-ignore, since the trailing /* bytes N - M */ comments made clang-format split every 16-byte row in two
  • tests/ is formatted too; only tests/fixtures/** is excluded. That is what broke test_kraepelin_algorithm in treewide: run clang-format #2035: it parses the step-sample fixtures as text and needs the { x, y, z} rows to keep their leading space
  • the CI job rebases onto the target branch like the other compliance jobs

Verification:

  • clang-format --dry-run --Werror (v22.1.8, same major as CI) is clean over all tracked .c/.h/.proto files
  • comment- and whitespace-stripped token streams are identical before/after for every file

🤖 Generated with Claude Code

@gmarull
gmarull requested a review from jplexer as a code owner September 16, 2026 13:00
@gmarull
gmarull force-pushed the clang-format branch 2 times, most recently from eada7a7 to 9e9ffcf Compare September 16, 2026 13:30
uses: ./.github/actions/rebase

- name: Run clang-format
uses: jidicula/clang-format-action@v4.18.0

@nschonni nschonni Sep 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, pinned to clang-format-version: "22".

Comment thread .clang-format-ignore Outdated
src/fw/apps/demo/demo_images/*
src/fw/apps/demo/fps_test_bitmaps.h
tools/clar/*
tests/**

@nschonni nschonni Sep 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traced it: test_kraepelin_algorithm parses the tests/fixtures/activity/step_samples/*.c files as text at runtime and only recognises a sample row when the first token is exactly { ({ -120, -376, -912},). Google's braced-list style drops that space, so the token became {-120,, zero samples were parsed and num_tests > 0 failed.

The fixtures are captured data whose layout is effectively the test's input format (and ~650k lines of pointless churn), so I now exclude only tests/fixtures/** and format the rest of tests/.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, changing my original message to a response doesn't send a notification, but glad you figured it out

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, we're not AGI yet then lol

@gmarull
gmarull force-pushed the clang-format branch 2 times, most recently from 759f225 to 4a0df20 Compare September 16, 2026 13:48
gmarull and others added 2 commits September 16, 2026 15:52
Keep the Google preset as the base and only list deviations. Compared to
the previous config, all the "short X on a single line" options are
disabled so functions, enums, ifs and loops always span multiple lines,
braced lists always break after the opening brace, call arguments are
not allowed to be moved as a whole to the next line, and consecutive
macro definitions are aligned so register maps and lookup tables stay
readable. String literals are never split so log and i18n messages
remain greppable.

Braced initializer members are indented by two columns and trailing
comments are separated by a single space, matching the prevailing
style of the existing sources.

Options that are already Google defaults (IndentWidth, UseTab) are
dropped. BreakAfterOpenBracketBracedList/BreakBeforeCloseBracketBracedList
require clang-format 22, which is what the CI action runs.

Template sources, generated bitmap data headers, the clar test framework
and the test fixtures are excluded from formatting via
.clang-format-ignore. The fixtures are captured data that some tests
parse as text at runtime, so their layout must not change.

Co-authored-by: Nick Schonning <nschonni@gmail.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Run clang-format 22 over every tracked C and proto source that is not
excluded by .clang-format-ignore. A second pass was needed on a handful
of files where trailing comment alignment is not stable after one run.

Co-authored-by: Nick Schonning <nschonni@gmail.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
@gmarull
gmarull merged commit b5dae34 into coredevices:main Sep 16, 2026
48 checks passed
@gmarull
gmarull deleted the clang-format branch September 16, 2026 14:14
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.

3 participants