diff options
Diffstat (limited to 'src/build.cc')
-rw-r--r-- | src/build.cc | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/src/build.cc b/src/build.cc index 8adbc54..ad30719 100644 --- a/src/build.cc +++ b/src/build.cc @@ -9,13 +9,16 @@ #include <chrono> #include <set> #include <thread> +#include <list> + +#include "ctor.h" using namespace std::chrono_literals; -int build(const Settings& settings, +int build(const ctor::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) @@ -23,12 +26,12 @@ int build(const Settings& settings, 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); } } @@ -81,7 +84,9 @@ 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(); @@ -103,13 +108,9 @@ int build(const Settings& settings, break; } - if(started_one) - { - std::this_thread::sleep_for(2ms); - } - 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); } } @@ -153,29 +154,23 @@ std::set<std::shared_ptr<Task>> getDepTasks(std::shared_ptr<Task> task) } } -int build(const Settings& settings, +int build(const ctor::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->target() == name || // match exact target output (ex. build/foo.o) - - (!task->derived() && // if non-derived task: - ( task->buildConfig().target == name || // match name - task->buildConfig().name == name ) // or target - ) - ) + if(*task == name) { 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, dryrun); @@ -197,14 +192,14 @@ int build(const Settings& settings, return 0; } -int build(const Settings& settings, +int build(const ctor::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) { @@ -218,7 +213,7 @@ int build(const Settings& settings, auto depSet = getDepTasks(task); for(const auto& task : depSet) { - ts.push_back(task); + ts.insert(task); } } } |