rospack.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008, Willow Garage, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
105 #ifndef ROSPACK_ROSPACK_H
106 #define ROSPACK_ROSPACK_H
107 
108 #include <boost/version.hpp>
109 
110 #if BOOST_VERSION < 106500
111 #include <boost/tr1/unordered_set.hpp>
112 #include <boost/tr1/unordered_map.hpp>
113 #else
114 #include <boost/unordered_set.hpp>
115 #include <boost/unordered_map.hpp>
116 #endif
117 
118 #include <list>
119 #include <map>
120 #include <set>
121 #include <string>
122 #include <vector>
123 #include "macros.h"
124 
125 //#ifdef ROSPACK_API_BACKCOMPAT_V1
126 #if 1 // def ROSPACK_API_BACKCOMPAT_V1
128 #endif
129 
130 // this is working around a problem coming from console_bridge < 0.4
131 // which defines macros with the names `logWarn` and `logError`
132 // which collide with the function names in this file
133 // this will declare the namespaced version of the macros if they don't exist
134 // and remove the two short macros which collide with the API in this file
135 #ifndef CONSOLE_BRIDGE_logError // class_loader < 0.3
136  #ifdef logError // class_loader < 0.4 was included
137  // avoid using the short macro to define the long, it is being removed below
138  #define CONSOLE_BRIDGE_logError(fmt, ...) \
139  console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_ERROR, fmt, ##__VA_ARGS__)
140  #endif
141 #endif
142 #ifdef logError // class_loader < 0.4 was included
143  // otherwise the function name in this file is replaced by the macro
144  #undef logError
145 #endif
146 
147 #ifndef CONSOLE_BRIDGE_logWarn // class_loader < 0.3
148  #ifdef logWarn // class_loader < 0.4 was included
149  // avoid using the short macro to define the long, it is being removed below
150  #define CONSOLE_BRIDGE_logWarn(fmt, ...) \
151  console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_WARN, fmt, ##__VA_ARGS__)
152  #endif
153 #endif
154 #ifdef logWarn // class_loader < 0.4 was included
155  // otherwise the function name in this file is replaced by the macro
156  #undef logWarn
157 #endif
158 
159 #ifndef CONSOLE_BRIDGE_logInform // class_loader < 0.3
160  #ifdef logInform // class_loader < 0.4 was included
161  // only provided for consistency
162  #define CONSOLE_BRIDGE_logInform(fmt, ...) \
163  console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_INFO, fmt, ##__VA_ARGS__)
164  // no immediate need to undefine since this is not used in this API
165  #endif
166 #endif
167 
168 #ifndef CONSOLE_BRIDGE_logDebug // class_loader < 0.3
169  #ifdef logDebug // class_loader < 0.4 was included
170  // only provided for consistency
171  #define CONSOLE_BRIDGE_logDebug(fmt, ...) \
172  console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_DEBUG, fmt, ##__VA_ARGS__)
173  // no immediate need to undefine since this is not used in this API
174  #endif
175 #endif
176 
177 namespace rospack
178 {
179 
180 typedef enum
181 {
185 
186 // Forward declarations
187 class Stackage;
189 
196 {
197  private:
198  std::string manifest_name_;
199  std::string cache_prefix_;
200  bool crawled_;
201  std::string name_;
202  std::string tag_;
203  bool quiet_;
204  std::vector<std::string> search_paths_;
205 #if BOOST_VERSION < 106500
206  std::tr1::unordered_map<std::string, std::vector<std::string> > dups_;
207  std::tr1::unordered_map<std::string, Stackage*> stackages_;
208 #else
209  boost::unordered_map<std::string, std::vector<std::string> > dups_;
210  boost::unordered_map<std::string, Stackage*> stackages_;
211 #endif
212  Stackage* findWithRecrawl(const std::string& name);
213  void log(const std::string& level, const std::string& msg, bool append_errno);
214  void clearStackages();
215  void addStackage(const std::string& path);
216  void crawlDetail(const std::string& path,
217  bool force,
218  int depth,
219  bool collect_profile_data,
220  std::vector<DirectoryCrawlRecord*>& profile_data,
221 #if BOOST_VERSION < 106500
222  std::tr1::unordered_set<std::string>& profile_hash);
223 #else
224  boost::unordered_set<std::string>& profile_hash);
225 #endif
226  bool isStackage(const std::string& path);
227  void loadManifest(Stackage* stackage);
228  void computeDeps(Stackage* stackage, bool ignore_errors=false, bool ignore_missing=false);
229  void computeDepsInternal(Stackage* stackage, bool ignore_errors, const std::string& depend_tag, bool ignore_missing=false);
230  bool isSysPackage(const std::string& pkgname);
231  void gatherDeps(Stackage* stackage, bool direct,
232  traversal_order_t order,
233  std::vector<Stackage*>& deps,
234  bool no_recursion_on_wet=false);
235  void gatherDepsFull(Stackage* stackage, bool direct,
236  traversal_order_t order, int depth,
237 #if BOOST_VERSION < 106500
238  std::tr1::unordered_set<Stackage*>& deps_hash,
239 #else
240  boost::unordered_set<Stackage*>& deps_hash,
241 #endif
242  std::vector<Stackage*>& deps,
243  bool get_indented_deps,
244  std::vector<std::string>& indented_deps,
245  bool no_recursion_on_wet=false);
246  std::string getCachePath();
247  std::string getCacheHash();
248  bool readCache();
249  void writeCache();
250  FILE* validateCache();
251  bool expandExportString(Stackage* stackage,
252  const std::string& instring,
253  std::string& outstring);
254  void depsWhyDetail(Stackage* from,
255  Stackage* to,
256  std::list<std::list<Stackage*> >& acc_list);
257 
258  void initPython();
259 
260  protected:
269  Rosstackage(const std::string& manifest_name,
270  const std::string& cache_prefix,
271  const std::string& name,
272  const std::string& tag);
273 
274  public:
278  virtual ~Rosstackage();
279 
284  virtual const char* usage() { return ""; }
296  void crawl(std::vector<std::string> search_path, bool force);
303  bool inStackage(std::string& name);
310  void setQuiet(bool quiet);
315  const std::string& getName() {return name_;}
324  bool getSearchPathFromEnv(std::vector<std::string>& sp);
331  bool find(const std::string& name, std::string& path);
338  bool contents(const std::string& name, std::set<std::string>& packages);
346  bool contains(const std::string& name,
347  std::string& stack,
348  std::string& path);
349 
354  void list(std::set<std::pair<std::string, std::string> >& list);
360  void listDuplicates(std::vector<std::string>& dups);
366  void listDuplicatesWithPaths(std::map<std::string, std::vector<std::string> >& dups);
377  bool deps(const std::string& name, bool direct, std::vector<std::string>& deps);
388  bool depsOn(const std::string& name, bool direct,
389  std::vector<std::string>& deps);
400  bool depsDetail(const std::string& name, bool direct, std::vector<Stackage*>& deps);
410  bool depsOnDetail(const std::string& name, bool direct,
411  std::vector<Stackage*>& deps, bool ignore_missing=false);
421  bool depsManifests(const std::string& name, bool direct,
422  std::vector<std::string>& manifests);
436  bool depsMsgSrv(const std::string& name, bool direct,
437  std::vector<std::string>& gens);
459  bool depsIndent(const std::string& name, bool direct,
460  std::vector<std::string>& deps);
477  bool depsWhy(const std::string& from,
478  const std::string& to,
479  std::string& output);
491  bool rosdeps(const std::string& name, bool direct,
492  std::set<std::string>& rosdeps);
493  void _rosdeps(Stackage* stackage, std::set<std::string>& rosdeps, const char* tag_name);
506  bool vcs(const std::string& name, bool direct,
507  std::vector<std::string>& vcs);
520  bool cpp_exports(const std::string& name, const std::string& type,
521  const std::string& attrib, bool deps_only,
522  std::vector<std::pair<std::string, bool> >& flags);
529  bool reorder_paths(const std::string& paths, std::string& reordered);
542  bool exports(const std::string& name, const std::string& lang,
543  const std::string& attrib, bool deps_only,
544  std::vector<std::string>& flags);
553  bool exports_dry_package(Stackage* stackage, const std::string& lang,
554  const std::string& attrib,
555  std::vector<std::string>& flags);
567  bool plugins(const std::string& name, const std::string& attrib,
568  const std::string& top,
569  std::vector<std::string>& flags);
595  bool profile(const std::vector<std::string>& search_path,
596  bool zombie_only,
597  int length,
598  std::vector<std::string>& dirs);
605  void logWarn(const std::string& msg,
606  bool append_errno = false);
613  void logError(const std::string& msg,
614  bool append_errno = false);
615 
616  /*
617  * @brief The manifest type.
618  * @return Either "package" or "stack".
619  */
620  virtual std::string get_manifest_type() { return ""; }
621 };
622 
628 {
629  public:
633  Rospack();
638  virtual const char* usage();
639 
640  virtual std::string get_manifest_type();
641 };
642 
648 {
649  public:
653  Rosstack();
658  virtual const char* usage();
659 
660  virtual std::string get_manifest_type();
661 };
662 
663 } // namespace rospack
664 
665 #endif
std::vector< std::string > search_paths_
Definition: rospack.h:204
std::string tag_
Definition: rospack.h:202
traversal_order_t
Definition: rospack.h:180
virtual std::string get_manifest_type()
Definition: rospack.h:620
std::string manifest_name_
Definition: rospack.h:198
std::tr1::unordered_map< std::string, std::vector< std::string > > dups_
Definition: rospack.h:206
std::string cache_prefix_
Definition: rospack.h:199
virtual const char * usage()
Usage string, to be overridden by derived classes.
Definition: rospack.h:284
Package crawler. Create one of these to operate on a package tree. Call public methods inherited from...
Definition: rospack.h:627
const std::string & getName()
Get the name of the tool that&#39;s in use (e.g., "rospack" or "rosstack")
Definition: rospack.h:315
The base class for package/stack ("stackage") crawlers. Users of the library should use the functiona...
Definition: rospack.h:195
std::tr1::unordered_map< std::string, Stackage * > stackages_
Definition: rospack.h:207
std::string name_
Definition: rospack.h:201
Stack crawler. Create one of these to operate on a stack tree. Call public methods inherited from Ros...
Definition: rospack.h:647
#define ROSPACK_DECL
Definition: macros.h:71


rospack
Author(s): Brian Gerkey, Morgan Quigley, Dirk Thomas
autogenerated on Thu Dec 10 2020 03:42:11