solver.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. /*
  2. * Copyright (c) 2007, Novell Inc.
  3. *
  4. * This program is licensed under the BSD license, read LICENSE.BSD
  5. * for further information
  6. */
  7. /*
  8. * solver.h
  9. *
  10. */
  11. #ifndef LIBSOLV_SOLVER_H
  12. #define LIBSOLV_SOLVER_H
  13. #include "pooltypes.h"
  14. #include "pool.h"
  15. #include "repo.h"
  16. #include "queue.h"
  17. #include "bitmap.h"
  18. #include "transaction.h"
  19. #include "rules.h"
  20. #include "problems.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. struct s_Solver {
  25. Pool *pool; /* back pointer to pool */
  26. Queue job; /* copy of the job we're solving */
  27. int (*solution_callback)(struct s_Solver *solv, void *data);
  28. void *solution_callback_data;
  29. int pooljobcnt; /* number of pooljob entries in job queue */
  30. #ifdef LIBSOLV_INTERNAL
  31. Repo *installed; /* copy of pool->installed */
  32. /* list of rules, ordered
  33. * pkg rules first, then features, updates, jobs, learnt
  34. * see start/end offsets below
  35. */
  36. Rule *rules; /* all rules */
  37. Id nrules; /* [Offset] index of the last rule */
  38. Id lastpkgrule; /* last package rule we added */
  39. Queue ruleassertions; /* Queue of all assertion rules */
  40. /* start/end offset for rule 'areas' */
  41. Id pkgrules_end; /* [Offset] dep rules end */
  42. Id featurerules; /* feature rules start/end */
  43. Id featurerules_end;
  44. Id updaterules; /* policy rules, e.g. keep packages installed or update. All literals > 0 */
  45. Id updaterules_end;
  46. Id jobrules; /* user rules */
  47. Id jobrules_end;
  48. Id infarchrules; /* inferior arch rules */
  49. Id infarchrules_end;
  50. Id duprules; /* dist upgrade rules */
  51. Id duprules_end;
  52. Id bestrules; /* rules from SOLVER_FORCEBEST */
  53. Id bestrules_up; /* update rule part starts here*/
  54. Id bestrules_end;
  55. Id *bestrules_info; /* < 0 : install rule, > 0 : pkg that needs to be updated */
  56. Id yumobsrules; /* rules from yum obsoletes handling */
  57. Id yumobsrules_end;
  58. Id *yumobsrules_info; /* the dependency for each rule */
  59. Id blackrules; /* rules from blacklisted packages */
  60. Id blackrules_end;
  61. Id strictrepopriorules; /* rules from strict priority repositories */
  62. Id strictrepopriorules_end;
  63. Id choicerules; /* choice rules (always weak) */
  64. Id choicerules_end;
  65. Id *choicerules_info; /* the rule we used to generate the choice rule */
  66. Id recommendsrules; /* rules from recommends pkg rules with disfavored literals */
  67. Id recommendsrules_end;
  68. Id *recommendsrules_info; /* the original pkg rule rule */
  69. Id learntrules; /* learnt rules, (end == nrules) */
  70. Map noupdate; /* don't try to update these
  71. installed solvables */
  72. Map multiversion; /* ignore obsoletes for these (multiinstall) */
  73. Map updatemap; /* bring these installed packages to the newest version */
  74. int updatemap_all; /* bring all packages to the newest version */
  75. Map bestupdatemap; /* create best rule for those packages */
  76. int bestupdatemap_all; /* bring all packages to the newest version */
  77. Map fixmap; /* fix these packages */
  78. int fixmap_all; /* fix all packages */
  79. Queue weakruleq; /* index into 'rules' for weak ones */
  80. Map weakrulemap; /* map rule# to '1' for weak rules, 1..learntrules */
  81. Id *watches; /* Array of rule offsets
  82. * watches has nsolvables*2 entries and is addressed from the middle
  83. * middle-solvable : decision to conflict, offset point to linked-list of rules
  84. * middle+solvable : decision to install: offset point to linked-list of rules
  85. */
  86. Queue ruletojob; /* index into job queue: jobs for which a rule exits */
  87. /* our decisions: */
  88. Queue decisionq; /* >0:install, <0:remove/conflict */
  89. Queue decisionq_why; /* index of rule, Offset into rules */
  90. Queue decisionq_reason; /* reason for decision, indexed by level */
  91. Id *decisionmap; /* map for all available solvables,
  92. * = 0: undecided
  93. * > 0: level of decision when installed,
  94. * < 0: level of decision when conflict */
  95. /* learnt rule history */
  96. Queue learnt_why;
  97. Queue learnt_pool;
  98. Queue branches;
  99. int propagate_index; /* index into decisionq for non-propagated decisions */
  100. Queue problems; /* list of lists of conflicting rules, < 0 for job rules */
  101. Queue solutions; /* refined problem storage space */
  102. Queue orphaned; /* orphaned packages (to be removed?) */
  103. int stats_learned; /* statistic */
  104. int stats_unsolvable; /* statistic */
  105. Map recommendsmap; /* recommended packages from decisionmap */
  106. Map suggestsmap; /* suggested packages from decisionmap */
  107. int recommends_index; /* recommendsmap/suggestsmap is created up to this level */
  108. Queue *recommendscplxq;
  109. Queue *suggestscplxq;
  110. Id *obsoletes; /* obsoletes for each installed solvable */
  111. Id *obsoletes_data; /* data area for obsoletes */
  112. Id *specialupdaters; /* updaters for packages with a limited update rule */
  113. /*-------------------------------------------------------------------------------------------------------------
  114. * Solver configuration
  115. *-------------------------------------------------------------------------------------------------------------*/
  116. int allowdowngrade; /* allow to downgrade installed solvable */
  117. int allownamechange; /* allow to change name of installed solvables */
  118. int allowarchchange; /* allow to change architecture of installed solvables */
  119. int allowvendorchange; /* allow to change vendor of installed solvables */
  120. int allowuninstall; /* allow removal of installed solvables */
  121. int noupdateprovide; /* true: update packages needs not to provide old package */
  122. int needupdateprovide; /* true: update packages must provide old package */
  123. int dosplitprovides; /* true: consider legacy split provides */
  124. int dontinstallrecommended; /* true: do not install recommended packages */
  125. int addalreadyrecommended; /* true: also install recommended packages that were already recommended by the installed packages */
  126. int dontshowinstalledrecommended; /* true: do not show recommended packages that are already installed */
  127. int noinfarchcheck; /* true: do not forbid inferior architectures */
  128. int keepexplicitobsoletes; /* true: honor obsoletes during multiinstall */
  129. int bestobeypolicy; /* true: stay in policy with the best rules */
  130. int noautotarget; /* true: do not assume targeted for up/dup jobs that contain no installed solvable */
  131. int focus_installed; /* true: resolve update rules first */
  132. int focus_best; /* true: resolve job dependencies first */
  133. int do_yum_obsoletes; /* true: add special yumobs rules */
  134. int urpmreorder; /* true: do special urpm package reordering */
  135. int strongrecommends; /* true: create weak rules for recommends */
  136. int install_also_updates; /* true: do not prune install job rules to installed packages */
  137. int only_namespace_recommended; /* true: only install packages recommended by namespace */
  138. int strict_repo_priority; /* true: only use packages from highest precedence/priority */
  139. int process_orphans; /* true: do special orphan processing */
  140. Map dupmap; /* dup to those packages */
  141. Map dupinvolvedmap; /* packages involved in dup process */
  142. int dupinvolvedmap_all; /* all packages are involved */
  143. int dup_allowdowngrade; /* dup mode: allow to downgrade installed solvable */
  144. int dup_allownamechange; /* dup mode: allow to change name of installed solvable */
  145. int dup_allowarchchange; /* dup mode: allow to change architecture of installed solvables */
  146. int dup_allowvendorchange; /* dup mode: allow to change vendor of installed solvables */
  147. Map droporphanedmap; /* packages to drop in dup mode */
  148. int droporphanedmap_all;
  149. Map cleandepsmap; /* try to drop these packages as of cleandeps erases */
  150. Queue *ruleinfoq; /* tmp space for solver_ruleinfo() */
  151. Queue *cleandeps_updatepkgs; /* packages we update in cleandeps mode */
  152. Queue *cleandeps_mistakes; /* mistakes we made */
  153. Queue *update_targets; /* update to specific packages */
  154. Queue *installsuppdepq; /* deps from the install namespace provides hack */
  155. Queue addedmap_deduceq; /* deduce addedmap from pkg rules */
  156. Id *instbuddy; /* buddies of installed packages */
  157. int keep_orphans; /* how to treat orphans */
  158. int break_orphans; /* how to treat orphans */
  159. Queue *brokenorphanrules; /* broken rules of orphaned packages */
  160. Map allowuninstallmap; /* ok to uninstall those */
  161. int allowuninstall_all;
  162. Map excludefromweakmap; /* remove them from candidates for supplements and recommends */
  163. Id *favormap; /* favor job index, > 0: favored, < 0: disfavored */
  164. int havedisfavored; /* do we have disfavored packages? */
  165. int installedpos; /* for resolve_installed */
  166. int do_extra_reordering; /* reorder for future installed packages */
  167. Queue *recommendsruleq; /* pkg rules comming from recommends */
  168. #endif /* LIBSOLV_INTERNAL */
  169. };
  170. typedef struct s_Solver Solver;
  171. /*
  172. * queue commands
  173. */
  174. #define SOLVER_SOLVABLE 0x01
  175. #define SOLVER_SOLVABLE_NAME 0x02
  176. #define SOLVER_SOLVABLE_PROVIDES 0x03
  177. #define SOLVER_SOLVABLE_ONE_OF 0x04
  178. #define SOLVER_SOLVABLE_REPO 0x05
  179. #define SOLVER_SOLVABLE_ALL 0x06
  180. #define SOLVER_SELECTMASK 0xff
  181. #define SOLVER_NOOP 0x0000
  182. #define SOLVER_INSTALL 0x0100
  183. #define SOLVER_ERASE 0x0200
  184. #define SOLVER_UPDATE 0x0300
  185. #define SOLVER_WEAKENDEPS 0x0400
  186. #define SOLVER_MULTIVERSION 0x0500
  187. #define SOLVER_LOCK 0x0600
  188. #define SOLVER_DISTUPGRADE 0x0700
  189. #define SOLVER_VERIFY 0x0800
  190. #define SOLVER_DROP_ORPHANED 0x0900
  191. #define SOLVER_USERINSTALLED 0x0a00
  192. #define SOLVER_ALLOWUNINSTALL 0x0b00
  193. #define SOLVER_FAVOR 0x0c00
  194. #define SOLVER_DISFAVOR 0x0d00
  195. #define SOLVER_BLACKLIST 0x0e00
  196. #define SOLVER_EXCLUDEFROMWEAK 0x1000
  197. #define SOLVER_JOBMASK 0xff00
  198. #define SOLVER_WEAK 0x010000
  199. #define SOLVER_ESSENTIAL 0x020000
  200. #define SOLVER_CLEANDEPS 0x040000
  201. /* ORUPDATE makes SOLVER_INSTALL not prune to installed
  202. * packages, thus updating installed packages */
  203. #define SOLVER_ORUPDATE 0x080000
  204. /* FORCEBEST makes the solver insist on best packages, so
  205. * you will get problem reported if the best package is
  206. * not installable. This can be used with INSTALL, UPDATE
  207. * and DISTUPGRADE */
  208. #define SOLVER_FORCEBEST 0x100000
  209. /* TARGETED is used in up/dup jobs to make the solver
  210. * treat the specified selection as target packages.
  211. * It is automatically assumed if the selection does not
  212. * contain an "installed" package unless the
  213. * NO_AUTOTARGET solver flag is set */
  214. #define SOLVER_TARGETED 0x200000
  215. /* This (SOLVER_INSTALL) job was automatically added
  216. * and thus does not the add to the userinstalled packages */
  217. #define SOLVER_NOTBYUSER 0x400000
  218. #define SOLVER_SETEV 0x01000000
  219. #define SOLVER_SETEVR 0x02000000
  220. #define SOLVER_SETARCH 0x04000000
  221. #define SOLVER_SETVENDOR 0x08000000
  222. #define SOLVER_SETREPO 0x10000000
  223. #define SOLVER_NOAUTOSET 0x20000000
  224. #define SOLVER_SETNAME 0x40000000
  225. #define SOLVER_SETMASK 0x7f000000
  226. /* legacy */
  227. #define SOLVER_NOOBSOLETES SOLVER_MULTIVERSION
  228. #define SOLVER_REASON_UNRELATED 0
  229. #define SOLVER_REASON_UNIT_RULE 1
  230. #define SOLVER_REASON_KEEP_INSTALLED 2
  231. #define SOLVER_REASON_RESOLVE_JOB 3
  232. #define SOLVER_REASON_UPDATE_INSTALLED 4
  233. #define SOLVER_REASON_CLEANDEPS_ERASE 5
  234. #define SOLVER_REASON_RESOLVE 6
  235. #define SOLVER_REASON_WEAKDEP 7
  236. #define SOLVER_REASON_RESOLVE_ORPHAN 8
  237. #define SOLVER_REASON_RECOMMENDED 16
  238. #define SOLVER_REASON_SUPPLEMENTED 17
  239. #define SOLVER_FLAG_ALLOW_DOWNGRADE 1
  240. #define SOLVER_FLAG_ALLOW_ARCHCHANGE 2
  241. #define SOLVER_FLAG_ALLOW_VENDORCHANGE 3
  242. #define SOLVER_FLAG_ALLOW_UNINSTALL 4
  243. #define SOLVER_FLAG_NO_UPDATEPROVIDE 5
  244. #define SOLVER_FLAG_SPLITPROVIDES 6
  245. #define SOLVER_FLAG_IGNORE_RECOMMENDED 7
  246. #define SOLVER_FLAG_ADD_ALREADY_RECOMMENDED 8
  247. #define SOLVER_FLAG_NO_INFARCHCHECK 9
  248. #define SOLVER_FLAG_ALLOW_NAMECHANGE 10
  249. #define SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES 11
  250. #define SOLVER_FLAG_BEST_OBEY_POLICY 12
  251. #define SOLVER_FLAG_NO_AUTOTARGET 13
  252. #define SOLVER_FLAG_DUP_ALLOW_DOWNGRADE 14
  253. #define SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE 15
  254. #define SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE 16
  255. #define SOLVER_FLAG_DUP_ALLOW_NAMECHANGE 17
  256. #define SOLVER_FLAG_KEEP_ORPHANS 18
  257. #define SOLVER_FLAG_BREAK_ORPHANS 19
  258. #define SOLVER_FLAG_FOCUS_INSTALLED 20
  259. #define SOLVER_FLAG_YUM_OBSOLETES 21
  260. #define SOLVER_FLAG_NEED_UPDATEPROVIDE 22
  261. #define SOLVER_FLAG_URPM_REORDER 23
  262. #define SOLVER_FLAG_FOCUS_BEST 24
  263. #define SOLVER_FLAG_STRONG_RECOMMENDS 25
  264. #define SOLVER_FLAG_INSTALL_ALSO_UPDATES 26
  265. #define SOLVER_FLAG_ONLY_NAMESPACE_RECOMMENDED 27
  266. #define SOLVER_FLAG_STRICT_REPO_PRIORITY 28
  267. #define GET_USERINSTALLED_NAMES (1 << 0) /* package names instead of ids */
  268. #define GET_USERINSTALLED_INVERTED (1 << 1) /* autoinstalled */
  269. #define GET_USERINSTALLED_NAMEARCH (1 << 2) /* package/arch tuples instead of ids */
  270. #define SOLVER_ALTERNATIVE_TYPE_RULE 1
  271. #define SOLVER_ALTERNATIVE_TYPE_RECOMMENDS 2
  272. #define SOLVER_ALTERNATIVE_TYPE_SUGGESTS 3
  273. extern Solver *solver_create(Pool *pool);
  274. extern void solver_free(Solver *solv);
  275. extern int solver_solve(Solver *solv, Queue *job);
  276. extern Transaction *solver_create_transaction(Solver *solv);
  277. extern int solver_set_flag(Solver *solv, int flag, int value);
  278. extern int solver_get_flag(Solver *solv, int flag);
  279. extern int solver_get_decisionlevel(Solver *solv, Id p);
  280. extern void solver_get_decisionqueue(Solver *solv, Queue *decisionq);
  281. extern int solver_get_lastdecisionblocklevel(Solver *solv);
  282. extern void solver_get_decisionblock(Solver *solv, int level, Queue *decisionq);
  283. extern void solver_get_orphaned(Solver *solv, Queue *orphanedq);
  284. extern void solver_get_recommendations(Solver *solv, Queue *recommendationsq, Queue *suggestionsq, int noselected);
  285. extern void solver_get_unneeded(Solver *solv, Queue *unneededq, int filtered);
  286. extern void solver_get_userinstalled(Solver *solv, Queue *q, int flags);
  287. extern void pool_add_userinstalled_jobs(Pool *pool, Queue *q, Queue *job, int flags);
  288. extern void solver_get_cleandeps(Solver *solv, Queue *cleandepsq);
  289. extern int solver_describe_decision(Solver *solv, Id p, Id *infop);
  290. extern void solver_describe_weakdep_decision(Solver *solv, Id p, Queue *whyq);
  291. extern int solver_alternatives_count(Solver *solv);
  292. extern int solver_get_alternative(Solver *solv, Id alternative, Id *idp, Id *fromp, Id *chosenp, Queue *choices, int *levelp);
  293. extern void solver_calculate_multiversionmap(Pool *pool, Queue *job, Map *multiversionmap);
  294. extern void solver_calculate_noobsmap(Pool *pool, Queue *job, Map *multiversionmap); /* obsolete */
  295. extern void solver_create_state_maps(Solver *solv, Map *installedmap, Map *conflictsmap);
  296. extern void solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps);
  297. extern int solver_calc_installsizechange(Solver *solv);
  298. extern void pool_job2solvables(Pool *pool, Queue *pkgs, Id how, Id what);
  299. extern int pool_isemptyupdatejob(Pool *pool, Id how, Id what);
  300. extern const char *solver_select2str(Pool *pool, Id select, Id what);
  301. extern const char *pool_job2str(Pool *pool, Id how, Id what, Id flagmask);
  302. extern const char *solver_alternative2str(Solver *solv, int type, Id id, Id from);
  303. /* iterate over all literals of a rule */
  304. #define FOR_RULELITERALS(l, pp, r) \
  305. for (pp = r->d < 0 ? -r->d - 1 : r->d, \
  306. l = r->p; l; l = (pp <= 0 ? (pp-- ? 0 : r->w2) : \
  307. pool->whatprovidesdata[pp++]))
  308. /* XXX: this currently doesn't work correctly for SOLVER_SOLVABLE_REPO and
  309. SOLVER_SOLVABLE_ALL */
  310. /* iterate over all packages selected by a job */
  311. #define FOR_JOB_SELECT(p, pp, select, what) \
  312. if (select == SOLVER_SOLVABLE_REPO || select == SOLVER_SOLVABLE_ALL) \
  313. p = pp = 0; \
  314. else for (pp = (select == SOLVER_SOLVABLE ? 0 : \
  315. select == SOLVER_SOLVABLE_ONE_OF ? what : \
  316. pool_whatprovides(pool, what)), \
  317. p = (select == SOLVER_SOLVABLE ? what : pool->whatprovidesdata[pp++]); \
  318. p ; p = pool->whatprovidesdata[pp++]) \
  319. if (select == SOLVER_SOLVABLE_NAME && \
  320. pool_match_nevr(pool, pool->solvables + p, what) == 0) \
  321. continue; \
  322. else
  323. /* weird suse stuff */
  324. extern void solver_trivial_installable(Solver *solv, Queue *pkgs, Queue *res);
  325. #ifdef __cplusplus
  326. }
  327. #endif
  328. #endif /* LIBSOLV_SOLVER_H */