Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plugin filter on Windows #567

Merged
merged 9 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/gz/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

19 changes: 14 additions & 5 deletions src/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -842,10 +842,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
8 changes: 6 additions & 2 deletions src/MainWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ 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_SUFFIX));
peci1 marked this conversation as resolved.
Show resolved Hide resolved

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