]> git.tdb.fi Git - builder.git/blob - source/packagemanager.h
Refactor transitive dependencies to work on all targets
[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         SearchPath binpkg_path;
28         SearchPath binpkg_files;
29         bool no_externals;
30         PackageMap packages;
31         Package *main_pkg;
32         std::set<std::string> not_found;
33         bool env_set;
34
35 public:
36         PackageManager(Builder &);
37         ~PackageManager();
38
39         /// Adds a location to look for source packages from.
40         void append_package_path(const Msp::FS::Path &);
41
42         /// Adds a location to look for binary packages from.
43         void append_binary_package_path(const Msp::FS::Path &);
44
45         /** Prevent creation of source packages. */
46         void set_no_externals(bool);
47
48         /** Adds a package to the manager.  Called from Package constructor. */
49         void add_package(Package *);
50
51         /** Returns a package from the cache. */
52         Package *get_package(const std::string &) const;
53
54         /** Returns the package that was added first.  This should be considered
55         the primary build target. */
56         Package &get_main_package() const;
57
58         const PackageMap &get_packages() const { return packages; }
59
60         /** Locates a package and loads it if necessary. */
61         Package *find_package(const std::string &);
62
63 private:
64         std::string run_pkgconfig(const std::string &, const std::string &);
65
66         /** Determines the source directory of a package.  Pkg-config is consulted
67         first, and if it fails, the package path is searched for matches.  The
68         package is expected to be located in a directory named after itself. */
69         Msp::FS::Path get_package_location(const std::string &);
70
71         /** Determines the file containing a binary package.  The file is expected
72         to be named after the package. */
73         Msp::FS::Path get_binary_package_file(const std::string &);
74
75 public:
76         void save_all_caches() const;
77 };
78
79 #endif