Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check_code_formating.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
clang-format --version

- name: Run clang-format check
run: python3 check_clang_format.py
run: python3 scripts/run_check_clang_format.py
3 changes: 0 additions & 3 deletions _Update.bat

This file was deleted.

25 changes: 25 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Repository management utilities

* `run_clang_format.py` — runs `clang-format` on all C/C++ source and header files located in:

* `core`
* `core_hd_mapping`
* `apps`
* `pybind`
* `shared`

* `run_check_clang_format.py` — checks whether running `clang-format` would modify any tracked project files. The script runs `run_clang_format.py` and then checks the Git working tree for changes. If formatting would produce changes, the check fails and lists the affected files.

* `run_submodules_sync_update.py` — initializes and updates Git submodules recursively using:
`git submodule sync` and `git submodule update --init --recursive`.

* `run_pull_submodules_changes.py` — updates submodules located under `3rdparty`. For each submodule, the script:

* reads the branch configured in `.gitmodules`;
* initializes the submodule if it is missing;
* fetches from `origin`;
* switches to the configured branch;
* performs a fast-forward-only pull;
* reports whether the submodule was actually updated.

Submodules without a branch configured in `.gitmodules` are reported and skipped.
24 changes: 20 additions & 4 deletions check_clang_format.py → scripts/run_check_clang_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import subprocess
import sys

PROJECT_DIRECTORY = os.path.abspath(os.path.dirname(__file__))
SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
PROJECT_DIRECTORY = os.path.abspath(os.path.join(SCRIPT_DIR, ".."))

FILE_LOCATIONS = [
os.path.join(PROJECT_DIRECTORY, "core"),
Expand All @@ -24,11 +25,13 @@

def get_files(input_paths: list[str], extensions: list[str]):
files = []

for input_path in input_paths:
for dirpath, _, filenames in os.walk(input_path):
for filename in filenames:
if filename.endswith(tuple(extensions)):
files.append(os.path.normpath(os.path.join(dirpath, filename)))

return files


Expand All @@ -45,17 +48,28 @@ def main():
formatted_files = set(get_files(FILE_LOCATIONS, FILE_EXTENSIONS))

formatted_files = {
os.path.relpath(path, PROJECT_DIRECTORY)
for path in formatted_files
os.path.relpath(path, PROJECT_DIRECTORY) for path in formatted_files
}

result = run([sys.executable, "run_clang_format.py"])
clang_format_script = os.path.join(
SCRIPT_DIR,
"run_clang_format.py",
)

result = run(
[
sys.executable,
clang_format_script,
]
)

if result.returncode != 0:
print("ERROR: run_clang_format.py failed")
print(result.stderr)
sys.exit(result.returncode)

status = run(["git", "status", "--porcelain"])

if status.returncode != 0:
print("ERROR: git status failed")
print(status.stderr)
Expand All @@ -71,8 +85,10 @@ def main():

if offending_files:
print("ERROR: clang-format produced changes in the following files:")

for f in offending_files:
print(f" {f}")

sys.exit(1)

print("clang-format check passed")
Expand Down
3 changes: 2 additions & 1 deletion run_clang_format.py → scripts/run_clang_format.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import os
import subprocess

PROJECT_DIRECTORY = os.path.join(os.path.abspath(os.path.dirname(__file__)))
SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
PROJECT_DIRECTORY = os.path.abspath(os.path.join(SCRIPT_DIR, ".."))

FILE_LOCATIONS = [os.path.join(PROJECT_DIRECTORY, 'core'),
os.path.join(PROJECT_DIRECTORY, 'core_hd_mapping'),
Expand Down
Loading
Loading