]> git.tdb.fi Git - builder.git/blob - source/target.h
Move some file-related things from Target to FileTarget
[builder.git] / source / target.h
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2009  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef TARGET_H_
9 #define TARGET_H_
10
11 #include <list>
12 #include <map>
13 #include <set>
14 #include <string>
15 #include <msp/time/timestamp.h>
16
17 class Action;
18 class Builder;
19 class Package;
20
21 class Target;
22 typedef std::list<Target *> TargetList;
23
24 /**
25 Targets make up the build graph.  This class is a base for all target types and
26 handles many common tasks.  See also FileTarget and VirtualTarget.
27 */
28 class Target
29 {
30 protected:
31         Builder &builder;
32         const Package *package;
33         std::string name;
34
35         bool buildable;
36         bool building;
37         bool rebuild;
38         std::string rebuild_reason;
39
40         TargetList depends;
41         bool deps_ready;
42
43         bool preparing;
44         bool prepared;
45
46         Target(Builder &, const Package *, const std::string &);
47 public:
48         virtual ~Target() { }
49
50         virtual const char *get_type() const = 0;
51         const std::string &get_name() const { return name; }
52         const Package *get_package() const { return package; }
53
54         /**
55         Tries to locate a target that will help getting this target built.  If all
56         dependencies are up-to-date, returns this target.  If there are no targets
57         ready to be built (maybe because they are being built right now), returns 0.
58         */
59         Target *get_buildable_target();
60
61         bool is_buildable() const { return buildable; }
62         bool get_rebuild() const { return rebuild; }
63         const std::string &get_rebuild_reason() const { return rebuild_reason; }
64         void add_depend(Target *);
65         const TargetList &get_depends() const { return depends; }
66         bool get_depends_ready() const { return deps_ready; }
67
68         /**
69         Finds dependencies for the target.  When all dependencies have been found,
70         the function should set deps_ready to true.
71         */
72         virtual void find_depends() { deps_ready = true; }
73
74         /**
75         Prepares the target by recursively preparing dependencies, then checking
76         whether rebuilding is needed.  A flag is used to prevent unnecessary
77         executions.
78         */
79         virtual void prepare();
80
81         /**
82         Starts building the target.  Returns the Action used for building.
83         */
84         Action *build();
85 protected:
86         void mark_rebuild(const std::string &);
87
88         /**
89         Checks if the target needs to be rebuilt and why.
90         */
91         virtual void check_rebuild() = 0;
92
93         /**
94         Creates and returns an Action suitable for building this target.
95         */
96         virtual Action *create_action() =0;
97
98         /**
99         Handler for the build_done signal of Action.
100         */
101         virtual void build_done();
102 };
103
104 typedef std::map<std::string, Target *> TargetMap;
105
106 #endif