#include <msp/io/print.h>
#include <msp/strings/format.h>
#include <msp/strings/utils.h>
-#include <msp/time/units.h>
+#include <msp/time/timedelta.h>
#include <msp/time/utils.h>
#include "binarypackage.h"
#include "builder.h"
PackageManager::PackageManager(Builder &b):
builder(b),
no_externals(false),
+ main_pkg(0),
env_set(false)
{ }
throw logic_error("Package is already managed");
}
+ if(packages.empty())
+ main_pkg = pkg;
+
packages.insert(PackageMap::value_type(pkg->get_name(), pkg));
}
-Package *PackageManager::find_package(const string &name)
+Package *PackageManager::get_package(const string &name) const
{
- PackageMap::iterator i = packages.find(name);
+ PackageMap::const_iterator i = packages.find(name);
if(i!=packages.end())
return i->second;
+ return 0;
+}
+
+Package &PackageManager::get_main_package() const
+{
+ if(!main_pkg)
+ throw logic_error("No packages");
+ return *main_pkg;
+}
+
+Package *PackageManager::find_package(const string &name)
+{
+ if(not_found.count(name))
+ return 0;
+
+ if(Package *pkg = get_package(name))
+ return pkg;
+
if(!no_externals)
{
FS::Path path = get_package_location(name);
if(!path.empty())
{
builder.load_build_file(path/"Build");
- i = packages.find(name);
+ PackageMap::iterator i = packages.find(name);
if(i!=packages.end())
return i->second;
}
if(!path.empty())
{
builder.load_build_file(path);
- i = packages.find(name);
- if(i!=packages.end())
- return i->second;
+ if(Package *pkg = get_package(name))
+ return pkg;
}
- Package *pkg = 0;
try
{
// Package source not found - create a binary package
string flags_str = run_pkgconfig(name, "flags");
- vector<string> flags = split(flags_str);
- pkg = BinaryPackage::from_flags(builder, name, flags);
+ BinaryPackage::Flags flags = split(flags_str);
+ flags_str = run_pkgconfig(name, "staticflags");
+ BinaryPackage::Flags static_flags = split(flags_str);
+ Package *pkg = BinaryPackage::from_flags(builder, name, flags, static_flags);
+ packages.insert(PackageMap::value_type(name, pkg));
+ return pkg;
}
catch(...)
{
- builder.problem(name, "not found");
+ not_found.insert(name);
+ return 0;
}
-
- packages.insert(PackageMap::value_type(name, pkg));
-
- return pkg;
}
string PackageManager::run_pkgconfig(const string &pkg, const string &what)
{
+#ifndef _WIN32
if(!env_set)
{
const FS::Path &prefix = builder.get_prefix();
argv.push_back("pkg-config");
if(what=="cflags" || what=="libs")
argv.push_back("--"+what);
- else if(what=="flags")
+ else if(what=="flags" || what=="staticflags")
{
argv.push_back("--cflags");
argv.push_back("--libs");
+ if(what=="staticflags")
+ argv.push_back("--static");
}
else
argv.push_back("--variable="+what);
builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end())));
return ExternalTask::run_and_capture_output(argv);
+#else
+ (void)pkg;
+ (void)what;
+ return string();
+#endif
}
FS::Path PackageManager::get_package_location(const string &name)
for(SearchPath::const_iterator i=pkg_path.begin(); i!=pkg_path.end(); ++i)
{
builder.get_logger().log("files", format("Traversing %s", *i));
- list<string> files = list_files(*i);
+ vector<string> files = list_files(*i);
unsigned count = 0;
- for(list<string>::const_iterator j=files.begin(); j!=files.end(); ++j)
+ for(vector<string>::const_iterator j=files.begin(); j!=files.end(); ++j)
{
FS::Path full = *i / *j;
if(FS::exists(full/"Build"))
for(list<FS::Path>::const_iterator i=binpkg_path.begin(); i!=binpkg_path.end(); ++i)
{
builder.get_logger().log("files", format("Traversing %s", *i));
- list<string> files = list_filtered(*i, "\\.bpk$");
- for(list<string>::const_iterator j=files.begin(); j!=files.end(); ++j)
+ vector<string> files = list_filtered(*i, "\\.bpk$");
+ for(vector<string>::const_iterator j=files.begin(); j!=files.end(); ++j)
binpkg_files.push_back(*i / *j);
builder.get_logger().log("packagemgr", format("%d binary packages found in %s", files.size(), *i));
}
return FS::Path();
}
+
+void PackageManager::save_all_caches() const
+{
+ for(PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
+ i->second->save_caches();
+}