Skip to content

Commit

Permalink
Migrate the winclang-format hook to invoke (#26162)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentClarret authored May 31, 2024
1 parent 6a4440e commit 4b98a4f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ repos:
- id: win-clang-format
name: win-clang-format
description: clang-format
entry: './tasks/git-hooks/wincpplang.py'
entry: 'inv pre-commit.check-winclang-format'
language: system
types_or: [c, c++, c#]
pass_filenames: false
- id: clang-format
name: clang-format
description: clang-format
Expand Down
31 changes: 0 additions & 31 deletions tasks/git-hooks/wincpplang.py

This file was deleted.

23 changes: 23 additions & 0 deletions tasks/pre_commit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import re
import sys

Expand All @@ -21,6 +22,28 @@ def update_pyapp_file() -> str:
return DEVA_PRE_COMMIT_CONFIG


@task
def check_winclang_format(ctx):
if os.name != 'nt': # Don't run on Linux
return

def find_clang_format(search_dirs):
for search_dir in search_dirs:
for root, _, files in os.walk(search_dir):
for basename in files:
if basename == 'clang-format.exe':
return os.path.join(root, basename)

clang_format_path = os.environ.get('CLANG_FORMAT_PATH')
if clang_format_path is None:
search_dirs = ['C:/Program Files/Microsoft Visual Studio', 'C:/Program Files (x86)/Microsoft Visual Studio']
clang_format_path = find_clang_format(search_dirs)

print(clang_format_path)

ctx.run(f'"{clang_format_path}" --dry-run --Werror {",".join(get_staged_files(ctx))}')


@task
def check_set_x(ctx):
# Select only relevant files
Expand Down

0 comments on commit 4b98a4f

Please sign in to comment.