Skip to content

Commit e7734ca

Browse files
authored
Add FrontEndManager::register_front_end(fs::path) & Refactor validate_path (#33296)
### Details: - Add `FrontEndManager::register_front_end(fs::path)` - Update tests to use `fs::path`, add one test for `std::string` ### Tickets: - [CVS-178343](https://jira.devtools.intel.com/browse/CVS-178343)
1 parent ef1436c commit e7734ca

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

src/core/tests/frontend/frontend_manager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
using namespace ov::frontend;
1717

18-
static std::string mock_fe_path() {
19-
static auto lib_name = std::string(FRONTEND_LIB_PREFIX) + "mock1" + std::string(FRONTEND_LIB_SUFFIX);
20-
return ov::util::path_join({ov::test::utils::getExecutableDirectory(), lib_name}).string();
18+
static std::filesystem::path mock_fe_path() {
19+
return ov::test::utils::to_fs_path(ov::test::utils::getExecutableDirectory()) /
20+
std::filesystem::path(FRONTEND_LIB_PREFIX).concat("mock1").concat(FRONTEND_LIB_SUFFIX);
2121
}
2222

2323
TEST(FrontEndManagerTest, testAvailableFrontEnds) {
@@ -42,7 +42,7 @@ TEST(FrontEndManagerTest, testAvailableFrontEnds) {
4242

4343
TEST(FrontEndManagerTest, testFailRegisterFEByWrongPath) {
4444
FrontEndManager fem;
45-
ASSERT_THROW(fem.register_front_end("mock1", mock_fe_path() + "_wrong"), ov::frontend::GeneralFailure);
45+
ASSERT_THROW(fem.register_front_end("mock1", mock_fe_path().concat("_wrong")), ov::frontend::GeneralFailure);
4646
}
4747

4848
TEST(FrontEndManagerTest, testMockPluginFrontEnd) {

src/frontends/common/include/openvino/frontend/frontend.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,7 @@ class FRONTEND_API FrontEnd {
167167

168168
virtual InputModel::Ptr load_impl(const std::vector<ov::Any>& variants) const;
169169

170-
void validate_path(const std::string& path) const;
171-
#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
172-
void validate_path(const std::wstring& path) const;
173-
#endif
170+
void validate_path(const std::filesystem::path& path) const;
174171

175172
std::vector<ov::Extension::Ptr> m_extensions;
176173

src/frontends/common/include/openvino/frontend/manager.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class FRONTEND_API FrontEndManager final {
7575
/// be created
7676
void register_front_end(const std::string& name, FrontEndFactory creator);
7777

78+
///@{
7879
/// \brief Register frontend with name and factory loaded from provided library
7980
///
8081
/// \param name Name of front end
@@ -84,6 +85,15 @@ class FRONTEND_API FrontEndManager final {
8485
/// to identify library full name
8586
void register_front_end(const std::string& name, const std::string& library_path);
8687

88+
void register_front_end(const std::string& name, const std::filesystem::path& library_path);
89+
90+
template <class Path, std::enable_if_t<std::is_constructible_v<std::string, Path>>* = nullptr>
91+
void register_front_end(const std::string& name, const Path& library_path) {
92+
// needed due to ambiguity between string and filesystem::path calls
93+
register_front_end(name, std::string(library_path));
94+
}
95+
///@}
96+
8797
private:
8898
class Impl;
8999

src/frontends/common/src/frontend.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,9 @@ std::string FrontEnd::get_name() const {
109109
FRONTEND_RETURN_STATEMENT("Getting frontend name", m_actual->get_name();)
110110
}
111111

112-
void FrontEnd::validate_path(const std::string& path) const {
112+
void FrontEnd::validate_path(const std::filesystem::path& path) const {
113113
FRONT_END_GENERAL_CHECK(util::directory_exists(path) || util::file_exists(path),
114114
get_name(),
115-
": Could not open the file: \"",
116-
path,
117-
'"');
115+
": Could not open the file: ",
116+
path);
118117
}
119-
120-
#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
121-
void FrontEnd::validate_path(const std::wstring& path) const {
122-
validate_path(ov::util::wstring_to_string(path));
123-
}
124-
#endif

src/frontends/common/src/manager.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ class FrontEndManager::Impl {
105105
m_plugins.push_back(std::move(plugin_info));
106106
}
107107

108-
void register_front_end(const std::string& name, const std::string& library_path) {
109-
auto lib_path = ov::util::get_plugin_path(ov::util::make_path(library_path));
108+
void register_front_end(const std::string& name, const std::filesystem::path& library_path) {
109+
auto lib_path = ov::util::get_plugin_path(library_path);
110110
PluginInfo plugin;
111111
plugin.m_file_path = ov::util::path_to_string(lib_path);
112112
plugin.m_file_name = ov::util::path_to_string(lib_path.filename());
@@ -238,6 +238,10 @@ void FrontEndManager::register_front_end(const std::string& name, FrontEndFactor
238238
}
239239

240240
void FrontEndManager::register_front_end(const std::string& name, const std::string& library_path) {
241+
m_impl->register_front_end(name, ov::util::make_path(library_path));
242+
}
243+
244+
void FrontEndManager::register_front_end(const std::string& name, const std::filesystem::path& library_path) {
241245
m_impl->register_front_end(name, library_path);
242246
}
243247

0 commit comments

Comments
 (0)