-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #224: Add a clang-format that matches the best the OpenSSL coding…
… style. (#241) This commit adds a `.clang-format` file at the root of the repository. This `.clang-format` file tries to match the best the OpenSSL coding style. This commit also reformats the existing code according to that `.clang-format`. Finally, it adds a new CircleCI job to ensure that the code is well-formatted.
- Loading branch information
thb-sb
authored
Sep 1, 2023
1 parent
a15fc1b
commit 3750149
Showing
29 changed files
with
4,353 additions
and
3,147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# OpenSSL formatting is close to Linux Kernel's , which is close | ||
# to LLVM's. | ||
BasedOnStyle: LLVM | ||
|
||
# The following rules tries to reproduce the OpenSSL coding style defined | ||
# in the following document: https://www.openssl.org/policies/technical/coding-style.html | ||
|
||
# Chapter 1: Indentation. | ||
|
||
## Use 4 space characters, not tabs. | ||
UseTab: Never | ||
IndentWidth: 4 | ||
|
||
## Pre-processor directives use one space for indents, after hash. | ||
IndentPPDirectives: AfterHash | ||
|
||
# This option seems to be broken on clang-format-14, but fixed in clang-format-15. | ||
# We keep it disabled for now. | ||
#PPIndentWidth: 1 | ||
|
||
# Chapter 2: Breaking long lines and strings | ||
|
||
## Don’t put multiple statements, or assignments, on a single line. | ||
AllowShortBlocksOnASingleLine: Never | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortEnumsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: None | ||
AllowShortIfStatementsOnASingleLine: Never | ||
AllowShortLoopsOnASingleLine: false | ||
AlwaysBreakAfterReturnType: None | ||
AlwaysBreakBeforeMultilineStrings: false | ||
AllowAllParametersOfDeclarationOnNextLine: false | ||
|
||
## The limit on the length of lines is 80 columns. | ||
ColumnLimit: 80 | ||
|
||
# Descendants are always substantially shorter than the parent and are placed substantially to the right. | ||
AlignAfterOpenBracket: Align | ||
AlignOperands: Align | ||
BreakBeforeBinaryOperators: true | ||
|
||
# Never break user-visible strings, however, because that breaks the ability to grep for them. | ||
BreakStringLiterals: false | ||
|
||
|
||
# Chapter 3: Placing Braces and Spaces | ||
|
||
SpaceBeforeAssignmentOperators: true | ||
|
||
# Use the same indentation level as for the switch statement. | ||
IndentCaseLabels: false | ||
|
||
## […] is to put the opening brace last on the line, and the closing brace first | ||
BreakBeforeBraces: Custom | ||
BraceWrapping: | ||
AfterClass: false | ||
AfterControlStatement: Never | ||
AfterEnum: false | ||
## There is one special case, however. Functions have the opening brace at the beginning of the next line | ||
AfterFunction: true | ||
AfterNamespace: false | ||
AfterStruct: false | ||
AfterUnion: false | ||
BeforeCatch: false | ||
BeforeElse: false | ||
BeforeWhile: false | ||
|
||
|
||
# Chapter 3.1: Spaces | ||
|
||
## When declaring pointer data or a function that returns a pointer type, the asterisk goes next to the data or function name, and not the type: | ||
PointerAlignment: Right | ||
|
||
## Do not use multiple consecutive spaces except in comments, for indentation, and for multi-line alignment of definitions, e.g.: | ||
AlignConsecutiveMacros: AcrossComments | ||
|
||
|
||
# Chapter 9: Macros and Enums | ||
|
||
## Macros with multiple statements should be enclosed in a do - while block | ||
AlignEscapedNewlines: Left |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ on: | |
branches: [ '*' ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
|
||
linux_intel: | ||
|
@@ -37,12 +37,14 @@ jobs: | |
run: ./scripts/runtests.sh -V | ||
- name: Verify nothing changes on re-generate code | ||
run: | | ||
apt-get update && apt-get install -y clang-format && \ | ||
git config --global user.name "ciuser" && \ | ||
git config --global user.email "[email protected]" && \ | ||
git config --global --add safe.directory `pwd` && \ | ||
export LIBOQS_SRC_DIR=`pwd`/liboqs && \ | ||
! pip3 install -r oqs-template/requirements.txt 2>&1 | grep ERROR && \ | ||
python3 oqs-template/generate.py && \ | ||
find . -type f -and '(' -name '*.h' -or -name '*.c' -or -name '*.inc' ')' | xargs clang-format -i && \ | ||
! git status | grep modified | ||
- name: Build .deb install package | ||
run: cpack | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
#!/bin/bash | ||
|
||
cd oqs-template | ||
cd oqs-template | ||
|
||
rm generate.yml | ||
|
||
# Step 1: Obtain current generate.yml from main: | ||
wget -c https://raw.githubusercontent.com/open-quantum-safe/openssl/OQS-OpenSSL_1_1_1-stable/oqs-template/generate.yml | ||
|
||
# Step 2: Run the generator: | ||
cd .. && python3 oqs-template/generate.py | ||
cd .. && python3 oqs-template/generate.py | ||
|
||
# Step 3: Run clang-format. | ||
find . -type f -and '(' -name '*.h' -or -name '*.c' -or -name '*.inc' ')' | xargs "${CLANG_FORMAT:-clang-format}" -i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.