diff --git a/pluginlib/CMakeLists.txt b/pluginlib/CMakeLists.txt index ac9e0bed..0689ac7c 100644 --- a/pluginlib/CMakeLists.txt +++ b/pluginlib/CMakeLists.txt @@ -27,34 +27,6 @@ ament_export_dependencies(ament_index_cpp class_loader rcutils rcpputils tinyxml ament_export_include_directories(include) ament_export_targets(${PROJECT_NAME}) -if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+") - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0) - # Before LLVM 7.0, filesystem is part of experimental - set(FILESYSTEM_LIB c++experimental) - elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) - # Before LLVM 9.0 you have to manually link the fs library - set(FILESYSTEM_LIB c++fs) - else() - # Starting at LLVM 9.0 filesystem is built in - set(FILESYSTEM_LIB) - endif() -elseif(CMAKE_CXX_COMPILER_ID MATCHES "QCC") - if(CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+") - set(FILESYSTEM_LIB c++fs) - else() - set(FILESYSTEM_LIB) - endif() -else() - set(FILESYSTEM_LIB stdc++fs) -endif() - -if(UNIX AND NOT APPLE) - # this is needed to use the experimental/filesystem on Linux, but cannot be passed with - # ament_export_libraries() because it is not absolute and cannot be found with find_library - target_link_libraries(${PROJECT_NAME} - INTERFACE ${FILESYSTEM_LIB}) -endif() - install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} ) @@ -72,23 +44,6 @@ install( if(BUILD_TESTING) find_package(ament_cmake_gtest REQUIRED) - # NOTE this block is also defined in pluginlib-extras.cmake - # changes here need to be duplicated there - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+") - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0) - # Before LLVM 7.0, filesystem is part of experimental - set(FILESYSTEM_LIB c++experimental) - elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) - # Before LLVM 9.0 you have to manually link the fs library - set(FILESYSTEM_LIB c++fs) - else() - # Starting at LLVM 9.0 filesystem is built in - set(FILESYSTEM_LIB) - endif() - else() - set(FILESYSTEM_LIB stdc++fs) - endif() - include_directories(include test/include) add_library(test_plugins SHARED ./test/test_plugins.cpp) @@ -124,9 +79,6 @@ if(BUILD_TESTING) TinyXML2 ) - if(UNIX AND NOT APPLE) - target_link_libraries(${PROJECT_NAME}_unique_ptr_test ${FILESYSTEM_LIB}) - endif() add_dependencies(${PROJECT_NAME}_unique_ptr_test "${mock_install_target}") endif() @@ -144,9 +96,6 @@ if(BUILD_TESTING) TinyXML2 ) - if(UNIX AND NOT APPLE) - target_link_libraries(${PROJECT_NAME}_utest ${FILESYSTEM_LIB}) - endif() add_dependencies(${PROJECT_NAME}_utest "${mock_install_target}") endif() diff --git a/pluginlib/include/pluginlib/class_loader_imp.hpp b/pluginlib/include/pluginlib/class_loader_imp.hpp index 61017417..a3bf34e9 100644 --- a/pluginlib/include/pluginlib/class_loader_imp.hpp +++ b/pluginlib/include/pluginlib/class_loader_imp.hpp @@ -68,11 +68,11 @@ #include "ament_index_cpp/get_resource.hpp" #include "ament_index_cpp/get_resources.hpp" #include "class_loader/class_loader.hpp" +#include "rcpputils/filesystem_helper.hpp" #include "rcpputils/shared_library.hpp" #include "rcutils/logging_macros.h" #include "./class_loader.hpp" -#include "./impl/filesystem_helper.hpp" #include "./impl/split.hpp" #ifdef _WIN32 @@ -510,7 +510,7 @@ std::string ClassLoader::getClassLibraryPath(const std::string & lookup_name) library_name.c_str()); for (auto it = paths_to_try.begin(); it != paths_to_try.end(); it++) { RCUTILS_LOG_DEBUG_NAMED("pluginlib.ClassLoader", "Checking path %s ", it->c_str()); - if (pluginlib::impl::fs::exists(*it)) { + if (rcpputils::fs::exists(*it)) { RCUTILS_LOG_DEBUG_NAMED("pluginlib.ClassLoader", "Library %s found at explicit path %s.", library_name.c_str(), it->c_str()); return *it; @@ -587,12 +587,12 @@ ClassLoader::getPackageFromPluginXMLFilePath(const std::string & plugin_xml_f // 2. Extract name of package from package.xml std::string package_name; - pluginlib::impl::fs::path p(plugin_xml_file_path); - pluginlib::impl::fs::path parent = p.parent_path(); + rcpputils::fs::path p(plugin_xml_file_path); + rcpputils::fs::path parent = p.parent_path(); // Figure out exactly which package the passed XML file is exported by. while (true) { - if (pluginlib::impl::fs::exists(parent / "package.xml")) { + if (rcpputils::fs::exists(parent / "package.xml")) { std::string package_file_path = (parent / "package.xml").string(); return extractPackageNameFromPackageXML(package_file_path); } @@ -613,7 +613,7 @@ template std::string ClassLoader::getPathSeparator() /***************************************************************************/ { - return std::string(1, pluginlib::impl::fs::path::preferred_separator); + return std::string(1, rcpputils::fs::kPreferredSeparator); } @@ -647,7 +647,7 @@ template std::string ClassLoader::joinPaths(const std::string & path1, const std::string & path2) /***************************************************************************/ { - pluginlib::impl::fs::path p1(path1); + rcpputils::fs::path p1(path1); return (p1 / path2).string(); } diff --git a/pluginlib/include/pluginlib/impl/filesystem_helper.hpp b/pluginlib/include/pluginlib/impl/filesystem_helper.hpp deleted file mode 100644 index de16133c..00000000 --- a/pluginlib/include/pluginlib/impl/filesystem_helper.hpp +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 2017, Open Source Robotics Foundation, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of the Willow Garage, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * 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 OWNER 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. - */ - -/// Includes std::filesystem and aliases the namespace to `pluginlib::impl::fs`. -/** - * If std::filesystem is not available the necessary functions are emulated. - */ - -#ifndef PLUGINLIB__IMPL__FILESYSTEM_HELPER_HPP_ -#define PLUGINLIB__IMPL__FILESYSTEM_HELPER_HPP_ - - -#if defined(__has_include) -# if __has_include() && __cplusplus >= 201703L -# include - -namespace pluginlib -{ -namespace impl -{ -namespace fs = std::filesystem; -} // namespace impl -} // namespace pluginlib - -# define PLUGINLIB__IMPL__FILESYSYEM_HELPER__HAS_STD_FILESYSTEM -# elif __has_include() -// MSVC deprecates and in favor of -// use this macro to acknowledge this deprecation and unblock the build break -# define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING -// Clang 9.0 deprecates experimental/filesystem in favor of C++17's -// std::filesystem. Since pluginlib currently targets C++14 but needs to -// support recent clang releases this acknowledges and suppresses the -// deprecation error. -# define _LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_FILESYSTEM -# include - -namespace pluginlib -{ -namespace impl -{ -namespace fs = std::experimental::filesystem; -} // namespace impl -} // namespace pluginlib - -# define PLUGINLIB__IMPL__FILESYSYEM_HELPER__HAS_STD_FILESYSTEM -# endif -#endif - -// The standard library does not provide it, so emulate it. -#ifndef PLUGINLIB__IMPL__FILESYSYEM_HELPER__HAS_STD_FILESYSTEM - -#include -#include - -#ifdef _WIN32 -#define CLASS_LOADER_IMPL_OS_DIRSEP '\\' -#else -#define CLASS_LOADER_IMPL_OS_DIRSEP '/' -#endif - -#ifdef _WIN32 - #include - #define access _access_s -#else - #include -#endif - -#include "./split.hpp" - -namespace pluginlib -{ -namespace impl -{ -namespace fs -{ - -class path -{ -public: - static constexpr char preferred_separator = CLASS_LOADER_IMPL_OS_DIRSEP; - - path() - : path("") - {} - - path(const std::string & p) // NOLINT(runtime/explicit): this is a conversion constructor - : path_(p), path_as_vector_(split(p, std::string(1, preferred_separator))) - {} - - std::string string() const - { - return path_; - } - - bool exists() const - { - return access(path_.c_str(), 0) == 0; - } - - std::vector::const_iterator cbegin() const - { - return path_as_vector_.cbegin(); - } - - std::vector::const_iterator cend() const - { - return path_as_vector_.cend(); - } - - path parent_path() const - { - path parent(""); - for (auto it = this->cbegin(); it != --this->cend(); ++it) { - parent /= *it; - } - return parent; - } - - path filename() const - { - return path_.empty() ? path() : *--this->cend(); - } - - path operator/(const std::string & other) - { - return this->operator/(path(other)); - } - - path & operator/=(const std::string & other) - { - this->operator/=(path(other)); - return *this; - } - - path operator/(const path & other) - { - return path(*this).operator/=(other); - } - - path & operator/=(const path & other) - { - this->path_ += CLASS_LOADER_IMPL_OS_DIRSEP + other.string(); - this->path_as_vector_.insert( - std::end(this->path_as_vector_), - std::begin(other.path_as_vector_), std::end(other.path_as_vector_)); - return *this; - } - -private: - std::string path_; - std::vector path_as_vector_; -}; - -inline bool exists(const path & path_to_check) -{ - return path_to_check.exists(); -} - -#undef CLASS_LOADER_IMPL_OS_DIRSEP - -} // namespace fs -} // namespace impl -} // namespace pluginlib - -#endif // PLUGINLIB__IMPL__FILESYSYEM_HELPER__HAS_STD_FILESYSTEM - -#undef PLUGINLIB__IMPL__FILESYSYEM_HELPER__HAS_STD_FILESYSTEM - -#endif // PLUGINLIB__IMPL__FILESYSTEM_HELPER_HPP_ diff --git a/pluginlib/pluginlib-extras.cmake b/pluginlib/pluginlib-extras.cmake index 52a733d5..bf79dfed 100644 --- a/pluginlib/pluginlib-extras.cmake +++ b/pluginlib/pluginlib-extras.cmake @@ -20,24 +20,3 @@ ament_register_extension("ament_package" "pluginlib" include("${pluginlib_DIR}/pluginlib_export_plugin_description_file.cmake") include("${pluginlib_DIR}/pluginlib_enable_plugin_testing.cmake") - -if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+") - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0) - # Before LLVM 7.0, filesystem is part of experimental - set(FILESYSTEM_LIB c++experimental) - elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) - # Before LLVM 9.0 you have to manually link the fs library - set(FILESYSTEM_LIB c++fs) - else() - # Starting at LLVM 9.0 filesystem is built in - set(FILESYSTEM_LIB) - endif() -else() - set(FILESYSTEM_LIB stdc++fs) -endif() - -if(UNIX AND NOT APPLE) - # this is needed to use the experimental/filesystem on Linux, but cannot be passed with - # ament_export_libraries() because it is not absolute and cannot be found with find_library - list(APPEND pluginlib_LIBRARIES ${FILESYSTEM_LIB}) -endif()