Skip to content
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

bun run clang-tidy #14162

Merged
merged 6 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ jobs:
- name: Install LLVM
run: |
curl -fsSL https://apt.llvm.org/llvm.sh | sudo bash -s -- ${{ env.LLVM_VERSION_MAJOR }} all
sudo apt-get update
sudo apt-get install -y ninja-build ccache
- name: Format
- name: Clang Format
env:
ENABLE_CCACHE: OFF
LLVM_VERSION: ${{ env.LLVM_VERSION }}
run: |
bun run clang-format -DLLVM_VERSION=${{ env.LLVM_VERSION }}
bun run clang-format:diff
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: clang-tidy

permissions:
contents: write

on:
workflow_call:
workflow_dispatch:
pull_request:
paths:
- ".github/workflows/clang-tidy.yml"
- ".clang-tidy"
- "package.json"
- "scripts/**"
- "cmake/**"
- "src/**/*.c"
- "src/**/*.cpp"
- "src/**/*.h"
- "packages/**/*.c"
- "packages/**/*.cpp"
- "packages/**/*.h"

env:
BUN_VERSION: "1.1.27"
LLVM_VERSION: "18.1.8"
LLVM_VERSION_MAJOR: "18"

jobs:
clang-tidy:
name: clang-tidy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: |
.github
.clang-tidy
package.json
scripts
cmake
src
packages
- name: Setup Bun
uses: ./.github/actions/setup-bun
with:
bun-version: ${{ env.BUN_VERSION }}
- name: Install LLVM
run: |
curl -fsSL https://apt.llvm.org/llvm.sh | sudo bash -s -- ${{ env.LLVM_VERSION_MAJOR }} all
- name: Clang Tidy
env:
ENABLE_CCACHE: OFF
LLVM_VERSION: ${{ env.LLVM_VERSION }}
run: |
bun run clang-tidy:diff
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "`bun run clang-tidy`"
7 changes: 5 additions & 2 deletions .github/workflows/prettier-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ jobs:
- name: Setup Dependencies
run: |
bun install
- name: Format
- name: Prettier Format
env:
ENABLE_CCACHE: OFF
SKIP_LLVM: ON
run: |
bun run prettier:extra
bun run prettier:diff
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/zig-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ jobs:
with:
bun-version: ${{ env.BUN_VERSION }}
- name: Zig Format
env:
ENABLE_CCACHE: OFF
SKIP_LLVM: ON
run: |
bun run zig-format -DENABLE_CCACHE=OFF -DSKIP_LLVM=ON
bun run zig-format:diff
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ include(CompilerFlags)

# --- Tools ---

include(SetupGit)
include(SetupBuildkite)
include(SetupBun)
include(SetupEsbuild)
Expand All @@ -43,4 +44,6 @@ include(BuildBun)
# --- Analysis ---

include(RunClangFormat)
include(RunClangTidy)
include(RunZigFormat)
include(RunPrettier)
6 changes: 6 additions & 0 deletions cmake/Globals.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ optionx(CACHE_STRATEGY "read-write|read-only|write-only|none" "The strategy to u

optionx(CI BOOL "If CI is enabled" DEFAULT OFF)

if(CI)
set(WARNING FATAL_ERROR)
else()
set(WARNING WARNING)
endif()

if(CI)
set(DEFAULT_VENDOR_PATH ${CACHE_PATH}/vendor)
else()
Expand Down
34 changes: 34 additions & 0 deletions cmake/analysis/RunClangFormat.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# https://clang.llvm.org/docs/ClangFormat.html

find_command(
VARIABLE
CLANG_FORMAT_PROGRAM
Expand Down Expand Up @@ -35,3 +37,35 @@ register_command(
${CLANG_FORMAT_SOURCES}
ALWAYS_RUN
)

if(GIT_CHANGED_SOURCES)
set(CLANG_FORMAT_CHANGED_SOURCES)
foreach(source ${CLANG_FORMAT_SOURCES})
list(FIND GIT_CHANGED_SOURCES ${source} index)
if(NOT ${index} EQUAL -1)
list(APPEND CLANG_FORMAT_CHANGED_SOURCES ${source})
endif()
endforeach()
endif()

if(CLANG_FORMAT_CHANGED_SOURCES)
set(CLANG_FORMAT_DIFF_COMMAND ${CLANG_FORMAT_PROGRAM}
-i # edits files in-place
--verbose
${CLANG_FORMAT_CHANGED_SOURCES}
)
else()
set(CLANG_FORMAT_DIFF_COMMAND ${CMAKE_COMMAND} -E echo "No changed files for clang-format")
endif()

register_command(
TARGET
clang-format-diff
COMMENT
"Running clang-format on changed files"
COMMAND
${CLANG_FORMAT_DIFF_COMMAND}
CWD
${BUILD_PATH}
ALWAYS_RUN
)
65 changes: 47 additions & 18 deletions cmake/analysis/RunClangTidy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,75 @@ find_command(
OFF
)

set(CLANG_TIDY_COMMAND ${CLANG_TIDY_PROGRAM} ${BUN_CPP_SOURCES}
set(CLANG_TIDY_SOURCES ${BUN_C_SOURCES} ${BUN_CXX_SOURCES})

set(CLANG_TIDY_COMMAND ${CLANG_TIDY_PROGRAM}
-p ${BUILD_PATH}
--config-file=${CWD}/.clang-tidy
--fix
--fix-errors
--fix-notes
)

if(CMAKE_COLOR_DIAGNOSTICS)
list(APPEND CLANG_TIDY_COMMAND --use-color)
endif()

# Extra clang-tidy checks that are normally disabled due to noise.
# e.g. JavaScriptCore/Lookup.h
set(CLANG_TIDY_EXTRA_COMMAND ${CLANG_TIDY_PROGRAM}
--checks=performance-*
)

register_command(
TARGET
clang-tidy
COMMENT
"Running clang-tidy"
COMMAND
${CLANG_TIDY_COMMAND}
${CLANG_TIDY_COMMAND}
${CLANG_TIDY_SOURCES}
--fix
--fix-errors
--fix-notes
CWD
${BUILD_PATH}
TARGETS
${bun}
ALWAYS_RUN
)

register_command(
TARGET
clang-tidy-extra
clang-tidy-check
COMMENT
"Checking clang-tidy"
COMMAND
${CLANG_TIDY_COMMAND}
${CLANG_TIDY_SOURCES}
CWD
${BUILD_PATH}
ALWAYS_RUN
)

if(GIT_CHANGED_SOURCES)
set(CLANG_TIDY_CHANGED_SOURCES)
foreach(source ${CLANG_TIDY_SOURCES})
list(FIND GIT_CHANGED_SOURCES ${source} index)
if(NOT ${index} EQUAL -1)
list(APPEND CLANG_TIDY_CHANGED_SOURCES ${source})
endif()
endforeach()
endif()

if(CLANG_TIDY_CHANGED_SOURCES)
set(CLANG_TIDY_DIFF_COMMAND ${CLANG_TIDY_PROGRAM}
${CLANG_TIDY_CHANGED_SOURCES}
--fix
--fix-errors
--fix-notes
)
else()
set(CLANG_TIDY_DIFF_COMMAND ${CMAKE_COMMAND} -E echo "No changed files for clang-tidy")
endif()

register_command(
TARGET
clang-tidy-diff
COMMENT
"Running clang-tidy with extra checks"
"Running clang-tidy on changed files"
COMMAND
${CLANG_TIDY_EXTRA_COMMAND}
${CLANG_TIDY_DIFF_COMMAND}
CWD
${BUILD_PATH}
TARGETS
${bun}
ALWAYS_RUN
)
123 changes: 123 additions & 0 deletions cmake/analysis/RunPrettier.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
if(CMAKE_HOST_WIN32)
setx(PRETTIER_EXECUTABLE ${CWD}/node_modules/.bin/prettier.exe)
else()
setx(PRETTIER_EXECUTABLE ${CWD}/node_modules/.bin/prettier)
endif()

set(PRETTIER_PATHS
${CWD}/src
${CWD}/packages/bun-error
${CWD}/packages/bun-types
${CWD}/packages/bun-inspector-protocol
${CWD}/packages/bun-inspector-frontend
${CWD}/packages/bun-debug-adapter-protocol
${CWD}/packages/bun-vscode
${CWD}/test
${CWD}/bench
${CWD}/.vscode
${CWD}/.buildkite
${CWD}/.github
)

set(PRETTIER_EXTENSIONS
*.jsonc?
*.ya?ml
*.jsx?
*.tsx?
*.mjs
*.cjs
*.mts
*.cts
)

set(PRETTIER_GLOBS)
foreach(path ${PRETTIER_PATHS})
foreach(extension ${PRETTIER_EXTENSIONS})
list(APPEND PRETTIER_GLOBS ${path}/${extension})
endforeach()
endforeach()

file(GLOB_RECURSE PRETTIER_SOURCES ${PRETTIER_GLOBS})

register_command(
COMMAND
${BUN_EXECUTABLE}
install
--frozen-lockfile
SOURCES
${CWD}/package.json
OUTPUTS
${PRETTIER_EXECUTABLE}
)

set(PRETTIER_COMMAND ${PRETTIER_EXECUTABLE}
--config=${CWD}/.prettierrc
--cache
)

register_command(
TARGET
prettier
COMMENT
"Running prettier"
COMMAND
${PRETTIER_COMMAND}
--write
${PRETTIER_SOURCES}
ALWAYS_RUN
)

register_command(
TARGET
prettier-extra
COMMENT
"Running prettier with extra plugins"
COMMAND
${PRETTIER_COMMAND}
--write
--plugin=prettier-plugin-organize-imports
${PRETTIER_SOURCES}
ALWAYS_RUN
)

register_command(
TARGET
prettier-check
COMMENT
"Checking prettier"
COMMAND
${PRETTIER_COMMAND}
--check
${PRETTIER_SOURCES}
ALWAYS_RUN
)

if(GIT_CHANGED_SOURCES)
set(PRETTIER_CHANGED_SOURCES)
foreach(source ${PRETTIER_SOURCES})
list(FIND PRETTIER_CHANGED_SOURCES ${source} index)
if(NOT ${index} EQUAL -1)
list(APPEND PRETTIER_CHANGED_SOURCES ${source})
endif()
endforeach()
endif()

if(PRETTIER_CHANGED_SOURCES)
set(PRETTIER_DIFF_COMMAND ${PRETTIER_COMMAND}
--write
--plugin=prettier-plugin-organize-imports
${PRETTIER_CHANGED_SOURCES}
)
else()
set(PRETTIER_DIFF_COMMAND ${CMAKE_COMMAND} -E echo "No changed files for prettier")
endif()

register_command(
TARGET
prettier-diff
COMMENT
"Running prettier on changed files"
COMMAND
${PRETTIER_DIFF_COMMAND}
ALWAYS_RUN
)
Loading