From 86c7aa6f516bf6ed000f3eef26748997d6677c14 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 12 Sep 2021 13:06:39 +0200 Subject: Separate target list creation from task list creation. --- src/tasks.cc | 50 +++++++++++++++++++++++++++++++++----------------- src/tasks.h | 12 +++++++++--- 2 files changed, 42 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/tasks.cc b/src/tasks.cc index 2d8f46e..1607b37 100644 --- a/src/tasks.cc +++ b/src/tasks.cc @@ -13,6 +13,34 @@ #include "task_so.h" #include "rebuild.h" +const std::deque& getTargets(const Settings& settings) +{ + static bool initialised{false}; + static std::deque targets; + if(!initialised) + { + for(std::size_t i = 0; i < numConfigFiles; ++i) + { + std::string path = + std::filesystem::path(configFiles[i].file).parent_path().string(); + if(settings.verbose > 1) + { + std::cout << configFiles[i].file << " in path " << path << "\n"; + } + auto configs = configFiles[i].cb(); + for(const auto& config : configs) + { + targets.push_back({config, path}); + } + } + initialised = true; + } + + return targets; +} + +namespace +{ std::list> taskFactory(const BuildConfiguration& config, const Settings& settings, const std::string& sourceDir) @@ -105,25 +133,13 @@ std::shared_ptr getNextTask(const std::list>& allTas std::list> getTasks(const Settings& settings) { - static std::deque build_configs; + auto& targets = getTargets(settings); std::list> tasks; - for(std::size_t i = 0; i < numConfigFiles; ++i) + for(const auto& target : targets) { - std::string path = - std::filesystem::path(configFiles[i].file).parent_path().string(); - if(settings.verbose > 1) - { - std::cout << configFiles[i].file << " in path " << path << "\n"; - } - auto configs = configFiles[i].cb(); - for(const auto& config : configs) - { - build_configs.push_back(config); - const auto& build_config = build_configs.back(); - std::vector objects; - auto t = taskFactory(build_config, settings, path); - tasks.insert(tasks.end(), t.begin(), t.end()); - } + std::vector objects; + auto t = taskFactory(target.config, settings, target.path); + tasks.insert(tasks.end(), t.begin(), t.end()); } return tasks; diff --git a/src/tasks.h b/src/tasks.h index 119c7d6..04610e6 100644 --- a/src/tasks.h +++ b/src/tasks.h @@ -4,15 +4,21 @@ #include #include #include +#include #include "task.h" class BuildConfiguration; class Settings; -std::list> taskFactory(const BuildConfiguration& config, - const Settings& settings, - const std::string& sourceDir); +struct Target +{ + BuildConfiguration config; + std::string path; +}; + +const std::deque& getTargets(const Settings& settings); + std::shared_ptr getNextTask(const std::list>& allTasks, std::list>& dirtyTasks); std::list> getTasks(const Settings& settings); -- cgit v1.2.3