Skip to content

Commit

Permalink
[CI] Enable clang-format check (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnhsieh-intel authored Oct 23, 2024
1 parent e3402a9 commit 7644873
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 6 deletions.
1 change: 0 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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/
11 changes: 10 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <venv-name>
source <venv-name>/bin/activate
pip install pre-commit
cd <path-to-onemkl>
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
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_backend_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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} <path/to/base_header.hpp> <path/to/backend_include.hpp> <namespace>
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_ct_instant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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} <path/to/general_ct_templates.hpp> <path/to/out_ct_header.hpp> <path/to/backend_include.hpp> <backend> <namespace>
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_ct_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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} <path/to/base_header.hpp> <path/to/out_headername.hpp>
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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} <path/to/header.hpp> <path/to/table.hpp> <path/to/out_wrappers.cpp> <libname>
Expand Down

0 comments on commit 7644873

Please sign in to comment.