diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 6c5a7a8d45de3..71217b87fdce6 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -29,7 +29,7 @@ jobs: OS_NAME: linux COMPILER: gcc BUILD_TYPE: Release - RUN_TESTS: OFF + RUN_TESTS: ON run: '.ci/script.sh' windows_2019: name: Build on Windows 2019 diff --git a/CHANGELOG.md b/CHANGELOG.md index ab42d70cf0aba..76dbfa30b3311 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ### [DART 6.10.0 (20XX-XX-XX)](https://github.com/dartsim/dart/milestone/58?closed=1) +* Common + + * Removed use of boost::filesystem in public APIs: [#1417](https://github.com/dartsim/dart/pull/1417) + * Kinematics * Added IkFast parameter accessors to IkFast class: [#1396](https://github.com/dartsim/dart/pull/1396) diff --git a/dart/common/SharedLibrary.cpp b/dart/common/SharedLibrary.cpp index c95fde4435b74..4465f7cae6af5 100644 --- a/dart/common/SharedLibrary.cpp +++ b/dart/common/SharedLibrary.cpp @@ -58,6 +58,12 @@ namespace common { //============================================================================== std::shared_ptr SharedLibrary::create( const boost::filesystem::path& path) +{ + return create(path.string()); +} + +//============================================================================== +std::shared_ptr SharedLibrary::create(const std::string& path) { return detail::SharedLibraryManager::getSingleton().load(path); } @@ -65,10 +71,17 @@ std::shared_ptr SharedLibrary::create( //============================================================================== SharedLibrary::SharedLibrary( ProtectedConstructionTag, const boost::filesystem::path& canonicalPath) - : mCanonicalPath(canonicalPath), mInstance(nullptr) + : SharedLibrary(ProtectedConstruction, canonicalPath.string()) { - mInstance - = static_cast(DYNLIB_LOAD(canonicalPath.string().c_str())); + // Do nothing +} + +//============================================================================== +SharedLibrary::SharedLibrary( + ProtectedConstructionTag, const std::string& canonicalPath) + : mCanonicalPath(canonicalPath), mPath(canonicalPath), mInstance(nullptr) +{ + mInstance = static_cast(DYNLIB_LOAD(canonicalPath.c_str())); if (!mInstance) { @@ -86,7 +99,7 @@ SharedLibrary::~SharedLibrary() if (DYNLIB_UNLOAD(mInstance)) { dterr << "[SharedLibrary::~SharedLibrary] Failed to unload library '" - << mCanonicalPath << "': " << getLastError() << "\n"; + << mPath << "': " << getLastError() << "\n"; } } @@ -96,6 +109,12 @@ const boost::filesystem::path& SharedLibrary::getCanonicalPath() const return mCanonicalPath; } +//============================================================================== +const std::string& SharedLibrary::path() const +{ + return mPath; +} + //============================================================================== bool SharedLibrary::isValid() const { diff --git a/dart/common/SharedLibrary.hpp b/dart/common/SharedLibrary.hpp index 500041f479723..ecdc1e808fbfe 100644 --- a/dart/common/SharedLibrary.hpp +++ b/dart/common/SharedLibrary.hpp @@ -35,7 +35,10 @@ #include #include + #include + +#include "dart/common/Deprecated.hpp" #include "dart/common/Platform.hpp" #if DART_OS_LINUX @@ -108,9 +111,25 @@ class SharedLibrary /// "/path/../to/yourfile". /// \return Pointer to the created SharedLibrary upon success in loading. /// Otherwise, returns nullptr. + /// \deprecated Deprecated in 6.10. Please use create(const std::string&) + /// instead. + DART_DEPRECATED(6.10) static std::shared_ptr create( const boost::filesystem::path& path); + /// Creates a SharedLibrary from a path to the shared library. + /// + /// \note SharedLibrary should be always created from this create function. + /// \param[in] path The path to the shared library. The path can be a relative + /// path or an absolute path. If the path doens't exist this function returns + /// nullptr. If the path exist, the path will be stored as the canonical path + /// where a canonical path is an absolute path that has no elements which are + /// symbolic links, and no dot or dot dot elements such as + /// "/path/../to/yourfile". + /// \return Pointer to the created SharedLibrary upon success in loading. + /// Otherwise, returns nullptr. + static std::shared_ptr create(const std::string& path); + /// Constructs from a path to the shared library. /// /// This constructor is only called by detail::SharedLibraryManager. @@ -122,15 +141,34 @@ class SharedLibrary /// \param[in] path The canonical path to the shared library. /// \return Pointer to the created SharedLibrary upon success in loading. /// Otherwise, returns nullptr. + /// \deprecated Deprecated in 6.10. Please use + /// SharedLibrary(ProtectedConstructionTag, const std::string&) instead. + DART_DEPRECATED(6.10) explicit SharedLibrary( ProtectedConstructionTag, const boost::filesystem::path& path); + /// Constructs from a path to the shared library. + /// + /// This constructor is only called by detail::SharedLibraryManager. + /// ProtectedConstructionTag is necessary to enforce creating SharedLibrary + /// using std::make_shared. + /// + /// \note Please use create() to contruct SharedLibrary instead of this + /// constructor. + /// \param[in] path The canonical path to the shared library. + /// \return Pointer to the created SharedLibrary upon success in loading. + /// Otherwise, returns nullptr. + explicit SharedLibrary(ProtectedConstructionTag, const std::string& path); + /// Destructor. virtual ~SharedLibrary(); /// Returns the path to the shared library file. const boost::filesystem::path& getCanonicalPath() const; + /// Returns the path to the shared library file. + const std::string& path() const; + /// Returns true if the shared library loading was successful. bool isValid() const; @@ -148,6 +186,12 @@ class SharedLibrary /// path that has no elements which are symbolic links, and no dot or dot dot /// elements such as "/path/../to/yourfile". boost::filesystem::path mCanonicalPath; + // TODO(JS): Remove in DART 7. + + /// Canonical path to the shared library where a canonical path is an absolute + /// path that has no elements which are symbolic links, and no dot or dot dot + /// elements such as "/path/../to/yourfile". + std::string mPath; /// Handle to the loaded library. DYNLIB_HANDLE mInstance; diff --git a/dart/common/detail/SharedLibraryManager.cpp b/dart/common/detail/SharedLibraryManager.cpp index 1a2d4c6abf154..c79a44109f800 100644 --- a/dart/common/detail/SharedLibraryManager.cpp +++ b/dart/common/detail/SharedLibraryManager.cpp @@ -32,6 +32,8 @@ #include "dart/common/detail/SharedLibraryManager.hpp" +#include + #include "dart/common/Console.hpp" #include "dart/common/SharedLibrary.hpp" @@ -42,9 +44,16 @@ namespace detail { //============================================================================== std::shared_ptr SharedLibraryManager::load( const boost::filesystem::path& path) +{ + return load(path.string()); +} + +//============================================================================== +std::shared_ptr SharedLibraryManager::load( + const std::string& path) { // Check if the given path exits - const bool exists = boost::filesystem::exists(path); + const bool exists = std::ifstream(path).good(); if (!exists) { dtwarn << "[SharedLibraryManager::load] Failed to load the shared library '" @@ -53,11 +62,11 @@ std::shared_ptr SharedLibraryManager::load( } // Convert the given path to the canonical path - const auto canonicalPath = boost::filesystem::canonical(path); + const auto canonicalPath = boost::filesystem::canonical(path).string(); - const auto iter = mLibraries.find(canonicalPath); + const auto iter = mSharedLibraries.find(canonicalPath); - const auto found = iter != mLibraries.end(); + const auto found = iter != mSharedLibraries.end(); if (found) { auto lib = iter->second.lock(); @@ -68,7 +77,7 @@ std::shared_ptr SharedLibraryManager::load( if (lib) return lib; else - mLibraries.erase(iter); + mSharedLibraries.erase(iter); } const auto newLib = std::make_shared( @@ -77,7 +86,7 @@ std::shared_ptr SharedLibraryManager::load( if (!newLib->isValid()) return nullptr; - mLibraries[canonicalPath] = newLib; + mSharedLibraries[canonicalPath] = newLib; assert(canonicalPath == newLib->getCanonicalPath()); return newLib; diff --git a/dart/common/detail/SharedLibraryManager.hpp b/dart/common/detail/SharedLibraryManager.hpp index ee0f6216a07ee..5128f1352af6b 100644 --- a/dart/common/detail/SharedLibraryManager.hpp +++ b/dart/common/detail/SharedLibraryManager.hpp @@ -34,12 +34,15 @@ #define DART_COMMON_DETAIL_SHAREDLIBRARYMANAGER_HPP_ #include +#include #include -#include -#include "dart/common/Singleton.hpp" +#include #include +#include "dart/common/Deprecated.hpp" +#include "dart/common/Singleton.hpp" + namespace std { template <> @@ -71,8 +74,21 @@ class SharedLibraryManager final : public Singleton /// Windows). /// \return Pointer to the shared library upon success. Otherwise, returns /// nullptr. + /// \deprecated Deprecated in 6.10. Please use load(const std::string&) + /// instead. + DART_DEPRECATED(6.10) std::shared_ptr load(const boost::filesystem::path& path); + /// Loads the shared library with the specified path. + /// + /// \param[in] path The path to the shared library. If the path doesn't + /// include the extension, this function will use the best guess depending on + /// the OS (e.g., '.so' for Linux, '.dylib' for macOS, and '.dll' for + /// Windows). + /// \return Pointer to the shared library upon success. Otherwise, returns + /// nullptr. + std::shared_ptr load(const std::string& path); + protected: friend class Singleton; @@ -80,6 +96,11 @@ class SharedLibraryManager final : public Singleton /// Map from library path to the library instances. std::unordered_map> mLibraries; + // TODO(JS): Remove this in DART 7. + + /// Map from library path to the library instances. + std::unordered_map> + mSharedLibraries; }; } // namespace detail