Skip to content

Commit 20fcd28

Browse files
authored
Formatting updates (#24)
* Formatting updates - formatting workflow - cmake-format - updated clang-format version * remove debug printing * formatting workflow fix
1 parent 32f9a3c commit 20fcd28

25 files changed

Lines changed: 580 additions & 610 deletions

.cmake-format.yaml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
parse:
2+
additional_commands:
3+
ptl_build_library:
4+
flags:
5+
- RECURSIVE
6+
kwargs:
7+
TYPE: '*'
8+
TARGET_NAME: '*'
9+
OUTPUT_NAME: '*'
10+
SOURCES: '*'
11+
EXTRA_ARGS: '*'
12+
override_spec: {}
13+
vartags: []
14+
proptags: []
15+
format:
16+
disable: false
17+
line_width: 90
18+
tab_size: 4
19+
use_tabchars: false
20+
fractional_tab_policy: use-space
21+
max_subgroups_hwrap: 2
22+
max_pargs_hwrap: 8
23+
max_rows_cmdline: 2
24+
separate_ctrl_name_with_space: false
25+
separate_fn_name_with_space: false
26+
dangle_parens: false
27+
dangle_align: child
28+
min_prefix_chars: 4
29+
max_prefix_chars: 10
30+
max_lines_hwrap: 2
31+
line_ending: unix
32+
command_case: lower
33+
keyword_case: upper
34+
always_wrap: []
35+
enable_sort: true
36+
autosort: false
37+
require_valid_layout: false
38+
layout_passes: {}
39+
markup:
40+
bullet_char: '*'
41+
enum_char: .
42+
first_comment_is_literal: false
43+
literal_comment_pattern: null
44+
fence_pattern: ^\s*([`~]{3}[`~]*)(.*)$
45+
ruler_pattern: ^\s*[^\w\s]{3}.*[^\w\s]{3}$
46+
explicit_trailing_pattern: '#<'
47+
hashruler_min_length: 10
48+
canonicalize_hashrulers: true
49+
enable_markup: true
50+
lint:
51+
disabled_codes: []
52+
function_pattern: '[0-9a-z_]+'
53+
macro_pattern: '[0-9A-Z_]+'
54+
global_var_pattern: '[A-Z][0-9A-Z_]+'
55+
internal_var_pattern: _[A-Z][0-9A-Z_]+
56+
local_var_pattern: '[a-z][a-z0-9_]+'
57+
private_var_pattern: _[0-9a-z_]+
58+
public_var_pattern: '[A-Z][0-9A-Z_]+'
59+
argument_var_pattern: '[a-z][a-z0-9_]+'
60+
keyword_pattern: '[A-Z][0-9A-Z_]+'
61+
max_conditionals_custom_parser: 2
62+
min_statement_spacing: 1
63+
max_statement_spacing: 2
64+
max_returns: 6
65+
max_branches: 12
66+
max_arguments: 5
67+
max_localvars: 15
68+
max_statements: 50
69+
encode:
70+
emit_byteorder_mark: false
71+
input_encoding: utf-8
72+
output_encoding: utf-8
73+
misc:
74+
per_command: {}

.github/workflows/formatting.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# This handles formatting for C/C++ source code and cmake code
2+
name: formatting
3+
4+
on:
5+
push:
6+
branches: [ master, develop ]
7+
pull_request:
8+
branches: [ master, develop ]
9+
10+
jobs:
11+
cxx-formatting:
12+
runs-on: ubuntu-20.04
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Install dependencies
17+
run: |
18+
sudo apt-get update
19+
sudo apt-get install -y clang-format-9 cmake
20+
- name: clang-format
21+
run: |
22+
cmake -B build-PTL -DPTL_USE_TBB=OFF .
23+
cmake --build build-PTL --target format-source
24+
rm -rf build-PTL
25+
if [ $(git diff | wc -l) -gt 0 ]; then
26+
echo -e "\nError! Source code not formatted. Run clang-format-9...\n"
27+
echo -e "\nFiles:\n"
28+
git diff --name-only
29+
echo -e "\nFull diff:\n"
30+
git diff
31+
exit 1
32+
fi
33+
34+
cmake-formatting:
35+
runs-on: ubuntu-20.04
36+
strategy:
37+
matrix:
38+
python-version: [3.8]
39+
40+
steps:
41+
- uses: actions/checkout@v2
42+
- name: Set up Python ${{ matrix.python-version }}
43+
uses: actions/setup-python@v2
44+
with:
45+
python-version: ${{ matrix.python-version }}
46+
- name: Install dependencies
47+
run: |
48+
sudo apt-get update
49+
sudo apt-get install -y cmake
50+
python -m pip install --upgrade pip
51+
pip install cmake-format pyyaml
52+
- name: cmake format
53+
run: |
54+
cmake -B build-PTL -DPTL_USE_TBB=OFF .
55+
cmake --build build-PTL --target format-cmake
56+
rm -rf build-PTL
57+
if [ $(git diff | wc -l) -gt 0 ]; then
58+
echo -e "\nError! CMake code not formatted. Run cmake-format...\n"
59+
echo -e "\nFiles:\n"
60+
git diff --name-only
61+
echo -e "\nFull diff:\n"
62+
git diff
63+
exit 1
64+
fi

CMakeLists.txt

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
################################################################################
2-
# cmake settings
1+
# -------------------------------------------------------------------------------------- #
2+
# cmake settings
33
#
44
cmake_minimum_required(VERSION 3.8...3.20)
55
if(${CMAKE_VERSION} VERSION_LESS 3.12)
@@ -28,15 +28,19 @@ string(REGEX REPLACE "(\n|\r)" "" VERSION_STRING "${VERSION_STRING}")
2828
string(REGEX REPLACE "[A-Za-z].*" "" VERSION_STRING "${VERSION_STRING}")
2929
set(PTL_VERSION "${VERSION_STRING}")
3030

31-
################################################################################
32-
# project setup
31+
# -------------------------------------------------------------------------------------- #
32+
# -------------------------------------------------------------------------------------- #
33+
# project setup
3334
#
34-
project(PTL LANGUAGES C CXX VERSION ${PTL_VERSION})
35+
project(
36+
PTL
37+
LANGUAGES C CXX
38+
VERSION ${PTL_VERSION})
3539

3640
# Postprocess version info to create variables for export to Version.hh
3741
set(PTL_VERSION_STRING "${PTL_VERSION_MAJOR}.${PTL_VERSION_MINOR}.${PTL_VERSION_PATCH}")
3842
math(EXPR PTL_VERSION_CODE
39-
"10000 * ${PTL_VERSION_MAJOR} + 100 * ${PTL_VERSION_MINOR} + ${PTL_VERSION_PATCH}")
43+
"10000 * ${PTL_VERSION_MAJOR} + 100 * ${PTL_VERSION_MINOR} + ${PTL_VERSION_PATCH}")
4044

4145
# Project-local CMake settings
4246
set(CMAKE_DIRECTORY_LABELS "PTL")
@@ -47,47 +51,51 @@ set(CMAKE_LINK_DEPENDS_NO_SHARED ON)
4751
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules)
4852
include(PTLCMakeUtilities)
4953

50-
################################################################################
54+
# -------------------------------------------------------------------------------------- #
5155
# Build/Install settings and options
5256
include(PTLInstallDirs)
5357
include(PTLBuildSettings)
5458

55-
################################################################################
59+
# -------------------------------------------------------------------------------------- #
5660
# User options
5761
ptl_add_option(PTL_USE_TBB "Enable TBB" ON)
58-
ptl_add_option(PTL_USE_LOCKS "Enable mutex locking in task subqueues for extra safety" OFF)
62+
ptl_add_option(PTL_USE_LOCKS "Enable mutex locking in task subqueues for extra safety"
63+
OFF)
5964
ptl_add_option(PTL_INSTALL_HEADERS "Install the headers" ON)
6065
ptl_add_option(PTL_INSTALL_CONFIG "Install the cmake configuration" ON)
6166

6267
if(DEFINED PTL_DEVELOPER_INSTALL)
63-
set(PTL_INSTALL_HEADERS ${PTL_DEVELOPER_INSTALL} CACHE BOOL "Set via PTL_DEVELOPER_INSTALL" FORCE)
64-
set(PTL_INSTALL_CONFIG ${PTL_DEVELOPER_INSTALL} CACHE BOOL "Set via PTL_DEVELOPER_INSTALL" FORCE)
68+
set(PTL_INSTALL_HEADERS
69+
${PTL_DEVELOPER_INSTALL}
70+
CACHE BOOL "Set via PTL_DEVELOPER_INSTALL" FORCE)
71+
set(PTL_INSTALL_CONFIG
72+
${PTL_DEVELOPER_INSTALL}
73+
CACHE BOOL "Set via PTL_DEVELOPER_INSTALL" FORCE)
6574
endif()
6675

67-
################################################################################
68-
# Build Dependencies
69-
# - Threads
76+
# -------------------------------------------------------------------------------------- #
77+
# Build Dependencies - Threads
7078
if(NOT WIN32)
7179
set(CMAKE_THREAD_PREFER_PTHREAD ON)
7280
set(THREADS_PREFER_PTHREAD_FLAG ON)
7381
endif()
7482
find_package(Threads REQUIRED)
7583

76-
# - TBB
84+
# * TBB
7785
if(PTL_USE_TBB)
7886
find_package(TBB 2017 REQUIRED)
7987
endif()
8088

81-
################################################################################
82-
# PTL Primary Build
89+
# -------------------------------------------------------------------------------------- #
90+
# PTL Primary Build
8391
add_subdirectory(source)
8492

85-
################################################################################
86-
# CMake/PkgConfig Support files
93+
# -------------------------------------------------------------------------------------- #
94+
# CMake/PkgConfig Support files
8795
include(PTLPackageConfigHelpers)
8896

89-
################################################################################
90-
# Examples build/test
97+
# -------------------------------------------------------------------------------------- #
98+
# Examples build/test
9199
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/examples)
92100
ptl_add_option(PTL_BUILD_EXAMPLES "Build examples" OFF)
93101
if(PTL_BUILD_EXAMPLES)
@@ -96,8 +104,8 @@ if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/examples)
96104
endif()
97105
endif()
98106

99-
################################################################################
100-
# Reporting if master project
107+
# -------------------------------------------------------------------------------------- #
108+
# Reporting if master project
101109
if(PTL_MASTER_PROJECT)
102110
ptl_print_features()
103111
endif()

0 commit comments

Comments
 (0)