diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000..3e9dc9f270 --- /dev/null +++ b/.clang-format @@ -0,0 +1,13 @@ +--- +BasedOnStyle: Google +IndentWidth: 4 +Language: Cpp +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +PointerAlignment: Left +ColumnLimit: 80 +AccessModifierOffset: 0 +KeepEmptyLinesAtTheStartOfBlocks: true \ No newline at end of file diff --git a/.github/check_format.sh b/.github/check_format.sh new file mode 100755 index 0000000000..b5c5e20e6f --- /dev/null +++ b/.github/check_format.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# +# check that all code complies w/ the clang-format specification +# +# if all is well, returns w/o errors and does not print anything. +# otherwise, return an error and print offending changes + +set -e # abort on error + +INCLUDE_DIRS=("apps core display plugins tests") + +if [ $# -ne 1 ]; then + echo "wrong number of arguments" + echo "" + echo "usage: check_format " + exit 1 +fi + +_binary=${CLANG_FORMAT_BINARY:-clang-format} + +$_binary --version + +cd $1 +$_binary -i -style=file $(find ${INCLUDE_DIRS} \( -iname '*.cpp' -or -iname '*.hpp' -or -iname '*.ipp' -or -iname '*.inl' -or -iname '*.cu' -or -iname '*.cuh' -or -iname '*.hip' -or -iname '*.sycl' \)) + +if ! [ -z $CI ] || ! [ -z $GITHUB_ACTIONS ]; then + mkdir changed + for f in $(git diff --name-only -- ${INCLUDE_DIRS[@]/#/:/}); do + cp --parents $f changed + done +fi + +echo "clang-format done" + +set +e +git diff --exit-code --stat -- ${INCLUDE_DIRS[@]/#/:/} +result=$? + +if [ "$result" -eq "128" ]; then + echo "Format was successfully applied" + echo "Could not create summary of affected files" + echo "Are you in a submodule?" + +fi + +exit $result diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 054eedde84..c9941a0890 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -6,7 +6,7 @@ on: branches: - main - 'release/**' - + jobs: ubuntu: runs-on: ubuntu-latest diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 0000000000..6dc7de92ca --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,21 @@ +name: Checks + +on: + push: + pull_request: + branches: + - main + +jobs: + format: + runs-on: ubuntu-latest + container: ghcr.io/acts-project/format10:v11 + steps: + - uses: actions/checkout@v2 + - name: Check + run: .github/check_format.sh . + - uses: actions/upload-artifact@v1 + if: failure() + with: + name: changed + path: changed diff --git a/apps/common/include/apps/common/display_bin_association.inl b/apps/common/include/apps/common/display_bin_association.inl index dd97ffc78d..60824862e1 100644 --- a/apps/common/include/apps/common/display_bin_association.inl +++ b/apps/common/include/apps/common/display_bin_association.inl @@ -1,42 +1,41 @@ /** Detray library, part of the ACTS project (R&D line) - * + * * (c) 2021 CERN for the benefit of the ACTS project - * + * * Mozilla Public License Version 2.0 */ #pragma once +#include + +#include +#include +#include + #include "core/detector.hpp" #include "core/transform_store.hpp" -#include "io/csv_io.hpp" #include "grids/associator.hpp" +#include "io/csv_io.hpp" +#include "style/styles.hpp" #include "utils/enumerate.hpp" #include "utils/generators.hpp" #include "view/draw.hpp" #include "view/views.hpp" -#include "style/styles.hpp" - -#include -#include -#include -#include -int main(int argc, char **argv) -{ +int main(int argc, char **argv) { using point2 = __plugin::point2; using namespace detray; using namespace matplot; - if (argc > 1) - { + if (argc > 1) { std::string first_arg = argv[1]; - if (first_arg == "-h" or first_arg == "--help") - { - std::cout << "[detray] Usage: 'display_bin_association detector_name '" << std::endl; + if (first_arg == "-h" or first_arg == "--help") { + std::cout + << "[detray] Usage: 'display_bin_association detector_name " + " '" + << std::endl; return 1; - } - else if (argc > 7) - { + } else if (argc > 7) { // Create a sub plot auto ax = matplot::subplot({0.1, 0.1, 0.65, 0.8}); @@ -47,8 +46,9 @@ int main(int argc, char **argv) std::string volumes_file = argv[3]; std::string grids_file = argv[4]; std::string grid_entries_file = argv[5]; - - auto d = detector_from_csv<>(name, surfaces_file, volumes_file, grids_file, grid_entries_file); + + auto d = detector_from_csv<>(name, surfaces_file, volumes_file, + grids_file, grid_entries_file); std::cout << "[detray] Detector read successfully." << std::endl; global_xy_view xy_view; @@ -89,7 +89,8 @@ int main(int argc, char **argv) // Grid drawing sections styles and addons // - styles and addons are on faint grid, cell, assoc std::vector