]> git.tdb.fi Git - builder.git/blobdiff - source/packagemanager.cpp
Adapt to changes in mspcore
[builder.git] / source / packagemanager.cpp
index 746755eaf2d36b4afac5273fbfc5fc9375c9f183..35c752e8e4e056d979e1b55d536f94e66219ea04 100644 (file)
@@ -5,7 +5,7 @@
 #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"
@@ -19,6 +19,7 @@ using namespace Msp;
 PackageManager::PackageManager(Builder &b):
        builder(b),
        no_externals(false),
+       main_pkg(0),
        env_set(false)
 { }
 
@@ -54,22 +55,43 @@ void PackageManager::add_package(Package *pkg)
                        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;
                }
@@ -79,31 +101,31 @@ Package *PackageManager::find_package(const string &name)
        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();
@@ -131,10 +153,12 @@ string PackageManager::run_pkgconfig(const string &pkg, const string &what)
        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);
@@ -143,6 +167,11 @@ string PackageManager::run_pkgconfig(const string &pkg, const string &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)
@@ -164,9 +193,9 @@ 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"))
@@ -206,8 +235,8 @@ FS::Path PackageManager::get_binary_package_file(const string &name)
                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));
                }
@@ -224,3 +253,9 @@ FS::Path PackageManager::get_binary_package_file(const string &name)
 
        return FS::Path();
 }
+
+void PackageManager::save_all_caches() const
+{
+       for(PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
+               i->second->save_caches();
+}