7 #include <boost/filesystem.hpp> 8 #include <boost/version.hpp> 10 #include <libxml/parser.h> 11 #include <libxml/xpath.h> 12 #include <libxml/xpathInternals.h> 13 #include <libxml/tree.h> 34 std::vector<std::string> missing_packages;
39 std::vector<std::string> ros_package_paths;
44 RTT::log(
RTT::Debug) <<
"Loading dependencies for ROS package \""<<
package << "\" from: ";
45 for(
size_t i=0; i<ros_package_paths.size(); i++) {
RTT::log(
RTT::Debug) << ros_package_paths[i]; }
48 rpack.
crawl(ros_package_paths,
true);
50 if ( ros_package_paths.size() == 0 ) {
51 RTT::log(
RTT::Error) <<
"No paths in the ROS_PACKAGE_PATH environment variable! Could not load ROS package \"" <<
package << "\"" << RTT::endlog();
56 std::vector<std::string> deps_to_import;
57 std::vector<std::string> search_paths;
61 std::queue<std::string> dep_names;
62 dep_names.push(package);
63 deps_to_import.push_back(package);
65 xmlChar * rtt_plugin_depend_xpath = xmlCharStrdup(
"/package/export/rtt_ros/plugin_depend/text()");
67 while(!dep_names.empty())
69 namespace fs = boost::filesystem;
72 std::string dep_name, dep_path;
73 dep_name = dep_names.front();
76 bool dep_found = rpack.
find(dep_name,dep_path);
84 fs::path package_xml_path = fs::path(dep_path) /
"package.xml";
85 bool is_rosbuild_package =
false;
88 if(!boost::filesystem::is_regular_file( package_xml_path.string() ) ) {
91 package_xml_path = fs::path(dep_path) /
"manifest.xml";
92 is_rosbuild_package =
true;
94 if(!boost::filesystem::is_regular_file( package_xml_path.string() ) ) {
95 RTT::log(
RTT::Error) <<
"No package.xml or manifest.xml file for ROS package \""<< dep_name <<
"\" found at "<<package_xml_path.branch_path() <<
RTT::endlog();
101 if (is_rosbuild_package) {
102 search_paths.push_back((fs::path(dep_path) /
"lib" /
"orocos").
string());
109 xmlDocPtr package_doc;
110 xmlXPathContextPtr xpath_ctx;
111 xmlXPathObjectPtr xpath_obj;
114 package_doc = xmlParseFile(package_xml_path.string().c_str());
115 xpath_ctx = xmlXPathNewContext(package_doc);
118 xpath_obj = xmlXPathEvalExpression(rtt_plugin_depend_xpath, xpath_ctx);
121 if(xmlXPathNodeSetIsEmpty(xpath_obj->nodesetval)) {
124 RTT::log(
RTT::Debug) <<
"ROS package \""<< dep_name <<
"\" has "<<xpath_obj->nodesetval->nodeNr<<
" RTT plugin dependencies." <<
RTT::endlog();
126 for(
int i=0; i < xpath_obj->nodesetval->nodeNr; i++) {
127 if(xpath_obj->nodesetval->nodeTab[i]) {
129 xmlChar * dep_str = xmlNodeGetContent(xpath_obj->nodesetval->nodeTab[i]);
133 dep_names.push(oss.
str());
136 deps_to_import.push_back(oss.
str());
141 xmlXPathFreeObject(xpath_obj);
142 xmlXPathFreeContext(xpath_ctx);
143 xmlFreeDoc(package_doc);
146 xmlFree(rtt_plugin_depend_xpath);
149 std::set<std::string> search_paths_seen;
150 std::string path_list = loader->getComponentPath();
151 for(std::vector<std::string>::reverse_iterator it = search_paths.rbegin();
152 it != search_paths.rend();
155 if (search_paths_seen.count(*it))
continue;
156 path_list = *it +
":" + path_list;
157 search_paths_seen.insert(*it);
163 for(std::vector<std::string>::reverse_iterator it = deps_to_import.rbegin();
164 it != deps_to_import.rend();
168 if(*it ==
"rtt_ros" || loader->isImported(*it)) {
174 if(loader->import(*it, path_list)) {
175 RTT::log(
RTT::Debug) <<
"Importing Orocos components from ROS package \""<<*it<<
"\" SUCCEEDED.";
178 missing_packages.push_back(*it);
179 RTT::log(
RTT::Debug) <<
"Importing Orocos components from ROS package \""<<*it<<
"\" FAILED.";
184 }
catch(std::string arg) {
185 RTT::log(
RTT::Debug) <<
"While processing the dependencies of " <<
package << ": Dependency is not a ros package: " << arg << RTT::endlog();
186 missing_packages.push_back(arg);
190 if(missing_packages.size() == 0) {
191 RTT::log(
RTT::Info) <<
"Loaded plugins from ROS package \"" <<
package << "\" and its dependencies." << RTT::endlog();
193 RTT::log(
RTT::Warning) <<
"Could not load RTT plugins from the following ROS packages (they might be empty, in which case this message can be ignored): "<<
RTT::endlog();
194 for(std::vector<std::string>::iterator it = missing_packages.begin();
195 it != missing_packages.end();
202 return missing_packages.size() == 0;
void setQuiet(bool quiet)
static boost::shared_ptr< ComponentLoader > Instance()
bool import(const std::string &package)
Import a ROS package and all of its rtt_ros/plugin_depend dependencies.
bool getSearchPathFromEnv(std::vector< std::string > &sp)
void crawl(std::vector< std::string > search_path, bool force)
bool find(const std::string &name, std::string &path)
static Logger::LogFunction endlog()