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