[Reland][Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
Summary: When building a project in a runtime mode, the compilation database is a separate CMake invocation. So its `compile_commands.json` file will be placed elsewhere in the `runtimes/runtime-bins` directory. This is somewhat annoying for ongoing development when a runtimes build is necessary. This patch adds some CMake magic to merge the two files. Fixed issue w/ standalone runtimes build by checking if the LLVM src and CMake src are the same.
This commit is contained in:
@@ -346,3 +346,21 @@ if(SUB_COMPONENTS)
|
||||
${CMAKE_CURRENT_BINARY_DIR}/runtimes/Components.cmake)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# If the user requested 'compile_commands.json' we merge the generated JSON from
|
||||
# the created directories.
|
||||
if(CMAKE_EXPORT_COMPILE_COMMANDS AND NOT ("${LLVM_BINARY_DIR}" STREQUAL "${CMAKE_BINARY_DIR}"))
|
||||
# Make a dependency so that we don't error if the file gets deleted somehow.
|
||||
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/compile_commands.json
|
||||
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/compile_commands.json)
|
||||
|
||||
file(TO_NATIVE_PATH "${LLVM_MAIN_SRC_DIR}/utils/merge-json.py" MERGE_JSON_PATH)
|
||||
add_custom_command(OUTPUT ${LLVM_BINARY_DIR}/compile_commands.json
|
||||
COMMAND ${CMAKE_COMMAND} -E touch ${LLVM_BINARY_DIR}/compile_commands.json
|
||||
COMMAND ${Python3_EXECUTABLE} ${MERGE_JSON_PATH}
|
||||
${LLVM_BINARY_DIR}/compile_commands.json
|
||||
${CMAKE_BINARY_DIR}/compile_commands.json
|
||||
-o ${LLVM_BINARY_DIR}/compile_commands.json
|
||||
DEPENDS ${CMAKE_BINARY_DIR}/compile_commands.json)
|
||||
add_custom_target(merge_runtime_commands ALL DEPENDS ${LLVM_BINARY_DIR}/compile_commands.json)
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user