From 9b2eda79fa2979bc848202ad16917b86b6a2be24 Mon Sep 17 00:00:00 2001 From: Martin Pecka Date: Sun, 3 Sep 2023 19:20:40 +0200 Subject: [PATCH 1/5] Fixed listing of plugins on Windows. Signed-off-by: Martin Pecka --- include/gz/gui/CMakeLists.txt | 4 ++++ src/Application.cc | 19 ++++++++++++++----- src/MainWindow.cc | 6 +++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/gz/gui/CMakeLists.txt b/include/gz/gui/CMakeLists.txt index b3842959e..80957c0fa 100644 --- a/include/gz/gui/CMakeLists.txt +++ b/include/gz/gui/CMakeLists.txt @@ -66,5 +66,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() diff --git a/src/Application.cc b/src/Application.cc index 062ce0f2e..3bb51bfa2 100644 --- a/src/Application.cc +++ b/src/Application.cc @@ -541,8 +541,8 @@ bool Application::LoadPlugin(const std::string &_filename, // Add default folder and install folder std::string home; common::env(GZ_HOMEDIR, home); - systemPaths.AddPluginPaths(home + "/.gz/gui/plugins:" + - GZ_GUI_PLUGIN_INSTALL_DIR); + systemPaths.AddPluginPaths(home + "/.gz/gui/plugins"); + systemPaths.AddPluginPaths(GZ_GUI_PLUGIN_INSTALL_DIR); auto pathToLib = systemPaths.FindSharedLibrary(_filename); if (pathToLib.empty()) @@ -842,10 +842,19 @@ std::vector>> { 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.find(SHARED_LIBRARY_SUFFIX) == suffixPos) ps.push_back(plugin); } diff --git a/src/MainWindow.cc b/src/MainWindow.cc index a084d485d..3f4ca6e79 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -135,8 +135,12 @@ QStringList MainWindow::PluginListModel() const { for (auto const &plugin : path.second) { + //TODO(anyone): Move this into gz-plugin to be reusable + // Remove lib and .so - auto pluginName = plugin.substr(3, plugin.find(".") - 3); + auto pluginName = plugin.substr( + strlen(SHARED_LIBRARY_PREFIX), + plugin.length() - strlen(SHARED_LIBRARY_SUFFIX)); // Split WWWCamelCase3D -> WWW Camel Case 3D std::regex reg("(\\B[A-Z][a-z])|(\\B[0-9])"); From 937583c2ef6584949936ab1313306477c5cd1db2 Mon Sep 17 00:00:00 2001 From: Martin Pecka Date: Mon, 4 Sep 2023 08:08:09 +0200 Subject: [PATCH 2/5] Improve comments Co-authored-by: Silvio Traversaro Signed-off-by: Martin Pecka --- src/MainWindow.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MainWindow.cc b/src/MainWindow.cc index 3f4ca6e79..a707f524b 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -137,7 +137,7 @@ QStringList MainWindow::PluginListModel() const { //TODO(anyone): Move this into gz-plugin to be reusable - // Remove lib and .so + // Remove shared library prefix and shared library suffix auto pluginName = plugin.substr( strlen(SHARED_LIBRARY_PREFIX), plugin.length() - strlen(SHARED_LIBRARY_SUFFIX)); From 2deb3dac7fb1747283435d3b49d6596e4b50a48f Mon Sep 17 00:00:00 2001 From: Martin Pecka Date: Mon, 4 Sep 2023 08:29:07 +0200 Subject: [PATCH 3/5] Fixed cpplint Signed-off-by: Martin Pecka --- src/Application.cc | 2 +- src/MainWindow.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Application.cc b/src/Application.cc index 3bb51bfa2..e9f1dc848 100644 --- a/src/Application.cc +++ b/src/Application.cc @@ -846,7 +846,7 @@ std::vector>> // ends with shared library suffix, any further checks would require // loading the plugin. - //TODO(anyone): Move this logic into gz-plugin to be reusable + // 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 diff --git a/src/MainWindow.cc b/src/MainWindow.cc index a707f524b..e3dae0bb4 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -135,7 +135,7 @@ QStringList MainWindow::PluginListModel() const { for (auto const &plugin : path.second) { - //TODO(anyone): Move this into gz-plugin to be reusable + // TODO(anyone): Move this into gz-plugin to be reusable // Remove shared library prefix and shared library suffix auto pluginName = plugin.substr( From 3382241ec0f1f1e65a84f1c4eeb51dc76f193681 Mon Sep 17 00:00:00 2001 From: Martin Pecka Date: Mon, 4 Sep 2023 10:38:21 +0200 Subject: [PATCH 4/5] Use rfind for search from back Co-authored-by: Silvio Traversaro Signed-off-by: Martin Pecka --- src/Application.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application.cc b/src/Application.cc index e9f1dc848..8edab8907 100644 --- a/src/Application.cc +++ b/src/Application.cc @@ -854,7 +854,7 @@ std::vector>> const auto suffixPos = plugin.length() - strlen(SHARED_LIBRARY_SUFFIX); if (plugin.find(SHARED_LIBRARY_PREFIX) == 0 && - plugin.find(SHARED_LIBRARY_SUFFIX) == suffixPos) + plugin.rfind(SHARED_LIBRARY_SUFFIX) == suffixPos) ps.push_back(plugin); } From 864ad6b2d92aee19bac0c25a50934890cedd11f1 Mon Sep 17 00:00:00 2001 From: Martin Pecka Date: Wed, 6 Sep 2023 07:49:20 +0200 Subject: [PATCH 5/5] Fixed plugin list filter on Linux Co-authored-by: Ian Chen Signed-off-by: Martin Pecka --- src/MainWindow.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/MainWindow.cc b/src/MainWindow.cc index e3dae0bb4..634d80d7c 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -140,7 +140,8 @@ QStringList MainWindow::PluginListModel() const // Remove shared library prefix and shared library suffix auto pluginName = plugin.substr( strlen(SHARED_LIBRARY_PREFIX), - plugin.length() - strlen(SHARED_LIBRARY_SUFFIX)); + 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])");