Skip to content

Commit

Permalink
port: 2 to main 2022-11-16 (#110)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll authored Nov 16, 2022
2 parents 5c0d2d3 + 865b827 commit 6aed7bb
Show file tree
Hide file tree
Showing 27 changed files with 353 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set(GZ_CMAKE_VER ${gz-cmake3_VERSION_MAJOR})
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

gz_configure_project(VERSION_SUFFIX pre1)
gz_configure_project()

#============================================================================
# Set project-specific options
Expand Down
73 changes: 72 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,47 @@

## Gazebo Plugin 2.x

### Gazebo Plugin 2.X.X (202X-XX-XX)
### Gazebo Plugin 2.0.0

1. Add option to use `RTLD_NODELETE` when loading a library.
* [Pull request #102](https://github.com/gazebosim/gz-plugin/pull/102)

1. Improve install instructions.
* [Pull request #106](https://github.com/gazebosim/gz-plugin/pull/106)

1. Version bumps for Garden and deprecations.
* [Pull request #74](https://github.com/gazebosim/gz-plugin/pull/74)
* [Pull request #76](https://github.com/gazebosim/gz-plugin/pull/76)
* [Pull request #77](https://github.com/gazebosim/gz-plugin/pull/77)

1. Ignition to Gazebo rename
* [Pull request #78](https://github.com/gazebosim/gz-plugin/pull/78)
* [Pull request #79](https://github.com/gazebosim/gz-plugin/pull/79)
* [Pull request #82](https://github.com/gazebosim/gz-plugin/pull/82)
* [Pull request #83](https://github.com/gazebosim/gz-plugin/pull/83)
* [Pull request #86](https://github.com/gazebosim/gz-plugin/pull/86)
* [Pull request #87](https://github.com/gazebosim/gz-plugin/pull/87)
* [Pull request #88](https://github.com/gazebosim/gz-plugin/pull/88)
* [Pull request #89](https://github.com/gazebosim/gz-plugin/pull/89)
* [Pull request #90](https://github.com/gazebosim/gz-plugin/pull/90)
* [Pull request #93](https://github.com/gazebosim/gz-plugin/pull/93)
* [Pull request #104](https://github.com/gazebosim/gz-plugin/pull/104)

1. CLI tool updates.
* [Pull request #55](https://github.com/gazebosim/gz-plugin/pull/55)
* [Pull request #65](https://github.com/gazebosim/gz-plugin/pull/65)
* [Pull request #69](https://github.com/gazebosim/gz-plugin/pull/69)
* [Pull request #80](https://github.com/gazebosim/gz-plugin/pull/80)
* [Pull request #92](https://github.com/gazebosim/gz-plugin/pull/92)

1. Update GoogleTest to latest version.
* [Pull request #91](https://github.com/gazebosim/gz-plugin/pull/91)

1. Clean unused lambda capture warning.
* [Pull request #95](https://github.com/gazebosim/gz-plugin/pull/95)

1. Support static plugins.
* [Pull request #97](https://github.com/gazebosim/gz-plugin/pull/97)

## Gazebo Plugin 1.x

Expand All @@ -24,6 +64,37 @@
1. Remove gz-tools from CMakeLists.txt. Not used
* [Pull request #56](https://github.com/gazebosim/gz-plugin/pull/56)


## Gazebo Plugin 1.x

### Gazebo Plugin 1.3.0 (2022-11-11)

1. ign -> gz Migrate Ignition Headers : gz-plugin
* [Pull request #101](https://github.com/gazebosim/gz-plugin/pull/101)

### Gazebo Plugin 1.3.0 (2022-08-15)

1. Remove redundant namespace references
* [Pull request #100](https://github.com/gazebosim/gz-plugin/pull/100)

1. Change `IGN_DESIGNATION` to `GZ_DESIGNATION`
* [Pull request #96](https://github.com/gazebosim/gz-plugin/pull/96)

1. Ignition -> Gazebo
* [Pull request #94](https://github.com/gazebosim/gz-plugin/pull/94)

1. Bash completion for flags
* [Pull request #81](https://github.com/gazebosim/gz-plugin/pull/81)

1. Add LICENSE file
* [Pull request #72](https://github.com/gazebosim/gz-plugin/pull/72)

1. Add Ubuntu Jammy CI
* [Pull request #68](https://github.com/gazebosim/gz-plugin/pull/68)

1. Install ruby commands on Windows
* [Pull request #63](https://github.com/gazebosim/gz-plugin/pull/63)

### Gazebo Plugin 1.2.0 (2021-03-30)

1. Infrastructure
Expand Down
2 changes: 2 additions & 0 deletions MigrationFromCommon.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ then you should continue to use it. It does not have a replacement in `gz-plugin

Here is a list of things that you *should* replace:

* `#include <ignition/common/PluginLoader.hh>` should be replaced with `#include <gz/plugin/Loader.hh>`
* `#include <gz/common/PluginLoader.hh>` should be replaced with `#include <gz/plugin/Loader.hh>`
* `gz::common::PluginLoader` should be replaced with `gz::plugin::Loader`
* `ignition::common::PluginLoader` should be replaced with `gz::plugin::Loader`
* When calling `Loader::Instantiate("....")` do **NOT** prefix the class name with `::`. E.g. `"::some_namespace::MyClass"` should now be `"some_namespace::MyClass"`.


Expand Down
3 changes: 1 addition & 2 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ gz_build_tests(
TYPE UNIT
SOURCES ${tests})


add_subdirectory(include/gz/plugin)
install(DIRECTORY include/gz DESTINATION ${GZ_INCLUDE_INSTALL_DIR_FULL})
install(DIRECTORY include/ignition DESTINATION ${GZ_INCLUDE_INSTALL_DIR_FULL})
2 changes: 1 addition & 1 deletion core/include/ignition/plugin/EnablePluginFromThis.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Open Source Robotics Foundation
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion core/include/ignition/plugin/Factory.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Open Source Robotics Foundation
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion core/include/ignition/plugin/Info.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Open Source Robotics Foundation
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion core/include/ignition/plugin/Plugin.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Open Source Robotics Foundation
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion core/include/ignition/plugin/PluginPtr.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Open Source Robotics Foundation
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion core/include/ignition/plugin/SpecializedPlugin.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Open Source Robotics Foundation
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion core/include/ignition/plugin/SpecializedPluginPtr.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Open Source Robotics Foundation
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion core/include/ignition/plugin/WeakPluginPtr.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Open Source Robotics Foundation
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion core/include/ignition/plugin/utility.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Open Source Robotics Foundation
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
11 changes: 11 additions & 0 deletions loader/include/gz/plugin/Loader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ namespace gz
public: std::unordered_set<std::string> LoadLib(
const std::string &_pathToLibrary);

/// \brief Load a library at the given path
///
/// \param[in] _pathToLibrary
/// The path to a library
/// \param[in] _noDelete
/// If true, RTLD_NODELETE will be used when loading the library.
///
/// \returns The set of plugins that have been loaded from the library
public: std::unordered_set<std::string> LoadLib(
const std::string &_pathToLibrary, bool _noDelete);

/// \brief Instantiates a plugin for the given plugin name
///
/// \param[in] _pluginNameOrAlias
Expand Down
2 changes: 1 addition & 1 deletion loader/include/ignition/plugin/Loader.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Open Source Robotics Foundation
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
21 changes: 17 additions & 4 deletions loader/src/Loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace gz
/// \return If a library exists at the given path, get a point to its dl
/// handle. If the library does not exist, get a nullptr.
public: std::shared_ptr<void> LoadLib(
const std::string &_pathToLibrary);
const std::string &_pathToLibrary, bool _noDelete);

/// \brief Using a dl handle produced by LoadLib, extract the
/// Info from the loaded library.
Expand Down Expand Up @@ -139,12 +139,18 @@ namespace gz
/////////////////////////////////////////////////
std::unordered_set<std::string> Loader::LoadLib(
const std::string &_pathToLibrary)
{
return this->LoadLib(_pathToLibrary, false);
}
/////////////////////////////////////////////////
std::unordered_set<std::string> Loader::LoadLib(
const std::string &_pathToLibrary, bool _noDelete)
{
std::unordered_set<std::string> newPlugins;

// Attempt to load the library at this path
const std::shared_ptr<void> &dlHandle =
this->dataPtr->LoadLib(_pathToLibrary);
this->dataPtr->LoadLib(_pathToLibrary, _noDelete);

// Quit early and return an empty set of plugin names if we did not
// actually get a valid dlHandle.
Expand Down Expand Up @@ -420,7 +426,7 @@ namespace gz

/////////////////////////////////////////////////
std::shared_ptr<void> Loader::Implementation::LoadLib(
const std::string &_full_path)
const std::string &_full_path, bool _noDelete)
{
std::shared_ptr<void> dlHandlePtr;

Expand All @@ -431,7 +437,14 @@ namespace gz

// NOTE: We open using RTLD_LOCAL instead of RTLD_GLOBAL to prevent the
// symbols of different libraries from writing over each other.
void *dlHandle = dlopen(_full_path.c_str(), RTLD_LAZY | RTLD_LOCAL);
#ifdef _WIN32
// RTLD_NODELETE is not defined in dlfcn-32.
(void) _noDelete;
int dlopenMode = RTLD_LAZY | RTLD_LOCAL;
#else
int dlopenMode = RTLD_LAZY | RTLD_LOCAL | (_noDelete ? RTLD_NODELETE : 0);
#endif
void *dlHandle = dlopen(_full_path.c_str(), dlopenMode);

const char *loadError = dlerror();
if (nullptr == dlHandle || nullptr != loadError)
Expand Down
4 changes: 3 additions & 1 deletion loader/src/cmd/gz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "gz/plugin/config.hh"
#include "gz.hh"

using Loader = gz::plugin::Loader;

//////////////////////////////////////////////////
extern "C" void cmdPluginInfo(
const char *_plugin, int _verbose)
Expand All @@ -34,7 +36,7 @@ extern "C" void cmdPluginInfo(
return;
}

gz::plugin::Loader pl;
Loader pl;
std::cout << "Loading plugin library file [" << _plugin << "]\n";

// Print names of plugins exported by library file
Expand Down
2 changes: 1 addition & 1 deletion register/include/ignition/plugin/Register.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Open Source Robotics Foundation
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion register/include/ignition/plugin/RegisterMore.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Open Source Robotics Foundation
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
5 changes: 4 additions & 1 deletion test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ foreach(test ${test_targets})
GzBadPluginSize
GzDummyPlugins
GzFactoryPlugins
GzTemplatedPlugins)
GzTemplatedPlugins
GzInstanceCounter)

target_compile_definitions(${test} PRIVATE
"${plugin_target}_LIB=\"$<TARGET_FILE:${plugin_target}>\"")
Expand All @@ -33,6 +34,8 @@ foreach(test
INTEGRATION_EnablePluginFromThis_TEST
INTEGRATION_factory
INTEGRATION_plugin
INTEGRATION_plugin_unload_with_nodelete
INTEGRATION_plugin_unload_without_nodelete
INTEGRATION_WeakPluginPtr)

if(TARGET ${test})
Expand Down
63 changes: 63 additions & 0 deletions test/integration/plugin_unload.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef GZ_PLUGIN_TEST_INTEGRATION_PLUGIN_UNLOAD_HH
#define GZ_PLUGIN_TEST_INTEGRATION_PLUGIN_UNLOAD_HH

#include <gtest/gtest.h>

#include <iostream>
#include <string>
#include <unordered_set>

#include "../plugins/InstanceCounter.hh"
#include "gz/plugin/Loader.hh"
#include "gz/plugin/PluginPtr.hh"
#include "gz/plugin/SpecializedPluginPtr.hh"

/////////////////////////////////////////////////
/// \brief Load the InstanceCounter plugin
/// \param[in] _nodelete True if RTLD_NODELETE should be used when loading the
/// \return Pointer to the plugin
gz::plugin::PluginPtr LoadInstanceCounter(bool _nodelete)
{
gz::plugin::Loader pl;

std::unordered_set<std::string> pluginNames =
pl.LoadLib(GzInstanceCounter_LIB, _nodelete);

return pl.Instantiate("test::util::InstanceCounter");
}

/////////////////////////////////////////////////
/// \brief Load plugin, Instantiate the InstanceCounter, check the number of
/// instances, and finally unload the plugin. Note, the plugin is unloaded when
/// `instanceCounterPlugin` goes out of scope.
/// \param[in] _nodelete True if RTLD_NODELETE should be used when loading the
/// library.
/// \param[in] _numExpectedInstances Expected number of instances of the plugin.
void LoadAndTestInstanceCounter(bool _nodelete, int _numExpectedInstances)
{
gz::plugin::PluginPtr instanceCounterPlugin = LoadInstanceCounter(_nodelete);
test::util::InstanceCounterBase *instanceCounter =
instanceCounterPlugin->QueryInterface<test::util::InstanceCounterBase>();
ASSERT_NE(nullptr, instanceCounter);

EXPECT_EQ(_numExpectedInstances, instanceCounter->Instances());
}

#endif
Loading

0 comments on commit 6aed7bb

Please sign in to comment.