From 3cfd7f103f9303517dbedf1e2b8e05a9ca502bd2 Mon Sep 17 00:00:00 2001 From: Krzysztof Jakubowski Date: Sat, 25 Nov 2023 13:03:13 +0100 Subject: [PATCH] WIP --- .clang-format | 5 +++- .github/workflows/test.yml | 29 +++++++++++++++++++ tools/format.py | 57 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test.yml create mode 100644 tools/format.py diff --git a/.clang-format b/.clang-format index f1d5567e..5f4071af 100644 --- a/.clang-format +++ b/.clang-format @@ -15,10 +15,13 @@ AllowShortFunctionsOnASingleLine: All NamespaceIndentation: Inner SpaceBeforeParens: Never FixNamespaceComments: false -Standard: Cpp11 +Standard: Latest IndentRequires: true BreakBeforeConceptDeclarations: false BreakBeforeTernaryOperators: false +#RequiresClausePosition: OwnLine +#IndentRequiresClause: true + DeriveLineEnding: false UseCRLF: false \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..eeb196fe --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,29 @@ +name: build + +on: + push: + pull_request: + workflow_run: + # Use a workflow as a trigger of scheduled builds. Forked repositories can disable scheduled builds by disabling + # "scheduled" workflow, while maintaining ability to perform local CI builds. + workflows: + - scheduled + branches: + - main + - test_actions + types: + - requested + +jobs: + cpp-formatting-check: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + + - name: Install Dependencies + run: | + git submodule update --init + + - name: Check formatting + run: | + python tools/format.py \ No newline at end of file diff --git a/tools/format.py b/tools/format.py new file mode 100644 index 00000000..a91e5b09 --- /dev/null +++ b/tools/format.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 + +import argparse, os, subprocess, shutil + +# if ! command -v clang-format &> /dev/null ; then +# echo "clang-format is not available. Please install version 14 " +# echo "and make sure that it is accessible from PATH." +# exit +# fi + +# cfversion=`clang-format --version | grep -Eo '[0-9]+' | head -1` +# if [ "$cfversion" != "14" ]; then +# echo "Warning: Invalid clang-format version: ${cfversion} (should be 14)" +# fi + +# clang-format -i *.cc *.h boxpack/*.cc boxpack/*.h + + +def verify_clang_format(): + if shutil.which('clang-format') is None: + print('clang-format is missing') + exit(1) + result = subprocess.run(['clang-format', '--version'], stdout=subprocess.PIPE) + tokens = result.stdout.decode("utf-8").split() + while len(tokens) > 0 and tokens[0] != 'clang-format': + tokens.pop(0) + if result.returncode != 0 or len(tokens) < 3 or tokens[0] != 'clang-format' or tokens[1] != 'version': + print('error while checking clang-format version') + exit(1) + version = tokens[2].split('.', 2) + print(f"clang-format version: {version[0]}.{version[1]}.{version[2]}") + + +def format_cpp(check: bool): + print("meh") + + +def main(): + parser = argparse.ArgumentParser( + prog='libfwk-format', + description='Tool for code formatting and format verification', + ) + parser.add_argument('-c', '--check', action='store_true') + args = parser.parse_args() + + libfwk_path = os.path.join(__file__, '..') + + if args.check: + print('Checking mode') + else: + print('Formatting mode') + + verify_clang_format() + + +if __name__ == "__main__": + main()