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..59188a7cc 100644 --- a/lib/Interpreter/DynamicLibraryManager.cpp +++ b/lib/Interpreter/DynamicLibraryManager.cpp @@ -284,10 +284,13 @@ namespace Cpp { // If it is an absolute path, don't try iterate over the paths. if (llvm::sys::path::is_absolute(libStem)) { - if (isSharedLibrary(libStem)) + if (isSharedLibrary(libStem)) { return normalizePath(libStem); - else + } else { + LLVM_DEBUG(dbgs() << "Dyld::lookupLibrary: '" << libStem.str() << "'" + << "is not a shared library\n"); return std::string(); + } } // Subst all known linker variables ($origin, @rpath, etc.) @@ -464,7 +467,8 @@ namespace Cpp { (Magic == file_magic::macho_fixed_virtual_memory_shared_lib || Magic == file_magic::macho_dynamically_linked_shared_lib || Magic == file_magic::macho_dynamically_linked_shared_lib_stub - || Magic == file_magic::macho_universal_binary) + || Magic == file_magic::macho_universal_binary + || Magic == file_magic::macho_bundle) #elif defined(LLVM_ON_UNIX) #ifdef __CYGWIN__ (Magic == file_magic::pecoff_executable) @@ -480,7 +484,6 @@ namespace Cpp { # error "Unsupported platform." #endif ; - return result; } diff --git a/unittests/CppInterOp/CMakeLists.txt b/unittests/CppInterOp/CMakeLists.txt index 08cd4ee9a..4c370e9f4 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(PluginsTests) +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..e48e28868 --- /dev/null +++ b/unittests/CppInterOp/TestSharedLib/CMakeLists.txt @@ -0,0 +1,7 @@ +add_llvm_library(TestSharedLib MODULE 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..be14c8c11 --- /dev/null +++ b/unittests/CppInterOp/TestSharedLib/TestSharedLib.h @@ -0,0 +1,2 @@ + +int ret_zero();