librospack
 All Classes Functions Pages
rospack.h
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/tr1/unordered_set.hpp>
109 #include <boost/tr1/unordered_map.hpp>
110 #include <string>
111 #include <vector>
112 #include <set>
113 #include <list>
114 
115 //#ifdef ROSPACK_API_BACKCOMPAT_V1
116 #if 1 // def ROSPACK_API_BACKCOMPAT_V1
117  #include "rospack/rospack_backcompat.h"
118 #endif
119 
120 
121 namespace rospack
122 {
123 
124 typedef enum
125 {
126  POSTORDER,
127  PREORDER
128 } traversal_order_t;
129 
130 // Forward declarations
131 class Stackage;
132 class DirectoryCrawlRecord;
133 
140 {
141  private:
142  std::string manifest_name_;
143  std::string cache_name_;
144  bool crawled_;
145  std::string name_;
146  std::string tag_;
147  bool quiet_;
148  std::vector<std::string> search_paths_;
149  std::tr1::unordered_set<std::string> dups_;
150  std::tr1::unordered_map<std::string, Stackage*> stackages_;
151  Stackage* findWithRecrawl(const std::string& name);
152  void log(const std::string& level, const std::string& msg, bool append_errno);
153  void addStackage(const std::string& path);
154  void crawlDetail(const std::string& path,
155  bool force,
156  int depth,
157  bool collect_profile_data,
158  std::vector<DirectoryCrawlRecord*>& profile_data,
159  std::tr1::unordered_set<std::string>& profile_hash);
160  bool depsOnDetail(const std::string& name, bool direct,
161  std::vector<Stackage*>& deps);
162  bool depsDetail(const std::string& name, bool direct,
163  std::vector<Stackage*>& deps);
164  bool isStackage(const std::string& path);
165  void loadManifest(Stackage* stackage);
166  void computeDeps(Stackage* stackage, bool ignore_errors=false);
167  void gatherDeps(Stackage* stackage, bool direct,
168  traversal_order_t order,
169  std::vector<Stackage*>& deps);
170  void gatherDepsFull(Stackage* stackage, bool direct,
171  traversal_order_t order, int depth,
172  std::tr1::unordered_set<Stackage*>& deps_hash,
173  std::vector<Stackage*>& deps,
174  bool get_indented_deps,
175  std::vector<std::string>& indented_deps);
176  std::string getCachePath();
177  bool readCache();
178  void writeCache();
179  FILE* validateCache();
180  bool expandExportString(Stackage* stackage,
181  const std::string& instring,
182  std::string& outstring);
183  void depsWhyDetail(Stackage* from,
184  Stackage* to,
185  std::list<std::list<Stackage*> >& acc_list);
186 
187  protected:
196  Rosstackage(const std::string& manifest_name,
197  const std::string& cache_name,
198  const std::string& name,
199  const std::string& tag);
200 
201  public:
205  virtual ~Rosstackage();
206 
211  virtual const char* usage() { return ""; }
223  void crawl(std::vector<std::string> search_path, bool force);
230  bool inStackage(std::string& name);
237  void setQuiet(bool quiet);
242  const std::string& getName() {return name_;}
251  bool getSearchPathFromEnv(std::vector<std::string>& sp);
258  bool find(const std::string& name, std::string& path);
265  bool contents(const std::string& name, std::set<std::string>& packages);
273  bool contains(const std::string& name,
274  std::string& stack,
275  std::string& path);
276 
281  void list(std::set<std::pair<std::string, std::string> >& list);
287  void listDuplicates(std::vector<std::string>& dups);
298  bool deps(const std::string& name, bool direct, std::vector<std::string>& deps);
309  bool depsOn(const std::string& name, bool direct,
310  std::vector<std::string>& deps);
322  bool depsManifests(const std::string& name, bool direct,
323  std::vector<std::string>& manifests);
337  bool depsMsgSrv(const std::string& name, bool direct,
338  std::vector<std::string>& gens);
360  bool depsIndent(const std::string& name, bool direct,
361  std::vector<std::string>& deps);
378  bool depsWhy(const std::string& from,
379  const std::string& to,
380  std::string& output);
392  bool rosdeps(const std::string& name, bool direct,
393  std::set<std::string>& rosdeps);
406  bool vcs(const std::string& name, bool direct,
407  std::vector<std::string>& vcs);
420  bool exports(const std::string& name, const std::string& lang,
421  const std::string& attrib, bool deps_only,
422  std::vector<std::string>& flags);
434  bool plugins(const std::string& name, const std::string& attrib,
435  const std::string& top,
436  std::vector<std::string>& flags);
462  bool profile(const std::vector<std::string>& search_path,
463  bool zombie_only,
464  int length,
465  std::vector<std::string>& dirs);
472  void logWarn(const std::string& msg,
473  bool append_errno = false);
480  void logError(const std::string& msg,
481  bool append_errno = false);
482 };
483 
488 class Rospack : public Rosstackage
489 {
490  public:
494  Rospack();
499  virtual const char* usage();
500 };
501 
506 class Rosstack : public Rosstackage
507 {
508  public:
512  Rosstack();
517  virtual const char* usage();
518 };
519 
520 } // namespace rospack
521 
522 #endif