netatalk icon indicating copy to clipboard operation
netatalk copied to clipboard

Add scripts for reformatting C and meson code

Open rdmark opened this issue 8 months ago • 4 comments

The new shell scripts depend on GNU indent, muon and git, and will return 0 if no code was modified, and 1 if the code was modified meaning that it wasn't compliant with the indent rules or muon's opinionated coding style

These checks now runs in the CI workflow as well

Depends on muon 0.4.0 or later and GNU indent 2.2.13 or later

Note that we have been using muon for this purpose at an ad-hoc basis for a long time, and this just formalized/automates it. See https://github.com/Netatalk/netatalk/wiki/Developer-Notes#formatting

rdmark avatar May 05 '25 21:05 rdmark

I encountered a significant drawback with using astyle and muon to enforce coding style. Namely, that different versions of these style checkers produce significantly different results. For instance, the latest Debian Trixie pre-release ships astyle 3.1, while Homebrew on macOS provides 3.6.9. With the same rc file, the two produce different formatting.

Right now, the only solution I can think of would be to mandate a specific canonical version of each and use that for styling exclusively. We don't want to have a bunch of noise in the commit history caused by going back and forth between style checker versions.

This also means that it will be cumbersome to enforce style checks in CI, since there's no guarantee that each and every contributor will be able to run the specific style checker version that we mandate, and therefore not able to address their own stylistic infractions effectively.

We may want to continue researching more stable C formatters, in particular.

rdmark avatar May 05 '25 23:05 rdmark

Curiously, even when running the exact same astyle version, 3.6.9 on macOS (homebrew) locally vs. in the GitHub workflow, we are getting different formatting results. There must be something environmental that affects how astyle interprets the rules.

rdmark avatar May 06 '25 06:05 rdmark

Repurposed this PR to only cover meson code reformatting with muon.

Note that the GitHub CI job for Formatting is currently using the macOS runner because 1) meson in Ubuntu 24.04 is too old (0.3.0) and produces non-compliant output and 2) we cannot use container images as runners because GitHub will not clone the netatalk git repo in the checkout workflow but rather fetch a zip archive (we rely on git to track changes after running muon). The proper solution would be for us to build our own runner container for this purpose that comes with git and muon 0.4.0 pre-installed. A project for another day.

rdmark avatar May 07 '25 05:05 rdmark

After additional experimentation, I'm back to using astyle 3.6.9 as the C code formatter. The discrepancies with v3.1 are not that many, and when scrutinizing the diff, all clear improvements (bugfixes in astyle).

As to what appeared to be environment discrepancies, turned out to be a matter of a handful of changes that took effect only upon a second run of the formatter. These were changes to particular lines that had gotten line breaks in the first round, and therefore subsequent changes to the latter fragment of the same line fell off.

To deal with the fact that v3.6.9 isn't available by default on many platforms yet, I have added verbose diff output in the CI logs, so that contributors can see exactly which changes are needed in case they have to make the edits by hand.

rdmark avatar May 10 '25 21:05 rdmark

Quality Gate Failed Quality Gate failed

Failed conditions
49 Security Hotspots

See analysis details on SonarQube Cloud

sonarqubecloud[bot] avatar May 12 '25 06:05 sonarqubecloud[bot]

This PR seems to have accidentally reverted my nbplkup patches

cheesestraws avatar May 17 '25 21:05 cheesestraws

Pardon, my effort to rebase with main clearly failed.

I pushed a commit directly to main that should bring this back: https://github.com/Netatalk/netatalk/commit/8aaf34f4f7fc37b89286c7eb74fd162f95c33948

Please let me know if anything else is missing.

rdmark avatar May 18 '25 07:05 rdmark

Looks like 2164 is missing also

cheesestraws avatar May 20 '25 20:05 cheesestraws

It looks like it was only the sort order of header includes in nbplkup.c that got reverted. Fixed with direct commit to main:

https://github.com/Netatalk/netatalk/commit/a771359e8542329496c74b6ee43df2ab66ec1442

rdmark avatar May 20 '25 21:05 rdmark

Cheers! I thought the PAP change had gone walkies too but that was me misreading - apologies

cheesestraws avatar May 20 '25 21:05 cheesestraws