From 1d93369a82c13c186e2d8f43f9df20abc40680ee Mon Sep 17 00:00:00 2001 From: Suyash Dongre Date: Tue, 16 Jul 2024 21:43:50 +0530 Subject: [PATCH 01/12] adding clang-tidy as linter tool Signed-off-by: Suyash Dongre --- ceph-pr-clang-tidy/build/build | 1 + .../config/ceph-pr-clang-tidy.yml | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 ceph-pr-clang-tidy/build/build create mode 100644 ceph-pr-clang-tidy/config/ceph-pr-clang-tidy.yml diff --git a/ceph-pr-clang-tidy/build/build b/ceph-pr-clang-tidy/build/build new file mode 100644 index 000000000..6b389d4c5 --- /dev/null +++ b/ceph-pr-clang-tidy/build/build @@ -0,0 +1 @@ +sudo apt-get install -y clang-tidy diff --git a/ceph-pr-clang-tidy/config/ceph-pr-clang-tidy.yml b/ceph-pr-clang-tidy/config/ceph-pr-clang-tidy.yml new file mode 100644 index 000000000..f80bc39d6 --- /dev/null +++ b/ceph-pr-clang-tidy/config/ceph-pr-clang-tidy.yml @@ -0,0 +1,61 @@ +- job: + name: ceph-pr-clang-tidy + node: small + project-type: freestyle + defaults: global + display-name: 'ceph: Clang-tidy checks' + concurrent: true + quiet-period: 5 + block-downstream: false + block-upstream: false + retry-count: 3 + properties: + - build-discarder: + days-to-keep: 15 + artifact-days-to-keep: 15 + - github: + url: https://github.com/ceph/ceph/ + + parameters: + - string: + name: ghprbPullId + description: "the GitHub pull id, like '72' in 'ceph/pull/72'" + default: origin/main + + scm: + - git: + url: https://github.com/ceph/ceph.git + name: origin + branches: + - origin/pr/${ghprbPullId}/merge + refspec: +refs/pull/${ghprbPullId}/*:refs/remotes/origin/pr/${ghprbPullId}/* + skip-tag: true + shallow-clone: true + honor-refspec: true + timeout: 20 + + triggers: + - github-pull-request: + allow-whitelist-orgs-as-admins: true + org-list: + - ceph + trigger-phrase: 'jenkins test clang-tidy' + only-trigger-phrase: false + github-hooks: true + permit-all: true + auto-close-on-fail: false + status-context: "Signed-off-by" + started-status: "checking if bugs exist in file" + success-status: "no bugs found" + failure-status: "bugs found" + + builders: + - shell: + !include-raw: + - ../../../scripts/build_utils.sh + - ../../build/build + + publishers: + - junit: + results: report.xml + allow-empty-results: true From f724d88c92f206da919f657b4847db33681ea425 Mon Sep 17 00:00:00 2001 From: Suyash Dongre Date: Sun, 21 Jul 2024 22:57:36 +0530 Subject: [PATCH 02/12] Added build steps Signed-off-by: Suyash Dongre --- ceph-pr-clang-tidy/build/build | 34 +++++++++++++++++++ .../config/ceph-pr-clang-tidy.yml | 6 ---- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/ceph-pr-clang-tidy/build/build b/ceph-pr-clang-tidy/build/build index 6b389d4c5..95fbe922e 100644 --- a/ceph-pr-clang-tidy/build/build +++ b/ceph-pr-clang-tidy/build/build @@ -1 +1,35 @@ +#!/bin/bash +set -ex + +docs_pr_only +if [ "$DOCS_ONLY" = true ]; then + echo "Only the doc/ dir changed. No need to run make check or API tests." + mkdir -p $WORKSPACE/build/out + echo "File created to avoid Jenkins' Artifact Archiving plugin from hanging" > $WORKSPACE/build/out/mgr.foo.log + exit 0 +fi + sudo apt-get install -y clang-tidy + +sudo apt-get install -y parallel + +build_debs ${VENV} ${vers} ${debian_version} + +output_file="clang-tidy-result" +file_list="files_to_check.txt" + +# Store the list of files from both rgw and osd directories +find "$WORKSPACE/src/rgw" \( -name '*.cpp' -o -name '*.hpp' -o -name '*.cc' \) > "$file_list" +find "$WORKSPACE/src/osd" \( -name '*.cpp' -o -name '*.hpp' -o -name '*.cc' \) >> "$file_list" + +# Run clang-tidy and save output +{ + echo "Files being checked:" + cat "$file_list" + echo + parallel -m clang-tidy -checks="-*,bugprone-use-after-move" -p "$WORKSPACE/build" {} < "$file_list" +} | tee "$WORKSPACE/build/$output_file" + +sudo chmod +x ../src/script/clang-tidy-to-junit.py + +cat "$WORKSPACE/build/$output_file" | ../src/script/clang-tidy-to-junit.py $WORKSPACE/src >"$WORKSPACE/report.xml" \ No newline at end of file diff --git a/ceph-pr-clang-tidy/config/ceph-pr-clang-tidy.yml b/ceph-pr-clang-tidy/config/ceph-pr-clang-tidy.yml index f80bc39d6..b8d5e70ae 100644 --- a/ceph-pr-clang-tidy/config/ceph-pr-clang-tidy.yml +++ b/ceph-pr-clang-tidy/config/ceph-pr-clang-tidy.yml @@ -16,12 +16,6 @@ - github: url: https://github.com/ceph/ceph/ - parameters: - - string: - name: ghprbPullId - description: "the GitHub pull id, like '72' in 'ceph/pull/72'" - default: origin/main - scm: - git: url: https://github.com/ceph/ceph.git From efeb4fab5faf4a6d44c4ba9c7f85e13136181f77 Mon Sep 17 00:00:00 2001 From: Suyash Dongre Date: Mon, 22 Jul 2024 09:27:58 +0530 Subject: [PATCH 03/12] added the script clang-tidy-to-junit for report generation Signed-off-by: Suyash Dongre --- ceph-pr-clang-tidy/build/LICENSE | 21 ++++ ceph-pr-clang-tidy/build/build | 4 +- .../build/clang-tidy-to-junit.py | 117 ++++++++++++++++++ .../{ => definitions}/ceph-pr-clang-tidy.yml | 3 +- 4 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 ceph-pr-clang-tidy/build/LICENSE create mode 100755 ceph-pr-clang-tidy/build/clang-tidy-to-junit.py rename ceph-pr-clang-tidy/config/{ => definitions}/ceph-pr-clang-tidy.yml (93%) diff --git a/ceph-pr-clang-tidy/build/LICENSE b/ceph-pr-clang-tidy/build/LICENSE new file mode 100644 index 000000000..e4605d415 --- /dev/null +++ b/ceph-pr-clang-tidy/build/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 PSPDFKit + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/ceph-pr-clang-tidy/build/build b/ceph-pr-clang-tidy/build/build index 95fbe922e..e3e4c1bd8 100644 --- a/ceph-pr-clang-tidy/build/build +++ b/ceph-pr-clang-tidy/build/build @@ -30,6 +30,6 @@ find "$WORKSPACE/src/osd" \( -name '*.cpp' -o -name '*.hpp' -o -name '*.cc' \) > parallel -m clang-tidy -checks="-*,bugprone-use-after-move" -p "$WORKSPACE/build" {} < "$file_list" } | tee "$WORKSPACE/build/$output_file" -sudo chmod +x ../src/script/clang-tidy-to-junit.py +sudo chmod +x clang-tidy-to-junit.py -cat "$WORKSPACE/build/$output_file" | ../src/script/clang-tidy-to-junit.py $WORKSPACE/src >"$WORKSPACE/report.xml" \ No newline at end of file +cat "$WORKSPACE/build/$output_file" | clang-tidy-to-junit.py $WORKSPACE/src >"$WORKSPACE/report.xml" \ No newline at end of file diff --git a/ceph-pr-clang-tidy/build/clang-tidy-to-junit.py b/ceph-pr-clang-tidy/build/clang-tidy-to-junit.py new file mode 100755 index 000000000..7a80ae2f3 --- /dev/null +++ b/ceph-pr-clang-tidy/build/clang-tidy-to-junit.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 + +import sys +import collections +import re +import logging +import itertools +from xml.sax.saxutils import escape + +# Create a `ErrorDescription` tuple with all the information we want to keep. +ErrorDescription = collections.namedtuple( + 'ErrorDescription', 'file line column error error_identifier description') + + +class ClangTidyConverter: + # All the errors encountered. + errors = [] + + # Parses the error. + # Group 1: file path + # Group 2: line + # Group 3: column + # Group 4: error message + # Group 5: error identifier + error_regex = re.compile( + r"^([\w\/\.\-\ ]+):(\d+):(\d+): (.+) (\[[\w\-,\.]+\])$") + + # This identifies the main error line (it has a [the-warning-type] at the end) + # We only create a new error when we encounter one of those. + main_error_identifier = re.compile(r'\[[\w\-,\.]+\]$') + + def __init__(self, basename): + self.basename = basename + + def print_junit_file(self, output_file): + # Write the header. + output_file.write(""" +""".format(error_count=len(self.errors))) + + sorted_errors = sorted(self.errors, key=lambda x: x.file) + + # Iterate through the errors, grouped by file. + for file, errorIterator in itertools.groupby(sorted_errors, key=lambda x: x.file): + errors = list(errorIterator) + error_count = len(errors) + + # Each file gets a test-suite + output_file.write("""\n \n""" + .format(error_count=error_count, file=file)) + for error in errors: + # Write each error as a test case. + output_file.write(""" + + +{htmldata} + + """.format(id="[{}/{}] {}".format(error.line, error.column, error.error_identifier), + message=escape(error.error, entities={"\"": """}), + htmldata=escape(error.description))) + output_file.write("\n \n") + output_file.write("\n") + + def process_error(self, error_array): + if len(error_array) == 0: + return + + result = self.error_regex.match(error_array[0]) + if result is None: + logging.warning( + 'Could not match error_array to regex: %s', error_array) + return + + # We remove the `basename` from the `file_path` to make prettier filenames in the JUnit file. + file_path = result.group(1).replace(self.basename, "") + error = ErrorDescription(file_path, int(result.group(2)), int( + result.group(3)), result.group(4), result.group(5), "\n".join(error_array[1:])) + self.errors.append(error) + + def convert(self, input_file, output_file): + # Collect all lines related to one error. + current_error = [] + for line in input_file: + # If the line starts with a `/`, it is a line about a file. + if line[0] == '/': + # Look if it is the start of a error + if self.main_error_identifier.search(line, re.M): + # If so, process any `current_error` we might have + self.process_error(current_error) + # Initialize `current_error` with the first line of the error. + current_error = [line] + else: + # Otherwise, append the line to the error. + current_error.append(line) + elif len(current_error) > 0: + # If the line didn't start with a `/` and we have a `current_error`, we simply append + # the line as additional information. + current_error.append(line) + else: + pass + + # If we still have any current_error after we read all the lines, + # process it. + if len(current_error) > 0: + self.process_error(current_error) + + # Print the junit file. + self.print_junit_file(output_file) + + +if __name__ == "__main__": + if len(sys.argv) < 2: + logging.error("Usage: %s base-filename-path", sys.argv[0]) + logging.error( + " base-filename-path: Removed from the filenames to make nicer paths.") + sys.exit(1) + converter = ClangTidyConverter(sys.argv[1]) + converter.convert(sys.stdin, sys.stdout) diff --git a/ceph-pr-clang-tidy/config/ceph-pr-clang-tidy.yml b/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml similarity index 93% rename from ceph-pr-clang-tidy/config/ceph-pr-clang-tidy.yml rename to ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml index b8d5e70ae..43aed73e9 100644 --- a/ceph-pr-clang-tidy/config/ceph-pr-clang-tidy.yml +++ b/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml @@ -39,7 +39,7 @@ permit-all: true auto-close-on-fail: false status-context: "Signed-off-by" - started-status: "checking if bugs exist in file" + started-status: "checking if bugs exist" success-status: "no bugs found" failure-status: "bugs found" @@ -48,6 +48,7 @@ !include-raw: - ../../../scripts/build_utils.sh - ../../build/build + - ../../build/clang-tidy-to-junit.py publishers: - junit: From 31aead3d4c51a42d6f84ff0e41bf5788dc51575b Mon Sep 17 00:00:00 2001 From: Suyash Dongre Date: Wed, 24 Jul 2024 18:23:44 +0530 Subject: [PATCH 04/12] refactored clang-tidy-to-junit.py execution Signed-off-by: Suyash Dongre --- ceph-pr-clang-tidy/build/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ceph-pr-clang-tidy/build/build b/ceph-pr-clang-tidy/build/build index e3e4c1bd8..5542a519f 100644 --- a/ceph-pr-clang-tidy/build/build +++ b/ceph-pr-clang-tidy/build/build @@ -32,4 +32,4 @@ find "$WORKSPACE/src/osd" \( -name '*.cpp' -o -name '*.hpp' -o -name '*.cc' \) > sudo chmod +x clang-tidy-to-junit.py -cat "$WORKSPACE/build/$output_file" | clang-tidy-to-junit.py $WORKSPACE/src >"$WORKSPACE/report.xml" \ No newline at end of file +clang-tidy-to-junit.py $WORKSPACE/src < "$WORKSPACE/build/$output_file" > "$WORKSPACE/report.xml" \ No newline at end of file From 600c0353737b733158f10e8039cf5178c8fbdd01 Mon Sep 17 00:00:00 2001 From: Suyash Dongre Date: Wed, 24 Jul 2024 18:43:56 +0530 Subject: [PATCH 05/12] refactored status-context Signed-off-by: Suyash Dongre --- ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml b/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml index 43aed73e9..565403e0a 100644 --- a/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml +++ b/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml @@ -38,7 +38,7 @@ github-hooks: true permit-all: true auto-close-on-fail: false - status-context: "Signed-off-by" + status-context: "Clang-tidy lint check" started-status: "checking if bugs exist" success-status: "no bugs found" failure-status: "bugs found" From 9935304e2197b7184d2f3a8f4abb03f3211168b2 Mon Sep 17 00:00:00 2001 From: Suyash Dongre Date: Sat, 27 Jul 2024 01:04:23 +0530 Subject: [PATCH 06/12] renamed LICENSE and added node configuration Signed-off-by: Suyash Dongre --- .../build/{LICENSE => LICENSE.clang-tidy-to-junit.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ceph-pr-clang-tidy/build/{LICENSE => LICENSE.clang-tidy-to-junit.py} (100%) diff --git a/ceph-pr-clang-tidy/build/LICENSE b/ceph-pr-clang-tidy/build/LICENSE.clang-tidy-to-junit.py similarity index 100% rename from ceph-pr-clang-tidy/build/LICENSE rename to ceph-pr-clang-tidy/build/LICENSE.clang-tidy-to-junit.py From 5e54b916f3c219cf4d870960ccba594d469a4489 Mon Sep 17 00:00:00 2001 From: Suyash Dongre Date: Sat, 27 Jul 2024 01:08:03 +0530 Subject: [PATCH 07/12] added node configuration Signed-off-by: Suyash Dongre --- ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml b/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml index 565403e0a..448244439 100644 --- a/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml +++ b/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml @@ -1,6 +1,6 @@ - job: name: ceph-pr-clang-tidy - node: small + node: jammy && small project-type: freestyle defaults: global display-name: 'ceph: Clang-tidy checks' From d64fdaae67da99a6dd303eebc4033298eb0c5f53 Mon Sep 17 00:00:00 2001 From: Suyash Dongre Date: Sat, 24 Aug 2024 14:30:18 +0530 Subject: [PATCH 08/12] configured to work with `copy_artifacts` plugin Instead of building Ceph, existing `build` would be copied from the job `ceph-pull-requests` (make-check) to save resources on building Ceph. Signed-off-by: Suyash Dongre --- ceph-pr-clang-tidy/build/build | 17 ++++++++------- .../config/definitions/ceph-pr-clang-tidy.yml | 21 +++---------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/ceph-pr-clang-tidy/build/build b/ceph-pr-clang-tidy/build/build index 5542a519f..13c76358e 100644 --- a/ceph-pr-clang-tidy/build/build +++ b/ceph-pr-clang-tidy/build/build @@ -13,23 +13,26 @@ sudo apt-get install -y clang-tidy sudo apt-get install -y parallel -build_debs ${VENV} ${vers} ${debian_version} - output_file="clang-tidy-result" file_list="files_to_check.txt" +# The file `ceph_build.tar.gz` is copied from the job `ceph-pull-request` using copy_artifacts +tar -xzf ceph_build.tar.gz -C "$WORKSPACE" + +rm ceph_build.tar.gz + # Store the list of files from both rgw and osd directories -find "$WORKSPACE/src/rgw" \( -name '*.cpp' -o -name '*.hpp' -o -name '*.cc' \) > "$file_list" -find "$WORKSPACE/src/osd" \( -name '*.cpp' -o -name '*.hpp' -o -name '*.cc' \) >> "$file_list" +find "$WORKSPACE/ceph/src/rgw" \( -name '*.cpp' -o -name '*.hpp' -o -name '*.cc' \) > "$file_list" +find "$WORKSPACE/ceph/src/osd" \( -name '*.cpp' -o -name '*.hpp' -o -name '*.cc' \) >> "$file_list" # Run clang-tidy and save output { echo "Files being checked:" cat "$file_list" echo - parallel -m clang-tidy -checks="-*,bugprone-use-after-move" -p "$WORKSPACE/build" {} < "$file_list" -} | tee "$WORKSPACE/build/$output_file" + parallel -m clang-tidy -checks="-*,bugprone-use-after-move" -p "$WORKSPACE/ceph/build" {} < "$file_list" +} | tee "$WORKSPACE/ceph/build/$output_file" sudo chmod +x clang-tidy-to-junit.py -clang-tidy-to-junit.py $WORKSPACE/src < "$WORKSPACE/build/$output_file" > "$WORKSPACE/report.xml" \ No newline at end of file +clang-tidy-to-junit.py $WORKSPACE/ceph/src < "$WORKSPACE/ceph/build/$output_file" > "$WORKSPACE/report.xml" \ No newline at end of file diff --git a/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml b/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml index 448244439..8ae8f683e 100644 --- a/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml +++ b/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml @@ -13,37 +13,22 @@ - build-discarder: days-to-keep: 15 artifact-days-to-keep: 15 - - github: - url: https://github.com/ceph/ceph/ - - scm: - - git: - url: https://github.com/ceph/ceph.git - name: origin - branches: - - origin/pr/${ghprbPullId}/merge - refspec: +refs/pull/${ghprbPullId}/*:refs/remotes/origin/pr/${ghprbPullId}/* - skip-tag: true - shallow-clone: true - honor-refspec: true - timeout: 20 triggers: - github-pull-request: allow-whitelist-orgs-as-admins: true org-list: - ceph - trigger-phrase: 'jenkins test clang-tidy' only-trigger-phrase: false - github-hooks: true - permit-all: true - auto-close-on-fail: false status-context: "Clang-tidy lint check" started-status: "checking if bugs exist" success-status: "no bugs found" failure-status: "bugs found" builders: + - copyartifact: + project: ceph-pull-requests + - shell: !include-raw: - ../../../scripts/build_utils.sh From 498e2a30aee4bb56f6c4a2c6538eafd7e3dc947f Mon Sep 17 00:00:00 2001 From: Suyashd999 Date: Sun, 24 Nov 2024 16:17:21 +0530 Subject: [PATCH 09/12] updated to run clang-tidy on all files --- ceph-pr-clang-tidy/build/build | 39 ++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/ceph-pr-clang-tidy/build/build b/ceph-pr-clang-tidy/build/build index 13c76358e..eb0693490 100644 --- a/ceph-pr-clang-tidy/build/build +++ b/ceph-pr-clang-tidy/build/build @@ -3,36 +3,47 @@ set -ex docs_pr_only if [ "$DOCS_ONLY" = true ]; then - echo "Only the doc/ dir changed. No need to run make check or API tests." + echo "Only the doc/ dir changed. No need to run make check or API tests." mkdir -p $WORKSPACE/build/out echo "File created to avoid Jenkins' Artifact Archiving plugin from hanging" > $WORKSPACE/build/out/mgr.foo.log exit 0 fi sudo apt-get install -y clang-tidy - sudo apt-get install -y parallel - output_file="clang-tidy-result" file_list="files_to_check.txt" # The file `ceph_build.tar.gz` is copied from the job `ceph-pull-request` using copy_artifacts tar -xzf ceph_build.tar.gz -C "$WORKSPACE" - rm ceph_build.tar.gz -# Store the list of files from both rgw and osd directories -find "$WORKSPACE/ceph/src/rgw" \( -name '*.cpp' -o -name '*.hpp' -o -name '*.cc' \) > "$file_list" -find "$WORKSPACE/ceph/src/osd" \( -name '*.cpp' -o -name '*.hpp' -o -name '*.cc' \) >> "$file_list" +# Get list of modified files in the current commit +cd "$WORKSPACE/ceph" +git diff --name-only HEAD~1 HEAD > modified_files.txt + +# Filter for only C++ files in rgw and osd directories +cat modified_files.txt | grep -E "^(src/rgw|src/osd).*\.(cpp|hpp|cc)$" > "$file_list" -# Run clang-tidy and save output +# Check if there are any files to analyze +if [ ! -s "$file_list" ]; then + echo "No C++ files were modified in rgw or osd directories in this commit." + mkdir -p "$WORKSPACE/ceph/build" + echo "No files to analyze" > "$WORKSPACE/ceph/build/$output_file" + # Create empty report to avoid potential CI issues + echo "" > "$WORKSPACE/report.xml" + exit 0 +fi + +# Run clang-tidy only on modified files and save output { - echo "Files being checked:" - cat "$file_list" - echo - parallel -m clang-tidy -checks="-*,bugprone-use-after-move" -p "$WORKSPACE/ceph/build" {} < "$file_list" + echo "Files being checked:" + cat "$file_list" + echo + # Add full path to files + sed -i "s|^|$WORKSPACE/ceph/|" "$file_list" + parallel -m clang-tidy -checks="-*,bugprone-use-after-move" -p "$WORKSPACE/ceph/build" {} < "$file_list" } | tee "$WORKSPACE/ceph/build/$output_file" sudo chmod +x clang-tidy-to-junit.py - -clang-tidy-to-junit.py $WORKSPACE/ceph/src < "$WORKSPACE/ceph/build/$output_file" > "$WORKSPACE/report.xml" \ No newline at end of file +./clang-tidy-to-junit.py $WORKSPACE/ceph/src < "$WORKSPACE/ceph/build/$output_file" > "$WORKSPACE/report.xml" \ No newline at end of file From 84e84184c20c163df4f70a9b6b2afa62fc916405 Mon Sep 17 00:00:00 2001 From: Suyash Dongre Date: Sat, 28 Dec 2024 18:00:37 +0530 Subject: [PATCH 10/12] Working with new "build/boost" and "build/include" from the tar file --- ceph-pr-clang-tidy/build/build | 42 ++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/ceph-pr-clang-tidy/build/build b/ceph-pr-clang-tidy/build/build index eb0693490..37554fd7b 100644 --- a/ceph-pr-clang-tidy/build/build +++ b/ceph-pr-clang-tidy/build/build @@ -1,25 +1,36 @@ #!/bin/bash set -ex -docs_pr_only -if [ "$DOCS_ONLY" = true ]; then - echo "Only the doc/ dir changed. No need to run make check or API tests." - mkdir -p $WORKSPACE/build/out - echo "File created to avoid Jenkins' Artifact Archiving plugin from hanging" > $WORKSPACE/build/out/mgr.foo.log - exit 0 -fi +# Clone the Ceph repository +git clone https://github.com/ceph/ceph.git "$WORKSPACE/ceph" +cd "$WORKSPACE/ceph" + +# Initialize and update submodules +git submodule update --init --recursive --progress + +# Install dependencies +sudo apt-get install -y curl +./install-deps.sh +sudo apt-get install -y python3-routes -sudo apt-get install -y clang-tidy -sudo apt-get install -y parallel +# Configure the build +./do_cmake.sh -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON +cd build + +# Replace the boost and include directories from the tar file +tar -xzf "$WORKSPACE/ceph_build.tar.gz" -C "$WORKSPACE" +rm "$WORKSPACE/ceph_build.tar.gz" +sudo rm -rf boost include +sudo mv "$WORKSPACE/build/boost" ./boost +sudo mv "$WORKSPACE/build/include" ./include + +# Prepare for Clang-Tidy +cd "$WORKSPACE/ceph" +sudo apt-get install -y clang-tidy parallel output_file="clang-tidy-result" file_list="files_to_check.txt" -# The file `ceph_build.tar.gz` is copied from the job `ceph-pull-request` using copy_artifacts -tar -xzf ceph_build.tar.gz -C "$WORKSPACE" -rm ceph_build.tar.gz - # Get list of modified files in the current commit -cd "$WORKSPACE/ceph" git diff --name-only HEAD~1 HEAD > modified_files.txt # Filter for only C++ files in rgw and osd directories @@ -45,5 +56,6 @@ fi parallel -m clang-tidy -checks="-*,bugprone-use-after-move" -p "$WORKSPACE/ceph/build" {} < "$file_list" } | tee "$WORKSPACE/ceph/build/$output_file" +# Generate the Clang-Tidy report sudo chmod +x clang-tidy-to-junit.py -./clang-tidy-to-junit.py $WORKSPACE/ceph/src < "$WORKSPACE/ceph/build/$output_file" > "$WORKSPACE/report.xml" \ No newline at end of file +./clang-tidy-to-junit.py "$WORKSPACE/ceph/src" < "$WORKSPACE/ceph/build/$output_file" > "$WORKSPACE/report.xml" From df5dc10ad3adf7744923cfab1ee3369fe0f72d4d Mon Sep 17 00:00:00 2001 From: Suyash Dongre Date: Tue, 31 Dec 2024 22:33:12 +0530 Subject: [PATCH 11/12] uses shallow clone Signed-off-by: Suyash Dongre --- ceph-pr-clang-tidy/build/build | 5 +---- .../config/definitions/ceph-pr-clang-tidy.yml | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ceph-pr-clang-tidy/build/build b/ceph-pr-clang-tidy/build/build index 37554fd7b..f1911f64b 100644 --- a/ceph-pr-clang-tidy/build/build +++ b/ceph-pr-clang-tidy/build/build @@ -1,8 +1,6 @@ #!/bin/bash set -ex -# Clone the Ceph repository -git clone https://github.com/ceph/ceph.git "$WORKSPACE/ceph" cd "$WORKSPACE/ceph" # Initialize and update submodules @@ -10,8 +8,8 @@ git submodule update --init --recursive --progress # Install dependencies sudo apt-get install -y curl -./install-deps.sh sudo apt-get install -y python3-routes +sudo apt-get install -y clang-tidy parallel # Configure the build ./do_cmake.sh -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON @@ -26,7 +24,6 @@ sudo mv "$WORKSPACE/build/include" ./include # Prepare for Clang-Tidy cd "$WORKSPACE/ceph" -sudo apt-get install -y clang-tidy parallel output_file="clang-tidy-result" file_list="files_to_check.txt" diff --git a/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml b/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml index 8ae8f683e..5bece94b2 100644 --- a/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml +++ b/ceph-pr-clang-tidy/config/definitions/ceph-pr-clang-tidy.yml @@ -13,7 +13,11 @@ - build-discarder: days-to-keep: 15 artifact-days-to-keep: 15 - + + parameters: + - string: + name: BRANCH + default: main triggers: - github-pull-request: allow-whitelist-orgs-as-admins: true @@ -25,9 +29,19 @@ success-status: "no bugs found" failure-status: "bugs found" + scm: + - git: + url: https://github.com/ceph/ceph.git + branches: + - $BRANCH + browser: auto + timeout: 20 + shallow-clone: true + wipe-workspace: true + builders: - copyartifact: - project: ceph-pull-requests + project: ceph-pull-requests - shell: !include-raw: From 7ba7caba6b29f0be5b6ac22a983a7043325be1ce Mon Sep 17 00:00:00 2001 From: Suyash Dongre Date: Wed, 29 Jan 2025 22:06:10 +0530 Subject: [PATCH 12/12] Build script optimized to reduce time taken for Jenkins job to execute --- ceph-pr-clang-tidy/build/build | 85 ++++++++++++++-------------------- 1 file changed, 36 insertions(+), 49 deletions(-) diff --git a/ceph-pr-clang-tidy/build/build b/ceph-pr-clang-tidy/build/build index f1911f64b..4f1ca22fa 100644 --- a/ceph-pr-clang-tidy/build/build +++ b/ceph-pr-clang-tidy/build/build @@ -1,58 +1,45 @@ #!/bin/bash -set -ex -cd "$WORKSPACE/ceph" +set -ex -# Initialize and update submodules -git submodule update --init --recursive --progress +BUILD_DIR="$WORKSPACE/ceph/build" +TAR_FILE_CEPH_DIRS="$WORKSPACE/ceph_directories.tar" +TAR_FILE_SOURCE="$WORKSPACE/source.tar" -# Install dependencies -sudo apt-get install -y curl -sudo apt-get install -y python3-routes -sudo apt-get install -y clang-tidy parallel +echo "Installing dependencies..." +sudo apt-get install -y curl python3-routes clang-tidy -# Configure the build -./do_cmake.sh -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON -cd build +echo "Cloning ceph repository..." +git clone https://github.com/ceph/ceph --depth 10 -# Replace the boost and include directories from the tar file -tar -xzf "$WORKSPACE/ceph_build.tar.gz" -C "$WORKSPACE" -rm "$WORKSPACE/ceph_build.tar.gz" +echo "Extracting ceph_directories.tar to $BUILD_DIR..." +sudo mkdir -p "$BUILD_DIR" +cd "$BUILD_DIR" sudo rm -rf boost include -sudo mv "$WORKSPACE/build/boost" ./boost -sudo mv "$WORKSPACE/build/include" ./include - -# Prepare for Clang-Tidy -cd "$WORKSPACE/ceph" -output_file="clang-tidy-result" -file_list="files_to_check.txt" - -# Get list of modified files in the current commit -git diff --name-only HEAD~1 HEAD > modified_files.txt - -# Filter for only C++ files in rgw and osd directories -cat modified_files.txt | grep -E "^(src/rgw|src/osd).*\.(cpp|hpp|cc)$" > "$file_list" - -# Check if there are any files to analyze -if [ ! -s "$file_list" ]; then - echo "No C++ files were modified in rgw or osd directories in this commit." - mkdir -p "$WORKSPACE/ceph/build" - echo "No files to analyze" > "$WORKSPACE/ceph/build/$output_file" - # Create empty report to avoid potential CI issues - echo "" > "$WORKSPACE/report.xml" - exit 0 +sudo tar -xf "../../$TAR_FILE_CEPH_DIRS" +cd - + +echo "Extracting source.tar to replace src..." +cd ceph +sudo rm -rf src +sudo tar -xf "../$TAR_FILE_SOURCE" +cd .. + +echo "Configuring build with CMake..." +cd "$BUILD_DIR" +sudo cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. +cd - + +echo "Running clang-tidy on modified files in src/rgw/..." +MODIFIED_FILES=$(cd ceph && git diff --name-only HEAD HEAD~1 | grep '^src/rgw/' || true) +if [[ -n "$MODIFIED_FILES" ]]; then + echo "Analyzing files: $MODIFIED_FILES" + cd "$BUILD_DIR" + MODIFIED_PATHS=$(echo "$MODIFIED_FILES" | sed 's|^|../|') + run-clang-tidy -checks="-*,bugprone-use-after-move" $MODIFIED_PATHS || true + cd - +else + echo "No modified files in src/rgw/ to analyze." fi -# Run clang-tidy only on modified files and save output -{ - echo "Files being checked:" - cat "$file_list" - echo - # Add full path to files - sed -i "s|^|$WORKSPACE/ceph/|" "$file_list" - parallel -m clang-tidy -checks="-*,bugprone-use-after-move" -p "$WORKSPACE/ceph/build" {} < "$file_list" -} | tee "$WORKSPACE/ceph/build/$output_file" - -# Generate the Clang-Tidy report -sudo chmod +x clang-tidy-to-junit.py -./clang-tidy-to-junit.py "$WORKSPACE/ceph/src" < "$WORKSPACE/ceph/build/$output_file" > "$WORKSPACE/report.xml" +echo "Script completed successfully."