Skip to content

Commit

Permalink
Fix plugin filter on Windows (#567)
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Pecka <[email protected]>
Signed-off-by: Jenn Nguyen <[email protected]>
Co-authored-by: Silvio Traversaro <[email protected]>
Co-authored-by: Ian Chen <[email protected]>
Co-authored-by: Jenn Nguyen <[email protected]>
Co-authored-by: Jenn Nguyen <[email protected]>
  • Loading branch information
5 people authored Nov 10, 2023
1 parent e898137 commit 2759bff
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions include/gz/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,9 @@ target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
TINYXML2::TINYXML2
)

target_compile_definitions(${PROJECT_LIBRARY_TARGET_NAME} PRIVATE
SHARED_LIBRARY_PREFIX=\"${CMAKE_SHARED_LIBRARY_PREFIX}\"
SHARED_LIBRARY_SUFFIX=\"${CMAKE_SHARED_LIBRARY_SUFFIX}\")

gz_install_all_headers()

15 changes: 12 additions & 3 deletions src/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -837,10 +837,19 @@ std::vector<std::pair<std::string, std::vector<std::string>>>
{
auto plugin = common::basename(*dirIter);

// All we verify is that the file starts with "lib", any further
// checks would require loading the plugin.
// All we verify is that the file starts with shared library prefix and
// ends with shared library suffix, any further checks would require
// loading the plugin.

if (plugin.find("lib") == 0)
// TODO(anyone): Move this logic into gz-plugin to be reusable

// This computation could underflow the unsigned range, but that is okay
// as in such case we would check if the suffix is placed somewhere much
// further than allowed filename length.
const auto suffixPos = plugin.length() - strlen(SHARED_LIBRARY_SUFFIX);

if (plugin.find(SHARED_LIBRARY_PREFIX) == 0 &&
plugin.rfind(SHARED_LIBRARY_SUFFIX) == suffixPos)
ps.push_back(plugin);
}

Expand Down
9 changes: 7 additions & 2 deletions src/MainWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,13 @@ QStringList MainWindow::PluginListModel() const
{
for (auto const &plugin : path.second)
{
// Remove lib and .so
auto pluginName = plugin.substr(3, plugin.find(".") - 3);
// TODO(anyone): Move this into gz-plugin to be reusable

// Remove shared library prefix and shared library suffix
auto pluginName = plugin.substr(
strlen(SHARED_LIBRARY_PREFIX),
plugin.length() - strlen(SHARED_LIBRARY_PREFIX) -
strlen(SHARED_LIBRARY_SUFFIX));

// Split WWWCamelCase3D -> WWW Camel Case 3D
std::regex reg("(\\B[A-Z][a-z])|(\\B[0-9])");
Expand Down

0 comments on commit 2759bff

Please sign in to comment.