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

Add helper functions for creating OS specific library names #29

Merged
merged 6 commits into from
Oct 26, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install:
- cd src
- python -c "import shutil; shutil.copytree('../..', './class_loader', ignore=shutil.ignore_patterns('build'))"
- git clone https://github.com/ros/console_bridge.git -b ros2
- git clone https://github.com/pocoproject/poco.git -b poco-1.6.1-release
- git clone --depth 1 https://github.com/pocoproject/poco.git -b poco-1.6.1-release
- mkdir ament
- cd ament
- git clone https://github.com/ament/ament_cmake.git
Expand All @@ -34,6 +34,8 @@ install:
- set "PATH=%PATH%;C:\Python34"
build_script:
- cd build
- python -u src\ament\ament_tools\scripts\ament.py build --build-tests
- |
python -u src\ament\ament_tools\scripts\ament.py build --build-tests --cmake-args -DENABLE_XML:BOOL=OFF -DENABLE_JSON:BOOL=OFF -DENABLE_MONGODB:BOOL=OFF -DENABLE_UTIL:BOOL=OFF -DENABLE_NET:BOOL=OFF -DENABLE_NETSSL:BOOL=OFF -DENABLE_CRYPTO:BOOL=OFF -DENABLE_DATA:BOOL=OFF -DENABLE_DATA_SQLITE:BOOL=OFF -DENABLE_DATA_MYSQL:BOOL=OFF -DENABLE_DATA_ODBC:BOOL=OFF -DENABLE_ZIP:BOOL=OFF -DENABLE_PAGECOMPILER:BOOL=OFF -DENABLE_PAGECOMPILER_FILE2PAGE:BOOL=OFF
- python -u src\ament\ament_tools\scripts\ament.py test --skip-build --skip-install --only class_loader
deploy: off
test: off
19 changes: 17 additions & 2 deletions include/class_loader/class_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,26 @@ namespace class_loader
{

/**
* returns runtime library extension for native os
*/
* returns the default library prefix for the native os
*/
CLASS_LOADER_PUBLIC
std::string systemLibraryPrefix();

/**
* returns runtime library extension for native os
*/
CLASS_LOADER_PUBLIC
std::string systemLibrarySuffix();

/**
* returns a platform specific version of a basic library name
*
* On *nix platforms the library name is prefixed with `lib`.
* On all platforms the output of class_loader::systemLibrarySuffix() is appended.
*/
CLASS_LOADER_PUBLIC
std::string systemLibraryFormat(const std::string & library_name);

/**
* @class ClassLoader
* @brief This class allows loading and unloading of dynamically linked libraries which contain class definitions from which objects can be created/destroyed during runtime (i.e. class_loader). Libraries loaded by a ClassLoader are only accessible within scope of that ClassLoader object.
Expand Down
19 changes: 19 additions & 0 deletions src/class_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,28 @@ bool ClassLoader::hasUnmanagedInstanceBeenCreated()
return ClassLoader::has_unmananged_instance_been_created_;
}

std::string systemLibraryPrefix()
{
#if !defined(WIN32)
return "lib";
#endif
return "";
}

std::string systemLibrarySuffix()
{
#if !defined(WIN32)
return Poco::SharedLibrary::suffix();
#else
// Return just .dll , as Poco::SharedLibrary::suffix() will return d.dll in debug mode.
// This isn't common for our usecase (instead debug libraries are placed in a `Debug` folder).
return ".dll";
#endif
}

std::string systemLibraryFormat(const std::string & library_name)
{
return systemLibraryPrefix() + library_name + systemLibrarySuffix();
}

ClassLoader::ClassLoader(const std::string & library_path, bool ondemand_load_unload)
Expand Down
2 changes: 2 additions & 0 deletions test/fviz_case_study/fviz_default_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class Bar : public FvizPluginBase
{
public:
virtual ~Bar() = default;
void speak()
{
foo("from plugin Bar");
Expand All @@ -15,6 +16,7 @@ class Bar : public FvizPluginBase
class Baz : public FvizPluginBase
{
public:
virtual ~Baz() = default;
void speak()
{
foo("from plugin Baz");
Expand Down
6 changes: 1 addition & 5 deletions test/fviz_case_study/fviz_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
#include "fviz.h"
#include "fviz_plugin_base.h"

#if defined(WIN32)
std::string name = "class_loader_Test_FvizDefaultPlugin";
#else
std::string name = "libclass_loader_Test_FvizDefaultPlugin" + class_loader::systemLibrarySuffix();
#endif
std::string name = class_loader::systemLibraryFormat("class_loader_Test_FvizDefaultPlugin");

int main(void)
{
Expand Down
1 change: 1 addition & 0 deletions test/fviz_case_study/fviz_plugin_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class FvizPluginBase
{
public:
virtual ~FvizPluginBase() {}
virtual void speak() = 0;
};

Expand Down
6 changes: 1 addition & 5 deletions test/fviz_case_study/fviz_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
#include "fviz.h"
#include "fviz_plugin_base.h"

#if defined(WIN32)
std::string name = "class_loader_Test_FvizDefaultPlugin";
#else
std::string name = "libclass_loader_Test_FvizDefaultPlugin" + class_loader::systemLibrarySuffix();
#endif
std::string name = class_loader::systemLibraryFormat("class_loader_Test_FvizDefaultPlugin");

TEST(FvizTest, basic_test)
{
Expand Down
9 changes: 2 additions & 7 deletions test/utest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@

#include "base.h"

#if defined(WIN32)
const std::string LIBRARY_1 = "class_loader_TestPlugins1";
const std::string LIBRARY_2 = "class_loader_TestPlugins2";
#else
const std::string LIBRARY_1 = "libclass_loader_TestPlugins1" + class_loader::systemLibrarySuffix();
const std::string LIBRARY_2 = "libclass_loader_TestPlugins2" + class_loader::systemLibrarySuffix();
#endif
const std::string LIBRARY_1 = class_loader::systemLibraryFormat("class_loader_TestPlugins1");
const std::string LIBRARY_2 = class_loader::systemLibraryFormat("class_loader_TestPlugins2");

TEST(ClassLoaderTest, basicLoad)
{
Expand Down