Skip to content

Commit 8482b35

Browse files
committed
Add information about using clang-format
1 parent 1dcc82c commit 8482b35

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

COMPILING.md

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# What architecture?
1+
# WHAT ARCHITECTURE?
22

33
CPROVER now needs a C++11 compliant compiler and works in the following
44
environments:
@@ -236,3 +236,73 @@ This will:
236236
2) Run all the regression tests
237237
3) Collate the coverage metrics
238238
4) Provide an HTML report of the current coverage
239+
240+
# USING CLANG-FORMAT
241+
242+
CBMC uses clang-format to ensure that the formatting of new patches is readable
243+
and consistent. There are two main ways of running clang-format: remotely, and
244+
locally.
245+
246+
## RUNNING CLANG-FORMAT REMOTELY
247+
248+
When patches are submitted to CBMC, they are automatically run through
249+
continuous integration (CI). One of the CI checks will run clang-format over
250+
the diff that your pull request introduces. If clang-format finds formatting
251+
issues at this point, the build will be failed, and a patch will be produced
252+
in the CI output that you can apply to your code so that it conforms to the
253+
style guidelines.
254+
255+
To apply the patch, copy and paste it into a local file (`patch.txt`) and then
256+
run:
257+
```
258+
patch -p1 -i patch.txt
259+
```
260+
Now, you can commit and push the formatting fixes.
261+
262+
## RUNNING CLANG-FORMAT LOCALLY
263+
264+
### INSTALLATION
265+
266+
To avoid waiting until you've made a PR to find formatting issues, you can
267+
install clang-format locally and run it against your code as you are working.
268+
269+
Different versions of clang-format have slightly different behaviors. CBMC uses
270+
clang-format-3.8 as it is available the repositories for Ubuntu 16.04 and
271+
Homebrew.
272+
To install, run:
273+
```
274+
sudo apt install clang-format-3.8 # Run this on Ubuntu, Debian etc.
275+
brew install clang-format-3.8 # Run this on a Mac with Homebrew installed
276+
```
277+
278+
### FORMATTING A RANGE OF COMMITS
279+
280+
Clang-format is distributed with a driver script called git-clang-format-3.8.
281+
This script can be used to format git diffs (rather than entire files).
282+
283+
After committing some code, it is recommended to run:
284+
```
285+
git-clang-format-3.8 upstream/develop
286+
```
287+
*Important:* If your branch is based on a branch other than `upstream/develop`,
288+
use the name or checksum of that branch instead. It is strongly recommended to
289+
rebase your work onto the tip of the branch it's based on before running
290+
`git-clang-format` in this way.
291+
292+
### RETROACTIVELY FORMATTING INDIVIDUAL COMMITS
293+
294+
If your works spans several commits and you'd like to keep the formatting
295+
correct in each individual commit, you can automatically rewrite the commits
296+
with correct formatting.
297+
298+
The following command will stop at each commit in the range and run
299+
clang-format on the diff at that point. This rewrites git history, so it's
300+
*unsafe*, and you should back up your branch before running this command:
301+
```
302+
git filter-branch --tree-filter 'git-clang-format-3.8 upstream/develop' \
303+
-- upstream/develop..HEAD
304+
```
305+
*Important*: `upstream/develop` should be changed in *both* places in the
306+
command above if your work is based on a different branch. It is strongly
307+
recommended to rebase your work onto the tip of the branch it's based on before
308+
running `git-clang-format` in this way.

0 commit comments

Comments
 (0)