-
Notifications
You must be signed in to change notification settings - Fork 3
Enable clang-tidy tooling #91
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
Open
colin-higgins
wants to merge
6
commits into
main
Choose a base branch
from
colin.higgins/static-analysis-groundwork
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e200618
Enable clang-tidy tooling
colin-higgins ad58f90
Install clang-tidy in the Alpine CI job
colin-higgins 0e23a6f
Pin clang-tidy-17 and run it in the devcontainer
colin-higgins 0e9f77d
Limit clang-tidy to configured module sources
colin-higgins 829b7f1
Run clang-tidy via CMake CXX_CLANG_TIDY
colin-higgins 4cc4def
Defer clang-tidy checks with existing findings
colin-higgins 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,36 @@ | ||
| # Shared clang-tidy baseline for dd-trace-cpp, httpd-datadog, and nginx-datadog. | ||
| # Keep this file in sync across those repositories. | ||
| Checks: > | ||
| -*, | ||
| bugprone-assert-side-effect, | ||
| bugprone-bool-pointer-implicit-conversion, | ||
| bugprone-copy-constructor-init, | ||
| bugprone-dangling-handle, | ||
| bugprone-forwarding-reference-overload, | ||
| bugprone-inaccurate-erase, | ||
| bugprone-infinite-loop, | ||
| bugprone-macro-repeated-side-effects, | ||
| bugprone-move-forwarding-reference, | ||
| bugprone-parent-virtual-call, | ||
| bugprone-posix-return, | ||
| bugprone-string-constructor, | ||
| bugprone-undelegated-constructor, | ||
| bugprone-unused-raii, | ||
| bugprone-virtual-near-miss, | ||
| misc-unused-using-decls, | ||
| readability-delete-null-pointer, | ||
| readability-redundant-control-flow, | ||
| readability-redundant-string-cstr | ||
| # Deferred until existing findings are cleaned up: | ||
| # bugprone-argument-comment | ||
| # bugprone-use-after-move | ||
| # misc-redundant-expression | ||
| # misc-static-assert | ||
| # modernize-redundant-void-arg | ||
| # performance-move-const-arg | ||
| # performance-noexcept-move-constructor | ||
| # readability-redundant-member-init | ||
| # readability-simplify-boolean-expr | ||
| WarningsAsErrors: '*' | ||
| HeaderFilterRegex: 'mod_datadog/src/' | ||
| FormatStyle: file |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #!/usr/bin/env bash | ||
| # Run the pinned clang-tidy through CMake in the httpd-datadog devcontainer. | ||
| # | ||
| # clang-tidy must use the same compiler, flags, and sysroot as the real | ||
| # build (ci-dev). CMake's CXX_CLANG_TIDY on mod_datadog does that: it | ||
| # invokes tidy with the exact compile line after `--`. Do not run tidy | ||
| # against a host compilation database. | ||
| # | ||
| # Usage: | ||
| # make lint-tidy | ||
| # ./scripts/clang-tidy.sh | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) | ||
| REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd) | ||
| cd "$REPO_ROOT" | ||
|
|
||
| # Must match LLVM_VERSION in .devcontainer/Dockerfile (major). | ||
| CLANG_TIDY_VERSION=17 | ||
|
|
||
| in_container() { | ||
| [[ -f /.dockerenv ]] || [[ -n "${KUBERNETES_SERVICE_HOST:-}" ]] || \ | ||
| [[ "${HTTPD_DATADOG_TIDY_IN_CONTAINER:-}" == "1" ]] | ||
| } | ||
|
|
||
| if ! in_container; then | ||
| if ! command -v docker >/dev/null 2>&1; then | ||
| >&2 echo "docker is required to run clang-tidy-${CLANG_TIDY_VERSION}." | ||
| exit 1 | ||
| fi | ||
| exec make -C "$REPO_ROOT" lint-tidy | ||
| fi | ||
|
|
||
| build_dir=${BUILD_DIR:-.clang-tidy-build} | ||
| tidy="clang-tidy-${CLANG_TIDY_VERSION}" | ||
|
|
||
| if ! command -v "$tidy" >/dev/null 2>&1 && command -v clang-tidy >/dev/null 2>&1; then | ||
| found_major=$(clang-tidy --version | sed -n 's/.*version \([0-9][0-9]*\).*/\1/p' | head -n 1) | ||
| if [[ "$found_major" == "$CLANG_TIDY_VERSION" ]]; then | ||
| tidy=clang-tidy | ||
| fi | ||
| fi | ||
|
|
||
| if ! command -v "$tidy" >/dev/null 2>&1; then | ||
| apk add --no-cache clang-extra-tools | ||
| if command -v clang-tidy >/dev/null 2>&1; then | ||
| found_major=$(clang-tidy --version | sed -n 's/.*version \([0-9][0-9]*\).*/\1/p' | head -n 1) | ||
| if [[ "$found_major" != "$CLANG_TIDY_VERSION" ]]; then | ||
| >&2 echo "clang-tidy ${found_major} is installed, but ${CLANG_TIDY_VERSION} is pinned." | ||
| exit 1 | ||
| fi | ||
| tidy=clang-tidy | ||
| fi | ||
| fi | ||
|
|
||
| if ! command -v "$tidy" >/dev/null 2>&1; then | ||
| >&2 echo "clang-tidy-${CLANG_TIDY_VERSION} is required (pinned)." | ||
| exit 1 | ||
| fi | ||
|
|
||
| compiler=${CXX:-clang++} | ||
| if ! command -v "$compiler" >/dev/null 2>&1; then | ||
| >&2 echo "$compiler is required (same toolchain as CMake)." | ||
| exit 1 | ||
| fi | ||
|
|
||
| compiler_major=$("$compiler" -dumpversion | cut -d. -f1) | ||
| tidy_major=$("$tidy" --version | sed -n 's/.*version \([0-9][0-9]*\).*/\1/p' | head -n 1) | ||
| if [[ "$compiler_major" != "$CLANG_TIDY_VERSION" || "$tidy_major" != "$CLANG_TIDY_VERSION" ]]; then | ||
| >&2 echo "clang-tidy and the CMake compiler must both be LLVM ${CLANG_TIDY_VERSION}." | ||
| >&2 echo " ${compiler}: ${compiler_major}" | ||
| >&2 echo " ${tidy}: ${tidy_major}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| git config --global --add safe.directory "$REPO_ROOT" >/dev/null 2>&1 || true | ||
| if [[ ! -f deps/dd-trace-cpp/CMakeLists.txt ]] || [[ ! -f deps/nginx-datadog/CMakeLists.txt ]]; then | ||
| git submodule update --init --depth=1 deps/dd-trace-cpp deps/nginx-datadog | ||
| fi | ||
|
|
||
| # Reconfigure so CXX_CLANG_TIDY is attached to mod_datadog, then compile | ||
| # that target. CMake passes the exact ci-dev compile line to tidy. | ||
| # RUM is off in ci-dev, so rum/ is not a source of mod_datadog. | ||
| cmake --preset=ci-dev -B "$build_dir" . \ | ||
| -DHTTPD_DATADOG_ENABLE_CLANG_TIDY=ON \ | ||
| -DHTTPD_DATADOG_CLANG_TIDY="$tidy" | ||
|
|
||
| cmake --build "$build_dir" --target mod_datadog |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This image is built from
.devcontainer/Dockerfile, whoseapk addlist installsclangandllvmbut not the extra-tools package that providesclang-tidy. Every new pull-request job therefore reachesscripts/clang-tidy.sh, fails its tool lookup, and exits before doing any analysis. Install clang-tidy in the devcontainer image or in this job.Useful? React with 👍 / 👎.