From 2dbf9d393789e8790fc2c8d08089ad8eee3db2a9 Mon Sep 17 00:00:00 2001 From: Jacob Oursland Date: Mon, 16 Jun 2025 22:53:26 -0700 Subject: [PATCH] CI: limit C++ lint to changed lines. --- .github/workflows/CI_master.yml | 3 +++ .github/workflows/sub_lint.yml | 10 ++++++++++ tools/lint/clang_tidy.py | 11 ++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI_master.yml b/.github/workflows/CI_master.yml index 55b2db64d7..c36304c27b 100644 --- a/.github/workflows/CI_master.yml +++ b/.github/workflows/CI_master.yml @@ -63,8 +63,11 @@ jobs: with: artifactBasename: Lint-${{ github.run_id }} changedFiles: ${{ needs.Prepare.outputs.changedFiles }} + changedLines: ${{ needs.Prepare.outputs.changedLines }} changedCppFiles: ${{ needs.Prepare.outputs.changedCppFiles }} + changedCppLines: ${{ needs.Prepare.outputs.changedCppLines }} changedPythonFiles: ${{ needs.Prepare.outputs.changedPythonFiles }} + changedPythonLines: ${{ needs.Prepare.outputs.changedPythonLines }} WrapUp: needs: [ diff --git a/.github/workflows/sub_lint.yml b/.github/workflows/sub_lint.yml index 9b020394db..ac31ef17e1 100644 --- a/.github/workflows/sub_lint.yml +++ b/.github/workflows/sub_lint.yml @@ -34,12 +34,21 @@ on: changedFiles: type: string required: true + changedLines: + type: string + required: false changedCppFiles: type: string required: true + changedCppLines: + type: string + required: false changedPythonFiles: type: string required: true + changedPythonLines: + type: string + required: false checkLineendings: default: false type: boolean @@ -317,6 +326,7 @@ jobs: run: | python3 tools/lint/clang_tidy.py \ --files "${{ inputs.changedCppFiles }}" \ + --line-filter '${{ inputs.changedCppLines }}' \ --clang-style "${{ inputs.clangStyle }}" \ --log-dir "${{ env.logdir }}" \ --report-file "${{ env.reportdir }}${{ env.reportfilename }}" diff --git a/tools/lint/clang_tidy.py b/tools/lint/clang_tidy.py index ea48be086c..8cb86c4f25 100644 --- a/tools/lint/clang_tidy.py +++ b/tools/lint/clang_tidy.py @@ -76,6 +76,11 @@ def main(): required=True, help="Clang-format style (e.g., 'file' to use .clang-format or a specific style).", ) + parser.add_argument( + "--line-filter", + required=False, + help='Line-filter for clang-tidy (i.e. [{"name":"file1.cpp","lines":[[1,3],[5,7]]},...])', + ) args = parser.parse_args() init_environment(args) @@ -96,7 +101,11 @@ def main(): enabled_checks_log = os.path.join(args.log_dir, "clang-tidy-enabled-checks.log") write_file(enabled_checks_log, enabled_output) - clang_cmd = clang_tidy_base_cmd + args.files.split() + clang_cmd = clang_tidy_base_cmd + if args.line_filter: + clang_cmd = clang_cmd + [f"--line-filter={args.line_filter}"] + clang_cmd = clang_cmd + args.files.split() + print("clang_cmd = ", clang_cmd) clang_stdout, clang_stderr, _ = run_command(clang_cmd) clang_tidy_output = clang_stdout + clang_stderr