#include "androidmanifestfile.h"
#include "androidmanifestgenerator.h"
#include "component.h"
+#include "internaltask.h"
#include "sharedlibrary.h"
#include "sourcepackage.h"
Task *AndroidManifestGenerator::run(const Target &target) const
{
const AndroidManifestFile &manifest = dynamic_cast<const AndroidManifestFile &>(target);
- Worker *worker = new Worker(manifest);
- return new InternalTask(worker);
+ return new InternalTask([&manifest]{ return _run(manifest); });
}
-
-void AndroidManifestGenerator::Worker::main()
+bool AndroidManifestGenerator::_run(const AndroidManifestFile &manifest)
{
const Component &comp = *manifest.get_component();
const SourcePackage &pkg = comp.get_package();
IO::print(out, "\t<uses-permission android:name=\"%s\" />\n", p);
out.write("</manifest>\n");
- status = Task::SUCCESS;
+ return true;
}
#ifndef ANDROIDMANIFESTGENERATOR_H_
#define ANDROIDMANIFESTGENERATOR_H_
-#include "internaltask.h"
#include "tool.h"
class AndroidManifestFile;
class AndroidManifestGenerator: public Tool
{
-private:
- class Worker: public InternalTask::Worker
- {
- private:
- const AndroidManifestFile &manifest;
-
- public:
- Worker(const AndroidManifestFile &m): manifest(m) { }
-
- private:
- void main() override;
- };
-
public:
AndroidManifestGenerator(Builder &b): Tool(b, "AMG") { }
Target *create_target(const std::vector<Target *> &, const std::string &) override;
Task *run(const Target &) const override;
+
+private:
+ static bool _run(const AndroidManifestFile &);
};
#endif
#include "builder.h"
#include "compilecommandsgenerator.h"
#include "compilecommandsjson.h"
+#include "internaltask.h"
#include "objectfile.h"
#include "sourcefile.h"
Task *CompileCommandsGenerator::run(const Target &target) const
{
const CompileCommandsJson &cmds = dynamic_cast<const CompileCommandsJson &>(target);
- Worker *worker = new Worker(cmds);
- return new InternalTask(worker);
+ return new InternalTask([&cmds]{ return _run(cmds); });
}
-
-void CompileCommandsGenerator::Worker::main()
+bool CompileCommandsGenerator::_run(const CompileCommandsJson &cmds)
{
- Builder &builder = target.get_package()->get_builder();
- const SourcePackage &spkg = *target.get_package();
+ Builder &builder = cmds.get_package()->get_builder();
+ const SourcePackage &spkg = *cmds.get_package();
string work_dir = c_escape(spkg.get_source_directory().str());
- IO::BufferedFile out(target.get_path().str(), IO::M_WRITE);
+ IO::BufferedFile out(cmds.get_path().str(), IO::M_WRITE);
IO::print(out, "[");
bool first = true;
IO::print(out, "\n]\n");
- status = Task::SUCCESS;
+ return true;
}
#ifndef COMPILECOMMANDSGENERATOR_H_
#define COMPILECOMMANDSGENERATOR_H_
-#include "internaltask.h"
#include "tool.h"
class CompileCommandsJson;
class CompileCommandsGenerator: public Tool
{
-private:
- class Worker: public InternalTask::Worker
- {
- private:
- const CompileCommandsJson ⌖
-
- public:
- Worker(const CompileCommandsJson &t): target(t) { }
-
- private:
- void main() override;
- };
-
public:
CompileCommandsGenerator(Builder &b): Tool(b, "CCJG") { }
Target *create_target(const std::vector<Target *> &, const std::string &) override;
Task *run(const Target &) const override;
+
+private:
+ static bool _run(const CompileCommandsJson &);
};
#endif
#include "builder.h"
#include "copy.h"
#include "installedfile.h"
+#include "internaltask.h"
using namespace std;
using namespace Msp;
Task *Copy::run(const Target &target) const
{
const InstalledFile &install = dynamic_cast<const InstalledFile &>(target);
- Worker *worker = new Worker(install);
- InternalTask *task = new InternalTask(worker);
+ InternalTask *task = new InternalTask([&install]{ return _run(install); });
task->add_file(install.get_path());
task->set_unlink();
return task;
}
-
-void Copy::Worker::main()
+bool Copy::_run(const InstalledFile &install)
{
- const FileTarget &source = target.get_source();
+ const FileTarget &source = install.get_source();
const FS::Path &src_path = source.get_path();
- const FS::Path &dst_path = target.get_path();
+ const FS::Path &dst_path = install.get_path();
try
{
catch(const exception &e)
{
IO::print(IO::cerr, "%s\n", e.what());
- status = Task::ERROR;
- return;
+ return false;
}
#ifndef _WIN32
if(stat(src_path.str().c_str(), &st)==0)
chmod(dst_path.str().c_str(), st.st_mode&0777);
- const FS::Path &link = target.get_symlink();
+ const FS::Path &link = install.get_symlink();
if(!link.empty())
{
FS::Path relpath = FS::relative(dst_path, FS::dirname(link));
}
#endif
- status = Task::SUCCESS;
+ return true;
}
#ifndef COPY_H_
#define COPY_H_
-#include <msp/core/thread.h>
-#include <msp/fs/path.h>
-#include "internaltask.h"
#include "tool.h"
class InstalledFile;
*/
class Copy: public Tool
{
-private:
- /**
- A worker thread that actually does the data transfer.
- */
- class Worker: public InternalTask::Worker
- {
- private:
- const InstalledFile ⌖
-
- public:
- Worker(const InstalledFile &t): target(t) { }
- private:
- void main() override;
- };
-
public:
Copy(Builder &b): Tool(b, "CP") { }
Target *create_target(const std::vector<Target *> &, const std::string &) override;
Task *run(const Target &) const override;
+
+private:
+ static bool _run(const InstalledFile &);
};
#endif
InternalTask::~InternalTask()
{
- worker->join();
- delete worker;
+ worker.join();
}
void InternalTask::start()
{
prepare();
- worker->launch();
+ worker.launch();
}
Task::Status InternalTask::check()
{
- Status result = worker->get_status();
+ Status result = worker.get_status();
if(result!=RUNNING)
signal_finished.emit(result==SUCCESS);
return result;
while((result = check())==RUNNING) ;
return result;
}
+
+
+void InternalTask::Worker::main()
+{
+ if(func())
+ status = Task::SUCCESS;
+ else
+ status = Task::ERROR;
+}
#ifndef INTERNALTASK_H_
#define INTERNALTASK_H_
+#include <functional>
#include <msp/core/thread.h>
#include "task.h"
*/
class InternalTask: public Task
{
-public:
+private:
class Worker: public Msp::Thread
{
friend class InternalTask;
- protected:
+ private:
+ std::function<bool()> func;
volatile Status status = Task::RUNNING;
- Worker() = default;
-
public:
+ Worker(std::function<bool()> f): func(f) { }
+
Status get_status() const { return status; }
+
+ private:
+ void main() override;
};
-private:
- Worker *worker;
+ Worker worker;
public:
- InternalTask(Worker *w): worker(w) { }
+ InternalTask(std::function<bool()> f): worker(f) { }
~InternalTask();
std::string get_command() const override { return "<internal>"; }
#include <msp/io/file.h>
#include <msp/io/print.h>
#include "builder.h"
+#include "internaltask.h"
#include "pkgconfigfile.h"
#include "pkgconfiggenerator.h"
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());
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)
{
#ifndef PKGCONFIGGENERATOR_H_
#define PKGCONFIGGENERATOR_H_
-#include "internaltask.h"
#include "tool.h"
class PkgConfigFile;
class PkgConfigGenerator: public Tool
{
-private:
- class Worker: public InternalTask::Worker
- {
- private:
- const PkgConfigFile ⌖
-
- public:
- Worker(const PkgConfigFile &t): target(t) { }
-
- private:
- void main() override;
-
- std::string prefixify(const Msp::FS::Path &, const Msp::FS::Path &);
- };
-
public:
PkgConfigGenerator(Builder &b): Tool(b, "PCG") { }
Target *create_target(const std::vector<Target *> &, const std::string &) override;
Task *run(const Target &) const override;
+
+private:
+ static bool _run(const PkgConfigFile &);
+ static std::string prefixify(const Msp::FS::Path &, const Msp::FS::Path &);
};
#endif
#include <msp/io/file.h>
#include <msp/io/print.h>
#include "builder.h"
+#include "internaltask.h"
#include "sourcepackage.h"
#include "tar.h"
#include "tarball.h"
Task *Tar::run(const Target &target) const
{
const TarBall &tarball = dynamic_cast<const TarBall &>(target);
- Worker *worker = new Worker(tarball);
- return new InternalTask(worker);
+ return new InternalTask([&tarball]{ return _run(tarball); });
}
-
-Tar::Worker::Worker(const TarBall &tb):
- tarball(tb)
-{ }
-
-void Tar::Worker::main()
+bool Tar::_run(const TarBall &tarball)
{
const FS::Path &pkg_src = tarball.get_package()->get_source_directory();
FS::Path basedir = FS::basepart(FS::basename(tarball.get_path()));
if(rel_path.size()>99)
{
IO::print("Can't store %s in tar archive - too long name\n", rel_path);
- status = Task::ERROR;
- return;
+ return false;
}
memcpy(buf, rel_path.data(), rel_path.size());
}
}
- status = Task::SUCCESS;
+ return true;
}
-void Tar::Worker::store_number(char *buf, unsigned value, unsigned length)
+void Tar::store_number(char *buf, unsigned value, unsigned length)
{
for(unsigned i=length; i--;)
{
#ifndef TAR_H_
#define TAR_H_
-#include <msp/core/thread.h>
-#include "internaltask.h"
#include "tool.h"
class TarBall;
class Tar: public Tool
{
-private:
- class Worker: public InternalTask::Worker
- {
- private:
- const TarBall &tarball;
-
- public:
- Worker(const TarBall &);
-
- private:
- void main() override;
- void store_number(char *, unsigned, unsigned);
- };
-
public:
Tar(Builder &);
Target *create_target(const std::vector<Target *> &, const std::string &) override;
Task *run(const Target &) const override;
+
+private:
+ static bool _run(const TarBall &);
+ static void store_number(char *, unsigned, unsigned);
};
#endif
#include "builder.h"
#include "csourcefile.h"
#include "executable.h"
+#include "internaltask.h"
#include "sourcepackage.h"
#include "vcxprojectfile.h"
#include "vcxprojectgenerator.h"
Task *VcxProjectGenerator::run(const Target &target) const
{
const VcxProjectFile &project = dynamic_cast<const VcxProjectFile &>(target);
- Worker *worker = new Worker(project);
- return new InternalTask(worker);
+ return new InternalTask([&project]{ return _run(project); });
}
-
-void VcxProjectGenerator::Worker::main()
+bool VcxProjectGenerator::_run(const VcxProjectFile &project)
{
- const SourcePackage &spkg = *target.get_package();
+ const SourcePackage &spkg = *project.get_package();
Builder &builder = spkg.get_builder();
- IO::BufferedFile out(target.get_path().str(), IO::M_WRITE);
+ IO::BufferedFile out(project.get_path().str(), IO::M_WRITE);
IO::print(out, "<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
IO::print(out, "\t<ItemGroup Label=\"ProjectConfigurations\">\n");
IO::print(out, "\t<PropertyGroup Label=\"Globals\">\n");
IO::print(out, "\t\t<VCProjectVersion>15.0</VCProjectVersion>\n");
IO::print(out, "\t\t<Keyword>MakeFileProj</Keyword>\n");
- IO::print(out, "\t\t<ProjectGuid>{%s}</ProjectGuid>\n", target.get_guid());
+ IO::print(out, "\t\t<ProjectGuid>{%s}</ProjectGuid>\n", project.get_guid());
IO::print(out, "\t</PropertyGroup>\n");
IO::print(out, "\t<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n");
IO::print(out, "\t<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n");
IO::print(out, "</Project>\n");
- status = Task::SUCCESS;
+ return true;
}
#ifndef VCXPROJECTGENERATOR_H_
#define VCXPROJECTGENERATOR_H_
-#include "internaltask.h"
#include "tool.h"
class VcxProjectFile;
class VcxProjectGenerator: public Tool
{
-private:
- class Worker: public InternalTask::Worker
- {
- private:
- const VcxProjectFile ⌖
-
- public:
- Worker(const VcxProjectFile &t): target(t) { }
-
- private:
- void main() override;
- };
-
public:
VcxProjectGenerator(Builder &b): Tool(b, "VCXG") { }
Target *create_target(const std::vector<Target *> &, const std::string &) override;
Task *run(const Target &) const override;
+
+private:
+ static bool _run(const VcxProjectFile &);
};
#endif
#include <msp/io/file.h>
#include <msp/io/print.h>
#include "builder.h"
+#include "internaltask.h"
#include "sourcepackage.h"
#include "vcxprojectfile.h"
#include "vssolutionfile.h"
Task *VsSolutionGenerator::run(const Target &target) const
{
const VsSolutionFile &solution = dynamic_cast<const VsSolutionFile &>(target);
- Worker *worker = new Worker(solution);
- return new InternalTask(worker);
+ return new InternalTask([&solution]{ return _run(solution); });
}
-
-void VsSolutionGenerator::Worker::main()
+bool VsSolutionGenerator::_run(const VsSolutionFile &solution)
{
- const SourcePackage &spkg = *target.get_package();
+ const SourcePackage &spkg = *solution.get_package();
Builder &builder = spkg.get_builder();
- IO::BufferedFile out(target.get_path().str(), IO::M_WRITE);
+ IO::BufferedFile out(solution.get_path().str(), IO::M_WRITE);
IO::print(out, "Microsoft Visual Studio Solution File, Format Version 12.00\n");
IO::print(out, "MinimumVisualStudioVersion = 10.0.40219.1\n");
vector<const VcxProjectFile *> projects;
- for(const Target *t: target.get_dependencies())
+ for(const Target *t: solution.get_dependencies())
if(const VcxProjectFile *project = dynamic_cast<const VcxProjectFile *>(t))
projects.push_back(project);
IO::print(out, "\tEndGlobalSection\n");
IO::print(out, "EndGlobal\n");
- status = Task::SUCCESS;
+ return true;
}
#ifndef VSSOLUTIONGENERATOR_H_
#define VSSOLUTIONGENERATOR_H_
-#include "internaltask.h"
#include "tool.h"
class VsSolutionFile;
class VsSolutionGenerator: public Tool
{
-private:
- class Worker: public InternalTask::Worker
- {
- private:
- const VsSolutionFile ⌖
-
- public:
- Worker(const VsSolutionFile &t): target(t) { }
-
- private:
- void main() override;
- };
-
public:
VsSolutionGenerator(Builder &b): Tool(b, "VSSG") { }
Target *create_target(const std::vector<Target *> &, const std::string &) override;
Task *run(const Target &) const override;
+
+private:
+ static bool _run(const VsSolutionFile &);
};
#endif