Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cmake: Fix identation #638

Draft
wants to merge 14 commits into
base: develop
Choose a base branch
from
110 changes: 110 additions & 0 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# ----------------------------------
# Options affecting listfile parsing
# ----------------------------------
with section("parse"):

# Specify structure for custom cmake functions
# pargs - positional arguments
# kwargs - keyword arguments
additional_commands = {
"userver_module": {
"pargs": 1,
"kwargs": {
"SOURCE_DIR": "*",
"LINK_LIBRARIES": "*",
"LINK_LIBRARIES_PRIVATE": "*",
"UTEST_SOURCES": "*",
"UTEST_DIRS": "*",
"UTEST_LINK_LIBRARIES": "*",
"INCLUDE_DIRS": "*",
"DBTEST_SOURCES": "*",
"DBTEST_DATABASES": "*",
"DBTEST_DIRS": "*",
"DBTEST_ENV": "*",
"DBTEST_LINK_LIBRARIES": "*",
"UBENCH_DIRS": "*",
"UBENCH_DATABASES": "*",
"UBENCH_SOURCES": "*",
"UBENCH_LINK_LIBRARIES": "*",
"UBENCH_ENV": "*",
"POSTGRES_TEST_DSN": "*",

},
"flags": ["NO_INSTALL"],
},
"_userver_directory_install": {
"kwargs": {
"COMPONENT": "*",
"DIRECTORY": "*",
"PROGRAMS": "*",
"FILES": "*",
"DESTINATION": "*",
},
},
"userver_target_generate_openapi_client": {
"pargs": 1,
"kwargs": {
"NAME": "*",
"OUTPUT_DIR": "*",
"SCHEMAS": "*",
"UTEST_LINK_LIBRARIES": "*",
},
},
"userver_target_generate_chaotic": {
"pargs": 1,
"kwargs": {
"ARGS": "*",
"FORMAT": "*",
"OUTPUT_DIR": "*",
"SCHEMAS": "*",
"RELATIVE_TO": "*",
},
"flags": ["UNIQUE"],
},
"userver_venv_setup": {
"kwargs": {
"NAME": "*",
"PYTHON_OUTPUT_VAR": "*",
"REQUIREMENTS": "*",
},
"flags": ["UNIQUE"],
},
"userver_add_grpc_library": {
"pargs": 1,
"kwargs": {
"PROTOS": "*",
"INCLUDE_DIRECTORIES": "*",
},
},
}

# -----------------------------
# Options affecting formatting.
# -----------------------------
with section("format"):

# Disable formatting entirely, making cmake-format a no-op
disable = False

# How wide to allow formatted cmake files
line_width = 120

# How many spaces to tab for indent
tab_size = 4

# If true, lines are indented using tab characters (utf-8 0x09) instead of
# <tab_size> space characters (utf-8 0x20). In cases where the layout would
# require a fractional tab character, the behavior of the fractional
# indentation is governed by <fractional_tab_policy>
use_tabchars = False

# If <use_tabchars> is True, then the value of this variable indicates how
# fractional indentions are handled during whitespace replacement. If set to
# 'use-space', fractional indentation is left as spaces (utf-8 0x20). If set
# to `round-up` fractional indentation is replaced with a single tab character
# (utf-8 0x09) effectively shifting the column to the next tabstop
fractional_tab_policy = "use-space"

# If a statement is wrapped to more than one line, than dangle the closing
# parenthesis on its own line.
dangle_parens = True
50 changes: 49 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,55 @@ jobs:
runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Check CMake files format
if: github.event_name == 'pull_request'
run: |
LIST_CHECK_FILES=$(git diff --name-only --diff-filter=d HEAD^1 HEAD | grep -E 'CMakeLists.txt$' | tr '\n' ' ')

echo "Changed files:"
echo "$LIST_CHECK_FILES"
if [[ -n ${LIST_CHECK_FILES} ]]
then
pip install cmake-format
for FILE in $LIST_CHECK_FILES; do
cmake-format --check $FILE &> output.txt || true
if grep -q "ERROR" output.txt; then
echo "Formatting issues found in $FILE. Running cmake-format to fix."
cmake-format -i $FILE
DIFF=$(git diff $FILE)
DIFF_OUTPUT="$DIFF_OUTPUT\n\nDiff for $FILE:\n\`\`\`diff\n$DIFF\n\`\`\`"
else
echo "No formatting issues in $FILE."
fi
done
if [[ -n ${DIFF_OUTPUT} ]]; then
DIFF_OUTPUT="## ❌ Check with [cmake-format](https:\/\/github.com\/cheshirekow\/cmake_format) failed\n\n$DIFF_OUTPUT"
fi
echo -e "$DIFF_OUTPUT" > diff_output.txt
else
echo "Nothing to check with cmake-format"
fi

- name: Create pull request comment with formatting issues
if: github.event_name == 'pull_request'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ -f diff_output.txt ]; then
DIFF_OUTPUT=$(cat diff_output.txt)
if [ -n "$DIFF_OUTPUT" ]; then
echo "Creating pull request comment with diff output..."
echo "$DIFF_OUTPUT" > comment.md
gh pr comment ${{ github.event.pull_request.number }} --body-file comment.md
echo "Failing the workflow due to formatting issues."
exit 1
fi
fi

- name: Restore cached directories
id: restore-cache
Expand Down
Loading
Loading