]> git.tdb.fi Git - builder.git/blob - source/lib/package.h
9a10991ec8e94028ae74d27e553ceec233424d87
[builder.git] / source / lib / package.h
1 #ifndef PACKAGE_H_
2 #define PACKAGE_H_
3
4 #include <string>
5 #include <vector>
6 #include <msp/datafile/objectloader.h>
7 #include "buildinfo.h"
8 #include "conditionalloader.h"
9 #include "config.h"
10
11 class Builder;
12
13 /**
14 A package is a distributable piece of software.  Package information may be
15 obtained in several ways: Build files of source packages, pkg-config for binary
16 packages and the builderrc file for binary packages with no pkg-config support.
17 */
18 class Package
19 {
20 public:
21         class Loader: public Msp::DataFile::ObjectLoader<Package>, public ArchitectureConditional
22         {
23         public:
24                 Loader(Package &);
25         private:
26                 void require(const std::string &);
27         };
28
29         using Requirements = std::vector<Package *>;
30
31 protected:
32         Builder &builder;
33
34         std::string name;
35         std::string label;
36
37         Requirements requires;
38         BuildInfo export_binfo;
39         bool prepared = false;
40         bool broken = false;
41         std::vector<std::string> problems;
42
43         bool use_pkgconfig = true;
44
45         Package(Builder &, const std::string &);
46 public:
47         virtual ~Package() { }
48
49         Builder &get_builder() const { return builder; }
50         const std::string &get_name() const { return name; }
51         const std::string &get_label() const { return label; }
52         const Requirements &get_required_packages() const { return requires; }
53
54         const BuildInfo &get_exported_build_info() const { return export_binfo; }
55
56         /// Indicates whether or not this package supports pkg-config
57         bool uses_pkgconfig() const { return use_pkgconfig; }
58
59         /** Prepares the package for building.  Recursively prepares all required
60         packages, populates build info and creates targets. */
61         void prepare();
62
63 protected:
64         virtual void do_prepare() { }
65
66 public:
67         bool is_prepared() const { return prepared; }
68
69         bool is_broken() const { return broken; }
70         const std::vector<std::string> &get_problems() const { return problems; }
71
72         virtual void save_caches() { }
73 };
74
75 #endif