[libc] Check if the hermetic test target exists
authorPetr Hosek <phosek@google.com>
Sat, 1 Jul 2023 03:37:41 +0000 (03:37 +0000)
committerPetr Hosek <phosek@google.com>
Wed, 5 Jul 2023 17:09:01 +0000 (17:09 +0000)
When crt1 isn't available, which is typical on baremetal, hermetic tests
aren't created and the hermetic test target won't be available.

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

libc/cmake/modules/LLVMLibCTestRules.cmake

index 8ce1952..b2666d4 100644 (file)
@@ -747,7 +747,7 @@ function(add_libc_test test_name)
   if(LIBC_ENABLE_HERMETIC_TESTS AND NOT LIBC_TEST_UNIT_TEST_ONLY)
     add_libc_hermetic_test(${test_name}.__hermetic__ ${LIBC_TEST_UNPARSED_ARGUMENTS})
     get_fq_target_name(${test_name} fq_test_name)
-    if(TARGET ${fq_test_name}.__unit__)
+    if(TARGET ${fq_test_name}.__hermetic__ AND TARGET ${fq_test_name}.__unit__)
       # Tests like the file tests perform file operations on disk file. If we
       # don't chain up the unit test and hermetic test, then those tests will
       # step on each other's files.