diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2022-05-29 14:55:51 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2022-06-09 22:15:32 +0200 |
commit | b74bd9e24e1205b7449404fd05172664b211d82c (patch) | |
tree | af69d4efbdddee347cd82c774880efa6820a0aa2 /src | |
parent | 15eea63a6e7da37e7b4d643f189e6de150268ff8 (diff) |
Make all task lists std::set instead of std::list to make sure to not contain duplicates.
Diffstat (limited to 'src')
-rw-r--r-- | src/build.cc | 21 | ||||
-rw-r--r-- | src/build.h | 10 | ||||
-rw-r--r-- | src/task.cc | 6 | ||||
-rw-r--r-- | src/task.h | 8 | ||||
-rw-r--r-- | src/tasks.cc | 41 | ||||
-rw-r--r-- | src/tasks.h | 18 | ||||
-rw-r--r-- | src/unittest.cc | 2 | ||||
-rw-r--r-- | src/unittest.h | 4 |
8 files changed, 56 insertions, 54 deletions
diff --git a/src/build.cc b/src/build.cc index 8adbc54..b0b4d06 100644 --- a/src/build.cc +++ b/src/build.cc @@ -9,13 +9,14 @@ #include <chrono> #include <set> #include <thread> +#include <list> 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) @@ -23,12 +24,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); } } @@ -155,7 +156,7 @@ 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}; @@ -172,10 +173,10 @@ int build(const Settings& settings, 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); @@ -200,11 +201,11 @@ 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) { @@ -218,7 +219,7 @@ int build(const Settings& settings, auto depSet = getDepTasks(task); for(const auto& task : depSet) { - ts.push_back(task); + ts.insert(task); } } } diff --git a/src/build.h b/src/build.h index 7be7517..f3a1419 100644 --- a/src/build.h +++ b/src/build.h @@ -4,7 +4,7 @@ #pragma once #include <string> -#include <list> +#include <set> #include <memory> #include "task.h" @@ -14,19 +14,19 @@ //! Dry-run returns number of dirty tasks but otherwise does nothing. 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 = false); //! Dry-run returns number of dirty tasks but otherwise does nothing. 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 = false); //! Dry-run returns number of dirty tasks but otherwise does nothing. 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 = false); diff --git a/src/task.cc b/src/task.cc index 8a9eefa..b8fce06 100644 --- a/src/task.cc +++ b/src/task.cc @@ -12,7 +12,7 @@ Task::Task(const BuildConfiguration& config) { } -int Task::registerDepTasks(const std::list<std::shared_ptr<Task>>& tasks) +int Task::registerDepTasks(const std::set<std::shared_ptr<Task>>& tasks) { for(const auto& depStr : depends()) { @@ -21,7 +21,7 @@ int Task::registerDepTasks(const std::list<std::shared_ptr<Task>>& tasks) { if(task->target() == depStr) { - dependsTasks.push_back(task); + dependsTasks.insert(task); found = true; } } @@ -146,7 +146,7 @@ std::string Task::compiler() const } } -std::list<std::shared_ptr<Task>> Task::getDependsTasks() +std::set<std::shared_ptr<Task>> Task::getDependsTasks() { return dependsTasks; } @@ -6,7 +6,7 @@ #include <vector> #include <string> #include <atomic> -#include <list> +#include <set> #include <memory> #include "libctor.h" @@ -25,7 +25,7 @@ class Task public: Task(const BuildConfiguration& config); - int registerDepTasks(const std::list<std::shared_ptr<Task>>& tasks); + int registerDepTasks(const std::set<std::shared_ptr<Task>>& tasks); virtual std::string name() const; bool dirty(); @@ -52,7 +52,7 @@ public: OutputSystem outputSystem() const; std::string compiler() const; - std::list<std::shared_ptr<Task>> getDependsTasks(); + std::set<std::shared_ptr<Task>> getDependsTasks(); virtual std::string source() const { return {}; } @@ -62,7 +62,7 @@ protected: virtual bool dirtyInner() { return false; } std::vector<std::string> dependsStr; - std::list<std::shared_ptr<Task>> dependsTasks; + std::set<std::shared_ptr<Task>> dependsTasks; const BuildConfiguration& config; TargetType target_type{TargetType::Auto}; Language source_language{Language::Auto}; diff --git a/src/tasks.cc b/src/tasks.cc index 8ab296f..8bb8de6 100644 --- a/src/tasks.cc +++ b/src/tasks.cc @@ -5,6 +5,7 @@ #include <filesystem> #include <deque> +#include <list> #include <iostream> #include <algorithm> @@ -76,9 +77,9 @@ const std::deque<Target>& getTargets(const Settings& settings, return targets; } -std::list<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config, - const Settings& settings, - const std::string& sourceDir) +std::set<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config, + const Settings& settings, + const std::string& sourceDir) { std::filesystem::path targetFile(config.target); @@ -106,12 +107,12 @@ std::list<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config, } std::vector<std::string> objects; - std::list<std::shared_ptr<Task>> tasks; + std::set<std::shared_ptr<Task>> tasks; for(const auto& file : config.sources) { - tasks.emplace_back(std::make_shared<TaskCC>(config, settings, - sourceDir, file)); - objects.push_back(tasks.back()->target()); + auto task = std::make_shared<TaskCC>(config, settings, sourceDir, file); + tasks.insert(task); + objects.push_back(task->target()); } switch(target_type) @@ -121,8 +122,8 @@ std::list<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config, break; case TargetType::StaticLibrary: - tasks.emplace_back(std::make_shared<TaskAR>(config, settings, config.target, - objects, sourceDir)); + tasks.insert(std::make_shared<TaskAR>(config, settings, config.target, + objects, sourceDir)); break; #ifndef BOOTSTRAP case TargetType::DynamicLibrary: @@ -132,14 +133,14 @@ std::list<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config, std::cerr << "Dynamic library target must have 'lib' prefix\n"; exit(1); } - tasks.emplace_back(std::make_shared<TaskSO>(config, settings, config.target, - objects, sourceDir)); + tasks.insert(std::make_shared<TaskSO>(config, settings, config.target, + objects, sourceDir)); break; case TargetType::Executable: case TargetType::UnitTest: - tasks.emplace_back(std::make_shared<TaskLD>(config, settings, config.target, - objects, sourceDir)); + tasks.insert(std::make_shared<TaskLD>(config, settings, config.target, + objects, sourceDir)); break; case TargetType::Object: @@ -153,8 +154,8 @@ std::list<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config, return tasks; } -std::shared_ptr<Task> getNextTask(const std::list<std::shared_ptr<Task>>& allTasks, - std::list<std::shared_ptr<Task>>& dirtyTasks) +std::shared_ptr<Task> getNextTask(const std::set<std::shared_ptr<Task>>& allTasks, + std::set<std::shared_ptr<Task>>& dirtyTasks) { for(auto dirtyTask = dirtyTasks.begin(); dirtyTask != dirtyTasks.end(); @@ -172,12 +173,12 @@ std::shared_ptr<Task> getNextTask(const std::list<std::shared_ptr<Task>>& allTas return nullptr; } -std::list<std::shared_ptr<Task>> getTasks(const Settings& settings, - const std::vector<std::string> names, - bool resolve_externals) +std::set<std::shared_ptr<Task>> getTasks(const Settings& settings, + const std::vector<std::string> names, + bool resolve_externals) { auto& targets = getTargets(settings, resolve_externals); - std::list<std::shared_ptr<Task>> tasks; + std::set<std::shared_ptr<Task>> tasks; for(const auto& target : targets) { if(names.empty() || @@ -185,7 +186,7 @@ std::list<std::shared_ptr<Task>> getTasks(const Settings& settings, { std::vector<std::string> objects; auto t = taskFactory(target.config, settings, target.path); - tasks.insert(tasks.end(), t.begin(), t.end()); + tasks.insert(t.begin(), t.end()); } } diff --git a/src/tasks.h b/src/tasks.h index f2a77d4..c547432 100644 --- a/src/tasks.h +++ b/src/tasks.h @@ -4,7 +4,7 @@ #pragma once #include <string> -#include <list> +#include <set> #include <memory> #include <deque> @@ -27,17 +27,17 @@ const std::deque<Target>& getTargets(const Settings& settings, //! fulfilled. //! The returned task is removed from the dirty list. //! Return nullptr if no dirty task is ready. -std::shared_ptr<Task> getNextTask(const std::list<std::shared_ptr<Task>>& allTasks, - std::list<std::shared_ptr<Task>>& dirtyTasks); +std::shared_ptr<Task> getNextTask(const std::set<std::shared_ptr<Task>>& allTasks, + std::set<std::shared_ptr<Task>>& dirtyTasks); //! Get list of tasks filtered by name including each of their direct //! dependency tasks (ie. objects tasks from their sources). -std::list<std::shared_ptr<Task>> getTasks(const Settings& settings, - const std::vector<std::string> names = {}, - bool resolve_externals = true); +std::set<std::shared_ptr<Task>> getTasks(const Settings& settings, + const std::vector<std::string> names = {}, + bool resolve_externals = true); //! Generate list of targets from a single configuration, including the final //! link target and all its objects files (if any). -std::list<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config, - const Settings& settings, - const std::string& sourceDir); +std::set<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config, + const Settings& settings, + const std::string& sourceDir); diff --git a/src/unittest.cc b/src/unittest.cc index ade2d0a..d02e4f2 100644 --- a/src/unittest.cc +++ b/src/unittest.cc @@ -9,7 +9,7 @@ #include "settings.h" #include "task.h" -int runUnitTests(std::list<std::shared_ptr<Task>>& tasks, +int runUnitTests(std::set<std::shared_ptr<Task>>& tasks, const Settings& settings) { bool ok{true}; diff --git a/src/unittest.h b/src/unittest.h index 7eef0e2..8dee33c 100644 --- a/src/unittest.h +++ b/src/unittest.h @@ -3,11 +3,11 @@ // See accompanying file LICENSE for details. #pragma once -#include <list> +#include <set> #include <memory> class Task; class Settings; -int runUnitTests(std::list<std::shared_ptr<Task>>& tasks, +int runUnitTests(std::set<std::shared_ptr<Task>>& tasks, const Settings& settings); |