From af05733a3a8ee249a6be23ae3862c4b49005115a Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Fri, 12 Aug 2022 12:10:03 +0400 Subject: [PATCH] Failed plugins search from current directory w/o LD_LIBRARY_PATH (#12499) --- samples/cpp/CMakeLists.txt | 9 ++---- .../tests/frontend/shared/include/utils.hpp | 6 ++-- .../tests/frontend/shared/src/utils.cpp | 32 ------------------- src/inference/src/ie_core.cpp | 11 +++++++ 4 files changed, 15 insertions(+), 43 deletions(-) diff --git a/samples/cpp/CMakeLists.txt b/samples/cpp/CMakeLists.txt index cc6436b05e2..aa54a749fe1 100644 --- a/samples/cpp/CMakeLists.txt +++ b/samples/cpp/CMakeLists.txt @@ -38,13 +38,8 @@ else() set(IE_MAIN_SAMPLES_DIR ${CMAKE_CURRENT_BINARY_DIR}) endif() -if(NOT(UNIX)) - set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) - set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) -else () - set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER}/lib) - set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER}/lib) -endif() +set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) +set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) set (CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) set (CMAKE_PDB_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) diff --git a/src/frontends/tests/frontend/shared/include/utils.hpp b/src/frontends/tests/frontend/shared/include/utils.hpp index 0377d674daa..9866296a9bc 100644 --- a/src/frontends/tests/frontend/shared/include/utils.hpp +++ b/src/frontends/tests/frontend/shared/include/utils.hpp @@ -15,10 +15,8 @@ // Helper functions namespace FrontEndTestUtils { -std::string find_ov_path(); -int run_tests(int argc, char** argv); -std::string get_current_executable_path(); +int run_tests(int argc, char** argv); inline std::tuple load_from_file(ov::frontend::FrontEndManager& fem, const std::string& frontend_name, const std::string& model_file) { @@ -52,7 +50,7 @@ inline int set_test_env(const char* name, const char* value) { inline void setupTestEnv() { NGRAPH_SUPPRESS_DEPRECATED_START - std::string fePath = ov::util::get_directory(find_ov_path()); + std::string fePath = ov::util::get_ov_lib_path(); set_test_env("OV_FRONTEND_PATH", fePath.c_str()); NGRAPH_SUPPRESS_DEPRECATED_END } diff --git a/src/frontends/tests/frontend/shared/src/utils.cpp b/src/frontends/tests/frontend/shared/src/utils.cpp index 5e38f7880d7..cc435b3a063 100644 --- a/src/frontends/tests/frontend/shared/src/utils.cpp +++ b/src/frontends/tests/frontend/shared/src/utils.cpp @@ -4,38 +4,6 @@ #include "utils.hpp" -#ifdef _WIN32 -# ifndef NOMINMAX -# define NOMINMAX -# endif -# include -# if defined(WINAPI_FAMILY) && !WINAPI_PARTITION_DESKTOP -# error "Only WINAPI_PARTITION_DESKTOP is supported, because of LoadLibrary[A|W]" -# endif -#elif defined(__linux) || defined(__APPLE__) -# include -#endif - -std::string FrontEndTestUtils::find_ov_path() { -#ifdef _WIN32 - HMODULE hModule = GetModuleHandleW(SHARED_LIB_PREFIX L"frontend_common" SHARED_LIB_SUFFIX); - WCHAR wpath[MAX_PATH]; - GetModuleFileNameW(hModule, wpath, MAX_PATH); - std::wstring ws(wpath); - std::string path(ws.begin(), ws.end()); - std::replace(path.begin(), path.end(), '\\', '/'); - path = ov::util::get_directory(path); - path += "/"; - return path; -#elif defined(__linux) || defined(__APPLE__) - Dl_info dl_info; - dladdr(reinterpret_cast(ngraph::to_lower), &dl_info); - return ov::util::get_absolute_file_path(dl_info.dli_fname); -#else -# error "Unsupported OS" -#endif -} - std::string FrontEndTestUtils::get_disabled_tests(const std::string& manifest_path) { std::string result = "-"; std::ifstream manifest_stream(manifest_path); diff --git a/src/inference/src/ie_core.cpp b/src/inference/src/ie_core.cpp index 81b425f3f43..7620ad7c873 100644 --- a/src/inference/src/ie_core.cpp +++ b/src/inference/src/ie_core.cpp @@ -104,9 +104,20 @@ ov::util::FilePath getPluginPath(const std::string& pluginName, bool needAddSuff auto pluginPath = ov::util::to_file_path(pluginName.c_str()); // 0. user can provide a full path + +#ifndef _WIN32 + try { + // dlopen works with absolute paths; otherwise searches from LD_LIBRARY_PATH + pluginPath = ov::util::to_file_path(ov::util::get_absolute_file_path(pluginName)); + } catch (const std::runtime_error&) { + // failed to resolve absolute path; not critical + } +#endif // _WIN32 + if (FileUtils::fileExist(pluginPath)) return pluginPath; + // ov::Core::register_plugin(plugin_name, device_name) case if (needAddSuffixes) pluginPath = FileUtils::makePluginLibraryName({}, pluginPath);