From e9caa17363ec81d4897c9579c116b47d9eced37d Mon Sep 17 00:00:00 2001 From: Dai-Ni Hsieh Date: Fri, 11 Oct 2024 11:15:34 -0700 Subject: [PATCH 1/2] [CI] Enable clang-format check --- .github/workflows/pr.yml | 13 +++++++++++++ .pre-commit-config.yaml | 8 ++++++++ 2 files changed, 21 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 0da2153c6..99a106cce 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -14,6 +14,19 @@ env: PARALLEL: -j 2 jobs: + format-checks: + runs-on: ubuntu-latest + name: clang-format check + steps: + - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 + - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0 + with: + python-version: '3.10' + cache: 'pip' + - name: Install pre-commit + run: pip install pre-commit + - name: Run clang-format check + run: pre-commit run --all-files --show-diff-on-failure --color always unit-tests: runs-on: ubuntu-latest # One runner for each domain diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..1be15eecd --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +repos: + +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: v19.1.0 + hooks: + - id: clang-format + files: \.(c|cxx|cpp|h|hxx|hpp)$ + exclude: ^deps/ From 64f17b4cf80df97eab47305619595da4c321c043 Mon Sep 17 00:00:00 2001 From: Dai-Ni Hsieh Date: Sun, 13 Oct 2024 19:16:46 -0700 Subject: [PATCH 2/2] [Docs][Scripts] Update 'clang-format'-related descriptions --- .github/pull_request_template.md | 1 - CONTRIBUTING.md | 11 ++++++++++- scripts/generate_backend_api.py | 2 +- scripts/generate_ct_instant.py | 2 +- scripts/generate_ct_templates.py | 2 +- scripts/generate_wrappers.py | 2 +- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 6fda36ac8..7ad921d8a 100755 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -13,7 +13,6 @@ Fixes # (GitHub issue) ## All Submissions - [ ] Do all unit tests pass locally? Attach a log. -- [ ] Have you formatted the code using clang-format? ## New interfaces diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2840fcbd6..7781b9c6e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -81,7 +81,16 @@ The general principle is to follow the style of existing/surrounding code. If yo ```sh clang-format -style=file -i foo.cpp ``` -This formats code using the `_clang_format` file found in the oneMKL top-level directory. +This formats code using the `_clang_format` file found in the oneMKL top-level directory. The version of `clang-format` is specified in [`.pre-commit-config.yaml`](https://github.com/oneapi-src/oneMKL/blob/develop/.pre-commit-config.yaml). Alternatively, you can install and run `pre-commit`, which will install the specified `clang-format` version automatically: +```sh +python3 -m venv +source /bin/activate +pip install pre-commit +cd +pre-commit run --all-files +deactivate +``` +By default, `pre-commit` caches data in `~/.cache/pre-commit`. You can set `PRE_COMMIT_HOME` to use another location. ### GN: General Naming diff --git a/scripts/generate_backend_api.py b/scripts/generate_backend_api.py index c3866270e..cc76a20b7 100755 --- a/scripts/generate_backend_api.py +++ b/scripts/generate_backend_api.py @@ -33,7 +33,7 @@ def usage(err = None): print('error: %s' % err) print('''\ Script to generate backend library header based on base_header.h -Note: requires clang-format 9.0.0 tool to be installed +Note: requires clang-format tool to be installed Usage: {script} diff --git a/scripts/generate_ct_instant.py b/scripts/generate_ct_instant.py index acc02e3ea..a30f53f21 100755 --- a/scripts/generate_ct_instant.py +++ b/scripts/generate_ct_instant.py @@ -33,7 +33,7 @@ def usage(err = None): print('error: %s' % err) print('''\ Script to generate CT API instantiations for backend based on general_ct_templates.hpp -Note: requires clang-format 9.0.0 tool to be installed +Note: requires clang-format tool to be installed Usage: {script} diff --git a/scripts/generate_ct_templates.py b/scripts/generate_ct_templates.py index 7f54d4f08..4827c43e1 100755 --- a/scripts/generate_ct_templates.py +++ b/scripts/generate_ct_templates.py @@ -33,7 +33,7 @@ def usage(err = None): print('error: %s' % err) print('''\ Script to generate header file for templated compile-time API based on base_header.h -Note: requires clang-format 9.0.0 tool to be installed +Note: requires clang-format tool to be installed Usage: {script} diff --git a/scripts/generate_wrappers.py b/scripts/generate_wrappers.py index 29947273f..c4e18d648 100755 --- a/scripts/generate_wrappers.py +++ b/scripts/generate_wrappers.py @@ -33,7 +33,7 @@ def usage(err = None): print('error: %s' % err) print('''\ Script to generate blank wrappers and pointers table based on header.hpp -Note: requires clang-format 9.0.0 tool +Note: requires clang-format tool Usage: {script}