librospack
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
bool exports(const std::string &name, const std::string &lang, const std::string &attrib, bool deps_only, std::vector< std::string > &flags)
Compute exports declared in a package and its dependencies. Used by rosbuild.
bool depsMsgSrv(const std::string &name, bool direct, std::vector< std::string > &gens)
List the marker files in a packages&#39;s dependencies that indicate that those packages contain auto-gen...
bool inStackage(std::string &name)
Is the current working directory a stackage?
bool contents(const std::string &name, std::set< std::string > &packages)
Compute the packages that are contained in a stack.
void listDuplicates(std::vector< std::string > &dups)
Identify duplicate stackages. Forces crawl.
bool deps(const std::string &name, bool direct, std::vector< std::string > &deps)
Compute dependencies of a stackage (i.e., stackages that this stackages depends on).
void setQuiet(bool quiet)
Control warning and error console output.
bool rosdeps(const std::string &name, bool direct, std::set< std::string > &rosdeps)
Compute rosdep entries that are declared in manifest of a package and its dependencies. Used by rosmake.
Rosstackage(const std::string &manifest_name, const std::string &cache_name, const std::string &name, const std::string &tag)
Constructor, only used by derived classes.
void list(std::set< std::pair< std::string, std::string > > &list)
List names and paths of all stackages.
Definition: rospack.h:121
bool contains(const std::string &name, std::string &stack, std::string &path)
Find the stack that contains a package.
bool getSearchPathFromEnv(std::vector< std::string > &sp)
Helper method to construct a directory search path by looking at relevant environment variables...
virtual const char * usage()
Usage string, to be overridden by derived classes.
Definition: rospack.h:211
bool depsManifests(const std::string &name, bool direct, std::vector< std::string > &manifests)
List the manifests of a stackage&#39;s dependencies. Used by rosbuild.
Package crawler. Create one of these to operate on a package tree. Call public methods inherited from...
Definition: rospack.h:488
bool depsOn(const std::string &name, bool direct, std::vector< std::string > &deps)
Compute reverse dependencies of a stackage (i.e., stackages that depend on this stackage). Forces crawl.
const std::string & getName()
Get the name of the tool that&#39;s in use (e.g., "rospack" or "rosstack")
Definition: rospack.h:242
The base class for package/stack ("stackage") crawlers. Users of the library should use the functiona...
Definition: rospack.h:139
void crawl(std::vector< std::string > search_path, bool force)
Crawl the filesystem, accumulating a database of stackages. May read results from a cache file instea...
bool vcs(const std::string &name, bool direct, std::vector< std::string > &vcs)
Compute vcs entries that are declared in manifest of a package and its dependencies. Was used by Hudson build scripts; might not be needed.
void logError(const std::string &msg, bool append_errno=false)
Log a error (usually goes to stderr).
bool depsIndent(const std::string &name, bool direct, std::vector< std::string > &deps)
Generate indented list of a stackage&#39;s dependencies, including duplicates. Intended for visual debugg...
bool profile(const std::vector< std::string > &search_path, bool zombie_only, int length, std::vector< std::string > &dirs)
Report on time taken to crawl for stackages. Intended for use in debugging misconfigured stackage tre...
bool find(const std::string &name, std::string &path)
Look for a stackage.
virtual ~Rosstackage()
Destructor.
Stack crawler. Create one of these to operate on a stack tree. Call public methods inherited from Ros...
Definition: rospack.h:506
bool plugins(const std::string &name, const std::string &attrib, const std::string &top, std::vector< std::string > &flags)
Compute exported plugins declared in packages that depend on a package. Forces crawl. Used by rosbuild and roslib.
bool depsWhy(const std::string &from, const std::string &to, std::string &output)
Compute all dependency chains from one stackage to another. Intended for visual debugging of dependen...
void logWarn(const std::string &msg, bool append_errno=false)
Log a warning (usually goes to stderr).