From 0008920eed996009068fe9f71512c436577b6220 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 2 Oct 2024 21:20:40 +0200 Subject: Ensure the initial task order is preserved. Fixes bad ordering during linking. --- src/tasks.cc | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'src/tasks.cc') diff --git a/src/tasks.cc b/src/tasks.cc index 22ad2d6..61c130b 100644 --- a/src/tasks.cc +++ b/src/tasks.cc @@ -70,11 +70,11 @@ const std::deque& getTargets(const ctor::settings& settings, return targets; } -std::set> taskFactory(const ctor::build_configuration& config, - const ctor::settings& settings, - const std::string& sourceDir) +std::vector> taskFactory(const ctor::build_configuration& config, + const ctor::settings& settings, + const std::string& sourceDir) { - std::set> tasks; + std::vector> tasks; std::filesystem::path targetFile(config.target); @@ -97,7 +97,7 @@ std::set> taskFactory(const ctor::build_configuration& con for(const auto& file : config.sources) { auto task = std::make_shared(config, settings, sourceDir, file); - tasks.insert(task); + tasks.push_back(task); objects.push_back(task->targetFile().string()); } } @@ -107,7 +107,7 @@ std::set> taskFactory(const ctor::build_configuration& con for(const auto& file : config.sources) { auto task = std::make_shared(config, settings, sourceDir, file); - tasks.insert(task); + tasks.push_back(task); objects.push_back(task->target()); } } @@ -127,8 +127,8 @@ std::set> taskFactory(const ctor::build_configuration& con case ctor::target_type::static_library: case ctor::target_type::unit_test_library: - tasks.insert(std::make_shared(config, settings, config.target, - objects, sourceDir)); + tasks.push_back(std::make_shared(config, settings, config.target, + objects, sourceDir)); break; #ifndef BOOTSTRAP case ctor::target_type::dynamic_library: @@ -138,14 +138,14 @@ std::set> taskFactory(const ctor::build_configuration& con std::cerr << "Dynamic library target must have 'lib' prefix\n"; exit(1); } - tasks.insert(std::make_shared(config, settings, config.target, - objects, sourceDir)); + tasks.push_back(std::make_shared(config, settings, config.target, + objects, sourceDir)); break; case ctor::target_type::executable: case ctor::target_type::unit_test: - tasks.insert(std::make_shared(config, settings, config.target, - objects, sourceDir)); + tasks.push_back(std::make_shared(config, settings, config.target, + objects, sourceDir)); break; case ctor::target_type::object: @@ -160,18 +160,19 @@ std::set> taskFactory(const ctor::build_configuration& con return tasks; } -std::shared_ptr getNextTask(const std::set>& allTasks, - std::set>& dirtyTasks) +std::shared_ptr getNextTask(const std::vector>& allTasks, + std::vector>& dirtyTasks) { for(auto dirtyTask = dirtyTasks.begin(); dirtyTask != dirtyTasks.end(); ++dirtyTask) { + auto task = *dirtyTask; //std::cout << "Examining target " << (*dirtyTask)->target() << "\n"; - if((*dirtyTask)->ready()) + if(task->ready()) { dirtyTasks.erase(dirtyTask); - return *dirtyTask; + return task; } } @@ -179,12 +180,12 @@ std::shared_ptr getNextTask(const std::set>& allTask return nullptr; } -std::set> getTasks(const ctor::settings& settings, - const std::vector names, - bool resolve_externals) +std::vector> getTasks(const ctor::settings& settings, + const std::vector names, + bool resolve_externals) { auto& targets = getTargets(settings, resolve_externals); - std::set> tasks; + std::vector> tasks; for(const auto& target : targets) { if(names.empty() || @@ -192,7 +193,7 @@ std::set> getTasks(const ctor::settings& settings, { std::vector objects; auto t = taskFactory(target.config, settings, target.path); - tasks.insert(t.begin(), t.end()); + tasks.insert(tasks.end(), t.begin(), t.end()); } } -- cgit v1.2.3