[lld] [llvm] [lld] Fixes for unitests in standalone builds (PR #83670)
Michał Górny via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 2 03:27:51 PST 2024
https://github.com/mgorny created https://github.com/llvm/llvm-project/pull/83670
1. Replace the obsolete `llvm_add_unittests()` CMake function with an explicit check for `TARGET llvm_gtest`. This is more consistent with the rest of the code, and it makes it possible to avoid checking out `third-party` tree.
2. Add `LLDUnitTests` test dependency to standalone builds. It is defined unconditionally, and actually necessary to ensure that unit tests will be built.
>From dacfba15dea46cf470489fafd1f7915107aa12a5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny at gentoo.org>
Date: Sat, 2 Mar 2024 12:16:07 +0100
Subject: [PATCH 1/3] [lld] Update unittest condition to check for llvm_gtest
target
Inline and update the rule for adding unittest directory, to use
the modern approach of checking for `llvm_gtest` target rather than
using the `llvm_add_unittests()` function. The latter used a check
for a header file from the third-party tree that is no longer necessary
nor used in standalone builds. This change also eliminates the last
use of this function, making it possible to remove it.
As a side effect, LLD_UNITTESTS_ADDED is no longer defined. However,
it is not used anywhere.
---
lld/CMakeLists.txt | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lld/CMakeLists.txt b/lld/CMakeLists.txt
index 595c286abd91a6..cd8ba627306edb 100644
--- a/lld/CMakeLists.txt
+++ b/lld/CMakeLists.txt
@@ -192,7 +192,9 @@ add_subdirectory(tools/lld)
if (LLVM_INCLUDE_TESTS)
add_custom_target(LLDUnitTests)
- llvm_add_unittests(LLD_UNITTESTS_ADDED)
+ if (TARGET llvm_gtest)
+ add_subdirectory(unittests)
+ endif()
add_subdirectory(test)
endif()
>From 41a8f26cdaa9432d9bf5d9ea223939545187c105 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny at gentoo.org>
Date: Sat, 2 Mar 2024 12:21:03 +0100
Subject: [PATCH 2/3] [cmake] Remove llvm_add_unittests
Remove the obsolete `llvm_add_unittests()` CMake function. It is
no longer used anywhere.
---
llvm/cmake/modules/AddLLVM.cmake | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 0f1734a64ee6e6..828de4bd9940d6 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -2509,13 +2509,3 @@ function(setup_host_tool tool_name setting_name exe_var_name target_var_name)
add_custom_target(${target_var_name} DEPENDS ${exe_name})
endif()
endfunction()
-
-# Adds the unittests folder if gtest is available.
-function(llvm_add_unittests tests_added)
- if (EXISTS ${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include/gtest/gtest.h)
- add_subdirectory(unittests)
- set(${tests_added} ON PARENT_SCOPE)
- else()
- message(WARNING "gtest not found, unittests will not be available")
- endif()
-endfunction()
>From 8e01f90c2017750c0aa356224bfdb5c2a06cf7bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny at gentoo.org>
Date: Sat, 2 Mar 2024 12:22:10 +0100
Subject: [PATCH 3/3] [lld] Add LLDUnitTests to test dependencies for
standalone builds
Add `LLDUnitTests` target to the test dependencies independently of
whether a standalone or non-standalone build is performed. This target
is defined unconditionally, and without it unittests would be skipped
silently. It was probably accidentally added under
the `NOT LLD_BUILT_STANDALONE` condition.
---
lld/test/CMakeLists.txt | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/lld/test/CMakeLists.txt b/lld/test/CMakeLists.txt
index 558da2b4421a2c..bb6164f19dcef3 100644
--- a/lld/test/CMakeLists.txt
+++ b/lld/test/CMakeLists.txt
@@ -38,11 +38,10 @@ configure_lit_site_cfg(
"LLD_SOURCE_DIR"
)
-set(LLD_TEST_DEPS lld)
+set(LLD_TEST_DEPS lld LLDUnitTests)
if (NOT LLD_BUILT_STANDALONE)
list(APPEND LLD_TEST_DEPS
FileCheck
- LLDUnitTests
count
dsymutil
llc
More information about the llvm-commits
mailing list