From cb5f269b13429f0e1ffbc41426227983e5ccaeba Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 20 Sep 2021 17:31:54 +0200 Subject: Simplify/fix task dependency calculation. And tasks unit-tests. --- src/task.cc | 8 +++----- src/task.h | 3 +-- src/task_ar.cc | 15 +-------------- src/task_ld.cc | 15 +-------------- src/task_so.cc | 15 +-------------- src/tasks.h | 8 ++++++++ 6 files changed, 15 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/task.cc b/src/task.cc index 962a02b..4cdfa5e 100644 --- a/src/task.cc +++ b/src/task.cc @@ -3,17 +3,15 @@ #include #include -Task::Task(const BuildConfiguration& config, - const std::vector& depends) - : dependsStr(depends) - , config(config) +Task::Task(const BuildConfiguration& config) + : config(config) , output_system(config.system) { } int Task::registerDepTasks(const std::list>& tasks) { - for(auto const& depStr : dependsStr) + for(const auto& depStr : depends()) { bool found{false}; for(const auto& task : tasks) diff --git a/src/task.h b/src/task.h index acbefb3..4461612 100644 --- a/src/task.h +++ b/src/task.h @@ -21,8 +21,7 @@ enum class State class Task { public: - Task(const BuildConfiguration& config, - const std::vector& depends = {}); + Task(const BuildConfiguration& config); int registerDepTasks(const std::list>& tasks); diff --git a/src/task_ar.cc b/src/task_ar.cc index 980d8b4..51d609e 100644 --- a/src/task_ar.cc +++ b/src/task_ar.cc @@ -22,26 +22,13 @@ std::string readFile(const std::string &fileName) return std::string(bytes.data(), fileSize); } - -std::vector addPrefix(const std::vector& lst, - const Settings& settings) -{ - std::vector out; - for(const auto& item : lst) - { - std::filesystem::path file = settings.builddir; - file /= item; - out.push_back(file.string()); - } - return out; -} } // namespace :: TaskAR::TaskAR(const BuildConfiguration& config, const Settings& settings, const std::string& target, const std::vector& objects) - : Task(config, addPrefix(config.depends, settings)) + : Task(config) , config(config) , settings(settings) { diff --git a/src/task_ld.cc b/src/task_ld.cc index ec68190..4eb64f4 100644 --- a/src/task_ld.cc +++ b/src/task_ld.cc @@ -21,26 +21,13 @@ std::string readFile(const std::string &fileName) return std::string(bytes.data(), fileSize); } - -std::vector addPrefix(const std::vector& lst, - const Settings& settings) -{ - std::vector out; - for(const auto& item : lst) - { - std::filesystem::path file = settings.builddir; - file /= item; - out.push_back(file.string()); - } - return out; -} } // namespace :: TaskLD::TaskLD(const BuildConfiguration& config, const Settings& settings, const std::string& target, const std::vector& objects) - : Task(config, addPrefix(config.depends, settings)) + : Task(config) , config(config) , settings(settings) { diff --git a/src/task_so.cc b/src/task_so.cc index ca7883f..519085a 100644 --- a/src/task_so.cc +++ b/src/task_so.cc @@ -21,26 +21,13 @@ std::string readFile(const std::string &fileName) return std::string(bytes.data(), fileSize); } - -std::vector addPrefix(const std::vector& lst, - const Settings& settings) -{ - std::vector out; - for(const auto& item : lst) - { - std::filesystem::path file = settings.builddir; - file /= item; - out.push_back(file.string()); - } - return out; -} } // namespace :: TaskSO::TaskSO(const BuildConfiguration& config, const Settings& settings, const std::string& target, const std::vector& objects) - : Task(config, addPrefix(config.depends, settings)) + : Task(config) , config(config) , settings(settings) { diff --git a/src/tasks.h b/src/tasks.h index e5d1daf..c5b326e 100644 --- a/src/tasks.h +++ b/src/tasks.h @@ -17,9 +17,17 @@ struct Target std::string path; }; +//! Get list of all registered targets const std::deque& getTargets(const Settings& settings); +//! Returns next dirty task from the dirtyTasks list that has all its dependencies +//! fulfilled. +//! The returned task is removed from the dirty list. +//! Return nullptr if no dirty task is ready. std::shared_ptr getNextTask(const std::list>& allTasks, std::list>& dirtyTasks); + +//! Get list of tasks filtered by name including each of their direct +//! dependency tasks (ie. objects tasks from their sources). std::list> getTasks(const Settings& settings, const std::vector names = {}); -- cgit v1.2.3