-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add tasks to run C++ static analysis using clang-tidy; Separate CMake project config into its own task. #18
Changes from 6 commits
d884cc9
6a471a2
10e4764
4db65bc
0f76926
f9ed9ac
b9fa11b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Lock to v18.x until we can upgrade our code to meet v19's formatting standards. | ||
clang-format~=18.1 | ||
clang-tidy>=19.1.0 | ||
yamllint>=1.35.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
version: "3" | ||
|
||
vars: | ||
G_SRC_CLP_FFI_JS_DIR: "{{.ROOT_DIR}}/src/clp_ffi_js" | ||
G_SRC_DIR: "{{.ROOT_DIR}}/src" | ||
G_SRC_CLP_FFI_JS_DIR: "{{.G_SRC_DIR}}/clp_ffi_js" | ||
G_LINT_VENV_DIR: "{{.G_BUILD_DIR}}/lint-venv" | ||
|
||
tasks: | ||
|
@@ -19,25 +20,62 @@ tasks: | |
cmd: "{{.ROOT_DIR}}/tools/yscope-dev-utils/lint-configs/symlink-cpp-lint-configs.sh" | ||
|
||
cpp-check: | ||
sources: &cpp_source_files | ||
cmds: | ||
- task: "cpp-format-check" | ||
- task: "cpp-static-check" | ||
|
||
cpp-fix: | ||
cmds: | ||
- task: "cpp-format-fix" | ||
- task: "cpp-static-fix" | ||
|
||
cpp-format-check: | ||
sources: &cpp_format_source_files | ||
- "{{.G_SRC_CLP_FFI_JS_DIR}}/.clang-format" | ||
- "{{.G_SRC_CLP_FFI_JS_DIR}}/**/*.cpp" | ||
- "{{.G_SRC_CLP_FFI_JS_DIR}}/**/*.h" | ||
- "{{.G_SRC_CLP_FFI_JS_DIR}}/**/*.hpp" | ||
- "{{.TASKFILE}}" | ||
- "tools/yscope-dev-utils/lint-configs/.clang-format" | ||
deps: ["cpp-configs", "venv"] | ||
cmds: | ||
- task: "clang-format" | ||
vars: | ||
FLAGS: "--dry-run" | ||
|
||
cpp-fix: | ||
sources: *cpp_source_files | ||
cpp-format-fix: | ||
sources: *cpp_format_source_files | ||
deps: ["cpp-configs", "venv"] | ||
cmds: | ||
- task: "clang-format" | ||
vars: | ||
FLAGS: "-i" | ||
|
||
cpp-static-check: | ||
# Alias task to `cpp-static-fix` since we don't currently support automatic fixes. | ||
# NOTE: clang-tidy does have the ability to fix some errors, but the fixes can be inaccurate. | ||
# When we eventually determine which errors can be safely fixed, we'll allow clang-tidy to | ||
# fix them. | ||
aliases: ["cpp-static-fix"] | ||
sources: | ||
# Dependency sources | ||
- "{{.G_CLP_FFI_JS_BUILD_DIR}}/_deps/*-src/**/*" | ||
- "{{.G_SRC_DIR}}/submodules/**/*" | ||
|
||
# clp-ffi-js sources | ||
- "{{.G_SRC_CLP_FFI_JS_DIR}}/**/*.cpp" | ||
- "{{.G_SRC_CLP_FFI_JS_DIR}}/**/*.h" | ||
- "{{.G_SRC_CLP_FFI_JS_DIR}}/**/*.hpp" | ||
Comment on lines
+66
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to include all source files? Say if some header in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would, but this task doesn't require compiling clp-ffi-js, right? (I might be misunderstanding your question.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't come up with an exact example since I'm not too familiar with clang-tidy rules. However, from my experience working with static analysis, any dependency changes can cause the checks in our code to fail. (In fact, sometimes it's easier to fix violations in the dependencies when there are too many violations due to a same issue in the dependency. ) Please correct me if this imaginary example is impossible - say we recently updated some function signature in CLP core code that some parameter changes its type from int64 to int32, but our clp-ffi-js code remains the same. If we keep passing an int64 value to the modified function, wouldn't a precision / value loss violation be raised? If we don't include the header, which is used in static checks in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see what you're saying. Yes, we should include the dependencies' source files. |
||
|
||
# Other sources | ||
- "{{.G_CLP_FFI_JS_BUILD_DIR}}/compile_commands.json" | ||
- "{{.ROOT_DIR}}/Taskfile.yml" | ||
- "{{.TASKFILE}}" | ||
- "tools/yscope-dev-utils/lint-configs/.clang-tidy" | ||
deps: [":config-cmake-project", "cpp-configs", "venv"] | ||
cmds: | ||
- task: "clang-tidy" | ||
|
||
yml: | ||
aliases: | ||
- "yml-check" | ||
|
@@ -57,15 +95,33 @@ tasks: | |
internal: true | ||
requires: | ||
vars: ["FLAGS"] | ||
deps: ["cpp-configs", "venv"] | ||
cmds: | ||
- |- | ||
. "{{.G_LINT_VENV_DIR}}/bin/activate" | ||
find "{{.G_SRC_CLP_FFI_JS_DIR}}" \ | ||
-type f \ | ||
\( -iname "*.cpp" -o -iname "*.h" -o -iname "*.hpp" \) \ | ||
-print0 | \ | ||
xargs -0 clang-format {{.FLAGS}} -Werror | ||
cmd: |- | ||
. "{{.G_LINT_VENV_DIR}}/bin/activate" | ||
find "{{.G_SRC_CLP_FFI_JS_DIR}}" \ | ||
-type f \ | ||
\( -iname "*.cpp" -o -iname "*.h" -o -iname "*.hpp" \) \ | ||
-print0 | \ | ||
xargs -0 clang-format {{.FLAGS}} -Werror | ||
Comment on lines
+98
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to the PR, but this is simply to reformat from |
||
|
||
clang-tidy: | ||
internal: true | ||
vars: | ||
FLAGS: >- | ||
-p {{.G_CLP_FFI_JS_BUILD_DIR}}/compile_commands.json | ||
--config-file=.clang-tidy | ||
cmd: |- | ||
. "{{.G_LINT_VENV_DIR}}/bin/activate" | ||
|
||
# Pass emscripten's cflags to clang-tidy by prefixing each one with `--extra-arg` | ||
EXTRA_ARGS=$("{{.G_EMSDK_DIR}}/upstream/emscripten/em++" --cflags \ | ||
| tr ' ' '\n' \ | ||
| sed 's/^/--extra-arg /' \ | ||
| tr '\n' ' ') | ||
find "{{.G_SRC_CLP_FFI_JS_DIR}}" \ | ||
-type f \ | ||
\( -iname "*.cpp" -o -iname "*.h" -o -iname "*.hpp" \) \ | ||
-print0 | \ | ||
xargs -0 clang-tidy {{.FLAGS}} $EXTRA_ARGS | ||
|
||
venv: | ||
internal: true | ||
|
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.
Do we need to add
G_EMSDK_CHECKSUM
here?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.
Yeah, my mistake. Let me restructure things to be clearer.
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.
Since we plan to move clang-format and clang-tidy into yscope-dev-utils, what do you think about the following? Move clang-format and clang-tidy's dependencies into cpp-format-* and cpp-static-* and make clang-format and clang-tidy idempotent.