- move solver test case generation to solve_and_commit
authorJan Kupec <jkupec@suse.cz>
Tue, 1 Apr 2008 20:21:30 +0000 (20:21 +0000)
committerJan Kupec <jkupec@suse.cz>
Tue, 1 Apr 2008 20:21:30 +0000 (20:21 +0000)
- set force resolve before test case generation

src/zypper-misc.cc
src/zypper-misc.h
src/zypper.cc

index 040e862..84bf202 100644 (file)
@@ -805,7 +805,7 @@ static void show_summary_of_type(Zypper & zypper,
  *  ZYPPER_EXIT_INF_REBOOT_NEEDED - if one of patches to be installed needs machine reboot,
  *  ZYPPER_EXIT_INF_RESTART_NEEDED - if one of patches to be installed needs package manager restart
  */
-int summary(Zypper & zypper)
+static int summary(Zypper & zypper)
 {
   int retv = -1; // nothing to do;
 
@@ -1042,14 +1042,11 @@ static int apply_locks(Zypper & zypper)
   return locks;
 }
 
-bool resolve(Zypper & zypper)
+static void set_force_resolution(Zypper & zypper)
 {
-  apply_locks(zypper);
-  dump_pool();
-
   // --force-resolution command line parameter value
   tribool force_resolution = indeterminate;
-  vector<string>::size_type count = copts.count("force-resolution");
+  unsigned int count = zypper.cOpts().count("force-resolution");
   if (count)
   {
     string value = copts["force-resolution"].front();
@@ -1091,14 +1088,26 @@ bool resolve(Zypper & zypper)
   ostringstream s;
   s << _("Force resolution:") << " " << (force_resolution ? _("Yes") : _("No"));
   zypper.out().info(s.str(), Out::HIGH);
-  God->resolver()->setForceResolve( force_resolution );
 
+  God->resolver()->setForceResolve(force_resolution);
+}
+
+/**
+ * Run the solver.
+ * 
+ * \return <tt>true</tt> if a solution has been found, <tt>false</tt> otherwise 
+ */
+static bool resolve(Zypper & zypper)
+{
+  apply_locks(zypper);
+  dump_pool(); // debug
+  set_force_resolution(zypper);
   zypper.out().info(_("Resolving dependencies..."), Out::HIGH);
   DBG << "Calling the solver..." << endl;
   return God->resolver()->resolvePool();
 }
 
-bool verify(Zypper & zypper)
+static bool verify(Zypper & zypper)
 {
   apply_locks(zypper);
   dump_pool();
@@ -1112,6 +1121,25 @@ bool verify(Zypper & zypper)
   return God->resolver()->verifySystem();
 }
 
+static void make_solver_test_case(Zypper & zypper)
+{
+  apply_locks(zypper);
+  set_force_resolution(zypper);
+  
+  string testcase_dir("/var/log/zypper.solverTestCase");
+
+  zypper.out().info(_("Generating solver test case..."));
+  if (God->resolver()->createSolverTestcase(testcase_dir))
+    zypper.out().info(boost::str(
+      format(_("Solver test case generated successfully at %s."))
+        % testcase_dir));
+  else
+  {
+    zypper.out().error(_("Error creating the solver test case."));
+    zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+  }
+}
+
 void patch_check ()
 {
   Out & out = Zypper::instance()->out();
@@ -1713,6 +1741,12 @@ void mark_updates(const ResKindSet & kinds, bool skip_interactive, bool best_eff
  */
 void solve_and_commit (Zypper & zypper)
 {
+  if (zypper.cOpts().count("debug-solver"))
+  {
+    make_solver_test_case(zypper);
+    return;
+  }
+
   MIL << "solving..." << endl;
 
   while (true) {
index 442a4f1..60c15ac 100644 (file)
@@ -36,16 +36,6 @@ void mark_by_capability (Zypper & zypper,
  */
 void remove_selections(Zypper & zypper);
 
-/** Show install summary */
-int show_summary(Zypper & zypper);
-
-/**
- * Run the solver.
- * 
- * \return <tt>true</tt> if a solution has been found, <tt>false</tt> otherwise 
- */
-bool resolve(Zypper & zypper);
-
 /** List patches */
 void show_patches(Zypper & zypper);
 
index 667712c..0ca0411 100644 (file)
@@ -1950,24 +1950,7 @@ void Zypper::doCommand()
           it != rpms_files_caps.end(); ++it )
       mark_by_capability (*this, true, kind, *it);
 
-    // solve dependencies
-    if (copts.count("debug-solver"))
-    {
-      God->applyLocks();
-      out().info(_("Generating solver test case..."));
-      if (God->resolver()->createSolverTestcase("/var/log/zypper.solverTestCase"))
-        out().info(_("Solver test case generated successfully at /var/log/zypper.solverTestCase."));
-      else
-      {
-        out().error(_("Error creating the solver test case."));
-        setExitCode(ZYPPER_EXIT_ERR_ZYPP);
-        return;
-      }
-    }
-    else
-    {
-      solve_and_commit(*this);
-    }
+    solve_and_commit(*this);
 
     return;
   }
@@ -2340,23 +2323,7 @@ void Zypper::doCommand()
     bool skip_interactive = copts.count("skip-interactive") || globalOpts().non_interactive;
     mark_updates( kinds, skip_interactive, best_effort );
 
-
-    if (copts.count("debug-solver"))
-    {
-      God->applyLocks();
-      out().info(_("Generating solver test case..."));
-      if (God->resolver()->createSolverTestcase("/var/log/zypper.solverTestCase"))
-        out().info(_("Solver test case generated successfully at /var/log/zypper.solverTestCase."));
-      else
-        out().error(_("Error creating the solver test case."));
-    }
-    // commit
-    // returns ZYPPER_EXIT_OK, ZYPPER_EXIT_ERR_ZYPP,
-    // ZYPPER_EXIT_INF_REBOOT_NEEDED, or ZYPPER_EXIT_INF_RESTART_NEEDED
-    else
-    {
-      solve_and_commit(*this);
-    }
+    solve_and_commit(*this);
 
     return; 
   }
@@ -2394,22 +2361,7 @@ void Zypper::doCommand()
     zypp::UpgradeStatistics opt_stats;
     God->resolver()->doUpgrade(opt_stats);
 
-    if (copts.count("debug-solver"))
-    {
-      God->applyLocks();
-      out().info(_("Generating solver test case..."));
-      if (God->resolver()->createSolverTestcase("/var/log/zypper.solverTestCase"))
-        out().info(_("Solver test case generated successfully at /var/log/zypper.solverTestCase."));
-      else
-        out().error(_("Error creating the solver test case."));
-    }
-    // commit
-    // returns ZYPPER_EXIT_OK, ZYPPER_EXIT_ERR_ZYPP,
-    // ZYPPER_EXIT_INF_REBOOT_NEEDED, or ZYPPER_EXIT_INF_RESTART_NEEDED
-    else
-    {
-      solve_and_commit(*this);
-    }
+    solve_and_commit(*this);
 
     return; 
   }