diff --git a/libmamba/include/mamba/core/solver.hpp b/libmamba/include/mamba/core/solver.hpp index f494623bcd..bb53e4d299 100644 --- a/libmamba/include/mamba/core/solver.hpp +++ b/libmamba/include/mamba/core/solver.hpp @@ -57,6 +57,7 @@ namespace mamba MSolver(MSolver&&) = delete; MSolver& operator=(MSolver&&) = delete; + void add_implicit_jobs(); void add_global_job(int job_flag); void add_jobs(const std::vector& jobs, int job_flag); void add_constraint(const std::string& job); diff --git a/libmamba/src/core/solver.cpp b/libmamba/src/core/solver.cpp index b4c7bcdd94..5b1777037b 100644 --- a/libmamba/src/core/solver.cpp +++ b/libmamba/src/core/solver.cpp @@ -14,6 +14,13 @@ #include "mamba/core/repo.hpp" #include "mamba/core/util.hpp" +extern "C" +{ +#include "solv/selection.h" +#include "solv/conda.h" +#include +} + namespace mamba { std::string MSolverProblem::to_string() const @@ -89,6 +96,48 @@ namespace mamba return false; } + std::vector find_latest(Pool* pool, const std::string& query) + { + Queue job, solvables; + queue_init(&job); + queue_init(&solvables); + + Id id = pool_conda_matchspec(pool, query.c_str()); + if (id) + { + queue_push2(&job, SOLVER_SOLVABLE_PROVIDES, id); + } + else + { + LOG_ERROR << "Could not generate query" << std::endl; + throw std::runtime_error("Could not generate query for " + query); + } + + selection_solvables(pool, &job, &solvables); + + std::vector result; + LOG_ERROR << "Found " << solvables.count << std::endl; + + for (int i = 0; i < solvables.count; ++i) + { + result.push_back(pool_id2solvable(pool, solvables.elements[i])); + } + + std::sort(result.begin(), + result.end(), + [pool](auto a, auto b) -> int + { + // LOG_ERROR << "EVR COMP " << std::endl; + + return pool_evrcmp(pool, a->evr, b->evr, EVRCMP_COMPARE) > 0; + }); + + queue_free(&job); + queue_free(&solvables); + + return result; + } + void MSolver::add_global_job(int job_flag) { queue_push2(&m_jobs, job_flag, 0); @@ -183,6 +232,27 @@ namespace mamba queue_push2(&m_jobs, job_flag | SOLVER_SOLVABLE_PROVIDES, inst_id); } + void MSolver::add_implicit_jobs() + { + LOG_ERROR << "Adding implicit jobs!" << std::endl; + for (const auto& install_spec : m_install_specs) + { + auto res = find_latest(m_pool, install_spec.str()); + if (res.size()) + { + auto latest = pool_id2str(m_pool, res[0]->evr); + + std::string version = install_spec.name + " " + latest; + LOG_ERROR << "Adding latest version " << version << std::endl; + + // LOG_INFO << "Adding job: " << ms.conda_build_form(); + + Id inst_id = pool_conda_matchspec(reinterpret_cast(m_pool), version.c_str()); + queue_push2(&m_jobs, SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES, inst_id); + } + } + } + void MSolver::add_jobs(const std::vector& jobs, int job_flag) { for (const auto& job : jobs) @@ -393,6 +463,7 @@ namespace mamba bool MSolver::solve() { bool success; + add_implicit_jobs(); m_solver = solver_create(m_pool); set_flags(m_flags);