summaryrefslogtreecommitdiff
path: root/src/task.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/task.cc')
-rw-r--r--src/task.cc146
1 files changed, 146 insertions, 0 deletions
diff --git a/src/task.cc b/src/task.cc
new file mode 100644
index 0000000..962a02b
--- /dev/null
+++ b/src/task.cc
@@ -0,0 +1,146 @@
+#include "task.h"
+
+#include <unistd.h>
+#include <iostream>
+
+Task::Task(const BuildConfiguration& config,
+ const std::vector<std::string>& depends)
+ : dependsStr(depends)
+ , config(config)
+ , output_system(config.system)
+{
+}
+
+int Task::registerDepTasks(const std::list<std::shared_ptr<Task>>& tasks)
+{
+ for(auto const& depStr : dependsStr)
+ {
+ bool found{false};
+ for(const auto& task : tasks)
+ {
+ if(task->target() == depStr)
+ {
+ dependsTasks.push_back(task);
+ found = true;
+ }
+ }
+ if(!found)
+ {
+ std::cerr << "Could not find dependency " << depStr << " needed by " <<
+ target() << " target\n";
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+std::string Task::name() const
+{
+ return config.target;
+}
+
+bool Task::dirty()
+{
+ for(const auto& task : dependsTasks)
+ {
+ if(task->dirty())
+ {
+ return true;
+ }
+ }
+
+ return dirtyInner();
+}
+
+bool Task::ready()
+{
+ for(const auto& task : dependsTasks)
+ {
+ if(task->dirty() || task->state() == State::Running)
+ {
+ return false;
+ }
+ }
+
+ task_state.store(State::Ready);
+ return true;
+}
+
+int Task::run()
+{
+ if(task_state.load() == State::Done)
+ {
+ return 0;
+ }
+
+ task_state.store(State::Running);
+ auto ret = runInner();
+ if(ret == 0)
+ {
+ task_state.store(State::Done);
+ }
+ else
+ {
+ task_state.store(State::Error);
+ }
+
+ return ret;
+}
+
+State Task::state() const
+{
+ return task_state.load();
+}
+
+const BuildConfiguration& Task::buildConfig() const
+{
+ return config;
+}
+
+TargetType Task::targetType() const
+{
+ return target_type;
+}
+
+Language Task::sourceLanguage() const
+{
+ return source_language;
+}
+
+OutputSystem Task::outputSystem() const
+{
+ return output_system;
+}
+
+std::string Task::compiler() const
+{
+ switch(sourceLanguage())
+ {
+ case Language::C:
+ switch(outputSystem())
+ {
+ case OutputSystem::Host:
+ return getConfiguration(cfg::host_cc, "/usr/bin/gcc");
+ case OutputSystem::Build:
+ return getConfiguration(cfg::build_cc, "/usr/bin/gcc");
+ }
+ case Language::Cpp:
+ switch(outputSystem())
+ {
+ case OutputSystem::Host:
+ return getConfiguration(cfg::host_cxx, "/usr/bin/g++");
+ case OutputSystem::Build:
+ return getConfiguration(cfg::build_cxx, "/usr/bin/g++");
+ }
+ default:
+ std::cerr << "Unknown CC target type\n";
+ exit(1);
+ break;
+ }
+}
+
+std::list<std::shared_ptr<Task>> Task::getDependsTasks()
+{
+ return dependsTasks;
+}