diff options
Diffstat (limited to 'src/build.cc')
-rw-r--r-- | src/build.cc | 87 |
1 files changed, 53 insertions, 34 deletions
diff --git a/src/build.cc b/src/build.cc index 1b70c5b..98952e0 100644 --- a/src/build.cc +++ b/src/build.cc @@ -9,31 +9,44 @@ #include <chrono> #include <set> #include <thread> +#include <list> + +#include "libctor.h" using namespace std::chrono_literals; int build(const Settings& settings, const std::string& name, - const std::list<std::shared_ptr<Task>>& tasks, - const std::list<std::shared_ptr<Task>>& all_tasks) + const std::set<std::shared_ptr<Task>>& tasks, + const std::set<std::shared_ptr<Task>>& all_tasks, + bool dryrun) { if(settings.verbose > 1) { std::cout << "Building '" << name << "'\n"; } - std::list<std::shared_ptr<Task>> dirtyTasks; + std::set<std::shared_ptr<Task>> dirtyTasks; for(auto task : tasks) { if(task->dirty()) { - dirtyTasks.push_back(task); + dirtyTasks.insert(task); } } + // Dry-run returns number of dirty tasks but otherwise does nothing. + if(dryrun) + { + return dirtyTasks.size(); + } + if(dirtyTasks.empty()) { - std::cout << "Nothing to be done for '"<< name << "'\n"; + if(settings.verbose > -1) + { + std::cout << "Nothing to be done for '"<< name << "'\n"; + } return 0; } @@ -71,32 +84,33 @@ int build(const Settings& settings, return task->run(); })); started_one = true; - std::this_thread::sleep_for(2ms); + // Make sure we don't start tasks on top of each other to prevent + // straining the disk. + std::this_thread::sleep_for(50ms); } for(auto process = processes.begin(); process != processes.end(); ++process) { - if(process->valid()) + if(process->valid() == false) { - if(process->get() != 0) - { - // TODO: Wait for other processes to finish before returning - return 1; - } - processes.erase(process); - break; + continue; } - } - if(started_one) - { - std::this_thread::sleep_for(2ms); + auto ret = process->get(); + if(ret != 0) + { + // NOTE Wait for other processes to finish before returning + return ret; + } + processes.erase(process); + break; } - else + + if(!started_one) // prevent polling too fast if no task is yet ready { - std::this_thread::sleep_for(200ms); + std::this_thread::sleep_for(10ms); } } @@ -104,11 +118,15 @@ int build(const Settings& settings, process != processes.end(); ++process) { + if(process->valid() == false) + { + continue; + } process->wait(); auto ret = process->get(); if(ret != 0) { - return 1; + return ret; } } @@ -138,23 +156,24 @@ std::set<std::shared_ptr<Task>> getDepTasks(std::shared_ptr<Task> task) int build(const Settings& settings, const std::string& name, - const std::list<std::shared_ptr<Task>>& all_tasks) + const std::set<std::shared_ptr<Task>>& all_tasks, + bool dryrun) { bool task_found{false}; for(auto task : all_tasks) { - if(task->name() == name || task->target() == name) + if(*task == name) { - std::cout << name << "\n"; task_found = true; auto depSet = getDepTasks(task); - std::list<std::shared_ptr<Task>> ts; + std::set<std::shared_ptr<Task>> ts; for(const auto& task : depSet) { - ts.push_back(task); + ts.insert(task); } - auto ret = build(settings, name, ts, all_tasks); + + auto ret = build(settings, name, ts, all_tasks, dryrun); if(ret != 0) { return ret; @@ -176,25 +195,25 @@ int build(const Settings& settings, int build(const Settings& settings, const std::string& name, const std::vector<Target>& targets, - const std::list<std::shared_ptr<Task>>& all_tasks) + const std::set<std::shared_ptr<Task>>& all_tasks, + bool dryrun) { bool task_found{false}; - std::list<std::shared_ptr<Task>> ts; + std::set<std::shared_ptr<Task>> ts; for(const auto& target : targets) { for(auto task : all_tasks) { - if(task->name() == target.config.target || - task->target() == target.config.target) + if(!task->derived() && // only consider non-derived tasks + task->buildConfig().target == target.config.target) { - std::cout << target.config.target << "\n"; task_found = true; auto depSet = getDepTasks(task); for(const auto& task : depSet) { - ts.push_back(task); + ts.insert(task); } } } @@ -206,5 +225,5 @@ int build(const Settings& settings, return 1; } - return build(settings, name, ts, all_tasks); + return build(settings, name, ts, all_tasks, dryrun); } |