Skip to content

Commit

Permalink
Squashed commit of the following: (#47)
Browse files Browse the repository at this point in the history
commit e8b0dd3
Author: Eric Cousineau <[email protected]>
Date:   Mon Oct 7 13:28:05 2019 -0400

    Forgot to update cpp package

    Signed-off-by: Eric Cousineau <[email protected]>

commit 2c29cb2
Author: Eric Cousineau <[email protected]>
Date:   Wed Sep 25 16:40:50 2019 -0400

    Address review

    Signed-off-by: Eric Cousineau <[email protected]>

commit e5d7f0c
Merge: 814b0a8 38eb801
Author: Eric Cousineau <[email protected]>
Date:   Wed Sep 25 16:39:52 2019 -0400

    Merge remote-tracking branch 'upstream/master' into issue/rcpputils_3

    Signed-off-by: Eric Cousineau <[email protected]>

commit 814b0a8
Author: Eric Cousineau <[email protected]>
Date:   Mon Mar 25 17:08:35 2019 -0400

    Add `rcpputils` for `find_library`

    Signed-off-by: Eric Cousineau <[email protected]>

Signed-off-by: Dirk Thomas <[email protected]>

Co-authored-by: Dirk Thomas <[email protected]>
  • Loading branch information
EricCousineau-TRI and dirk-thomas authored Feb 1, 2020
1 parent 1769ba8 commit cf99ca8
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 195 deletions.
3 changes: 2 additions & 1 deletion rosidl_typesupport_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ find_package(ament_cmake_ros REQUIRED)
# provides FindPoco.cmake and Poco on platforms without it
find_package(poco_vendor)
find_package(Poco COMPONENTS Foundation)
find_package(rcpputils REQUIRED)
find_package(rosidl_generator_c REQUIRED)

link_directories(${Poco_LIBRARY_DIR})
Expand Down Expand Up @@ -50,7 +51,7 @@ target_include_directories(${PROJECT_NAME}
if(Poco_FOUND)
ament_target_dependencies(${PROJECT_NAME} "Poco")
endif()
ament_target_dependencies(${PROJECT_NAME} "rosidl_generator_c")
ament_target_dependencies(${PROJECT_NAME} "rcpputils" "rosidl_generator_c")
ament_export_libraries(${PROJECT_NAME})

ament_index_register_resource("rosidl_runtime_packages")
Expand Down
1 change: 1 addition & 0 deletions rosidl_typesupport_c/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<buildtool_depend>ament_cmake_ros</buildtool_depend>

<depend>rcpputils</depend>
<build_depend>libpoco-dev</build_depend>
<build_depend>poco_vendor</build_depend>
<build_depend>rosidl_generator_c</build_depend>
Expand Down
87 changes: 0 additions & 87 deletions rosidl_typesupport_c/src/type_support_dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,90 +13,3 @@
// limitations under the License.

#include "type_support_dispatch.hpp"

#include <list>
#include <string>

#include <fstream>
#include <sstream>

namespace rosidl_typesupport_c
{

std::string find_library_path(const std::string & library_name)
{
const char * env_var;
char separator;
const char * filename_prefix;
const char * filename_extension;
#ifdef _WIN32
env_var = "PATH";
separator = ';';
filename_prefix = "";
filename_extension = ".dll";
#elif __APPLE__
env_var = "DYLD_LIBRARY_PATH";
separator = ':';
filename_prefix = "lib";
filename_extension = ".dylib";
#else
env_var = "LD_LIBRARY_PATH";
separator = ':';
filename_prefix = "lib";
filename_extension = ".so";
#endif
std::string search_path = get_env_var(env_var);
std::list<std::string> search_paths = split(search_path, separator);

std::string filename = filename_prefix;
filename += library_name + filename_extension;

for (auto it : search_paths) {
std::string path = it + "/" + filename;
if (is_file_exist(path.c_str())) {
return path;
}
}
return "";
}

std::string get_env_var(const char * env_var)
{
char * value = nullptr;
#ifndef _WIN32
value = getenv(env_var);
#else
size_t value_size;
_dupenv_s(&value, &value_size, env_var);
#endif
std::string value_str = "";
if (value) {
value_str = value;
#ifdef _WIN32
free(value);
#endif
}
// printf("get_env_var(%s) = %s\n", env_var, value_str.c_str());
return value_str;
}

std::list<std::string> split(const std::string & value, const char delimiter)
{
std::list<std::string> list;
std::istringstream ss(value);
std::string s;
while (std::getline(ss, s, delimiter)) {
list.push_back(s);
}
// printf("split(%s) = %zu\n", value.c_str(), list.size());
return list;
}

bool is_file_exist(const char * filename)
{
std::ifstream h(filename);
// printf("is_file_exist(%s) = %s\n", filename, h.good() ? "true" : "false");
return h.good();
}

} // namespace rosidl_typesupport_c
11 changes: 2 additions & 9 deletions rosidl_typesupport_c/src/type_support_dispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,13 @@
#include "Poco/SharedLibrary.h"
#endif

#include "rcpputils/find_library.hpp"
#include "rosidl_typesupport_c/identifier.h"
#include "rosidl_typesupport_c/type_support_map.h"

namespace rosidl_typesupport_c
{

std::string find_library_path(const std::string & library_name);

std::string get_env_var(const char * env_var);

std::list<std::string> split(const std::string & value, const char delimiter);

bool is_file_exist(const char * filename);

extern const char * typesupport_identifier;

template<typename TypeSupport>
Expand All @@ -65,7 +58,7 @@ get_typesupport_handle_function(
snprintf(
library_name, 1023, "%s__%s",
map->package_name, identifier);
std::string library_path = find_library_path(library_name);
std::string library_path = rcpputils::find_library_path(library_name);
if (library_path.empty()) {
fprintf(stderr, "Failed to find library '%s'\n", library_name);
return nullptr;
Expand Down
3 changes: 2 additions & 1 deletion rosidl_typesupport_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ find_package(ament_cmake_ros REQUIRED)
# provides FindPoco.cmake and Poco on platforms without it
find_package(poco_vendor)
find_package(Poco COMPONENTS Foundation)
find_package(rcpputils REQUIRED)
find_package(rosidl_generator_c REQUIRED)

link_directories(${Poco_LIBRARY_DIR})
Expand Down Expand Up @@ -47,7 +48,7 @@ target_include_directories(${PROJECT_NAME}
if(Poco_FOUND)
ament_target_dependencies(${PROJECT_NAME} "Poco")
endif()
ament_target_dependencies(${PROJECT_NAME} "rosidl_generator_c")
ament_target_dependencies(${PROJECT_NAME} "rcpputils" "rosidl_generator_c")
ament_export_libraries(${PROJECT_NAME})

ament_index_register_resource("rosidl_runtime_packages")
Expand Down
1 change: 1 addition & 0 deletions rosidl_typesupport_cpp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<buildtool_depend>ament_cmake_ros</buildtool_depend>

<depend>rcpputils</depend>
<build_depend>libpoco-dev</build_depend>
<build_depend>poco_vendor</build_depend>
<build_depend>rosidl_generator_c</build_depend>
Expand Down
87 changes: 0 additions & 87 deletions rosidl_typesupport_cpp/src/type_support_dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,90 +13,3 @@
// limitations under the License.

#include "type_support_dispatch.hpp"

#include <list>
#include <string>

#include <fstream>
#include <sstream>

namespace rosidl_typesupport_cpp
{

std::string find_library_path(const std::string & library_name)
{
const char * env_var;
char separator;
const char * filename_prefix;
const char * filename_extension;
#ifdef _WIN32
env_var = "PATH";
separator = ';';
filename_prefix = "";
filename_extension = ".dll";
#elif __APPLE__
env_var = "DYLD_LIBRARY_PATH";
separator = ':';
filename_prefix = "lib";
filename_extension = ".dylib";
#else
env_var = "LD_LIBRARY_PATH";
separator = ':';
filename_prefix = "lib";
filename_extension = ".so";
#endif
std::string search_path = get_env_var(env_var);
std::list<std::string> search_paths = split(search_path, separator);

std::string filename = filename_prefix;
filename += library_name + filename_extension;

for (auto it : search_paths) {
std::string path = it + "/" + filename;
if (is_file_exist(path.c_str())) {
return path;
}
}
return "";
}

std::string get_env_var(const char * env_var)
{
char * value = nullptr;
#ifndef _WIN32
value = getenv(env_var);
#else
size_t value_size;
_dupenv_s(&value, &value_size, env_var);
#endif
std::string value_str = "";
if (value) {
value_str = value;
#ifdef _WIN32
free(value);
#endif
}
// printf("get_env_var(%s) = %s\n", env_var, value_str.c_str());
return value_str;
}

std::list<std::string> split(const std::string & value, const char delimiter)
{
std::list<std::string> list;
std::istringstream ss(value);
std::string s;
while (std::getline(ss, s, delimiter)) {
list.push_back(s);
}
// printf("split(%s) = %zu\n", value.c_str(), list.size());
return list;
}

bool is_file_exist(const char * filename)
{
std::ifstream h(filename);
// printf("is_file_exist(%s) = %s\n", filename, h.good() ? "true" : "false");
return h.good();
}

} // namespace rosidl_typesupport_cpp
12 changes: 2 additions & 10 deletions rosidl_typesupport_cpp/src/type_support_dispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,18 @@
#include <cstdio>
#include <cstring>

#include <list>
#include <string>

#ifdef ROSIDL_TYPESUPPORT_CPP_USE_POCO
#include "Poco/SharedLibrary.h"
#endif

#include "rcpputils/find_library.hpp"
#include "rosidl_typesupport_cpp/type_support_map.h"

namespace rosidl_typesupport_cpp
{

std::string find_library_path(const std::string & library_name);

std::string get_env_var(const char * env_var);

std::list<std::string> split(const std::string & value, const char delimiter);

bool is_file_exist(const char * filename);

extern const char * typesupport_identifier;

template<typename TypeSupport>
Expand All @@ -64,7 +56,7 @@ get_typesupport_handle_function(
snprintf(
library_name, 1023, "%s__%s",
map->package_name, identifier);
std::string library_path = find_library_path(library_name);
std::string library_path = rcpputils::find_library_path(library_name);
if (library_path.empty()) {
fprintf(stderr, "Failed to find library '%s'\n", library_name);
return nullptr;
Expand Down

0 comments on commit cf99ca8

Please sign in to comment.