-
Notifications
You must be signed in to change notification settings - Fork 311
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
[runSofa] autoload plugins (2nd version) #301
Merged
damienmarchal
merged 14 commits into
sofa-framework:master
from
fredroy:autoload_plugins2
Jul 5, 2017
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0077687
CMake: generates at configure time list of all compiled plugins
fredroy 649f61a
SofaFramework: PluginManager read/write files handles version
fredroy 2cc04fb
runSofa: load automatically plugins list (default or customized)
fredroy 5dea9be
runSofa: move all plugin config generation CMake code into runSofa ap…
fredroy 47f42c5
Fix paths for Linux and Mac
fredroy 03b181a
[runSofa] add test for autoload
fredroy fb65261
[runSofa] reflect the change in the CHANGELOG
fredroy 3bc4c51
[runSofa_test] remove warning
fredroy 30e5bd3
[SofaHelper] Utils: add helper function to retrieve the plugin directory
fredroy 6f646a5
[runSofa] cleanup and use previous implemented function
fredroy 844ab8c
[SofaHelper] PluginManager: add deprecation message + new test (and t…
fredroy eaf64af
Merge branch 'master' of github.com:sofa-framework/sofa into autoload…
fredroy 2d733a4
[SofaFramework_test] fix test
fredroy 66d9d67
[SofaHelper] Fix linking problem in MSVC/Debug mode due to missing im…
fredroy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
applications/projects/runSofa/cmake/GeneratePluginConfig.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
|
||
macro(sofa_generate_plugin_config config_filename) | ||
# Generate default list of plugins (according to the options) | ||
get_property(_allTargets GLOBAL PROPERTY __GlobalTargetList__) | ||
get_property(_allTargetNames GLOBAL PROPERTY __GlobalTargetNameList__) | ||
|
||
list(LENGTH _allTargets nbTargets) | ||
math(EXPR len "${nbTargets} - 1") | ||
|
||
set(_pluginPrefix "PLUGIN") | ||
foreach(counter RANGE ${len}) | ||
list(GET _allTargets ${counter} _target) | ||
list(GET _allTargetNames ${counter} _targetName) | ||
|
||
string(SUBSTRING "${_targetName}" 0 6 _testPlugin) | ||
if(${_testPlugin} MATCHES "${_pluginPrefix}.*") | ||
if(${${_targetName}}) | ||
get_target_property(_version ${_target} VERSION ) | ||
if(${_version} MATCHES ".*NOTFOUND") | ||
set(_version "NO_VERSION") | ||
endif() | ||
string(CONCAT _pluginConfig "${_pluginConfig}\n${_target} ${_version}") | ||
endif() | ||
endif() | ||
endforeach() | ||
FILE(WRITE ${config_filename} ${_pluginConfig}) | ||
|
||
# only useful for devs working directly with a build version (not installed) | ||
# With Win/MVSC, we can only know $CONFIG at build time | ||
if (MSVC) | ||
add_custom_target(do_always ALL | ||
COMMAND "${CMAKE_COMMAND}" -E copy "${config_filename}" "${CMAKE_BINARY_DIR}/bin/$<CONFIG>/" | ||
) | ||
endif(MSVC) | ||
|
||
endmacro() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(runSofa_test) | ||
|
||
|
||
set(SOURCE_FILES | ||
runSofa_test.cpp | ||
) | ||
|
||
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ) | ||
target_link_libraries(${PROJECT_NAME} SofaTest SofaGTestMain) | ||
|
||
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) |
84 changes: 84 additions & 0 deletions
84
applications/projects/runSofa/runSofa_test/runSofa_test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/****************************************************************************** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for adding tests with your new features. |
||
* SOFA, Simulation Open-Framework Architecture, development version * | ||
* (c) 2006-2017 INRIA, USTL, UJF, CNRS, MGH * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify it * | ||
* under the terms of the GNU General Public License as published by the Free * | ||
* Software Foundation; either version 2 of the License, or (at your option) * | ||
* any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, but WITHOUT * | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * | ||
* more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License along * | ||
* with this program. If not, see <http://www.gnu.org/licenses/>. * | ||
******************************************************************************* | ||
* Authors: The SOFA Team and external contributors (see Authors.txt) * | ||
* * | ||
* Contact information: contact@sofa-framework.org * | ||
******************************************************************************/ | ||
|
||
#include <fstream> | ||
#include <gtest/gtest.h> | ||
#include <SofaTest/Sofa_test.h> | ||
|
||
#include <sofa/helper/Utils.h> | ||
#include <sofa/helper/system/PluginManager.h> | ||
#include <sofa/helper/system/FileRepository.h> | ||
|
||
namespace sofa | ||
{ | ||
|
||
using sofa::helper::system::DataRepository; | ||
using sofa::helper::system::PluginRepository; | ||
using sofa::helper::system::PluginManager; | ||
|
||
class runSofa_test : public Sofa_test<> | ||
{ | ||
protected: | ||
std::string m_testConfigPluginName; | ||
std::string m_testConfigPluginPath; | ||
std::string m_testPluginName; | ||
|
||
runSofa_test() { | ||
|
||
} | ||
|
||
void SetUp() | ||
{ | ||
const std::string& pluginDir = helper::Utils::getPluginDirectory(); | ||
|
||
m_testConfigPluginName = "test_plugin_list.conf"; | ||
m_testConfigPluginPath = pluginDir + "/" + m_testConfigPluginName; | ||
m_testPluginName = "TestPlugin"; | ||
|
||
//generate on the fly test list | ||
std::ofstream testPluginList; | ||
testPluginList.open(m_testConfigPluginPath); | ||
testPluginList << m_testPluginName << std::endl; | ||
testPluginList.close(); | ||
} | ||
void TearDown() | ||
{ | ||
|
||
} | ||
|
||
}; | ||
|
||
TEST_F(runSofa_test, runSofa_autoload) | ||
{ | ||
PluginManager& pm = PluginManager::getInstance(); | ||
|
||
ASSERT_EQ(pm.getPluginMap().size(), 0U); | ||
pm.readFromIniFile(m_testConfigPluginPath); | ||
PluginManager::getInstance().init(); | ||
ASSERT_GT(pm.getPluginMap().size(), 0U); | ||
const std::string pluginPath = pm.findPlugin(m_testPluginName); | ||
ASSERT_GT(pluginPath.size(), 0U); | ||
helper::system::Plugin& p = pm.getPluginMap()[pluginPath]; | ||
ASSERT_EQ(0, std::string(p.getModuleName()).compare(m_testPluginName)); | ||
} | ||
|
||
} // namespace sofa |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old ini file does not have the version number.
Maybe you can implement a backward compatibility hook, I'm not sure this could work like that but
here is the idea:
Why not having the version number into the filename (as linux is doing libpng.1.0.so) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it already work with previous format (w/o version) but you're right about a deprecated message.
About the version thing in the filename, it is done already on Mac and Linux (e.g libFredPlugin.0.1.dylib is created and a symbolic link libFredPlugin points to it).
I guess you would like to load a specific version, e.g
CImgPlugin 0.5 then load CImgPlugin.0.5.dylib if not warning/error about the version, right ?
I think it should be the purpose of a future PR which will
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick answer,
I agree this could be for a future PR.