]> git.tdb.fi Git - builder.git/blobdiff - source/pkgconfiggenerator.cpp
Refactor InternalTask to take a functor
[builder.git] / source / pkgconfiggenerator.cpp
index 02f142331a124c8d4db38e8df0b630a28afd8ba7..a6178a7328c5e66fa5ad22df0bc0686013e0367b 100644 (file)
@@ -2,6 +2,7 @@
 #include <msp/io/file.h>
 #include <msp/io/print.h>
 #include "builder.h"
+#include "internaltask.h"
 #include "pkgconfigfile.h"
 #include "pkgconfiggenerator.h"
 
@@ -16,17 +17,15 @@ Target *PkgConfigGenerator::create_target(const vector<Target *> &, const string
 Task *PkgConfigGenerator::run(const Target &target) const
 {
        const PkgConfigFile &pkgc = dynamic_cast<const PkgConfigFile &>(target);
-       Worker *worker = new Worker(pkgc);
-       return new InternalTask(worker);
+       return new InternalTask([&pkgc]{ return _run(pkgc); });
 }
 
-
-void PkgConfigGenerator::Worker::main()
+bool PkgConfigGenerator::_run(const PkgConfigFile &pkgc)
 {
-       Builder &builder = target.get_package()->get_builder();
-       const SourcePackage &spkg = *target.get_package();
+       Builder &builder = pkgc.get_package()->get_builder();
+       const SourcePackage &spkg = *pkgc.get_package();
 
-       IO::BufferedFile out(target.get_path().str(), IO::M_WRITE);
+       IO::BufferedFile out(pkgc.get_path().str(), IO::M_WRITE);
        IO::print(out, "prefix=%s\n", builder.get_prefix().str());
        IO::print(out, "source=%s\n\n", spkg.get_source_directory());
 
@@ -60,10 +59,10 @@ void PkgConfigGenerator::Worker::main()
                        IO::print(out, " -D%s=%s", kvp.first, kvp.second);
        out.put('\n');
 
-       status = Task::SUCCESS;
+       return true;
 }
 
-string PkgConfigGenerator::Worker::prefixify(const FS::Path &path, const FS::Path &prefix)
+string PkgConfigGenerator::prefixify(const FS::Path &path, const FS::Path &prefix)
 {
        if(FS::descendant_depth(path, prefix)>=0)
        {