-
Notifications
You must be signed in to change notification settings - Fork 570
Clang‐format
This page contains some notes for working with clang-format.
Clang-format has a large number of options to tune the formatting: https://clang.llvm.org/docs/ClangFormatStyleOptions.html
The clang format configuration file for the MueLu package can be found at https://github.com/trilinos/Trilinos/blob/master/packages/muelu/.clang-format .
PRs that contain code changes to packages/muelu/
are checked using the action at
https://github.com/trilinos/Trilinos/blob/master/.github/workflows/muelu_clang_format.yml
https://pre-commit.com allows to run clang-format locally.
Create a file .pre-commit-config.yaml
in the root of the Trilinos source tree:
files: "packages/(muelu|tempus)/.*pp"
exclude: "packages/tempus/examples/.*"
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v14.0.1
hooks:
- id: clang-format
types_or: [c++, c, cuda]
Then install pre-commit via
python3 -m pip install pre-commit
pre-commit install
On Mac one can also install pre-commit via
brew install pre-commit
NOTE: Please do not commit the file .pre-commit-config.yaml
.
The first run of clang-format can make a lot of changes. In order to not spoil git-blame
we maintain a list of these commits in .git-blame-ignore-revs
. In order to configure git to ignore them, simply do:
git config blame.ignoreRevsFile .git-blame-ignore-revs
- Create a configuration file
.clang-format
underpackages/myPackage
. See https://github.com/trilinos/Trilinos/blob/master/packages/muelu/.clang-format for an example. - Run
clang-format
for the first time. Please make sure you are using a clang-format version 14 as the output can differ between versions. One simple way to achieve this is to use pre-commit viapre-commit run --all-files
. Just make sure thatpackages/myPackage
is listed in the pre-commit configuration. - Commit the changes (the new
.clang-format
and the code changes; do not commit.pre-commit-config.yaml
). - Add the SHA for the previous commit to https://github.com/trilinos/Trilinos/blob/master/.git-blame-ignore-revs so that the formatting changes are ignored by git-blame.
- Add
./packages/myPackage
to thesource
field in https://github.com/trilinos/Trilinos/blob/master/.github/workflows/muelu_clang_format.yml
Copyright © Trilinos a Series of LF Projects, LLC
For web site terms of use, trademark policy and other project policies please see https://lfprojects.org.
Trilinos Developer Home
Trilinos Package Owners
Policies
New Developers
Trilinos PR/CR
Productivity++
Support Policy
Test Dashboard Policy
Testing Policy
Managing Issues
New Issue Quick Ref
Handling Stale Issues and Pull Requests
Release Notes
Software Quality Plan
Proposing a New Package
Guidance on Copyrights and Licenses
Tools
CMake
Doxygen
git
GitHub Notifications
Mail lists
Clang-format
Version Control
Initial git setup
'feature'/'develop'/'master' (cheatsheet)
Simple centralized workflow
Building
SEMS Dev Env
Mac OS X
ATDM Platforms
Containers
Development Tips
Automated Workflows
Testing
Test Harness
Pull Request Testing
Submitting a Pull Request
Pull Request Workflow
Reproducing PR Errors
Addressing Test Failures
Trilinos Status Table Archive
Pre-push (Checkin) Testing
Remote pull/test/push
PR Creation & Approval Guidelines for Tpetra, Ifpack2, and MueLu Developers