Skip to content

Commit

Permalink
[clangd] Fix test failure when it's built with compiler flags unknown…
Browse files Browse the repository at this point in the history
… by clang

If LLVM is built with a compiler other than clang, the `compile_commands.json`
file may contain compiler flags unknown by clang.  When a clangd test is copied
into the build directory and checked, clangd will pick the unknown flag from
the file and cause a test failure.  Create an empty `compile_commands.json` in
the test directory nested in the build directory to override it.

Reviewed By: thesamesam

Differential Revision: https://reviews.llvm.org/D150582
  • Loading branch information
xry111 authored and thesamesam committed May 16, 2023
1 parent 7f37066 commit 4ddae8b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions clang-tools-extra/clangd/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
)

# Copy an empty compile_commands.json to override the compile_commands.json
# in the top level build directory. Or if a clangd test involves creating a
# temporary source file in the build directory and run clangd to check it,
# it can pick up unrecognizable command options when LLVM is built with
# another compiler or a different version of Clang.
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json
${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json
)

add_lit_testsuite(check-clangd "Running the Clangd regression tests"
# clangd doesn't put unittest configs in test/unit like every other project.
# Because of that, this needs to pass two folders here, while every other
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/test/compile_commands.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]

0 comments on commit 4ddae8b

Please sign in to comment.