]> git.tdb.fi Git - builder.git/blobdiff - source/builder.cpp
Add a method to query the existence of dependencies in cache
[builder.git] / source / builder.cpp
index 69bd607bb3d8cdaa519df5dc460a3bf67e70ac2c..ed749f818e464bb7df7ba8d00d44d11e6f16e313 100644 (file)
 #include "binarypackage.h"
 #include "builder.h"
 #include "copy.h"
+#include "externaltask.h"
 #include "gnuarchiver.h"
 #include "gnuccompiler.h"
 #include "gnucxxcompiler.h"
 #include "gnulinker.h"
 #include "installedfile.h"
-#include "misc.h"
 #include "package.h"
-#include "pkgconfig.h"
+#include "pkgconfigfile.h"
 #include "pkgconfiggenerator.h"
 #include "sharedlibrary.h"
 #include "sourcepackage.h"
@@ -305,7 +305,7 @@ int Builder::main()
 
 string Builder::run_pkgconfig(const string &pkg, const string &what)
 {
-       list<string> argv;
+       vector<string> argv;
        argv.push_back("pkg-config");
        if(what=="cflags" || what=="libs")
                argv.push_back("--"+what);
@@ -321,12 +321,17 @@ string Builder::run_pkgconfig(const string &pkg, const string &what)
        if(verbose>=4)
                IO::print("Running %s\n", join(argv.begin(), argv.end()));
 
-       int status;
-       string res = run_command(argv, &status);
-       if(status)
+       ExternalTask task(argv, FS::Path());
+       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));
 
-       return res;
+       return task.get_output();
 }
 
 Package *Builder::get_package(const string &name)
@@ -504,8 +509,8 @@ int Builder::create_targets()
 
                if(spkg->get_install_flags()&(SourcePackage::LIB|SourcePackage::INCLUDE))
                {
-                       PkgConfig *pc = new PkgConfig(*this, *spkg);
-                       install->add_depend(new InstalledFile(*this, *spkg, *pc));
+                       PkgConfigFile *pc = new PkgConfigFile(*this, *spkg);
+                       install->add_depend(toolchain.get_tool("CP").create_target(*pc));
                }
        }
 
@@ -584,7 +589,20 @@ int Builder::do_build()
                                        IO::print("%-4s  %s\n", tgt->get_tool()->get_tag(), tgt->get_name());
                                Task *task = tgt->build();
                                if(task)
-                                       tasks.push_back(task);
+                               {
+                                       if(verbose>=2)
+                                               IO::print("%s\n", task->get_command());
+                                       if(dry_run)
+                                       {
+                                               task->signal_finished.emit(true);
+                                               delete task;
+                                       }
+                                       else
+                                       {
+                                               task->start();
+                                               tasks.push_back(task);
+                                       }
+                               }
 
                                if(show_progress)
                                        IO::print("%d of %d target%s built\033[1G", count, total, (total!=1 ? "s" : ""));
@@ -648,7 +666,8 @@ int Builder::do_clean()
 
        for(set<Target *>::iterator i=clean_tgts.begin(); i!=clean_tgts.end(); ++i)
                if(FileTarget *ft = dynamic_cast<FileTarget *>(*i))
-                       unlink(ft->get_path());
+                       if(ft->get_mtime())
+                               FS::unlink(ft->get_path());
 
        return 0;
 }