Imported Upstream version 0.7.27
[platform/upstream/libsolv.git] / src / rules.h
1 /*
2  * Copyright (c) 2007-2009, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * rules.h
10  *
11  */
12
13 #ifndef LIBSOLV_RULES_H
14 #define LIBSOLV_RULES_H
15
16 #include "pooltypes.h"
17 #include "bitmap.h"
18 #include "queue.h"
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24
25 /* ----------------------------------------------
26  * Rule
27  *
28  *   providerN(B) == Package Id of package providing tag B
29  *   N = 1, 2, 3, in case of multiple providers
30  *
31  * A requires B : !A | provider1(B) | provider2(B)
32  *
33  * A conflicts B : (!A | !provider1(B)) & (!A | !provider2(B)) ...
34  *
35  * 'not' is encoded as a negative Id
36  *
37  * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
38  *
39  * There are a lot of rules, so the struct is kept as small as
40  * possible. Do not add new members unless there is no other way.
41  */
42
43 typedef struct s_Rule {
44   Id p;         /* first literal in rule */
45   Id d;         /* Id offset into 'list of providers terminated by 0' as used by whatprovides; pool->whatprovides + d */
46                 /* in case of binary rules, d == 0, w1 == p, w2 == other literal */
47                 /* in case of disabled rules: ~d, aka -d - 1 */
48   Id w1, w2;    /* watches, literals not-yet-decided */
49                 /* if !w2, assertion, not rule */
50   Id n1, n2;    /* next rules in linked list, corresponding to w1, w2 */
51 } Rule;
52
53
54 typedef enum {
55   SOLVER_RULE_UNKNOWN = 0,
56   SOLVER_RULE_PKG = 0x100,
57   SOLVER_RULE_PKG_NOT_INSTALLABLE,
58   SOLVER_RULE_PKG_NOTHING_PROVIDES_DEP,
59   SOLVER_RULE_PKG_REQUIRES,
60   SOLVER_RULE_PKG_SELF_CONFLICT,
61   SOLVER_RULE_PKG_CONFLICTS,
62   SOLVER_RULE_PKG_SAME_NAME,
63   SOLVER_RULE_PKG_OBSOLETES,
64   SOLVER_RULE_PKG_IMPLICIT_OBSOLETES,
65   SOLVER_RULE_PKG_INSTALLED_OBSOLETES,
66   SOLVER_RULE_PKG_RECOMMENDS,
67   SOLVER_RULE_PKG_CONSTRAINS,
68   SOLVER_RULE_PKG_SUPPLEMENTS,
69   SOLVER_RULE_UPDATE = 0x200,
70   SOLVER_RULE_FEATURE = 0x300,
71   SOLVER_RULE_JOB = 0x400,
72   SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP,
73   SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM,
74   SOLVER_RULE_JOB_UNKNOWN_PACKAGE,
75   SOLVER_RULE_JOB_UNSUPPORTED,
76   SOLVER_RULE_DISTUPGRADE = 0x500,
77   SOLVER_RULE_INFARCH = 0x600,
78   SOLVER_RULE_CHOICE = 0x700,
79   SOLVER_RULE_LEARNT = 0x800,
80   SOLVER_RULE_BEST = 0x900,
81   SOLVER_RULE_YUMOBS = 0xa00,
82   SOLVER_RULE_RECOMMENDS = 0xb00,
83   SOLVER_RULE_BLACK = 0xc00,
84   SOLVER_RULE_STRICT_REPO_PRIORITY = 0xd00
85 } SolverRuleinfo;
86
87 #define SOLVER_RULE_TYPEMASK    0xff00
88
89 struct s_Solver;
90
91 /*-------------------------------------------------------------------
92  * disable rule
93  */
94
95 static inline void
96 solver_disablerule(struct s_Solver *solv, Rule *r)
97 {
98   if (r->d >= 0)
99     r->d = -r->d - 1;
100 }
101
102 /*-------------------------------------------------------------------
103  * enable rule
104  */
105
106 static inline void
107 solver_enablerule(struct s_Solver *solv, Rule *r)
108 {
109   if (r->d < 0)
110     r->d = -r->d - 1;
111 }
112
113 extern Rule *solver_addrule(struct s_Solver *solv, Id p, Id p2, Id d);
114 extern void solver_unifyrules(struct s_Solver *solv);
115 extern int solver_rulecmp(struct s_Solver *solv, Rule *r1, Rule *r2);
116 extern void solver_shrinkrules(struct s_Solver *solv, int nrules);
117
118 /* pkg rules */
119 extern void solver_addpkgrulesforsolvable(struct s_Solver *solv, Solvable *s, Map *m);
120 extern void solver_addpkgrulesforweak(struct s_Solver *solv, Map *m);
121 extern void solver_addpkgrulesforlinked(struct s_Solver *solv, Map *m);
122 extern void solver_addpkgrulesforupdaters(struct s_Solver *solv, Solvable *s, Map *m, int allow_all);
123
124 /* update/feature rules */
125 extern void solver_addfeaturerule(struct s_Solver *solv, Solvable *s);
126 extern void solver_addupdaterule(struct s_Solver *solv, Solvable *s);
127
128 /* infarch rules */
129 extern void solver_addinfarchrules(struct s_Solver *solv, Map *addedmap);
130
131 /* dup rules */
132 extern void solver_createdupmaps(struct s_Solver *solv);
133 extern void solver_freedupmaps(struct s_Solver *solv);
134 extern void solver_addduprules(struct s_Solver *solv, Map *addedmap);
135
136 /* choice rules */
137 extern void solver_addchoicerules(struct s_Solver *solv);
138 extern void solver_disablechoicerules(struct s_Solver *solv, Rule *r);
139
140 /* best rules */
141 extern void solver_addbestrules(struct s_Solver *solv, int havebestinstalljobs, int haslockjob);
142
143 /* yumobs rules */
144 extern void solver_addyumobsrules(struct s_Solver *solv);
145
146 /* black rules */
147 extern void solver_addblackrules(struct s_Solver *solv);
148
149 /* recommends rules */
150 extern void solver_addrecommendsrules(struct s_Solver *solv);
151
152 /* channel priority rules */
153 extern void solver_addstrictrepopriorules(struct s_Solver *solv, Map *addedmap);
154
155 /* policy rule disabling/reenabling */
156 extern void solver_disablepolicyrules(struct s_Solver *solv);
157 extern void solver_reenablepolicyrules(struct s_Solver *solv, int jobidx);
158 extern void solver_reenablepolicyrules_cleandeps(struct s_Solver *solv, Id pkg);
159
160 /* rule info */
161 extern int solver_allruleinfos(struct s_Solver *solv, Id rid, Queue *rq);
162 extern SolverRuleinfo solver_ruleinfo(struct s_Solver *solv, Id rid, Id *fromp, Id *top, Id *depp);
163 extern SolverRuleinfo solver_ruleclass(struct s_Solver *solv, Id rid);
164 extern void solver_ruleliterals(struct s_Solver *solv, Id rid, Queue *q);
165 extern int  solver_rule2jobidx(struct s_Solver *solv, Id rid);
166 extern Id   solver_rule2job(struct s_Solver *solv, Id rid, Id *whatp);
167 extern Id   solver_rule2solvable(struct s_Solver *solv, Id rid);
168 extern void solver_rule2rules(struct s_Solver *solv, Id rid, Queue *q, int recursive);
169 extern Id   solver_rule2pkgrule(struct s_Solver *solv, Id rid);
170 extern const char *solver_ruleinfo2str(struct s_Solver *solv, SolverRuleinfo type, Id source, Id target, Id dep);
171
172 /* rule infos for weakdep decisions */
173 extern int  solver_allweakdepinfos(struct s_Solver *solv, Id p, Queue *rq);
174 extern SolverRuleinfo solver_weakdepinfo(struct s_Solver *solv, Id p, Id *fromp, Id *top, Id *depp);
175
176 /* orphan handling */
177 extern void solver_breakorphans(struct s_Solver *solv);
178 extern void solver_check_brokenorphanrules(struct s_Solver *solv, Queue *dq);
179
180
181 /* legacy */
182 #define SOLVER_RULE_RPM SOLVER_RULE_PKG
183 #define SOLVER_RULE_RPM_NOT_INSTALLABLE SOLVER_RULE_PKG_NOT_INSTALLABLE
184 #define SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP SOLVER_RULE_PKG_NOTHING_PROVIDES_DEP
185 #define SOLVER_RULE_RPM_PACKAGE_REQUIRES SOLVER_RULE_PKG_REQUIRES
186 #define SOLVER_RULE_RPM_SELF_CONFLICT SOLVER_RULE_PKG_SELF_CONFLICT
187 #define SOLVER_RULE_RPM_PACKAGE_CONFLICT SOLVER_RULE_PKG_CONFLICTS
188 #define SOLVER_RULE_RPM_SAME_NAME SOLVER_RULE_PKG_SAME_NAME
189 #define SOLVER_RULE_RPM_PACKAGE_OBSOLETES SOLVER_RULE_PKG_OBSOLETES
190 #define SOLVER_RULE_RPM_IMPLICIT_OBSOLETES SOLVER_RULE_PKG_IMPLICIT_OBSOLETES
191 #define SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES SOLVER_RULE_PKG_INSTALLED_OBSOLETES
192
193 #ifdef __cplusplus
194 }
195 #endif
196
197 #endif
198