]> git.tdb.fi Git - builder.git/blob - source/analyzer.h
Fix rebuild graph walking over symlinks
[builder.git] / source / analyzer.h
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2007, 2009  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef ANALYZER_H_
9 #define ANALYZER_H_
10
11 #include <list>
12 #include <set>
13 #include <string>
14 #include <vector>
15
16 class Builder;
17 class Target;
18
19 /**
20 Performs various kinds of dependency analysis on the build tree.
21 */
22 class Analyzer
23 {
24 public:
25         enum Mode
26         {
27                 DEPS,     //< Skip over "trivial" targets such as Install and Compile
28                 ALLDEPS,  //< Print out absolutely every target
29                 REBUILD,  //< Print targets that are going to be rebuilt
30                 RDEPS     //< Print targets that depend on the given targets
31         };
32
33 private:
34         typedef std::vector<std::string> TableRow;
35         typedef std::list<TableRow> Table;
36
37         Builder &builder;
38         Mode mode;
39         Table table;
40         unsigned max_depth;
41         bool full_paths;
42         std::map<const Target *, std::set<Target *> > rdepends;
43
44 public:
45         Analyzer(Builder &);
46         void set_mode(Mode m) { mode = m; }
47         void set_max_depth(unsigned m) { max_depth = m; }
48         void set_full_paths(bool f) { full_paths = f; }
49
50         /**
51         Performs the analysis and prints out the resulting dependency tree.
52         */
53         void analyze();
54
55 private:
56         /**
57         Adds rows to the table for the given target and its dependencies.
58         */
59         void build_depend_table(Target &, unsigned);
60
61         /**
62         Prints out the table that resulted from the analysis.
63         */
64         void print_table() const;
65
66         static bool target_order(const Target *, const Target *);
67         static bool target_order_full(const Target *, const Target *);
68 };
69
70 #endif