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