[CMake] Add special case for processing LLDB_DOTEST_ARGS

Summary:
Allow to run the test suite when building LLDB Standalone with Xcode against a provided LLVM build-tree that used a single-configuration generator like Ninja.

So far both test drivers, lit-based `check-lldb` as well as `lldb-dotest`, were looking for test dependencies (clang/dsymutil/etc.) in a subdirectory with the configuration name (Debug/Release/etc.). It was implicitly assuming that both, LLDB and the provided LLVM used the same generator. In practice, however, the opposite is quite common: build the dependencies with Ninja and LLDB with Xcode for development*. With this patch it becomes the default.

(* In fact, it turned out that the Xcode<->Xcode variant didn't even build out of the box. It's fixed since D62879)

Once this is sound, I'm planning the following steps:
* add stage to the [lldb-cmake-standalone bot](http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake-standalone/) to build and test it
* update `Building LLDB with Xcode` section in the docs
* bring the same mechanism to swift-lldb
* fade out the manually maintained Xcode project

On macOS build and test like this:
```
$ git clone https://github.com/llvm/llvm-project.git /path/to/llvm-project

$ cd /path/to/lldb-dev-deps
$ cmake -GNinja -C/path/to/llvm-project/lldb/cmake/caches/Apple-lldb-macOS.cmake -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi" /path/to/llvm-project/llvm
$ ninja

$ cd /path/to/lldb-dev-xcode
$ cmake -GXcode -C/path/to/llvm-project/lldb/cmake/caches/Apple-lldb-macOS.cmake -DLLDB_BUILD_FRAMEWORK=Off -DLLVM_DIR=/path/to/lldb-dev-deps/lib/cmake/llvm -DClang_DIR=/path/to/lldb-dev-deps/lib/cmake/clang /path/to/llvm-project/lldb
$ xcodebuild -configuration Debug -target check-lldb
$ xcodebuild -configuration Debug -target lldb-dotest
$ ./Debug/bin/lldb-dotest
```

Reviewers: JDevlieghere, jingham, xiaobai, stella.stamenova, labath

Reviewed By: stella.stamenova

Subscribers: labath, mgorny, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D62859

llvm-svn: 362803
This commit is contained in:
Stefan Granitz 2019-06-07 14:32:51 +00:00
parent 128e8e8fb9
commit 088410ffc6
2 changed files with 49 additions and 3 deletions

View File

@ -1,6 +1,7 @@
# Test runner infrastructure for LLDB. This configures the LLDB test trees
# for use by Lit, and delegates to LLVM's lit test handlers.
# LLVM_BUILD_MODE is used in lit.site.cfg
if (CMAKE_CFG_INTDIR STREQUAL ".")
set(LLVM_BUILD_MODE ".")
else ()
@ -12,10 +13,35 @@ if (CMAKE_SIZEOF_VOID_P EQUAL 8)
endif()
get_property(LLDB_DOTEST_ARGS GLOBAL PROPERTY LLDB_DOTEST_ARGS_PROPERTY)
set(dotest_args_replacement ${LLVM_BUILD_MODE})
if(LLDB_BUILT_STANDALONE)
# In paths to our build-tree, replace CMAKE_CFG_INTDIR with our configuration name placeholder.
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} config_runtime_output_dir ${LLVM_RUNTIME_OUTPUT_INTDIR})
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_DOTEST_ARGS "${LLDB_DOTEST_ARGS}")
# Remaining ones must be paths to the provided LLVM build-tree.
if(LLVM_CONFIGURATION_TYPES)
# LLDB uses single-config; LLVM multi-config; pick one and prefer Release types.
# Otherwise, if both use multi-config the default is fine.
if(NOT CMAKE_CONFIGURATION_TYPES)
if(RelWithDebInfo IN_LIST LLVM_CONFIGURATION_TYPES)
set(dotest_args_replacement RelWithDebInfo)
elseif(Release IN_LIST LLVM_CONFIGURATION_TYPES)
set(dotest_args_replacement Release)
else()
list(GET LLVM_CONFIGURATION_TYPES 0 dotest_args_replacement)
endif()
endif()
else()
# Common case: LLVM used a single-configuration generator like Ninja.
set(dotest_args_replacement ".")
endif()
endif()
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_DOTEST_ARGS "${LLDB_DOTEST_ARGS}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_LIBS_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_DOTEST_ARGS "${LLDB_DOTEST_ARGS}")
list(APPEND LLDB_TEST_DEPS
LLDBUnitTests

View File

@ -5,8 +5,28 @@ set_target_properties(lldb-dotest PROPERTIES FOLDER "lldb utils")
get_property(LLDB_DOTEST_ARGS GLOBAL PROPERTY LLDB_DOTEST_ARGS_PROPERTY)
# Generate wrapper for each build mode.
if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
# Generate lldb-dotest Python driver script for each build mode.
if(LLDB_BUILT_STANDALONE)
foreach(config_type ${CMAKE_CONFIGURATION_TYPES})
# In paths to our build-tree, replace CMAKE_CFG_INTDIR with our actual configuration names.
string(REPLACE ${CMAKE_CFG_INTDIR} ${config_type} config_runtime_output_dir ${LLVM_RUNTIME_OUTPUT_INTDIR})
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_DOTEST_ARGS "${LLDB_DOTEST_ARGS}")
# Remaining ones must be paths to the provided LLVM build-tree.
if(${config_type} IN_LIST LLVM_CONFIGURATION_TYPES)
# Multi-configuration generator like Xcode (with a matching config).
string(REPLACE ${CMAKE_CFG_INTDIR} ${config_type} LLDB_DOTEST_ARGS "${LLDB_DOTEST_ARGS}")
else()
# Single-configuration generator like Ninja.
string(REPLACE ${CMAKE_CFG_INTDIR} "." LLDB_DOTEST_ARGS "${LLDB_DOTEST_ARGS}")
endif()
configure_file(
lldb-dotest.in
${config_runtime_output_dir}/lldb-dotest @ONLY
)
endforeach()
elseif(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
foreach(LLVM_BUILD_MODE ${CMAKE_CONFIGURATION_TYPES})
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_DOTEST_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_DOTEST_ARGS "${LLDB_DOTEST_ARGS}")