Skip to content

Commit

Permalink
[CI] Add clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Flakebi committed Feb 28, 2023
1 parent 47792d9 commit d2b2c8f
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 3 deletions.
36 changes: 36 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Checks: '-*,clang-analyzer-*,clang-diagnostic-*,-clang-analyzer-core.CallAndMessage,-clang-analyzer-core.DivideZero,-clang-analyzer-core.NonNullParamChecker,-clang-analyzer-core.NullDereference,-clang-analyzer-core.uninitialized.UndefReturn,-clang-analyzer-core.UndefinedBinaryOperatorResult,-clang-analyzer-optin.cplusplus.VirtualCall,llvm-*,-llvm-include-order,-llvm-qualified-auto,-llvm-header-guard,performance-*,misc-*,-misc-no-recursion,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,readability-simplify-boolean-expr,readability-redundant-nullptr-comparison,readability-redundant-parentheses,readability-declaration-inline-comment'
CheckOptions:
- { key: readability-identifier-naming.ParameterCase, value: camelBack }
- { key: readability-identifier-naming.ParameterRemovePrefixes, value: 'p,b,pfn' }
- { key: readability-identifier-naming.VariableCase, value: camelBack }
- { key: readability-identifier-naming.VariableRemovePrefixes, value: 'p,b,pfn' }
# Need to ignore static field 'ID' because otherwise clang-tidy dives into an llvm
# include file and changes 'ID' to 'm_id' there, which is bad.
- { key: readability-identifier-naming.ClassMemberIgnoredRegexp, value: '^ID|mm.*$' }
- { key: readability-identifier-naming.ClassMemberCase, value: camelBack }
- { key: readability-identifier-naming.ClassMemberRemovePrefixes, value: 'p,b,pfn,m_p,m_b' }
- { key: readability-identifier-naming.ClassMemberPrefix, value: m_ }
- { key: readability-identifier-naming.ClassConstantCase, value: CamelCase }
- { key: readability-identifier-naming.ClassConstantRemovePrefixes, value: 'p,b,pfn,m_p,m_b' }
- { key: readability-identifier-naming.StaticVariableCase, value: CamelCase }
- { key: readability-identifier-naming.StaticVariableRemovePrefixes, value: 'p,b,pfn,s_,s_p' }
- { key: readability-identifier-naming.GlobalVariableIgnoredRegexp, value: 'mm.*' }
- { key: readability-identifier-naming.GlobalVariableCase, value: CamelCase }
- { key: readability-identifier-naming.GlobalVariableRemovePrefixes, value: 'p,b,pfn,g_,g_p' }
- { key: readability-identifier-naming.ConstantMemberIgnoredRegexp, value: 'mm.*' }
- { key: readability-identifier-naming.ConstantMemberCase, value: camelBack }
- { key: readability-identifier-naming.ConstantMemberRemovePrefixes, value: 'p,b,pfn,m_p,m_b' }
- { key: readability-identifier-naming.ConstantMemberPrefix, value: m_ }
- { key: readability-identifier-naming.PublicMemberCase, value: camelBack }
- { key: readability-identifier-naming.PublicMemberIgnoredRegexp, value: '^pSymName$' }
- { key: readability-identifier-naming.PublicMemberPrefix, value: '' }
- { key: readability-identifier-naming.PublicMemberRemovePrefixes, value: 'p,b,pfn,m_,m_p,m_b' }
- { key: readability-identifier-naming.MemberCase, value: camelBack }
- { key: readability-identifier-naming.MemberPrefix, value: m_ }
- { key: readability-identifier-naming.MemberRemovePrefixes, value: 'p,b,pfn,m_p,m_b' }
- { key: readability-identifier-naming.MethodCase, value: camelBack }
- { key: readability-identifier-naming.MethodIgnoredRegexp, value: '^Create$|^CreateACos$|^CreateACosh$|^CreateASin$|^CreateASinh$|^CreateATan$|^CreateATan2$|^CreateATanh$|^CreateBarrier$|^CreateBinaryIntrinsic$|^CreateCosh$|^CreateCrossProduct$|^CreateCubeFace.*$|^CreateDemoteToHelperInvocation$|^CreateDerivative$|^CreateDeterminant$|^CreateDotProduct$|^CreateEmitVertex$|^CreateEndPrimitive$|^CreateExp$|^CreateExtract.*$|^CreateFaceForward$|^CreateFClamp$|^CreateFindSMsb$|^CreateFma$|^CreateFMax$|^CreateFMax3$|^CreateFMid3$|^CreateFMin$|^CreateFMin3$|^CreateFMod$|^CreateFpTruncWithRounding$|^CreateFract$|^CreateFSign$|^CreateGet.*$|^CreateImage.*$|^CreateIndexDescPtr$|^CreateInsertBitField$|^CreateIntrinsic$|^CreateInverseSqrt$|^CreateIs.*$|^CreateKill$|^CreateLdexp$|^CreateLoad.*$|^CreateLog$|^CreateMapToInt32$|^CreateMatrix.*$|^CreateNormalizeVector$|^CreateOuterProduct$|^CreatePower$|^CreateQuantizeToFp16$|^CreateRead.*$|^CreateReflect$|^CreateRefract$|^CreateSAbs$|^CreateSinh$|^CreateSMod$|^CreateSmoothStep$|^CreateSSign$|^CreateSubgroup.*$|^CreateTan$|^CreateTanh$|^CreateTransposeMatrix$|^CreateUnaryIntrinsic$|^CreateVectorTimesMatrix$|^CreateWrite.*Output$|^Serialize$|^Merge$|^Destroy$|^ConvertColorBufferFormatToExportFormat$|^BuildShaderModule$|^BuildGraphicsPipeline$|^BuildComputePipeline$|^IsVertexFormatSupported$|^DumpSpirvBinary$|^BeginPipelineDump$|^EndPipelineDump$|^DumpPipelineBinary$|^DumpPipelineExtraInfo$|^GetShaderHash$|^GetPipelineHash$|^GetPipelineName$|^CreateShaderCache$|^ReadFromBuffer$|^GetSectionIndex$|^GetSymbolsBySectionIndex$|^GetSectionData$' }
- { key: readability-identifier-naming.FunctionIgnoredRegexp, value: 'EnableOuts|EnableErrs' }
- { key: readability-identifier-naming.FunctionCase, value: camelBack }
- { key: readability-identifier-naming.TypeCase, value: CamelCase }
- { key: readability-identifier-naming.TypeRemovePrefixes, value: PFN_ }
29 changes: 29 additions & 0 deletions .github/workflows/check-clang-tidy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Code style check

on:
pull_request:

jobs:
clang-tidy:
name: clang-tidy
runs-on: "ubuntu-22.04"
steps:
- name: Checkout LLPC
run: |
git clone https://github.com/${GITHUB_REPOSITORY}.git .
git fetch origin +${GITHUB_SHA}:${GITHUB_REF} --update-head-ok
git checkout ${GITHUB_SHA}
- name: Generate Docker base image tag string
run: |
echo "IMAGE_TAG=amdvlkadmin/amdvlk_release_clang:nightly" \
| tee -a $GITHUB_ENV
- name: Fetch the latest prebuilt AMDVLK
run: docker pull "$IMAGE_TAG"
- name: Build and Test with Docker
run: docker build . --file docker/dialects-clang-tidy.Dockerfile
--build-arg AMDVLK_IMAGE="$IMAGE_TAG"
--build-arg DIALECTS_REPO_NAME="${GITHUB_REPOSITORY}"
--build-arg DIALECTS_REPO_REF="${GITHUB_REF}"
--build-arg DIALECTS_REPO_SHA="${GITHUB_SHA}"
--build-arg DIALECTS_BASE_REF="${{ github.base_ref }}"
--tag dialects/ci-dialects
2 changes: 1 addition & 1 deletion .github/workflows/check-dialects-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Fetch the latest prebuilt AMDVLK
run: docker pull "$IMAGE_TAG"
- name: Build and Test with Docker
run: docker build . --file docker/Dockerfile
run: docker build . --file docker/dialects.Dockerfile
--build-arg AMDVLK_IMAGE="$IMAGE_TAG"
--build-arg DIALECTS_REPO_NAME="${GITHUB_REPOSITORY}"
--build-arg DIALECTS_REPO_REF="${GITHUB_REF}"
Expand Down
62 changes: 62 additions & 0 deletions docker/dialects-clang-tidy.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# Dockerfile for llvm-dialects Continuous Integration.
# Sample invocation:
# docker build . \
# --file docker/dialects-clang-tidy.Dockerfile \
# --build-arg AMDVLK_IMAGE=amdvlkadmin/amdvlk_release_clang:nightly \
# --build-arg DIALECTS_REPO_NAME=GPUOpen-Drivers/llvm-dialects \
# --build-arg DIALECTS_REPO_REF=<GIT_REF> \
# --build-arg DIALECTS_REPO_SHA=<GIT_SHA> \
# --tag dialects-ci/dialects
#
# Required arguments:
# - AMDVLK_IMAGE: Base image name for prebuilt amdvlk
# - DIALECTS_REPO_NAME: Name of the llvm-dialects repository to clone
# - DIALECTS_REPO_REF: ref name to checkout
# - DIALECTS_REPO_SHA: SHA of the commit to checkout
# - DIALECTS_BASE_REF: ref name for the base of the tested change
#

# Resume build from the specified image.
ARG AMDVLK_IMAGE
FROM "$AMDVLK_IMAGE"

ARG DIALECTS_REPO_NAME
ARG DIALECTS_REPO_REF
ARG DIALECTS_REPO_SHA
ARG DIALECTS_BASE_REF

# Use bash instead of sh in this docker file.
SHELL ["/bin/bash", "-c"]

# Copy helper scripts into container.
COPY docker/*.sh /vulkandriver/

RUN /vulkandriver/update-dialects.sh
RUN git -C /vulkandriver/drivers/llpc/imported/llvm-dialects fetch origin "$DIALECTS_BASE_REF" --update-head-ok

# Run CMake.
WORKDIR /vulkandriver/builds/ci-build
RUN source /vulkandriver/env.sh \
&& cmake .

# Run clang-tidy. Detect failures by searching for a colon. An empty line or "No relevant changes found." signals success.
WORKDIR /vulkandriver/drivers/llpc/imported/llvm-dialects
RUN ln -s /vulkandriver/builds/ci-build/compile_commands.json \
&& git diff "origin/$DIALECTS_BASE_REF" -U0 \
| /vulkandriver/drivers/llvm-project/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py \
-p1 -j$(nproc) -iregex '.*\\.(cpp|cc|c\\+\\+|cxx|c|cl|h|hpp|m|mm)' >not-tidy.diff \
&& if ! grep -q : not-tidy.diff ; then \
echo "Clean code. Success."; \
else \
echo "Code not tidy."; \
echo "Please run clang-tidy-diff on your changes and push again:"; \
echo " git diff origin/$DIALECTS_BASE_REF -U0 --no-color | ../llvm-project/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py -p1 -fix"; \
echo ""; \
echo "To disable a lint, add \`// NOLINT\` at the end of the line."; \
echo ""; \
echo "Diff:"; \
cat not-tidy.diff; \
echo ""; \
exit 3; \
fi
4 changes: 2 additions & 2 deletions docker/Dockerfile → docker/dialects.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Dockerfile for llvm-dialects Continuous Integration.
# Sample invocation:
# docker build . \
# --file docker/Dockerfile \
# --file docker/dialects.Dockerfile \
# --build-arg AMDVLK_IMAGE=amdvlkadmin/amdvlk_release_gcc_assertions:nightly \
# --build-arg DIALECTS_REPO_NAME=GPUOpen-Drivers/llvm-dialects \
# --build-arg DIALECTS_REPO_REF=<GIT_REF> \
Expand All @@ -11,7 +11,7 @@
#
# Required arguments:
# - AMDVLK_IMAGE: Base image name for prebuilt amdvlk
# - DIALECTS_REPO_NAME: Name of the llpc repository to clone
# - DIALECTS_REPO_NAME: Name of the llvm-dialects repository to clone
# - DIALECTS_REPO_REF: ref name to checkout
# - DIALECTS_REPO_SHA: SHA of the commit to checkout
#
Expand Down

0 comments on commit d2b2c8f

Please sign in to comment.