[CMake][NFC] Refactor iOS simulator/device test configuration generation code for...
authorDan Liew <dan@su-root.co.uk>
Wed, 22 Jan 2020 22:11:17 +0000 (14:11 -0800)
committerDan Liew <dan@su-root.co.uk>
Thu, 23 Jan 2020 20:44:00 +0000 (12:44 -0800)
Summary:
The previous code hard-coded platform names but compiler-rt's CMake
build system actually already knows which Apple platforms ASan supports.

This change uses this information to enumerate the different Apple
platforms.

rdar://problem/58798733

Reviewers: kubamracek, yln

Subscribers: mgorny, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

compiler-rt/cmake/config-ix.cmake
compiler-rt/test/asan/CMakeLists.txt

index 3aad08e..c1d0f65 100644 (file)
@@ -224,6 +224,18 @@ function(get_test_cflags_for_apple_platform platform arch cflags_out)
   set(${cflags_out} "${test_cflags_str}" PARENT_SCOPE)
 endfunction()
 
+function(get_capitalized_apple_platform platform platform_capitalized)
+  # TODO(dliew): Remove uses of this function. It exists to preserve needlessly complex
+  # directory naming conventions used by the Sanitizer lit test suites.
+  is_valid_apple_platform("${platform}" is_valid_platform)
+  if (NOT is_valid_platform)
+    message(FATAL_ERROR "\"${platform}\" is not a valid apple platform")
+  endif()
+  string(TOUPPER "${platform}" platform_upper)
+  string(REGEX REPLACE "OSSIM$" "OSSim" platform_upper_capitalized "${platform_upper}")
+  set(${platform_capitalized} "${platform_upper_capitalized}" PARENT_SCOPE)
+endfunction()
+
 function(is_valid_apple_platform platform is_valid_out)
   set(is_valid FALSE)
   if ("${platform}" STREQUAL "")
index e67a0e8..316442e 100644 (file)
@@ -82,56 +82,43 @@ endforeach()
 # variable to select which iOS device or simulator to use, e.g.:
 # SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"
 if(APPLE)
-  # FIXME(dliew): This logic should be refactored to the way UBSan Darwin
-  # testing is done.
   set(EXCLUDE_FROM_ALL ON)
-
   set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
   set(ASAN_TEST_DYNAMIC True)
+  set(ASAN_APPLE_PLATFORMS ${SANITIZER_COMMON_SUPPORTED_OS})
 
-  list_intersect(ASAN_TEST_IOSSIM_ARCHS ASAN_SUPPORTED_ARCH DARWIN_iossim_ARCHS)
-  foreach(arch ${ASAN_TEST_IOSSIM_ARCHS})
-    set(ASAN_TEST_APPLE_PLATFORM "iossim")
-    set(ASAN_TEST_TARGET_ARCH ${arch})
-    get_test_cflags_for_apple_platform(
-      "${ASAN_TEST_APPLE_PLATFORM}"
-      "${ASAN_TEST_TARGET_ARCH}"
-      ASAN_TEST_TARGET_CFLAGS
-      )
-    set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-${ASAN_TEST_APPLE_PLATFORM}")
-    get_bits_for_arch(${arch} ASAN_TEST_BITS)
-    string(TOUPPER ${arch} ARCH_UPPER_CASE)
-    set(CONFIG_NAME "IOSSim${ARCH_UPPER_CASE}Config")
-    configure_lit_site_cfg(
-      ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
-      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
-      )
-    add_lit_testsuite(check-asan-iossim-${arch} "AddressSanitizer iOS Simulator ${arch} tests"
-      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
-      DEPENDS ${ASAN_TEST_DEPS})
-  endforeach()
-
-  list_intersect(ASAN_TEST_IOS_ARCHS ASAN_SUPPORTED_ARCH DARWIN_ios_ARCHS)
-  foreach (arch ${ASAN_TEST_IOS_ARCHS})
-    set(ASAN_TEST_APPLE_PLATFORM "ios")
-    set(ASAN_TEST_TARGET_ARCH ${arch})
-    get_test_cflags_for_apple_platform(
-      "${ASAN_TEST_APPLE_PLATFORM}"
-      "${arch}"
-      ASAN_TEST_TARGET_CFLAGS)
-    set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-${ASAN_TEST_APPLE_PLATFORM}")
-    get_bits_for_arch(${arch} ASAN_TEST_BITS)
-    string(TOUPPER ${arch} ARCH_UPPER_CASE)
-    set(CONFIG_NAME "IOS${ARCH_UPPER_CASE}Config")
-    configure_lit_site_cfg(
-      ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
-      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
-      )
-    add_lit_testsuite(check-asan-ios-${arch} "AddressSanitizer iOS ${arch} tests"
-      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
-      DEPENDS ${ASAN_TEST_DEPS})
+  foreach(platform ${ASAN_APPLE_PLATFORMS})
+    if ("${platform}" STREQUAL "osx")
+      # Skip macOS because it's handled by the code above that builds tests for the host machine.
+      continue()
+    endif()
+    list_intersect(
+      ASAN_TEST_${platform}_ARCHS
+      ASAN_SUPPORTED_ARCH
+      DARWIN_${platform}_ARCHS
+    )
+    foreach(arch ${ASAN_TEST_${platform}_ARCHS})
+      get_test_cflags_for_apple_platform(
+        "${platform}"
+        "${arch}"
+        ASAN_TEST_TARGET_CFLAGS
+        )
+      string(TOUPPER "${arch}" ARCH_UPPER_CASE)
+      get_capitalized_apple_platform("${platform}" PLATFORM_CAPITALIZED)
+      set(CONFIG_NAME "${PLATFORM_CAPITALIZED}${ARCH_UPPER_CASE}Config")
+      set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-${platform}")
+      set(ASAN_TEST_APPLE_PLATFORM "${platform}")
+      set(ASAN_TEST_TARGET_ARCH "${arch}")
+      get_bits_for_arch(${arch} ASAN_TEST_BITS)
+      configure_lit_site_cfg(
+        ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
+        ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
+        )
+      add_lit_testsuite(check-asan-${platform}-${arch} "AddressSanitizer ${platform} ${arch} tests"
+        ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
+        DEPENDS ${ASAN_TEST_DEPS})
+    endforeach()
   endforeach()
-
   set(EXCLUDE_FROM_ALL OFF)
 endif()