]> git.tdb.fi Git - builder.git/blob - source/analyzer.h
Refactor transitive dependencies to work on all targets
[builder.git] / source / analyzer.h
1 #ifndef ANALYZER_H_
2 #define ANALYZER_H_
3
4 #include <list>
5 #include <map>
6 #include <set>
7 #include <string>
8 #include <vector>
9
10 class Builder;
11 class Target;
12
13 /**
14 Performs various kinds of dependency analysis on the build tree.
15 */
16 class Analyzer
17 {
18 public:
19         enum Mode
20         {
21                 DEPS,     //< Skip over "trivial" targets such as InstalledFile
22                 ALLDEPS,  //< Print out absolutely every target
23                 REBUILD,  //< Print targets that are going to be rebuilt
24                 RDEPS     //< Print targets that depend on the given targets
25         };
26
27 private:
28         typedef std::vector<std::string> TableRow;
29         typedef std::list<TableRow> Table;
30
31         Builder &builder;
32         Mode mode;
33         Table table;
34         unsigned max_depth;
35         bool full_paths;
36         std::map<const Target *, std::set<Target *> > rdepends;
37
38 public:
39         Analyzer(Builder &);
40
41         void set_mode(Mode m) { mode = m; }
42         void set_max_depth(unsigned m) { max_depth = m; }
43         void set_full_paths(bool f) { full_paths = f; }
44
45         /// Performs the analysis and prints out the resulting dependency tree.
46         void analyze();
47
48 private:
49         /** Adds rows for a target, then recursively adds rows for dependencies as
50         needed. */
51         void build_depend_table(Target &, unsigned);
52
53         /// Prints out the table that resulted from the analysis.
54         void print_table() const;
55
56         static bool target_order(const Target *, const Target *);
57         static bool target_order_full(const Target *, const Target *);
58 };
59
60 #endif