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