1 /* vim: sw=2 et cino=>4,n-2,{1s
5 * Copyright (c) 2009, Novell Inc.
7 * This program is licensed under the BSD license, read LICENSE.BSD
8 * for further information
22 #include "repo_solv.h"
24 #include "repo_susetags.h"
25 #include "repo_rpmmd.h"
30 #include "sat_xfopen.h"
36 printf("Usage:\n%s: <arch> [options..] repo [--nocheck repo]...\n"
37 "\t--exclude <pattern>\twhitespace-separated list of (sub-)"
38 "packagenames to ignore\n"
39 "\t--withsrc\t\tAlso check dependencies of src.rpm\n\n"
46 main(int argc, char **argv)
54 char *arch, *exclude_pat;
57 Id rpmid, rpmarch, rpmrel, archlock;
69 pool_setarch(pool, arch);
70 for (i = 2; i < argc; i++)
75 if (!strcmp(argv[i], "--withsrc"))
80 if (!strcmp(argv[i], "--nocheck"))
83 nocheck = pool->nsolvables;
86 if (!strcmp(argv[i], "--exclude"))
90 printf("--exclude needs a whitespace separated list of substrings as parameter\n");
93 exclude_pat = argv[i + 1];
98 if (!strcmp(argv[i], "-"))
100 else if ((fp = sat_xfopen(argv[i], 0)) == 0)
105 Repo *repo = repo_create(pool, argv[i]);
107 if (l >= 8 && !strcmp(argv[i] + l - 8, "packages"))
109 repo_add_susetags(repo, fp, 0, 0, 0);
111 else if (l >= 11 && !strcmp(argv[i] + l - 11, "packages.gz"))
113 repo_add_susetags(repo, fp, 0, 0, 0);
115 else if (l >= 14 && !strcmp(argv[i] + l - 14, "primary.xml.gz"))
117 repo_add_rpmmd(repo, fp, 0, 0);
120 if (l >= 8 && !strcmp(argv[i] + l - 8, "Packages"))
122 repo_add_debpackages(repo, fp, 0);
124 else if (l >= 11 && !strcmp(argv[i] + l - 11, "Packages.gz"))
126 repo_add_debpackages(repo, fp, 0);
129 else if (repo_add_solv(repo, fp))
131 fprintf(stderr, "could not add repo %s\n", argv[i]);
137 pool_addfileprovides(pool);
138 pool_createwhatprovides(pool);
139 rpmid = pool_str2id(pool, "rpm", 0);
140 rpmarch = pool_str2id(pool, arch, 0);
143 if (rpmid && rpmarch)
145 for (p = 1; p < pool->nsolvables; p++)
147 Solvable *s = pool->solvables + p;
148 if (s->name == rpmid && s->arch == rpmarch)
151 if (p < pool->nsolvables)
152 rpmrel = pool_rel2id(pool, rpmid, rpmarch, REL_ARCH, 1);
159 queue_init(&archlocks);
160 for (p = 1; p < pool->nsolvables; p++)
162 Solvable *s = pool->solvables + p;
165 if (withsrc && (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC))
167 queue_push(&cand, p);
170 if (!pool_installable(pool, s))
172 if (rpmrel && s->arch != rpmarch)
175 FOR_PROVIDES(rp, rpp, s->name)
177 if (pool->solvables[rp].name != s->name)
179 if (pool->solvables[rp].arch == rpmarch)
184 queue_push(&archlocks, p);
188 queue_push(&cand, p);
193 archlock = pool_queuetowhatprovides(pool, &archlocks);
195 /* prune cand by doing weak installs */
198 solv = solver_create(pool);
200 for (i = 0; i < cand.count; i++)
202 p = cand.elements[i];
203 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE|SOLVER_WEAK);
208 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_NAME);
209 queue_push(&job, rpmrel);
213 queue_push(&job, SOLVER_LOCK|SOLVER_SOLVABLE_ONE_OF);
214 queue_push(&job, archlock);
216 solver_set_flag(solv, SOLVER_FLAG_IGNORE_RECOMMENDED, 1);
217 solver_solve(solv, &job);
219 for (i = j = 0; i < cand.count; i++)
221 p = cand.elements[i];
222 if (solver_get_decisionlevel(solv, p) <= 0)
224 cand.elements[j++] = p;
228 Solvable *s = pool->solvables + p;
229 if (!strcmp(pool_id2str(pool, s->name), "libusb-compat-devel"))
231 cand.elements[j++] = p;
241 /* now check every candidate */
242 for (i = 0; i < cand.count; i++)
247 p = cand.elements[i];
248 if (nocheck && p >= nocheck)
252 char *ptr, *save = 0, *pattern;
254 pattern = strdup(exclude_pat);
256 for (ptr = strtok_r(pattern, " ", &save);
258 ptr = strtok_r(NULL, " ", &save))
260 if (*ptr && strstr(pool_solvid2str(pool, p), ptr))
270 s = pool->solvables + p;
271 solv = solver_create(pool);
273 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE);
277 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_NAME);
278 queue_push(&job, rpmrel);
282 queue_push(&job, SOLVER_LOCK|SOLVER_SOLVABLE_ONE_OF);
283 queue_push(&job, archlock);
285 solver_set_flag(solv, SOLVER_FLAG_IGNORE_RECOMMENDED, 1);
286 problemcount = solver_solve(solv, &job);
293 printf("can't install %s:\n", pool_solvable2str(pool, s));
294 while ((problem = solver_next_problem(solv, problem)) != 0)
296 solver_findallproblemrules(solv, problem, &rids);
297 for (j = 0; j < rids.count; j++)
299 Id probr = rids.elements[j];
304 solver_allruleinfos(solv, probr, &rinfo);
305 for (k = 0; k < rinfo.count; k += 4)
307 Id dep, source, target;
308 source = rinfo.elements[k + 1];
309 target = rinfo.elements[k + 2];
310 dep = rinfo.elements[k + 3];
311 switch (rinfo.elements[k])
313 case SOLVER_RULE_DISTUPGRADE:
315 case SOLVER_RULE_INFARCH:
316 s = pool_id2solvable(pool, source);
317 printf(" %s has inferior architecture\n", pool_solvable2str(pool, s));
319 case SOLVER_RULE_UPDATE:
321 case SOLVER_RULE_JOB:
323 case SOLVER_RULE_RPM:
324 printf(" some dependency problem\n");
326 case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
327 printf(" nothing provides requested %s\n", pool_dep2str(pool, dep));
329 case SOLVER_RULE_RPM_NOT_INSTALLABLE:
330 s = pool_id2solvable(pool, source);
331 printf(" package %s is not installable\n", pool_solvable2str(pool, s));
333 case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP:
334 s = pool_id2solvable(pool, source);
335 printf(" nothing provides %s needed by %s\n", pool_dep2str(pool, dep), pool_solvable2str(pool, s));
338 Reldep *rd = GETRELDEP(pool, dep);
339 if (!ISRELDEP(rd->name))
342 FOR_PROVIDES(rp, rpp, rd->name)
343 printf(" (we have %s)\n", pool_solvable2str(pool, pool->solvables + rp));
347 case SOLVER_RULE_RPM_SAME_NAME:
348 s = pool_id2solvable(pool, source);
349 s2 = pool_id2solvable(pool, target);
350 printf(" cannot install both %s and %s\n", pool_solvable2str(pool, s), pool_solvable2str(pool, s2));
352 case SOLVER_RULE_RPM_PACKAGE_CONFLICT:
353 s = pool_id2solvable(pool, source);
354 s2 = pool_id2solvable(pool, target);
355 printf(" package %s conflicts with %s provided by %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, dep), pool_solvable2str(pool, s2));
357 case SOLVER_RULE_RPM_PACKAGE_OBSOLETES:
358 s = pool_id2solvable(pool, source);
359 s2 = pool_id2solvable(pool, target);
360 printf(" package %s obsoletes %s provided by %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, dep), pool_solvable2str(pool, s2));
362 case SOLVER_RULE_RPM_PACKAGE_REQUIRES:
363 s = pool_id2solvable(pool, source);
364 printf(" package %s requires %s, but none of the providers can be installed\n", pool_solvable2str(pool, s), pool_dep2str(pool, dep));
366 case SOLVER_RULE_RPM_SELF_CONFLICT:
367 s = pool_id2solvable(pool, source);
368 printf(" package %s conflicts with %s provided by itself\n", pool_solvable2str(pool, s), pool_dep2str(pool, dep));
378 if (!strcmp(pool_id2str(pool, s->name), "libusb-compat-devel"))
380 solver_printdecisions(solv);