]> git.tdb.fi Git - builder.git/blob - source/packagemanager.h
Inline simple constructors
[builder.git] / source / packagemanager.h
1 #ifndef PACKAGEMANAGER_H_
2 #define PACKAGEMANAGER_H_
3
4 #include <map>
5 #include <set>
6 #include <string>
7 #include <vector>
8 #include <msp/fs/path.h>
9
10 class Builder;
11 class Package;
12
13 /**
14 Keeps track of packages.  Also responsible for locating previously unknown
15 packages by name.
16 */
17 class PackageManager
18 {
19 private:
20         Builder &builder;
21         std::vector<Msp::FS::Path> pkg_path;
22         std::vector<Msp::FS::Path> pkg_dirs;
23         std::vector<Msp::FS::Path> binpkg_path;
24         std::vector<Msp::FS::Path> binpkg_files;
25         bool no_externals = false;
26         std::map<std::string, Package *> packages;
27         Package *main_pkg = 0;
28         std::set<std::string> not_found;
29         bool env_set = false;
30
31 public:
32         PackageManager(Builder &b): builder(b) { }
33         ~PackageManager();
34
35         /// Adds a location to look for source packages from.
36         void append_package_path(const Msp::FS::Path &);
37
38         /// Adds a location to look for binary packages from.
39         void append_binary_package_path(const Msp::FS::Path &);
40
41         /** Prevent creation of source packages. */
42         void set_no_externals(bool);
43
44         /** Adds a package to the manager.  Called from Package constructor. */
45         void add_package(Package *);
46
47         /** Returns a package from the cache. */
48         Package *get_package(const std::string &) const;
49
50         /** Returns the package that was added first.  This should be considered
51         the primary build target. */
52         Package &get_main_package() const;
53
54         const std::map<std::string, Package *> &get_packages() const { return packages; }
55
56         /** Locates a package and loads it if necessary. */
57         Package *find_package(const std::string &);
58
59 private:
60         std::string run_pkgconfig(const std::string &, const std::string &);
61
62         /** Determines the source directory of a package.  Pkg-config is consulted
63         first, and if it fails, the package path is searched for matches.  The
64         package is expected to be located in a directory named after itself. */
65         Msp::FS::Path get_package_location(const std::string &);
66
67         /** Determines the file containing a binary package.  The file is expected
68         to be named after the package. */
69         Msp::FS::Path get_binary_package_file(const std::string &);
70
71 public:
72         void save_all_caches() const;
73 };
74
75 #endif