]> git.tdb.fi Git - builder.git/blob - source/lib/filetarget.h
Refactor transitive dependencies to work on all targets
[builder.git] / source / lib / filetarget.h
1 #ifndef FILETARGET_H_
2 #define FILETARGET_H_
3
4 #include <msp/fs/path.h>
5 #include "libbuilder_api.h"
6 #include "target.h"
7
8 /**
9 An intermediate base class for targets that represent files.  Almost all target
10 classes are derived from this.
11 */
12 class LIBBUILDER_API FileTarget: public Target
13 {
14 protected:
15         Msp::FS::Path path;
16         Msp::Time::TimeStamp mtime;
17         unsigned size = 0;
18         Msp::FS::Path install_location;
19         bool nested_build_sig = false;
20         bool arch_in_build_sig = false;
21
22         FileTarget(Builder &b, const Msp::FS::Path &a);
23         FileTarget(Builder &b, const SourcePackage &p, const Msp::FS::Path &a);
24 private:
25         FileTarget(Builder &, const SourcePackage *, const Msp::FS::Path &);
26         void stat();
27         static std::string generate_name(Builder &, const SourcePackage *, const Msp::FS::Path &);
28
29 public:
30         const Msp::FS::Path &get_path() const { return path; }
31         const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
32         unsigned get_size() const { return size; }
33
34         bool is_installable() const { return !install_location.empty(); }
35         const Msp::FS::Path &get_install_location() const { return install_location; }
36
37         /// Changes the mtime of the target to the current time.
38         void touch();
39
40         FileTarget *get_real_target() override { return this; }
41
42 protected:
43         Target *resolve_transitive_dependency(Target &, Target &) const override;
44
45         void check_rebuild() override;
46
47         virtual std::string create_build_signature() const;
48
49         void build(Task &) override;
50
51         void build_finished(bool) override;
52
53 public:
54         void clean() override;
55 };
56
57 #endif