]> git.tdb.fi Git - builder.git/blob - source/packagemanager.h
Let PackageManager take care of PKG_CONFIG_PATH
[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 public:
19         typedef std::map<std::string, Package *> PackageMap;
20
21 private:
22         typedef std::list<Msp::FS::Path> SearchPath;
23
24         Builder &builder;
25         SearchPath pkg_path;
26         SearchPath pkg_dirs;
27         bool no_externals;
28         PackageMap packages;
29         bool env_set;
30
31 public:
32         PackageManager(Builder &);
33         ~PackageManager();
34
35         /** Prevent creation of source packages. */
36         void set_no_externals(bool);
37
38         /** Adds a package to the manager.  Called from Package constructor. */
39         void add_package(Package *);
40
41         /** Returns a package from the cache. */
42         Package *get_package(const std::string &);
43
44         const PackageMap &get_packages() const { return packages; }
45
46         /** Locates a package and creates it if necessary. */
47         Package *find_package(const std::string &);
48
49 private:
50         std::string run_pkgconfig(const std::string &, const std::string &);
51
52         /** Determines the source directory of a package.  Pkg-config is consulted
53         first, and if it fails, the package path is searched for matches. */
54         Msp::FS::Path get_package_location(const std::string &);
55 };
56
57 #endif