]> git.tdb.fi Git - builder.git/blobdiff - source/packagemanager.cpp
ComponentList typedef isn't needed outside of SourcePackage
[builder.git] / source / packagemanager.cpp
index c3d693961dd332d188a7a6e7b93547ed1e486623..730f02271e32a5261c95829b89b51604c1296bef 100644 (file)
@@ -1,3 +1,4 @@
+#include <cstdlib>
 #include <msp/fs/dir.h>
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
@@ -17,7 +18,8 @@ using namespace Msp;
 
 PackageManager::PackageManager(Builder &b):
        builder(b),
-       no_externals(false)
+       no_externals(false),
+       env_set(false)
 {
        pkg_path.push_back(builder.get_cwd()/".");
        pkg_path.push_back(builder.get_cwd()/"..");
@@ -87,6 +89,29 @@ Package *PackageManager::find_package(const string &name)
 
 string PackageManager::run_pkgconfig(const string &pkg, const string &what)
 {
+       if(!env_set)
+       {
+               const FS::Path &prefix = builder.get_prefix();
+               if(prefix.str()!="/usr")
+               {
+                       FS::Path pcdir = prefix/"lib/pkgconfig";
+                       if(const char *pcp = getenv("PKG_CONFIG_PATH"))
+                       {
+                               vector<string> path = split(pcp, ':');
+                               bool found = false;
+                               for(vector<string>::const_iterator i=path.begin(); (!found && i!=path.end()); ++i)
+                                       found = (*i==pcdir.str());
+                               if(!found)
+                               {
+                                       path.push_back(pcdir.str());
+                                       setenv("PKG_CONFIG_PATH", join(path.begin(), path.end(), ":").c_str(), true);
+                               }
+                       }
+                       else
+                               setenv("PKG_CONFIG_PATH", pcdir.str().c_str(), true);
+               }
+       }
+
        ExternalTask::Arguments argv;
        argv.push_back("pkg-config");
        if(what=="cflags" || what=="libs")
@@ -100,26 +125,14 @@ string PackageManager::run_pkgconfig(const string &pkg, const string &what)
                argv.push_back("--variable="+what);
        argv.push_back(pkg);
 
-       if(builder.get_verbose()>=4)
-               IO::print("Running %s\n", join(argv.begin(), argv.end()));
-
-       ExternalTask task(argv);
-       task.set_stdout(ExternalTask::CAPTURE);
-       task.set_stderr(ExternalTask::IGNORE);
-       task.start();
-       Task::Status status;
-       while((status=task.check())==Task::RUNNING)
-               Time::sleep(10*Time::msec);
-       if(status==Task::ERROR)
-               throw runtime_error(format("pkg-config for package %s failed", pkg));
+       builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end())));
 
-       return task.get_output();
+       return ExternalTask::run_and_capture_output(argv);
 }
 
 FS::Path PackageManager::get_package_location(const string &name)
 {
-       if(builder.get_verbose()>=3)
-               IO::print("Looking for package %s\n", name);
+       builder.get_logger().log("packagemgr", format("Looking for package %s", name));
 
        try
        {
@@ -135,6 +148,7 @@ FS::Path PackageManager::get_package_location(const string &name)
        {
                for(list<FS::Path>::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);
                        for(list<string>::const_iterator j=files.begin(); j!=files.end(); ++j)
                        {
@@ -143,8 +157,7 @@ FS::Path PackageManager::get_package_location(const string &name)
                                        pkg_dirs.push_back(full);
                        }
                }
-               if(builder.get_verbose()>=3)
-                       IO::print("%d packages found in path\n", pkg_dirs.size());
+               builder.get_logger().log("packagemgr", format("%d packages found in path", pkg_dirs.size()));
        }
 
        bool msp = !name.compare(0, 3, "msp");