Unverified Commit 6f977ef6 authored by Justin Carpentier's avatar Justin Carpentier Committed by GitHub
Browse files

Merge pull request #1467 from wxmerkt/topic/support-for-ros-devel-spaces

Work-around for finding meshes of URDFs in ROS devel spaces #1463
parents 276e41e7 12d25a7a
Pipeline #15163 passed with stage
in 152 minutes and 57 seconds
<?xml version="1.0"?>
<package format="3">
<name>pinocchio</name>
<version>2.6.1</version>
<version>2.6.3</version>
<description>A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives.</description>
<!-- The maintainer listed here is for the ROS release to receive emails for the buildfarm.
Please check the repository URL for full list of authors and maintainers. -->
......
......@@ -3,8 +3,10 @@
//
#include <cstdlib>
#include <boost/filesystem.hpp>
#include "pinocchio/utils/file-explorer.hpp"
namespace fs = boost::filesystem;
namespace pinocchio
{
......@@ -18,9 +20,8 @@ namespace pinocchio
{
std::string policyStr(env_var_value);
// Add a separator at the end so that last path is also retrieved
policyStr += std::string(":");
policyStr += delimiter;
size_t lastOffset = 0;
while(true)
{
size_t offset = policyStr.find_first_of(delimiter, lastOffset);
......@@ -44,10 +45,21 @@ namespace pinocchio
std::vector<std::string> rosPaths()
{
std::vector<std::string> raw_list_of_paths;
extractPathFromEnvVar("ROS_PACKAGE_PATH", raw_list_of_paths);
extractPathFromEnvVar("AMENT_PREFIX_PATH", raw_list_of_paths);
// Work-around for https://github.com/stack-of-tasks/pinocchio/issues/1463
// To support ROS devel/isolated spaces, we also need to look one package above the package.xml:
fs::path path;
std::vector<std::string> list_of_paths;
extractPathFromEnvVar("ROS_PACKAGE_PATH",list_of_paths);
extractPathFromEnvVar("AMENT_PREFIX_PATH",list_of_paths);
for (std::vector<std::string>::iterator it = raw_list_of_paths.begin(); it != raw_list_of_paths.end(); ++it) {
list_of_paths.push_back(*it);
path = fs::path(*it);
if (fs::exists(path / "package.xml")) {
list_of_paths.push_back(fs::path(path / "..").string());
}
}
return list_of_paths;
}
......
......@@ -23,7 +23,12 @@ namespace pinocchio
*/
PINOCCHIO_DLLAPI std::vector<std::string>
extractPathFromEnvVar(const std::string & env_var_name,
const std::string & delimiter = ":");
#ifdef _WIN32
const std::string & delimiter = ";"
#else
const std::string & delimiter = ":"
#endif
);
/**
......@@ -31,18 +36,23 @@ namespace pinocchio
*
* @param[in] env_var_name The name of the environment variable.
* @param[out] list_of_paths List of path to fill with the paths extracted from the environment variable value.
* @param[in] delimiter The delimiter between two consecutive paths.
* @param[in] delimiter The delimiter between two consecutive paths.
*/
PINOCCHIO_DLLAPI void
extractPathFromEnvVar(const std::string & env_var_name,
std::vector<std::string> & list_of_paths,
const std::string & delimiter = ":");
#ifdef _WIN32
const std::string & delimiter = ";"
#else
const std::string & delimiter = ":"
#endif
);
/**
* @brief Parse the environment variable ROS_PACKAGE_PATH and extract paths
* @brief Parse the environment variables ROS_PACKAGE_PATH / AMENT_PREFIX_PATH and extract paths
*
* @return The vector of paths extracted from the environment variable ROS_PACKAGE_PATH
* @return The vector of paths extracted from the environment variables ROS_PACKAGE_PATH / AMENT_PREFIX_PATH
*/
PINOCCHIO_DLLAPI std::vector<std::string> rosPaths();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment