]> git.tdb.fi Git - builder.git/blobdiff - source/packagemanager.h
Move package management to a separate class
[builder.git] / source / packagemanager.h
diff --git a/source/packagemanager.h b/source/packagemanager.h
new file mode 100644 (file)
index 0000000..96c3dca
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef PACKAGEMANAGER_H_
+#define PACKAGEMANAGER_H_
+
+#include <list>
+#include <map>
+#include <string>
+#include <msp/fs/path.h>
+
+class Builder;
+class Package;
+
+/**
+Keeps track of packages.  Also responsible for locating previously unknown
+packages by name.
+*/
+class PackageManager
+{
+public:
+       typedef std::map<std::string, Package *> PackageMap;
+
+private:
+       typedef std::list<Msp::FS::Path> SearchPath;
+
+       Builder &builder;
+       SearchPath pkg_path;
+       SearchPath pkg_dirs;
+       bool no_externals;
+       PackageMap packages;
+
+public:
+       PackageManager(Builder &);
+       ~PackageManager();
+
+       void set_no_externals(bool);
+
+       /** Adds a package to the manager.  Called from Package constructor. */
+       void add_package(Package *);
+
+       /** Returns a package from the cache. */
+       Package *get_package(const std::string &);
+
+       const PackageMap &get_packages() const { return packages; }
+
+       /** Locates a package and creates it if necessary. */
+       Package *find_package(const std::string &);
+
+private:
+       std::string run_pkgconfig(const std::string &, const std::string &);
+
+       /** Determines the source directory of a package.  Pkg-config is consulted
+       first, and if it fails, the package path is searched for matches. */
+       Msp::FS::Path get_package_location(const std::string &);
+};
+
+#endif