diff --git a/.cmake-format.py b/.cmake-format.py index 706f8e6dbc0..40a9ea23f49 100644 --- a/.cmake-format.py +++ b/.cmake-format.py @@ -1,7 +1,29 @@ # Copyright 2021 Marcus Müller # SPDX-License-Identifier: LGPL-3.0-or-later -from tools import clang_format_helper -_clang_format = clang_format_helper.clang_format_options() +class _clang_format_options: + def __init__(self, clangfile=None): + if not clangfile: + clangfile = ".clang-format" + self.lines = [] + with open(clangfile, encoding="utf-8") as opened: + for line in opened: + if line.strip().startswith("#"): + continue + self.lines.append(line.rstrip().split(":")) + + def __getitem__(self, string): + path = string.split(".") + value = None + for crumble in path: + for line in self.lines: + if line[0].strip() == crumble: + if len(line) > 1: + value = line[1].strip().rstrip() + break + return value + + +_clang_format = _clang_format_options() with section("parse"): additional_commands = { @@ -14,12 +36,13 @@ } }, } + with section("markup"): first_comment_is_literal = True enable_markup = False + with section("format"): disable = False - line_width = int(_clang_format["ColumnLimit"]) tab_size = int(_clang_format["IndentWidth"]) min_prefix_chars = tab_size @@ -27,14 +50,9 @@ use_tabchars = _clang_format["UseTab"] in ("ForIndentation", "ForContinuationAndIndentation", "Always") - - # separate_ctrl_name_with_space = clang_format["SpaceBeforeParens"] in ( - # "ControlStatements", "ControlStatementsExceptControlMacros", "Always") separate_ctrl_name_with_space = False - # separate_fn_name_with_space = clang_format["SpaceBeforeParens"] != "Never" separate_fn_name_with_space = False dangle_parens = False - command_case = 'canonical' keyword_case = 'upper' diff --git a/tools/clang_format_helper.py b/tools/clang_format_helper.py deleted file mode 100644 index b205ac42e94..00000000000 --- a/tools/clang_format_helper.py +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2021 Marcus Müller -# SPDX-License-Identifier: LGPL-3.0-or-later -class clang_format_options: - def __init__(self, clangfile=None): - if not clangfile: - clangfile = ".clang-format" - self.lines = [] - with open(clangfile, encoding="utf-8") as opened: - for line in opened: - if line.strip().startswith("#"): - continue - self.lines.append(line.rstrip().split(":")) - - def __getitem__(self, string): - path = string.split(".") - value = None - for crumble in path: - for line in self.lines: - if line[0].strip() == crumble: - if len(line) > 1: - value = line[1].strip().rstrip() - break - return value