From 49b7b0e9a1869966f4b97e6b098dda7df97a408b Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Fri, 14 Jan 2022 07:09:01 -0800 Subject: [PATCH] Remove use of boost::filesystem --- dart/CMakeLists.txt | 5 + dart/common/Filesystem.hpp | 109 ++++++++++++++++++++ dart/common/Optional.hpp | 3 - dart/common/SharedLibrary.cpp | 6 +- dart/common/SharedLibrary.hpp | 12 +-- dart/common/detail/SharedLibraryManager.cpp | 4 +- dart/common/detail/SharedLibraryManager.hpp | 14 ++- dart/gui/osg/render/MeshShapeNode.cpp | 15 ++- dart/utils/mjcf/detail/Compiler.cpp | 2 - 9 files changed, 138 insertions(+), 32 deletions(-) create mode 100644 dart/common/Filesystem.hpp diff --git a/dart/CMakeLists.txt b/dart/CMakeLists.txt index 87ee87891077f..8c7ecda232a76 100644 --- a/dart/CMakeLists.txt +++ b/dart/CMakeLists.txt @@ -158,7 +158,12 @@ endif() if(TARGET octomap) target_link_libraries(dart PUBLIC octomap) endif() + +# C++ standard settings target_compile_features(dart PUBLIC cxx_std_17) +if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) + target_link_libraries(dart PUBLIC "stdc++fs") +endif() # Build DART with all available SIMD instructions if(DART_ENABLE_SIMD) diff --git a/dart/common/Filesystem.hpp b/dart/common/Filesystem.hpp new file mode 100644 index 0000000000000..e04acb2d7647e --- /dev/null +++ b/dart/common/Filesystem.hpp @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2011-2021, The DART development contributors: + * https://github.com/dartsim/dart/blob/main/LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "dart/common/Platform.hpp" + +#if !defined(DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL) + + // Check for feature test macro for + #if defined(__cpp_lib_filesystem) + #define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 + + // Check for feature test macro for + #elif defined(__cpp_lib_experimental_filesystem) + #define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 + + // We can't check if headers exist... + // Let's assume experimental to be safe + #elif !defined(__has_include) + #define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 + + // Check if the header "" exists + #elif __has_include() + + // If we're compiling on Visual Studio and are not compiling with C++17, we + // need to use experimental + #ifdef _MSC_VER + + // Check and include header that defines "_HAS_CXX17" + #if __has_include() + #include + + // Check for enabled C++17 support + #if defined(_HAS_CXX17) && _HAS_CXX17 + // We're using C++17, so let's use the normal version + #define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 + #endif + #endif + + // If the marco isn't defined yet, that means any of the other VS specific + // checks failed, so we need to use experimental + #ifndef DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL + #define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 + #endif + + // Not on Visual Studio. Let's use the normal version + #else // #ifdef _MSC_VER + #define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 + #endif + + // Check if the header "" exists + #elif __has_include() + #define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 + + // Fail if neither header is available with a nice error message + #else + #error Could not find system header "" or "" + #endif + + // We priously determined that we need the exprimental version + #if DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL + // Include it + #include + +namespace dart::common { + +namespace filesystem = ::std::experimental::filesystem; +using error_code = ::std::error_code; + +} // namespace dart::common + + // We have a decent compiler and can use the normal version + #else + // Include it + #include + +namespace dart::common { +namespace filesystem = ::std::filesystem; +using error_code = ::std::error_code; +} // namespace dart::common + + #endif + +#endif // #ifndef DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL diff --git a/dart/common/Optional.hpp b/dart/common/Optional.hpp index ad59949b2044e..758dfb296d5c0 100644 --- a/dart/common/Optional.hpp +++ b/dart/common/Optional.hpp @@ -35,14 +35,11 @@ #include -#include "dart/common/Deprecated.hpp" - namespace dart { namespace common { /// \deprecated Use std::optional instead template -DART_DEPRECATED(6.13) using optional = std::optional; } // namespace common diff --git a/dart/common/SharedLibrary.cpp b/dart/common/SharedLibrary.cpp index 53673b431e353..9b14741c58bb9 100644 --- a/dart/common/SharedLibrary.cpp +++ b/dart/common/SharedLibrary.cpp @@ -57,7 +57,7 @@ namespace common { //============================================================================== std::shared_ptr SharedLibrary::create( - const boost::filesystem::path& path) + const common::filesystem::path& path) { return create(path.string()); } @@ -70,7 +70,7 @@ std::shared_ptr SharedLibrary::create(const std::string& path) //============================================================================== SharedLibrary::SharedLibrary( - ProtectedConstructionTag, const boost::filesystem::path& canonicalPath) + ProtectedConstructionTag, const common::filesystem::path& canonicalPath) : SharedLibrary(ProtectedConstruction, canonicalPath.string()) { // Do nothing @@ -104,7 +104,7 @@ SharedLibrary::~SharedLibrary() } //============================================================================== -const boost::filesystem::path& SharedLibrary::getCanonicalPath() const +const common::filesystem::path& SharedLibrary::getCanonicalPath() const { return mCanonicalPath; } diff --git a/dart/common/SharedLibrary.hpp b/dart/common/SharedLibrary.hpp index 93dfc1cf5ff9d..8137061575c27 100644 --- a/dart/common/SharedLibrary.hpp +++ b/dart/common/SharedLibrary.hpp @@ -36,9 +36,8 @@ #include #include -#include - #include "dart/common/Deprecated.hpp" +#include "dart/common/Filesystem.hpp" #include "dart/common/Platform.hpp" #if DART_OS_LINUX @@ -115,7 +114,7 @@ class SharedLibrary /// instead. DART_DEPRECATED(6.10) static std::shared_ptr create( - const boost::filesystem::path& path); + const common::filesystem::path& path); /// Creates a SharedLibrary from a path to the shared library. /// @@ -145,7 +144,7 @@ class SharedLibrary /// SharedLibrary(ProtectedConstructionTag, const std::string&) instead. DART_DEPRECATED(6.10) explicit SharedLibrary( - ProtectedConstructionTag, const boost::filesystem::path& path); + ProtectedConstructionTag, const common::filesystem::path& path); /// Constructs from a path to the shared library. /// @@ -164,7 +163,7 @@ class SharedLibrary virtual ~SharedLibrary(); /// Returns the path to the shared library file. - const boost::filesystem::path& getCanonicalPath() const; + const common::filesystem::path& getCanonicalPath() const; /// Returns the path to the shared library file. const std::string& path() const; @@ -185,7 +184,8 @@ class SharedLibrary /// 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". - boost::filesystem::path mCanonicalPath; + /// \deprecated Use mCanonicalPath2 instead. + common::filesystem::path mCanonicalPath; // TODO(JS): Remove in DART 7. /// Canonical path to the shared library where a canonical path is an absolute diff --git a/dart/common/detail/SharedLibraryManager.cpp b/dart/common/detail/SharedLibraryManager.cpp index 96358e9da29f5..c10e7dfb572aa 100644 --- a/dart/common/detail/SharedLibraryManager.cpp +++ b/dart/common/detail/SharedLibraryManager.cpp @@ -43,7 +43,7 @@ namespace detail { //============================================================================== std::shared_ptr SharedLibraryManager::load( - const boost::filesystem::path& path) + const common::filesystem::path& path) { return load(path.string()); } @@ -62,7 +62,7 @@ std::shared_ptr SharedLibraryManager::load( } // Convert the given path to the canonical path - const auto canonicalPath = boost::filesystem::canonical(path).string(); + const auto canonicalPath = common::filesystem::canonical(path).string(); const auto iter = mSharedLibraries.find(canonicalPath); diff --git a/dart/common/detail/SharedLibraryManager.hpp b/dart/common/detail/SharedLibraryManager.hpp index bf17aa168d1fd..2f9cf836e98d9 100644 --- a/dart/common/detail/SharedLibraryManager.hpp +++ b/dart/common/detail/SharedLibraryManager.hpp @@ -37,20 +37,18 @@ #include #include -#include -#include - #include "dart/common/Deprecated.hpp" +#include "dart/common/Filesystem.hpp" #include "dart/common/Singleton.hpp" namespace std { template <> -struct hash +struct hash<::dart::common::filesystem::path> { - size_t operator()(const boost::filesystem::path& p) const + size_t operator()(const ::dart::common::filesystem::path& p) const { - return boost::filesystem::hash_value(p); + return ::dart::common::filesystem::hash_value(p); } }; @@ -77,7 +75,7 @@ class SharedLibraryManager final : public Singleton /// \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); + std::shared_ptr load(const common::filesystem::path& path); /// Loads the shared library with the specified path. /// @@ -94,7 +92,7 @@ class SharedLibraryManager final : public Singleton protected: /// Map from library path to the library instances. - std::unordered_map> + std::unordered_map> mLibraries; // TODO(JS): Remove this in DART 7. diff --git a/dart/gui/osg/render/MeshShapeNode.cpp b/dart/gui/osg/render/MeshShapeNode.cpp index b3c082b22d933..a5537ef4725c1 100644 --- a/dart/gui/osg/render/MeshShapeNode.cpp +++ b/dart/gui/osg/render/MeshShapeNode.cpp @@ -34,7 +34,6 @@ #include -#include #include #include #include @@ -43,6 +42,7 @@ #include #include "dart/common/Console.hpp" +#include "dart/common/Filesystem.hpp" #include "dart/dynamics/MeshShape.hpp" #include "dart/dynamics/SimpleFrame.hpp" #include "dart/gui/osg/Utils.hpp" @@ -228,8 +228,6 @@ bool checkSpecularSanity(const aiColor4D& c) //============================================================================== void MeshShapeNode::extractData(bool firstTime) { - namespace bf = boost::filesystem; - const aiScene* scene = mMeshShape->getMesh(); const aiNode* root = scene->mRootNode; @@ -302,7 +300,7 @@ void MeshShapeNode::extractData(bool firstTime) textureImageArray.reserve(count); aiString imagePath; - boost::system::error_code ec; + std::error_code ec; for (auto j = 0u; j < count; ++j) { if ((textureTypeAndCount.first == aiTextureType_NONE) @@ -313,10 +311,11 @@ void MeshShapeNode::extractData(bool firstTime) else { aiMat->GetTexture(type, j, &imagePath); - const bf::path meshPath = mMeshShape->getMeshPath(); - const bf::path relativeImagePath = imagePath.C_Str(); - const bf::path absoluteImagePath - = bf::canonical(relativeImagePath, meshPath.parent_path(), ec); + const common::filesystem::path meshPath = mMeshShape->getMeshPath(); + const common::filesystem::path relativeImagePath = imagePath.C_Str(); + const common::filesystem::path absoluteImagePath + = common::filesystem::canonical( + relativeImagePath, meshPath.parent_path(), ec); if (ec) { diff --git a/dart/utils/mjcf/detail/Compiler.cpp b/dart/utils/mjcf/detail/Compiler.cpp index 2ad25807b4c50..c699d6898d32a 100644 --- a/dart/utils/mjcf/detail/Compiler.cpp +++ b/dart/utils/mjcf/detail/Compiler.cpp @@ -32,8 +32,6 @@ #include "dart/utils/mjcf/detail/Compiler.hpp" -#include - #include "dart/utils/XmlHelpers.hpp" namespace dart {