Hi everyone,

For fun(?), I have come up with a clang-format file that's pretty darn
close to our current style.

However, the problem is that most of our files don't actually meet our
style guide! :'( So, running this clang-format generates an enormous
changeset. Skimming through the (100,000+) changes clang-format makes all
of them look "correct" to me. But I didn't check them all, just a few
spot-checks.

I've put together a WIP commit as an example of what it looks like to run
clang-format on gem5. There are a few caveats, however.

1. BitUnion really confuses clang-format for two reasons: (1) We indent the
code inside the BitUntion macro. (2) there are no semicolons after the
macro calls for BitUnion and EndBitUntion.
2. There are a few lines that go over 79 characters, but they're easy to
manually fix (it's only 4 files).
3. When I ran style.py on all files in src/ there were a huge number that
had invalid sorting of includes. In at least one case, this causes compiler
failures when I let style.py fix it.
4. I'm skipping sorting includes with clang-format right now. There is a
way to specify the blocks that we define, but I don't want to dive into
this right now. I'll create a Jira issue so we can come back to it.

Finally, I'm using the following shell script to test things. This runs sed
to tell clang-format to ignore the BitUnion blocks, runs clang-format, and
then undoes the sed script.

If this seems like something we want to continue with, then I'll commit
these changes and we can add clang-format to the commit hooks.

Clang-format file:
https://gem5-review.googlesource.com/c/public/gem5/+/49063
The giant changeset:
https://gem5-review.googlesource.com/c/public/gem5/+/49064/

The script I used (don't judge my sed ability :D):
```
# Make clang-format ignore bitunions
grep -r -l BitUnion src | xargs sed -i -e '/^ *BitUnion.*(.*)/i \
// clang-format off' -e '/^ *EndBitUnion(.*)/a; \
// clang-format on'

# undo the change to the bitunion file
git checkout src/base/bitunion.hh

# Run clang format
find src -name "*.cc" -or -name "*.hh" -exec clang-format -style=file -i {}
\;

# Remove clang-format off in BitUnion files
grep -r -l BitUnion src | xargs sed -i -e '/^ *\/\/ clang-format.*$/d' -e
'/^; *$/d'
```

Cheers,
Jason
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to