From 6d38011bb93451dd9da3294614d821c77ac91687 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 30 Mar 2011 17:23:43 +0200 Subject: add a first round of stuff needed for talking between APT and solvers based on a very early draft for EDSP by Stefano APT can now write a scenario as well as load most stuff from it. --- apt-pkg/algorithms.cc | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'apt-pkg/algorithms.cc') diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index 0b4366e5e..2ca3404a0 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -20,12 +20,15 @@ #include #include #include - +#include + #include #include #include #include #include + +#include /*}}}*/ using namespace std; @@ -731,7 +734,25 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg) return true; } /*}}}*/ -// ProblemResolver::Resolve - Run the resolution pass /*{{{*/ +// ProblemResolver::Resolve - calls a resolver to fix the situation /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool pkgProblemResolver::Resolve(bool BrokenFix) +{ + std::string const solver = _config->Find("APT::Solver::Name", "internal"); + if (solver != "internal") + { + FILE* output = fopen("/tmp/universe.log", "w"); + edspWriter::WriteUniverse(Cache, output); + fclose(output); + output = fopen("/tmp/request.log", "w"); + edspWriter::WriteRequest(Cache, output); + fclose(output); + } + return ResolveInternal(BrokenFix); +} + /*}}}*/ +// ProblemResolver::ResolveInternal - Run the resolution pass /*{{{*/ // --------------------------------------------------------------------- /* This routines works by calculating a score for each package. The score is derived by considering the package's priority and all reverse @@ -745,12 +766,10 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg) The BrokenFix flag enables a mode where the algorithm tries to upgrade packages to advoid problems. */ -bool pkgProblemResolver::Resolve(bool BrokenFix) +bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) { pkgDepCache::ActionGroup group(Cache); - unsigned long Size = Cache.Head().PackageCount; - // Record which packages are marked for install bool Again = false; do @@ -780,7 +799,9 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) clog << "Starting" << endl; MakeScores(); - + + unsigned long const Size = Cache.Head().PackageCount; + /* We have to order the packages so that the broken fixing pass operates from highest score to lowest. This prevents problems when high score packages cause the removal of lower score packages that -- cgit v1.2.3 From e3674d91d27a7290d2b01e14eb2540e10be9d883 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 30 Mar 2011 22:15:40 +0200 Subject: be able to write solutions, too --- apt-pkg/algorithms.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'apt-pkg/algorithms.cc') diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index 2ca3404a0..35752a5c4 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -748,6 +748,12 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) output = fopen("/tmp/request.log", "w"); edspWriter::WriteRequest(Cache, output); fclose(output); + if (ResolveInternal(BrokenFix) == false) + return false; + output = fopen("/tmp/solution.log", "w"); + edspWriter::WriteSolution(Cache, output); + fclose(output); + return true; } return ResolveInternal(BrokenFix); } -- cgit v1.2.3 From e0a78caad639a3fa8d50edf3374a06805ab86315 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 31 Mar 2011 11:58:24 +0200 Subject: rename the 'universe' to 'scenario' to reflect the naming in the draft --- apt-pkg/algorithms.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-pkg/algorithms.cc') diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index 35752a5c4..b55ff2897 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -742,8 +742,8 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) std::string const solver = _config->Find("APT::Solver::Name", "internal"); if (solver != "internal") { - FILE* output = fopen("/tmp/universe.log", "w"); - edspWriter::WriteUniverse(Cache, output); + FILE* output = fopen("/tmp/scenario.log", "w"); + edspWriter::WriteScenario(Cache, output); fclose(output); output = fopen("/tmp/request.log", "w"); edspWriter::WriteRequest(Cache, output); -- cgit v1.2.3 From c3b851268e6e900be2bf0bd715435db9010fd591 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 31 Mar 2011 15:10:13 +0200 Subject: =?UTF-8?q?rename=20edspwriter=20to=20straight=20edsp=20in=20tople?= =?UTF-8?q?vel=20as=20it=20does=20more=20than=20just=20writing=20stuff?= =?UTF-8?q?=E2=80=A6=20it=20also=20reads=20and=20can=20work=20for=20both:?= =?UTF-8?q?=20-=20APT=20talking=20to=20an=20external=20solver=20-=20an=20e?= =?UTF-8?q?xternal=20solver=20(understanding=20EDSP)=20talking=20to=20APT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apt-pkg/algorithms.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'apt-pkg/algorithms.cc') diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index b55ff2897..00f558420 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include @@ -743,15 +743,15 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) if (solver != "internal") { FILE* output = fopen("/tmp/scenario.log", "w"); - edspWriter::WriteScenario(Cache, output); + EDSP::WriteScenario(Cache, output); fclose(output); output = fopen("/tmp/request.log", "w"); - edspWriter::WriteRequest(Cache, output); + EDSP::WriteRequest(Cache, output); fclose(output); if (ResolveInternal(BrokenFix) == false) return false; output = fopen("/tmp/solution.log", "w"); - edspWriter::WriteSolution(Cache, output); + EDSP::WriteSolution(Cache, output); fclose(output); return true; } -- cgit v1.2.3 From 6d5bd6147e210bfb93e4ce0009d4e71c5995eab1 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 1 Apr 2011 12:04:13 +0200 Subject: Read and apply install/remove requests correctly --- apt-pkg/algorithms.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'apt-pkg/algorithms.cc') diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index 00f558420..aabb511a2 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -743,10 +743,8 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) if (solver != "internal") { FILE* output = fopen("/tmp/scenario.log", "w"); - EDSP::WriteScenario(Cache, output); - fclose(output); - output = fopen("/tmp/request.log", "w"); EDSP::WriteRequest(Cache, output); + EDSP::WriteScenario(Cache, output); fclose(output); if (ResolveInternal(BrokenFix) == false) return false; -- cgit v1.2.3 From 2029276f0343c96481d0d3cbbc367420b4a5f864 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 2 Apr 2011 15:47:14 +0200 Subject: send the scenario through a pipe to the solver and get the solution back The solution is NOT interpreted so far. --- apt-pkg/algorithms.cc | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'apt-pkg/algorithms.cc') diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index aabb511a2..bbe315ef7 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -740,18 +740,46 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg) bool pkgProblemResolver::Resolve(bool BrokenFix) { std::string const solver = _config->Find("APT::Solver::Name", "internal"); + if (solver != "internal") { - FILE* output = fopen("/tmp/scenario.log", "w"); +// std::string const file = _config->FindDir("Dir::Bin::Solvers") + solver; + std::string const file = solver; + if (RealFileExists(file.c_str()) == false) + return _error->Error("Can't call external solver '%s' as it is not available: %s", solver.c_str(), file.c_str()); + int external[4] = {-1, -1, -1, -1}; + if (pipe(external) != 0 || pipe(external + 2) != 0) + return _error->Errno("Resolve", "Can't create needed IPC pipes for EDSP"); + for (int i = 0; i < 4; ++i) + SetCloseExec(external[i], true); + + pid_t Solver = ExecFork(); + if (Solver == 0) + { + dup2(external[0], STDIN_FILENO); + dup2(external[3], STDOUT_FILENO); + const char* calling[2] = { file.c_str(), 0 }; + execv(calling[0], (char**) calling); + std::cerr << "Failed to execute solver '" << solver << "'!" << std::endl; + _exit(100); + } + close(external[0]); + close(external[3]); + + if (WaitFd(external[1], true, 5) == false) + return _error->Errno("Resolve", "Waiting on availability of solver stdin timed out"); + + FILE* output = fdopen(external[1], "w"); + if (output == NULL) + return _error->Errno("Resolve", "fdopen on solver stdin failed"); EDSP::WriteRequest(Cache, output); EDSP::WriteScenario(Cache, output); fclose(output); - if (ResolveInternal(BrokenFix) == false) - return false; - output = fopen("/tmp/solution.log", "w"); - EDSP::WriteSolution(Cache, output); - fclose(output); - return true; + + if (EDSP::ReadResponse(external[2], Cache) == false) + return _error->Error("Reading solver response failed"); + + return ExecWait(Solver, solver.c_str(), false); } return ResolveInternal(BrokenFix); } -- cgit v1.2.3 From 98d6aaa8fd2e5c3e9671560781ab23c99f66d7a4 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 2 May 2011 13:22:14 +0200 Subject: handle Dir::Bin::Solvers as a list of directories and find the solver in this list of directories --- apt-pkg/algorithms.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'apt-pkg/algorithms.cc') diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index bbe315ef7..e40f74122 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -743,10 +743,18 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) if (solver != "internal") { -// std::string const file = _config->FindDir("Dir::Bin::Solvers") + solver; - std::string const file = solver; - if (RealFileExists(file.c_str()) == false) - return _error->Error("Can't call external solver '%s' as it is not available: %s", solver.c_str(), file.c_str()); + std::vector const solverDirs = _config->FindVector("Dir::Bin::Solvers"); + std::string file; + for (std::vector::const_iterator dir = solverDirs.begin(); + dir != solverDirs.end(); ++dir) { + file = flCombine(*dir, solver); + if (RealFileExists(file.c_str()) == true) + break; + file.clear(); + } + + if (file.empty() == true) + return _error->Error("Can't call external solver '%s' as it is not in a configured directory!", solver.c_str()); int external[4] = {-1, -1, -1, -1}; if (pipe(external) != 0 || pipe(external + 2) != 0) return _error->Errno("Resolve", "Can't create needed IPC pipes for EDSP"); -- cgit v1.2.3 From ac5fbff8c55db2bd1cde194600115a874d9d0c73 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 2 May 2011 13:55:51 +0200 Subject: refactor: move solver execution into his own EDSP method --- apt-pkg/algorithms.cc | 42 +++++------------------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) (limited to 'apt-pkg/algorithms.cc') diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index e40f74122..82b1d608d 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -743,51 +743,19 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) if (solver != "internal") { - std::vector const solverDirs = _config->FindVector("Dir::Bin::Solvers"); - std::string file; - for (std::vector::const_iterator dir = solverDirs.begin(); - dir != solverDirs.end(); ++dir) { - file = flCombine(*dir, solver); - if (RealFileExists(file.c_str()) == true) - break; - file.clear(); - } - - if (file.empty() == true) - return _error->Error("Can't call external solver '%s' as it is not in a configured directory!", solver.c_str()); - int external[4] = {-1, -1, -1, -1}; - if (pipe(external) != 0 || pipe(external + 2) != 0) - return _error->Errno("Resolve", "Can't create needed IPC pipes for EDSP"); - for (int i = 0; i < 4; ++i) - SetCloseExec(external[i], true); - - pid_t Solver = ExecFork(); - if (Solver == 0) - { - dup2(external[0], STDIN_FILENO); - dup2(external[3], STDOUT_FILENO); - const char* calling[2] = { file.c_str(), 0 }; - execv(calling[0], (char**) calling); - std::cerr << "Failed to execute solver '" << solver << "'!" << std::endl; - _exit(100); - } - close(external[0]); - close(external[3]); - - if (WaitFd(external[1], true, 5) == false) - return _error->Errno("Resolve", "Waiting on availability of solver stdin timed out"); + int solver_in, solver_out; + if (EDSP::ExecuteSolver(solver.c_str(), &solver_in, &solver_out) == false) + return false; - FILE* output = fdopen(external[1], "w"); + FILE* output = fdopen(solver_in, "w"); if (output == NULL) return _error->Errno("Resolve", "fdopen on solver stdin failed"); EDSP::WriteRequest(Cache, output); EDSP::WriteScenario(Cache, output); fclose(output); - if (EDSP::ReadResponse(external[2], Cache) == false) + if (EDSP::ReadResponse(solver_out, Cache) == false) return _error->Error("Reading solver response failed"); - - return ExecWait(Solver, solver.c_str(), false); } return ResolveInternal(BrokenFix); } -- cgit v1.2.3 From 76d4aab06d3c5edd60362fd14b38eb43416616f0 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 2 May 2011 17:06:47 +0200 Subject: doesn't execute autoremove marker setting if an external solver is called and instead rely on the Autoremove tagging to show us what could be done. (apt-internal-solver doesn't support this currently as it doesn't load the auto-information into the cache) --- apt-pkg/algorithms.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'apt-pkg/algorithms.cc') diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index 82b1d608d..fea9e92e1 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -756,6 +756,8 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) if (EDSP::ReadResponse(solver_out, Cache) == false) return _error->Error("Reading solver response failed"); + + return true; } return ResolveInternal(BrokenFix); } -- cgit v1.2.3 From 741b7da9de1d2ab470728f1e7f38b25e0d6a556c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 3 May 2011 10:50:25 +0200 Subject: implement external solver calling for upgrade and dist-upgrade, too --- apt-pkg/algorithms.cc | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'apt-pkg/algorithms.cc') diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index fea9e92e1..5d9fefaa6 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -332,6 +332,10 @@ bool pkgFixBroken(pkgDepCache &Cache) */ bool pkgDistUpgrade(pkgDepCache &Cache) { + std::string const solver = _config->Find("APT::Solver::Name", "internal"); + if (solver != "internal") + return EDSP::ResolveExternal(solver.c_str(), Cache, false, true, false); + pkgDepCache::ActionGroup group(Cache); /* Upgrade all installed packages first without autoinst to help the resolver @@ -384,6 +388,10 @@ bool pkgDistUpgrade(pkgDepCache &Cache) to install packages not marked for install */ bool pkgAllUpgrade(pkgDepCache &Cache) { + std::string const solver = _config->Find("APT::Solver::Name", "internal"); + if (solver != "internal") + return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false); + pkgDepCache::ActionGroup group(Cache); pkgProblemResolver Fix(&Cache); @@ -740,25 +748,8 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg) bool pkgProblemResolver::Resolve(bool BrokenFix) { std::string const solver = _config->Find("APT::Solver::Name", "internal"); - if (solver != "internal") - { - int solver_in, solver_out; - if (EDSP::ExecuteSolver(solver.c_str(), &solver_in, &solver_out) == false) - return false; - - FILE* output = fdopen(solver_in, "w"); - if (output == NULL) - return _error->Errno("Resolve", "fdopen on solver stdin failed"); - EDSP::WriteRequest(Cache, output); - EDSP::WriteScenario(Cache, output); - fclose(output); - - if (EDSP::ReadResponse(solver_out, Cache) == false) - return _error->Error("Reading solver response failed"); - - return true; - } + return EDSP::ResolveExternal(solver.c_str(), Cache, false, false, false); return ResolveInternal(BrokenFix); } /*}}}*/ @@ -1230,6 +1221,19 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) in that it does not install or remove any packages. It is assumed that the system was non-broken previously. */ bool pkgProblemResolver::ResolveByKeep() +{ + std::string const solver = _config->Find("APT::Solver::Name", "internal"); + if (solver != "internal") + return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false); + return ResolveByKeepInternal(); +} + /*}}}*/ +// ProblemResolver::ResolveByKeepInternal - Resolve problems using keep /*{{{*/ +// --------------------------------------------------------------------- +/* This is the work horse of the soft upgrade routine. It is very gental + in that it does not install or remove any packages. It is assumed that the + system was non-broken previously. */ +bool pkgProblemResolver::ResolveByKeepInternal() { pkgDepCache::ActionGroup group(Cache); -- cgit v1.2.3 From b57c0e355d7f27a74c860ed73700cf9241cb4e61 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 9 May 2011 18:00:28 +0200 Subject: implement proper progress report with OpProgress --- apt-pkg/algorithms.cc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'apt-pkg/algorithms.cc') diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index 5d9fefaa6..31c3e9c28 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -333,8 +333,10 @@ bool pkgFixBroken(pkgDepCache &Cache) bool pkgDistUpgrade(pkgDepCache &Cache) { std::string const solver = _config->Find("APT::Solver::Name", "internal"); - if (solver != "internal") - return EDSP::ResolveExternal(solver.c_str(), Cache, false, true, false); + if (solver != "internal") { + OpTextProgress Prog(*_config); + return EDSP::ResolveExternal(solver.c_str(), Cache, false, true, false, &Prog); + } pkgDepCache::ActionGroup group(Cache); @@ -389,8 +391,10 @@ bool pkgDistUpgrade(pkgDepCache &Cache) bool pkgAllUpgrade(pkgDepCache &Cache) { std::string const solver = _config->Find("APT::Solver::Name", "internal"); - if (solver != "internal") - return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false); + if (solver != "internal") { + OpTextProgress Prog(*_config); + return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, &Prog); + } pkgDepCache::ActionGroup group(Cache); @@ -748,8 +752,10 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg) bool pkgProblemResolver::Resolve(bool BrokenFix) { std::string const solver = _config->Find("APT::Solver::Name", "internal"); - if (solver != "internal") - return EDSP::ResolveExternal(solver.c_str(), Cache, false, false, false); + if (solver != "internal") { + OpTextProgress Prog(*_config); + return EDSP::ResolveExternal(solver.c_str(), Cache, false, false, false, &Prog); + } return ResolveInternal(BrokenFix); } /*}}}*/ @@ -1223,8 +1229,10 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) bool pkgProblemResolver::ResolveByKeep() { std::string const solver = _config->Find("APT::Solver::Name", "internal"); - if (solver != "internal") - return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false); + if (solver != "internal") { + OpTextProgress Prog(*_config); + return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, &Prog); + } return ResolveByKeepInternal(); } /*}}}*/ -- cgit v1.2.3