satsolver 0.16.3
|
00001 /* 00002 * Copyright (c) 2007, Novell Inc. 00003 * 00004 * This program is licensed under the BSD license, read LICENSE.BSD 00005 * for further information 00006 */ 00007 00008 /* 00009 * pool.h 00010 * 00011 */ 00012 00013 #ifndef SATSOLVER_POOL_H 00014 #define SATSOLVER_POOL_H 00015 00016 #ifdef __cplusplus 00017 extern "C" { 00018 #endif 00019 00020 #include <stdio.h> 00021 00022 #include "satversion.h" 00023 #include "pooltypes.h" 00024 #include "poolid.h" 00025 #include "solvable.h" 00026 #include "bitmap.h" 00027 #include "queue.h" 00028 #include "strpool.h" 00029 00030 /* well known ids */ 00031 #include "knownid.h" 00032 00033 /* well known solvable */ 00034 #define SYSTEMSOLVABLE 1 00035 00036 00037 /* how many strings to maintain (round robin) */ 00038 #define POOL_TMPSPACEBUF 16 00039 00040 //----------------------------------------------- 00041 00042 struct _Repo; 00043 struct _Repodata; 00044 struct _Repokey; 00045 struct _KeyValue; 00046 00047 typedef struct _Repopos { 00048 struct _Repo *repo; 00049 Id solvid; 00050 Id repodataid; 00051 Id schema; 00052 Id dp; 00053 } Repopos; 00054 00055 struct _Pool { 00056 void *appdata; /* application private pointer */ 00057 00058 struct _Stringpool ss; 00059 00060 Reldep *rels; /* table of rels: Id -> Reldep */ 00061 int nrels; /* number of unique rels */ 00062 Hashtable relhashtbl; /* hashtable: (name,evr,op)Hash -> Id */ 00063 Hashmask relhashmask; 00064 00065 struct _Repo **repos; 00066 int nrepos; 00067 00068 struct _Repo *installed; /* packages considered installed */ 00069 00070 Solvable *solvables; 00071 int nsolvables; 00072 00073 const char **languages; 00074 int nlanguages; 00075 Id *languagecache; 00076 int languagecacheother; 00077 00078 /* flags to tell the library how the installed rpm works */ 00079 int promoteepoch; /* true: missing epoch is replaced by epoch of dependency */ 00080 int obsoleteusesprovides; /* true: obsoletes are matched against provides, not names */ 00081 int implicitobsoleteusesprovides; /* true: implicit obsoletes due to same name are matched against provides, not names */ 00082 int obsoleteusescolors; /* true: obsoletes check arch color */ 00083 int noinstalledobsoletes; /* true: ignore obsoletes of installed packages */ 00084 int novirtualconflicts; /* true: conflicts on names, not on provides */ 00085 int allowselfconflicts; /* true: packages which conflict with itself are installable */ 00086 #ifdef MULTI_SEMANTICS 00087 int disttype; 00088 #endif 00089 00090 Id *id2arch; /* map arch ids to scores */ 00091 unsigned char *id2color; /* map arch ids to colors */ 00092 Id lastarch; /* last valid entry in id2arch/id2color */ 00093 00094 Queue vendormap; /* map vendor to vendorclasses mask */ 00095 00096 /* providers data, as two-step indirect list 00097 * whatprovides[Id] -> Offset into whatprovidesdata for name 00098 * whatprovidesdata[Offset] -> ID_NULL-terminated list of solvables providing Id 00099 */ 00100 Offset *whatprovides; /* Offset to providers of a specific name, Id -> Offset */ 00101 Offset *whatprovides_rel; /* Offset to providers of a specific relation, Id -> Offset */ 00102 00103 Id *whatprovidesdata; /* Ids of solvable providing Id */ 00104 Offset whatprovidesdataoff; /* next free slot within whatprovidesdata */ 00105 int whatprovidesdataleft; /* number of 'free slots' within whatprovidesdata */ 00106 00107 /* If nonzero, then consider only the solvables with Ids set in this 00108 bitmap for solving. If zero, consider all solvables. */ 00109 Map *considered; 00110 00111 Id (*nscallback)(struct _Pool *, void *data, Id name, Id evr); 00112 void *nscallbackdata; 00113 00114 /* our tmp space string space */ 00115 char *tmpspacebuf[POOL_TMPSPACEBUF]; 00116 int tmpspacelen[POOL_TMPSPACEBUF]; 00117 int tmpspacen; 00118 00119 /* debug mask and callback */ 00120 int debugmask; 00121 void (*debugcallback)(struct _Pool *, void *data, int type, const char *str); 00122 void *debugcallbackdata; 00123 00124 /* load callback */ 00125 int (*loadcallback)(struct _Pool *, struct _Repodata *, void *); 00126 void *loadcallbackdata; 00127 00128 /* search position */ 00129 Repopos pos; 00130 }; 00131 00132 #ifdef MULTI_SEMANTICS 00133 # define DISTTYPE_RPM 0 00134 # define DISTTYPE_DEB 1 00135 #endif 00136 00137 #define SAT_FATAL (1<<0) 00138 #define SAT_ERROR (1<<1) 00139 #define SAT_WARN (1<<2) 00140 #define SAT_DEBUG_STATS (1<<3) 00141 #define SAT_DEBUG_RULE_CREATION (1<<4) 00142 #define SAT_DEBUG_PROPAGATE (1<<5) 00143 #define SAT_DEBUG_ANALYZE (1<<6) 00144 #define SAT_DEBUG_UNSOLVABLE (1<<7) 00145 #define SAT_DEBUG_SOLUTIONS (1<<8) 00146 #define SAT_DEBUG_POLICY (1<<9) 00147 #define SAT_DEBUG_RESULT (1<<10) 00148 #define SAT_DEBUG_JOB (1<<11) 00149 #define SAT_DEBUG_SCHUBI (1<<12) 00150 #define SAT_DEBUG_SOLVER (1<<13) 00151 #define SAT_DEBUG_TRANSACTION (1<<14) 00152 00153 #define SAT_DEBUG_TO_STDERR (1<<30) 00154 00155 //----------------------------------------------- 00156 00157 00158 /* mark dependencies with relation by setting bit31 */ 00159 00160 #define MAKERELDEP(id) ((id) | 0x80000000) 00161 #define ISRELDEP(id) (((id) & 0x80000000) != 0) 00162 #define GETRELID(id) ((id) ^ 0x80000000) /* returns Id */ 00163 #define GETRELDEP(pool, id) ((pool)->rels + ((id) ^ 0x80000000)) /* returns Reldep* */ 00164 00165 #define REL_GT 1 00166 #define REL_EQ 2 00167 #define REL_LT 4 00168 00169 #define REL_AND 16 00170 #define REL_OR 17 00171 #define REL_WITH 18 00172 #define REL_NAMESPACE 19 00173 #define REL_ARCH 20 00174 #define REL_FILECONFLICT 21 00175 00176 #if !defined(__GNUC__) && !defined(__attribute__) 00177 # define __attribute__(x) 00178 #endif 00179 00183 extern Pool *pool_create(void); 00187 extern void pool_free(Pool *pool); 00188 00189 extern void pool_setdebuglevel(Pool *pool, int level); 00190 #ifdef MULTI_SEMANTICS 00191 extern void pool_setdisttype(Pool *pool, int disttype); 00192 #endif 00193 00194 extern void pool_debug(Pool *pool, int type, const char *format, ...) __attribute__((format(printf, 3, 4))); 00195 00196 extern char *pool_alloctmpspace(Pool *pool, int len); 00197 extern char *pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3); 00198 00199 extern void pool_set_installed(Pool *pool, struct _Repo *repo); 00200 00204 extern Id pool_add_solvable(Pool *pool); 00205 extern Id pool_add_solvable_block(Pool *pool, int count); 00206 00207 extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids); 00208 static inline Solvable *pool_id2solvable(const Pool *pool, Id p) 00209 { 00210 return pool->solvables + p; 00211 } 00212 00213 extern const char *solvable2str(Pool *pool, Solvable *s); 00214 static inline const char *solvid2str(Pool *pool, Id p) 00215 { 00216 return solvable2str(pool, pool->solvables + p); 00217 } 00218 00219 void pool_set_languages(Pool *pool, const char **languages, int nlanguages); 00220 Id pool_id2langid(Pool *pool, Id id, const char *lang, int create); 00221 00222 Id solvable_lookup_id(Solvable *s, Id keyname); 00223 unsigned int solvable_lookup_num(Solvable *s, Id keyname, unsigned int notfound); 00224 const char *solvable_lookup_str(Solvable *s, Id keyname); 00225 const char *solvable_lookup_str_poollang(Solvable *s, Id keyname); 00226 const char *solvable_lookup_str_lang(Solvable *s, Id keyname, const char *lang, int usebase); 00227 int solvable_lookup_bool(Solvable *s, Id keyname); 00228 int solvable_lookup_void(Solvable *s, Id keyname); 00229 char * solvable_get_location(Solvable *s, unsigned int *medianrp); 00230 const unsigned char *solvable_lookup_bin_checksum(Solvable *s, Id keyname, Id *typep); 00231 const char *solvable_lookup_checksum(Solvable *s, Id keyname, Id *typep); 00232 int solvable_lookup_idarray(Solvable *s, Id keyname, Queue *q); 00233 int solvable_identical(Solvable *s1, Solvable *s2); 00234 Id solvable_selfprovidedep(Solvable *s); 00235 00236 int solvable_trivial_installable_map(Solvable *s, Map *installedmap, Map *conflictsmap); 00237 int solvable_trivial_installable_repo(Solvable *s, struct _Repo *installed); 00238 int solvable_trivial_installable_queue(Solvable *s, Queue *installed); 00239 00240 void pool_create_state_maps(Pool *pool, Queue *installed, Map *installedmap, Map *conflictsmap); 00241 00242 int pool_match_nevr_rel(Pool *pool, Solvable *s, Id d); 00243 int pool_match_dep(Pool *pool, Id d1, Id d2); 00244 00245 static inline int pool_match_nevr(Pool *pool, Solvable *s, Id d) 00246 { 00247 if (!ISRELDEP(d)) 00248 return d == s->name; 00249 else 00250 return pool_match_nevr_rel(pool, s, d); 00251 } 00252 00253 00257 extern void pool_createwhatprovides(Pool *pool); 00258 extern void pool_addfileprovides(Pool *pool); 00259 extern void pool_addfileprovides_ids(Pool *pool, struct _Repo *installed, Id **idp); 00260 extern void pool_freewhatprovides(Pool *pool); 00261 extern Id pool_queuetowhatprovides(Pool *pool, Queue *q); 00262 00263 extern Id pool_addrelproviders(Pool *pool, Id d); 00264 00265 static inline Id pool_whatprovides(Pool *pool, Id d) 00266 { 00267 Id v; 00268 if (!ISRELDEP(d)) 00269 return pool->whatprovides[d]; 00270 v = GETRELID(d); 00271 if (pool->whatprovides_rel[v]) 00272 return pool->whatprovides_rel[v]; 00273 return pool_addrelproviders(pool, d); 00274 } 00275 00276 static inline Id *pool_whatprovides_ptr(Pool *pool, Id d) 00277 { 00278 Id off = pool_whatprovides(pool, d); 00279 return pool->whatprovidesdata + off; 00280 } 00281 00282 static inline void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata) 00283 { 00284 pool->debugcallback = debugcallback; 00285 pool->debugcallbackdata = debugcallbackdata; 00286 } 00287 00288 static inline void pool_setdebugmask(Pool *pool, int mask) 00289 { 00290 pool->debugmask = mask; 00291 } 00292 00293 static inline void pool_setloadcallback(Pool *pool, int (*cb)(struct _Pool *, struct _Repodata *, void *), void *loadcbdata) 00294 { 00295 pool->loadcallback = cb; 00296 pool->loadcallbackdata = loadcbdata; 00297 } 00298 00299 /* search the pool. the following filters are available: 00300 * p - search just this solvable 00301 * key - search only this key 00302 * match - key must match this string 00303 */ 00304 void pool_search(Pool *pool, Id p, Id key, const char *match, int flags, int (*callback)(void *cbdata, Solvable *s, struct _Repodata *data, struct _Repokey *key, struct _KeyValue *kv), void *cbdata); 00305 00306 void pool_clear_pos(Pool *pool); 00307 00308 00309 typedef struct _DUChanges { 00310 const char *path; 00311 int kbytes; 00312 int files; 00313 } DUChanges; 00314 00315 void pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps); 00316 int pool_calc_installsizechange(Pool *pool, Map *installedmap); 00317 void pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res); 00318 void pool_trivial_installable_noobsoletesmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *noobsoletesmap); 00319 00320 const char *pool_lookup_str(Pool *pool, Id entry, Id keyname); 00321 Id pool_lookup_id(Pool *pool, Id entry, Id keyname); 00322 unsigned int pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned int notfound); 00323 int pool_lookup_void(Pool *pool, Id entry, Id keyname); 00324 const unsigned char *pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep); 00325 const char *pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep); 00326 00327 void pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts); 00328 00329 00330 00331 /* loop over all providers of d */ 00332 #define FOR_PROVIDES(v, vp, d) \ 00333 for (vp = pool_whatprovides(pool, d) ; (v = pool->whatprovidesdata[vp++]) != 0; ) 00334 00335 /* loop over all repositories */ 00336 /* note that idx is not the repoid */ 00337 #define FOR_REPOS(idx, r) \ 00338 for (idx = 0; idx < pool->nrepos; idx++) \ 00339 if ((r = pool->repos[idx]) != 0) 00340 00341 00342 #define POOL_DEBUG(type, ...) do {if ((pool->debugmask & (type)) != 0) pool_debug(pool, (type), __VA_ARGS__);} while (0) 00343 #define IF_POOLDEBUG(type) if ((pool->debugmask & (type)) != 0) 00344 00345 #ifdef __cplusplus 00346 } 00347 #endif 00348 00349 00350 #endif /* SATSOLVER_POOL_H */