-
Notifications
You must be signed in to change notification settings - Fork 811
test clang-tidy #21213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
test clang-tidy #21213
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
8634b16
init
KornevNikita b5c6a5e
dummy-change
KornevNikita 6ced96e
strace
KornevNikita 8bfa716
fix-linux-precommit
KornevNikita 026088d
upload-compile-commands
KornevNikita 185b6c4
fix-path
KornevNikita 0b76b48
configure-within-workflow
KornevNikita 2a75004
use-precommit-file
KornevNikita f6936ee
Revert "use-precommit-file"
KornevNikita e853660
Merge remote-tracking branch 'origin/sycl' into clang-tidy-workflow
KornevNikita 8fe04a2
use-precommit-file
KornevNikita 77029bf
fix-error
KornevNikita c3f0fe3
set-env
KornevNikita 994a4a3
set-env
KornevNikita 02a15c0
get-rid-of-ccache-and-co
KornevNikita e323673
no strace
KornevNikita b26e51d
remove-gcc-flags
KornevNikita a2582bf
strace
KornevNikita b7dc6a4
fix-strace-log-path
KornevNikita 6ff9946
final?
KornevNikita 5b6d8cf
forgot uses
KornevNikita ce96468
remove-needs
KornevNikita da566f5
checkout-scripts-folder
KornevNikita File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| name: clang-tidy | ||
|
|
||
| on: | ||
| workflow_call: | ||
|
|
||
| permissions: read-all | ||
|
|
||
| jobs: | ||
| run-clang-tidy: | ||
| runs-on: [Linux, build] | ||
| container: | ||
| image: ghcr.io/intel/llvm/sycl_ubuntu2404_nightly:latest | ||
|
||
| options: -u 1001:1001 | ||
| steps: | ||
| - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | ||
| with: | ||
| sparse-checkout: | | ||
| devops/actions | ||
| devops/scripts | ||
|
Comment on lines
+15
to
+19
Check warningCode scanning / zizmor credential persistence through GitHub Actions artifacts Warning
credential persistence through GitHub Actions artifacts
|
||
| - name: Register cleanup after job is finished | ||
| uses: ./devops/actions/cleanup | ||
|
|
||
| - name: Check diff | ||
| id: should_run_tidy | ||
| run: | | ||
| echo "Downloading the diff" | ||
| curl -L "${{ github.server_url }}/${{ github.repository }}/pull/${{ github.event.pull_request.number }}.diff" -o pr.diff | ||
|
|
||
| if python3 devops/scripts/should_run_clang-tidy.py pr.diff; then | ||
| echo "run=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "run=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - if: steps.should_run_tidy.outputs.run == 'true' | ||
| uses: ./devops/actions/cached_checkout | ||
| with: | ||
| path: src | ||
| ref: ${{ github.sha }} | ||
| cache_path: "/__w/repo_cache/" | ||
| - name: Configure | ||
| if: steps.should_run_tidy.outputs.run == 'true' | ||
| env: | ||
| CC: gcc | ||
| CXX: g++ | ||
| CUDA_LIB_PATH: "/usr/local/cuda/lib64/stubs" | ||
| run: | | ||
| mkdir -p $GITHUB_WORKSPACE/build | ||
| cd $GITHUB_WORKSPACE/build | ||
| python3 $GITHUB_WORKSPACE/src/buildbot/configure.py -w $GITHUB_WORKSPACE \ | ||
| -s $GITHUB_WORKSPACE/src -o $GITHUB_WORKSPACE/build -t Release \ | ||
| --ci-defaults -DCMAKE_EXPORT_COMPILE_COMMANDS=ON | ||
|
|
||
| - name: Preprocess compile_commands.json | ||
| if: steps.should_run_tidy.outputs.run == 'true' | ||
| run: | | ||
| # Remove commands containing "-D__INTEL_PREVIEW_BREAKING_CHANGES" to avoid running on the same file twice. | ||
| jq '[ .[] | select(.command | contains("-D__INTEL_PREVIEW_BREAKING_CHANGES") | not) ]' $GITHUB_WORKSPACE/build/compile_commands.json > $GITHUB_WORKSPACE/build/compile_commands.temp.json | ||
| mv $GITHUB_WORKSPACE/build/compile_commands.temp.json $GITHUB_WORKSPACE/build/compile_commands.json | ||
|
|
||
| # Remove gcc-specific flags | ||
| perl -0777 -pe ' | ||
| s/(?:^|[ \t])\-Wno-class-memaccess(?=$|[ \t])//g; | ||
| s/(?:^|[ \t])\-Wno-dangling-reference(?=$|[ \t])//g; | ||
| s/(?:^|[ \t])\-Wno-stringop-overread(?=$|[ \t])//g; | ||
| s/[ \t]{2,}/ /g; | ||
| ' -i $GITHUB_WORKSPACE/build/compile_commands.json | ||
|
|
||
| - name: Run clang-tidy on modified files | ||
| if: steps.should_run_tidy.outputs.run == 'true' | ||
| # Exeprimental workflow, it won't affect the pre-commit status in case of failure. | ||
| continue-on-error: true | ||
| run: | | ||
| cd "$GITHUB_WORKSPACE/src" | ||
| python3 "$GITHUB_WORKSPACE/src/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py" \ | ||
| -clang-tidy-binary "/opt/sycl/bin/clang-tidy" \ | ||
| -p 1 \ | ||
| -path "$GITHUB_WORKSPACE/build" \ | ||
| -checks "clang-analyzer-*,bugprone-*,performance-*,-bugprone-std-namespace-modification" \ | ||
| < "$GITHUB_WORKSPACE/pr.diff" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # This script checks if a diff contains changes that should be inspected by | ||
| # clang-tidy. | ||
|
|
||
| from __future__ import annotations | ||
| import re | ||
| import sys | ||
| from typing import Iterator | ||
|
|
||
| EXCLUDE_PATH_RE = re.compile(r"(?:^|/)(test|test-e2e|unittests)(?:/|$)") | ||
|
|
||
|
|
||
| def is_relevant_path(path: str) -> bool: | ||
| return EXCLUDE_PATH_RE.search(path) is None | ||
|
|
||
|
|
||
| # This iterator splits a diff file into separate sections like: | ||
| # diff --git a/path-to/file b/path-to/file | ||
| # ... code changes ... | ||
| def iter_diff_sections(diff_content: str) -> Iterator[str]: | ||
| section_lines: list[str] = [] | ||
| started = False | ||
|
|
||
| for line in diff_content.splitlines(True): # keep '\n' | ||
| if line.startswith("diff --git "): | ||
| if started and section_lines: | ||
| yield "".join(section_lines) | ||
| section_lines = [] | ||
| started = True | ||
|
|
||
| if started: | ||
| section_lines.append(line) | ||
|
|
||
| if started and section_lines: | ||
| yield "".join(section_lines) | ||
|
|
||
|
|
||
| def main() -> int: | ||
| diff_path = sys.argv[1] | ||
| with open(diff_path, "r", encoding="utf-8", errors="replace") as f: | ||
| diff_content = f.read() | ||
|
|
||
| should_run = False | ||
| for section in iter_diff_sections(diff_content): | ||
| lines = section.splitlines() | ||
| # Skip removed files. | ||
| if lines[4] == "+++ /dev/null": | ||
| continue | ||
| result_file = lines[3] | ||
| # Skip non-c++ files. | ||
| if not result_file.endswith((".cpp", ".hpp", ".h")): | ||
| continue | ||
| # Skip tests etc. | ||
| if not is_relevant_path(result_file): | ||
| continue | ||
| # Check if any non-comment string was added. | ||
| for line in lines[4:]: | ||
| if line.startswith("+") and not line[1:].lstrip().startswith("//"): | ||
| should_run = True | ||
| break | ||
| if should_run == True: | ||
| break | ||
|
|
||
| sys.exit(0 if should_run else 1) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / zizmor
unpinned image references Error