mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-04-19 22:39:03 +00:00
* Add basic setup for precommit * Update README.md with instructions on installing precommit hooks --------- Co-authored-by: Illia Silin <98187287+illsilin@users.noreply.github.com> Co-authored-by: Bartlomiej Wroblewski <bwroblewski10@gmail.com>
This commit is contained in:
14
.pre-commit-config.yaml
Normal file
14
.pre-commit-config.yaml
Normal file
@@ -0,0 +1,14 @@
|
||||
repos:
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: clang-format
|
||||
name: clang-format
|
||||
entry: clang-format-10 -i --style=file
|
||||
language: system
|
||||
types_or: [c++, inc]
|
||||
- id: copyright-year-checker
|
||||
name: copyright-year-checker
|
||||
entry: script/check_copyright_year.sh
|
||||
verbose: false
|
||||
language: script
|
||||
types: [c++]
|
||||
18
README.md
18
README.md
@@ -109,6 +109,24 @@ make install
|
||||
|
||||
Instructions for using CK as a pre-built kernel library are under [client_example](/client_example)
|
||||
|
||||
## Contributing
|
||||
|
||||
When you contribute to Composable Kernel, make sure to run `clang-format` on all the changed files. We highly recommend using git hooks that are managed by the `pre-commit` framework. To install hooks, run:
|
||||
|
||||
```bash
|
||||
sudo script/install_precommit.sh
|
||||
```
|
||||
|
||||
This way, `pre-commit` will add the appropriate hooks to your local repository and automatically run `clang-format` (and possibly additional checks) before any commit is created.
|
||||
|
||||
If you need to uninstall hooks from the repository, you can do so by running the following command:
|
||||
|
||||
```bash
|
||||
script/uninstall_precommit.sh
|
||||
```
|
||||
|
||||
If for any reason, you need to temporarily disable precommit hooks, you can add the `--no-verify` option to the `git commit` command.
|
||||
|
||||
## Caveat
|
||||
### Kernel Timing and Verification
|
||||
|
||||
|
||||
17
script/check_copyright_year.sh
Executable file
17
script/check_copyright_year.sh
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
current_year=$(date +%Y)
|
||||
exit_code=0
|
||||
|
||||
for file in $@; do
|
||||
if grep -q "Copyright (c)" $file
|
||||
then
|
||||
if ! grep -q "Copyright (c).*$current_year" $file
|
||||
then
|
||||
echo "ERROR: File $file has a copyright notice without the current year ($current_year)."
|
||||
exit_code=1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
exit $exit_code
|
||||
20
script/install_precommit.sh
Executable file
20
script/install_precommit.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
run_and_check() {
|
||||
"$@"
|
||||
status=$?
|
||||
if [ $status -ne 0 ]; then
|
||||
echo "Error with \"$@\": Exited with status $status"
|
||||
exit $status
|
||||
fi
|
||||
return $status
|
||||
}
|
||||
|
||||
echo "I: Installing tools required for pre-commit checks..."
|
||||
run_and_check apt install clang-format-10
|
||||
|
||||
echo "I: Installing pre-commit itself..."
|
||||
run_and_check pip3 install pre-commit
|
||||
run_and_check pre-commit install
|
||||
|
||||
echo "I: Installation successful."
|
||||
1
script/uninstall_precommit.sh
Executable file
1
script/uninstall_precommit.sh
Executable file
@@ -0,0 +1 @@
|
||||
pre-commit uninstall
|
||||
Reference in New Issue
Block a user