Skip to content

Commit c869cbf

Browse files
committed
[test] Move utility functions into reusable CMake file.
Some pieces of the main CMakeLists.txt file are useful to future CMakeLists.txt. In order to avoid duplication, move those pieces into a new SwiftTestsUtils.cmake to be able to include the functions from other files. This should not modify anything in the behaviour of the build.
1 parent 887464b commit c869cbf

File tree

2 files changed

+56
-14
lines changed

2 files changed

+56
-14
lines changed

test/CMakeLists.txt

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
2+
3+
include(SwiftTestUtils)
4+
15
function(swift_configure_lit_site_cfg source_path destination_path installed_name)
26
if (CMAKE_CFG_INTDIR STREQUAL ".")
37
set(SWIFT_BUILD_MODE ".")
@@ -197,24 +201,14 @@ foreach(SDK ${SWIFT_SDKS})
197201
# and one with the the macCatalyst ios-macabi triple. The build_flavors list will
198202
# have have only the "default" flavor for all SDKs and architectures except
199203
# OSX when macCatalyst support is enabled.
200-
set(build_flavors "default")
201-
if(SWIFT_ENABLE_MACCATALYST AND "${SDK}" STREQUAL "OSX")
202-
list(APPEND build_flavors "ios-like" )
203-
endif()
204+
get_swift_test_build_flavors(build_flavors "${SDK}")
204205

205206
foreach(BUILD_FLAVOR ${build_flavors})
206207
# Configure variables for this subdirectory.
207-
set(VARIANT_SUFFIX "-${SWIFT_SDK_${SDK}_LIB_SUBDIR}-${ARCH}")
208-
get_versioned_target_triple(VARIANT_TRIPLE ${SDK} ${ARCH} "${SWIFT_SDK_${SDK}_DEPLOYMENT_VERSION}")
209208
set(VARIANT_SDK "${SWIFT_SDK_${SDK}_ARCH_${ARCH}_PATH}")
210-
set(DEFAULT_OSX_VARIANT_SUFFIX "")
211-
212-
if(BUILD_FLAVOR STREQUAL "ios-like")
213-
set(DEFAULT_OSX_VARIANT_SUFFIX "${VARIANT_SUFFIX}")
214-
# Use the macCatalyst target triple and compiler resources for the iOS-like build flavor.
215-
set(VARIANT_SUFFIX "-${SWIFT_SDK_${SDK}_LIB_SUBDIR}-maccatalyst-${ARCH}")
216-
set(VARIANT_TRIPLE "${ARCH}-apple-ios13.0-macabi")
217-
endif()
209+
get_swift_test_variant_suffix(VARIANT_SUFFIX "${SDK}" "${ARCH}" "${BUILD_FLAVOR}")
210+
get_swift_test_versioned_target_triple(VARIANT_TRIPLE "${SDK}" "${ARCH}" "${SWIFT_SDK_${SDK}_DEPLOYMENT_VERSION}" "${BUILD_FLAVOR}")
211+
get_swift_test_default_osx_variant_suffix(DEFAULT_OSX_VARIANT_SUFFIX "${VARIANT_SUFFIX}" "${BUILD_FLAVOR}")
218212

219213
# A directory where to put the xUnit-style XML test results.
220214
set(SWIFT_TEST_RESULTS_DIR
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# SwiftTestUtils.cmake
2+
#
3+
# Utility functions for Swift testing targets
4+
5+
# Get the possible build flavors for testing
6+
function(get_swift_test_build_flavors build_flavors_out_var sdk)
7+
set(build_flavors "default")
8+
if(SWIFT_ENABLE_MACCATALYST AND "${sdk}" STREQUAL "OSX")
9+
list(APPEND build_flavors "ios-like")
10+
endif()
11+
12+
set(${build_flavors_out_var} ${build_flavors} PARENT_SCOPE)
13+
endfunction()
14+
15+
# Get the variant suffix for test targets and folders
16+
function(get_swift_test_variant_suffix variant_suffix_out_var sdk arch build_flavor)
17+
if(build_flavor STREQUAL "ios-like")
18+
set(variant_suffix "-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-maccatalyst-${arch}")
19+
else()
20+
set(variant_suffix "-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
21+
endif()
22+
23+
set(${variant_suffix_out_var} "${variant_suffix}" PARENT_SCOPE)
24+
endfunction()
25+
26+
27+
# Get the variant triple for test targets
28+
function(get_swift_test_versioned_target_triple variant_triple_out_var sdk arch build_flavor)
29+
if(build_flavor STREQUAL "ios-like")
30+
# Use the macCatalyst target triple and compiler resources for the iOS-like build flavor.
31+
set(variant_triple "${arch}-apple-ios13.0-macabi")
32+
else()
33+
get_versioned_target_triple(variant_triple ${sdk} ${arch} "${SWIFT_SDK_${sdk}_DEPLOYMENT_VERSION}")
34+
endif()
35+
36+
set(${variant_triple_out_var} "${variant_triple}" PARENT_SCOPE)
37+
endfunction()
38+
39+
# Get the default OSX variant suffix for test targets
40+
function(get_swift_test_default_osx_variant_suffix suffix_out_var original_variant_suffix build_flavor)
41+
set(suffix "")
42+
if(build_flavor STREQUAL "ios-like")
43+
set(suffix "${variant_suffix}")
44+
endif()
45+
46+
set(${suffix_out_var} "${suffix}" PARENT_SCOPE)
47+
endfunction()
48+

0 commit comments

Comments
 (0)