Commit e5bbc0f6 authored by Wolfgang Merkt's avatar Wolfgang Merkt
Browse files

Make file-explorer support Windows, add work-around for ROS paths

parent da30d860
Pipeline #15153 passed with stage
in 209 minutes and 39 seconds
......@@ -6,13 +6,18 @@
#include <boost/filesystem.hpp>
#include "pinocchio/utils/file-explorer.hpp"
#ifdef _WIN32
const char delimiter = ';';
#else
const char delimiter = ':';
#endif
namespace fs = boost::filesystem;
namespace pinocchio
{
void extractPathFromEnvVar(const std::string & env_var_name,
std::vector<std::string> & list_of_paths,
const std::string & delimiter)
std::vector<std::string> & list_of_paths)
{
const char * env_var_value = std::getenv(env_var_name.c_str());
......@@ -20,25 +25,13 @@ 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;
std::string path_string;
path_string.reserve(500);
fs::path path;
while(true)
{
size_t offset = policyStr.find_first_of(delimiter, lastOffset);
if (offset < policyStr.size()) {
path_string = policyStr.substr(lastOffset, offset - lastOffset);
path = fs::path(path_string);
list_of_paths.push_back(path_string);
// 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:
if (fs::exists(path / "package.xml")) {
list_of_paths.push_back(fs::path(path / "..").string());
}
}
if (offset < policyStr.size())
list_of_paths.push_back(policyStr.substr(lastOffset, offset - lastOffset));
if (offset == std::string::npos)
break;
else
......@@ -47,20 +40,30 @@ namespace pinocchio
}
}
std::vector<std::string> extractPathFromEnvVar(const std::string & env_var_name,
const std::string & delimiter)
std::vector<std::string> extractPathFromEnvVar(const std::string & env_var_name)
{
std::vector<std::string> list_of_paths;
extractPathFromEnvVar(env_var_name,list_of_paths,delimiter);
extractPathFromEnvVar(env_var_name,list_of_paths);
return list_of_paths;
}
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 (const auto& path_string : raw_list_of_paths) {
list_of_paths.push_back(path_string);
path = fs::path(path_string);
if (fs::exists(path / "package.xml")) {
list_of_paths.push_back(fs::path(path / "..").string());
}
}
return list_of_paths;
}
......
......@@ -17,13 +17,11 @@ namespace pinocchio
* @brief Parse an environment variable if exists and extract paths according to the delimiter.
*
* @param[in] env_var_name The name of the environment variable.
* @param[in] delimiter The delimiter between two consecutive paths.
*
* @return The vector of paths extracted from the environment variable value.
*/
PINOCCHIO_DLLAPI std::vector<std::string>
extractPathFromEnvVar(const std::string & env_var_name,
const std::string & delimiter = ":");
extractPathFromEnvVar(const std::string & env_var_name);
/**
......@@ -31,12 +29,10 @@ 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.
*/
PINOCCHIO_DLLAPI void
extractPathFromEnvVar(const std::string & env_var_name,
std::vector<std::string> & list_of_paths,
const std::string & delimiter = ":");
std::vector<std::string> & list_of_paths);
/**
......
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