From 5216155ec500c59e74a0c5bf9b9f255432f325ac Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Thu, 19 Oct 2023 17:52:33 +0000 Subject: [PATCH 1/2] Add missing dependency for LoadRequestedPlugins --- lib/Interpreter/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Interpreter/CMakeLists.txt b/lib/Interpreter/CMakeLists.txt index 19e3c4cbf..c7429e47b 100644 --- a/lib/Interpreter/CMakeLists.txt +++ b/lib/Interpreter/CMakeLists.txt @@ -36,6 +36,7 @@ target_link_libraries(clangCppInterOp PRIVATE ${cling_clang_interp} clangAST clangBasic + clangFrontend clangLex clangSema dl From 72624fd5b014b57c488cfb05a07a66de98d75574 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Thu, 19 Oct 2023 18:10:44 +0000 Subject: [PATCH 2/2] Add testing infrastructure for the DynamicLibraryManager. --- lib/Interpreter/CMakeLists.txt | 1 - lib/Interpreter/DynamicLibraryManager.cpp | 6 ++++-- unittests/CppInterOp/CMakeLists.txt | 12 ++++++++++++ unittests/CppInterOp/DynamicLibraryManagerTest.cpp | 8 ++++++++ unittests/CppInterOp/TestSharedLib/CMakeLists.txt | 7 +++++++ unittests/CppInterOp/TestSharedLib/TestSharedLib.cpp | 3 +++ unittests/CppInterOp/TestSharedLib/TestSharedLib.h | 6 ++++++ 7 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 unittests/CppInterOp/DynamicLibraryManagerTest.cpp create mode 100644 unittests/CppInterOp/TestSharedLib/CMakeLists.txt create mode 100644 unittests/CppInterOp/TestSharedLib/TestSharedLib.cpp create mode 100644 unittests/CppInterOp/TestSharedLib/TestSharedLib.h diff --git a/lib/Interpreter/CMakeLists.txt b/lib/Interpreter/CMakeLists.txt index c7429e47b..fcc3d68a2 100644 --- a/lib/Interpreter/CMakeLists.txt +++ b/lib/Interpreter/CMakeLists.txt @@ -46,4 +46,3 @@ string(REPLACE ";" "\;" _VER CPPINTEROP_VERSION) set_source_files_properties(CppInterOp.cpp PROPERTIES COMPILE_DEFINITIONS "LLVM_BINARY_DIR=\"${LLVM_BINARY_DIR}\";CPPINTEROP_VERSION=\"${_VAR}\"" ) - diff --git a/lib/Interpreter/DynamicLibraryManager.cpp b/lib/Interpreter/DynamicLibraryManager.cpp index 28ae99856..b5a65c0f8 100644 --- a/lib/Interpreter/DynamicLibraryManager.cpp +++ b/lib/Interpreter/DynamicLibraryManager.cpp @@ -286,8 +286,10 @@ namespace Cpp { if (llvm::sys::path::is_absolute(libStem)) { if (isSharedLibrary(libStem)) return normalizePath(libStem); - else - return std::string(); + + LLVM_DEBUG(dbgs() << "Dyld::lookupLibrary: '" << libStem.str() << "'" + << "is not a shared library\n"); + return std::string(); } // Subst all known linker variables ($origin, @rpath, etc.) diff --git a/unittests/CppInterOp/CMakeLists.txt b/unittests/CppInterOp/CMakeLists.txt index 08cd4ee9a..7ca5e5dfa 100644 --- a/unittests/CppInterOp/CMakeLists.txt +++ b/unittests/CppInterOp/CMakeLists.txt @@ -19,3 +19,15 @@ target_link_libraries(CppInterOpTests ) export_executable_symbols(CppInterOpTests) + +unset(LLVM_LINK_COMPONENTS) + +add_cppinterop_unittest(DynamicLibraryManagerTests DynamicLibraryManagerTest.cpp) +target_link_libraries(DynamicLibraryManagerTests + PRIVATE + clangCppInterOp + ) + +add_dependencies(DynamicLibraryManagerTests TestSharedLib) +#export_executable_symbols_for_plugins(TestSharedLib) +add_subdirectory(TestSharedLib) diff --git a/unittests/CppInterOp/DynamicLibraryManagerTest.cpp b/unittests/CppInterOp/DynamicLibraryManagerTest.cpp new file mode 100644 index 000000000..c7dea4c2f --- /dev/null +++ b/unittests/CppInterOp/DynamicLibraryManagerTest.cpp @@ -0,0 +1,8 @@ +#include "gtest/gtest.h" + +#include "clang/Interpreter/CppInterOp.h" + +TEST(DynamicLibraryManagerTest, Sanity) { + EXPECT_TRUE(Cpp::CreateInterpreter()); + EXPECT_TRUE(Cpp::LoadLibrary("TestSharedLib")); +} diff --git a/unittests/CppInterOp/TestSharedLib/CMakeLists.txt b/unittests/CppInterOp/TestSharedLib/CMakeLists.txt new file mode 100644 index 000000000..0111ea0f3 --- /dev/null +++ b/unittests/CppInterOp/TestSharedLib/CMakeLists.txt @@ -0,0 +1,7 @@ +add_llvm_library(TestSharedLib SHARED BUILDTREE_ONLY TestSharedLib.cpp) +# Put TestSharedLib next to the unit test executable. +set_output_directory(TestSharedLib + BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../ + LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../ + ) +set_target_properties(TestSharedLib PROPERTIES FOLDER "Tests") diff --git a/unittests/CppInterOp/TestSharedLib/TestSharedLib.cpp b/unittests/CppInterOp/TestSharedLib/TestSharedLib.cpp new file mode 100644 index 000000000..c0d7c474c --- /dev/null +++ b/unittests/CppInterOp/TestSharedLib/TestSharedLib.cpp @@ -0,0 +1,3 @@ +#include "TestSharedLib.h" + +int ret_zero() { return 0; } diff --git a/unittests/CppInterOp/TestSharedLib/TestSharedLib.h b/unittests/CppInterOp/TestSharedLib/TestSharedLib.h new file mode 100644 index 000000000..9577f66d6 --- /dev/null +++ b/unittests/CppInterOp/TestSharedLib/TestSharedLib.h @@ -0,0 +1,6 @@ +#ifndef UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H +#define UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H + +int ret_zero(); + +#endif // UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H