11 #include <boost/filesystem.hpp> 12 #include <boost/tokenizer.hpp> 14 #include <sys/types.h> 20 static std::map<std::string, std::string>
g_cache;
26 namespace fs = boost::filesystem;
33 std::vector<std::string> sp;
35 g_pack.
crawl(sp,
false);
38 char* env_cmake = getenv(
"CMAKE_PREFIX_PATH");
41 std::string cmakePath = env_cmake;
42 boost::char_separator<char> sep(
":");
43 boost::tokenizer<boost::char_separator<char>> tok(cmakePath, sep);
48 if(!fs::exists(path /
".catkin"))
52 g_catkin_workspaces.push_back(path.string());
62 auto it = g_cache.find(package);
63 if(it == g_cache.end())
66 if(!g_pack.
find(package, path))
69 g_cache[package] = path;
81 for(fs::recursive_directory_iterator it(path); it != fs::recursive_directory_iterator(); ++it)
83 if(it->path().filename() == name
84 && fs::is_regular_file(it->path())
85 && access(it->path().c_str(), X_OK) == 0)
87 return it->path().string();
94 static std::string
_getExecutable(
const std::string& package,
const std::string& name)
100 for(
const auto& workspace : g_catkin_workspaces)
102 fs::path workspacePath(workspace);
104 fs::path execPath = workspacePath /
"lib" /
package / name;
105 if(fs::exists(execPath) && access(execPath.c_str(), X_OK) == 0)
106 return execPath.string();
109 if(!sharePath.empty())
115 if(!packageDir.empty())
119 return std::string();
124 std::pair<std::string, std::string> key(package, name);
126 auto it = g_executableCache.find(key);
127 if(it != g_executableCache.end())
131 g_executableCache[key] = result;
142 for(
const auto& workspace : g_catkin_workspaces)
144 fs::path workspacePath(workspace);
146 fs::path execPath = workspacePath /
"lib" / package;
147 fs::path filePath = execPath / name;
148 if(fs::exists(filePath) && access(filePath.c_str(), X_OK) == 0)
149 return execPath.string();
151 fs::path sharePath = workspacePath /
"share" / package;
152 filePath = sharePath / name;
153 if(fs::exists(filePath) && access(filePath.c_str(), X_OK) == 0)
154 return sharePath.string();
159 fs::path filePath = packageDir / name;
160 if(fs::exists(filePath) && access(filePath.c_str(), X_OK) == 0)
161 return packageDir.string();
164 return std::string();
static std::vector< std::string > g_catkin_workspaces
static rospack::Rospack g_pack
static std::string getExecutableInPath(const fs::path &path, const std::string &name)
static bool g_initialized
static std::string getPath(const std::string &package)
static std::string findPathToFile(const std::string &package, const std::string &name)
Find path to a package file.
static std::map< std::string, std::string > g_cache
bool getSearchPathFromEnv(std::vector< std::string > &sp)
static std::map< std::pair< std::string, std::string >, std::string > g_executableCache
void crawl(std::vector< std::string > search_path, bool force)
bool find(const std::string &name, std::string &path)
static std::string _getExecutable(const std::string &package, const std::string &name)
static std::string getExecutable(const std::string &package, const std::string &name)