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 "common_myfopen.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 = myfopen(argv[i])) == 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 = str2id(pool, "rpm", 0);
140 rpmarch = 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 = 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 solv->dontinstallrecommended = 1;
217 solver_solve(solv, &job);
219 for (i = j = 0; i < cand.count; i++)
221 p = cand.elements[i];
222 if (solv->decisionmap[p] <= 0)
224 cand.elements[j++] = p;
228 Solvable *s = pool->solvables + p;
229 if (!strcmp(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++)
246 p = cand.elements[i];
247 if (nocheck && p >= nocheck)
251 char *ptr, *save = 0, *pattern;
253 pattern = strdup(exclude_pat);
255 for (ptr = strtok_r(pattern, " ", &save);
257 ptr = strtok_r(NULL, " ", &save))
259 if (*ptr && strstr(solvid2str(pool, p), ptr))
269 s = pool->solvables + p;
270 solv = solver_create(pool);
272 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE);
276 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_NAME);
277 queue_push(&job, rpmrel);
281 queue_push(&job, SOLVER_LOCK|SOLVER_SOLVABLE_ONE_OF);
282 queue_push(&job, archlock);
284 solv->dontinstallrecommended = 1;
285 solver_solve(solv, &job);
286 if (solv->problems.count)
292 printf("can't install %s:\n", solvable2str(pool, s));
293 while ((problem = solver_next_problem(solv, problem)) != 0)
295 solver_findallproblemrules(solv, problem, &rids);
296 for (j = 0; j < rids.count; j++)
298 Id probr = rids.elements[j];
303 solver_allruleinfos(solv, probr, &rinfo);
304 for (k = 0; k < rinfo.count; k += 4)
306 Id dep, source, target;
307 source = rinfo.elements[k + 1];
308 target = rinfo.elements[k + 2];
309 dep = rinfo.elements[k + 3];
310 switch (rinfo.elements[k])
312 case SOLVER_PROBLEM_DISTUPGRADE_RULE:
314 case SOLVER_PROBLEM_INFARCH_RULE:
315 s = pool_id2solvable(pool, source);
316 printf(" %s has inferior architecture\n", solvable2str(pool, s));
318 case SOLVER_PROBLEM_UPDATE_RULE:
320 case SOLVER_PROBLEM_JOB_RULE:
322 case SOLVER_PROBLEM_RPM_RULE:
323 printf(" some dependency problem\n");
325 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
326 printf(" nothing provides requested %s\n", dep2str(pool, dep));
328 case SOLVER_PROBLEM_NOT_INSTALLABLE:
329 s = pool_id2solvable(pool, source);
330 printf(" package %s is not installable\n", solvable2str(pool, s));
332 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
333 s = pool_id2solvable(pool, source);
334 printf(" nothing provides %s needed by %s\n", dep2str(pool, dep), solvable2str(pool, s));
337 Reldep *rd = GETRELDEP(pool, dep);
338 if (!ISRELDEP(rd->name))
341 FOR_PROVIDES(rp, rpp, rd->name)
342 printf(" (we have %s)\n", solvable2str(pool, pool->solvables + rp));
346 case SOLVER_PROBLEM_SAME_NAME:
347 s = pool_id2solvable(pool, source);
348 s2 = pool_id2solvable(pool, target);
349 printf(" cannot install both %s and %s\n", solvable2str(pool, s), solvable2str(pool, s2));
351 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
352 s = pool_id2solvable(pool, source);
353 s2 = pool_id2solvable(pool, target);
354 printf(" package %s conflicts with %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
356 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
357 s = pool_id2solvable(pool, source);
358 s2 = pool_id2solvable(pool, target);
359 printf(" package %s obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
361 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
362 s = pool_id2solvable(pool, source);
363 printf(" package %s requires %s, but none of the providers can be installed\n", solvable2str(pool, s), dep2str(pool, dep));
365 case SOLVER_PROBLEM_SELF_CONFLICT:
366 s = pool_id2solvable(pool, source);
367 printf(" package %s conflicts with %s provided by itself\n", solvable2str(pool, s), dep2str(pool, dep));
377 if (!strcmp(id2str(pool, s->name), "libusb-compat-devel"))
379 solver_printdecisions(solv);