2 * Copyright (c) 2012, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
19 #include "poolvendor.h"
21 #include "repo_susetags.h"
22 #include "repo_solv.h"
24 #include "solverdebug.h"
27 #include "solv_xfopen.h"
29 #ifndef ENABLE_SUSEREPO
30 # define DISABLE_JOIN2
31 # include "tools_util.h"
33 # include "repo_susetags.h"
36 static struct job2str {
40 { SOLVER_NOOP, "noop" },
41 { SOLVER_INSTALL, "install" },
42 { SOLVER_ERASE, "erase" },
43 { SOLVER_UPDATE, "update" },
44 { SOLVER_WEAKENDEPS, "weakendeps" },
45 { SOLVER_NOOBSOLETES, "noobsoletes" },
46 { SOLVER_LOCK, "lock" },
47 { SOLVER_DISTUPGRADE, "distupgrade" },
48 { SOLVER_VERIFY, "verify" },
49 { SOLVER_DROP_ORPHANED, "droporphaned" },
50 { SOLVER_USERINSTALLED, "userinstalled" },
54 static struct jobflags2str {
58 { SOLVER_WEAK, "weak" },
59 { SOLVER_ESSENTIAL, "essential" },
60 { SOLVER_CLEANDEPS, "cleandeps" },
61 { SOLVER_SETEV, "setev" },
62 { SOLVER_SETEVR, "setevr" },
63 { SOLVER_SETARCH, "setarch" },
64 { SOLVER_SETVENDOR, "setvendor" },
65 { SOLVER_SETREPO, "setrepo" },
66 { SOLVER_NOAUTOSET, "noautoset" },
70 static struct resultflags2str {
73 } resultflags2str[] = {
74 { TESTCASE_RESULT_TRANSACTION, "transaction" },
75 { TESTCASE_RESULT_PROBLEMS, "problems" },
76 { TESTCASE_RESULT_ORPHANED, "orphaned" },
77 { TESTCASE_RESULT_RECOMMENDED, "recommended" },
78 { TESTCASE_RESULT_UNNEEDED, "unneeded" },
82 static struct solverflags2str {
86 } solverflags2str[] = {
87 { SOLVER_FLAG_ALLOW_DOWNGRADE, "allowdowngrade", 0 },
88 { SOLVER_FLAG_ALLOW_ARCHCHANGE, "allowarchchange", 0 },
89 { SOLVER_FLAG_ALLOW_VENDORCHANGE, "allowvendorchange", 0 },
90 { SOLVER_FLAG_ALLOW_UNINSTALL, "allowuninstall", 0 },
91 { SOLVER_FLAG_NO_UPDATEPROVIDE, "noupdateprovide", 0 },
92 { SOLVER_FLAG_SPLITPROVIDES, "splitprovides", 0 },
93 { SOLVER_FLAG_IGNORE_RECOMMENDED, "ignorerecommended", 0 },
94 { SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, "addalreadyrecommended", 0 },
95 { SOLVER_FLAG_NO_INFARCHCHECK, "noinfarchcheck", 0 },
99 static struct poolflags2str {
103 } poolflags2str[] = {
104 { POOL_FLAG_PROMOTEEPOCH, "promoteepoch", 0 },
105 { POOL_FLAG_FORBIDSELFCONFLICTS, "forbidselfconflicts", 0 },
106 { POOL_FLAG_OBSOLETEUSESPROVIDES, "obsoleteusesprovides", 0 },
107 { POOL_FLAG_IMPLICITOBSOLETEUSESPROVIDES, "implicitobsoleteusesprovides", 0 },
108 { POOL_FLAG_OBSOLETEUSESCOLORS, "obsoleteusescolors", 0 },
109 { POOL_FLAG_NOINSTALLEDOBSOLETES, "noinstalledobsoletes", 0 },
114 typedef struct strqueue {
119 #define STRQUEUE_BLOCK 63
122 strqueue_init(Strqueue *q)
129 strqueue_free(Strqueue *q)
132 for (i = 0; i < q->nstr; i++)
133 solv_free(q->str[i]);
134 q->str = solv_free(q->str);
139 strqueue_push(Strqueue *q, const char *s)
141 q->str = solv_extend(q->str, q->nstr, 1, sizeof(*q->str), STRQUEUE_BLOCK);
142 q->str[q->nstr++] = solv_strdup(s);
146 strqueue_pushjoin(Strqueue *q, const char *s1, const char *s2, const char *s3)
148 q->str = solv_extend(q->str, q->nstr, 1, sizeof(*q->str), STRQUEUE_BLOCK);
149 q->str[q->nstr++] = solv_dupjoin(s1, s2, s3);
153 strqueue_sort_cmp(const void *ap, const void *bp, void *dp)
155 const char *a = *(const char **)ap;
156 const char *b = *(const char **)bp;
157 return strcmp(a ? a : "", b ? b : "");
161 strqueue_sort(Strqueue *q)
164 solv_sort(q->str, q->nstr, sizeof(*q->str), strqueue_sort_cmp, 0);
168 strqueue_sort_u(Strqueue *q)
172 for (i = j = 0; i < q->nstr; i++)
173 if (!j || strqueue_sort_cmp(q->str + i, q->str + j - 1, 0) != 0)
174 q->str[j++] = q->str[i];
179 strqueue_join(Strqueue *q)
183 for (i = 0; i < q->nstr; i++)
185 l += strlen(q->str[i]) + 1;
186 l++; /* trailing \0 */
189 for (i = 0; i < q->nstr; i++)
192 strcpy(rp, q->str[i]);
201 strqueue_split(Strqueue *q, const char *s)
206 while ((p = strchr(s, '\n')) != 0)
208 q->str = solv_extend(q->str, q->nstr, 1, sizeof(*q->str), STRQUEUE_BLOCK);
209 q->str[q->nstr] = solv_malloc(p - s + 1);
211 memcpy(q->str[q->nstr], s, p - s);
212 q->str[q->nstr][p - s] = 0;
221 strqueue_diff(Strqueue *sq1, Strqueue *sq2, Strqueue *osq)
224 while (i < sq1->nstr && j < sq2->nstr)
226 int r = strqueue_sort_cmp(sq1->str + i, sq2->str + j, 0);
230 strqueue_pushjoin(osq, "-", sq1->str[i++], 0);
232 strqueue_pushjoin(osq, "+", sq2->str[j++], 0);
234 while (i < sq1->nstr)
235 strqueue_pushjoin(osq, "-", sq1->str[i++], 0);
236 while (j < sq2->nstr)
237 strqueue_pushjoin(osq, "+", sq2->str[j++], 0);
241 pool_isknownarch(Pool *pool, Id id)
243 if (!id || id == ID_EMPTY)
245 if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
247 if (!pool->id2arch || (id > pool->lastarch || !pool->id2arch[id]))
253 testcase_str2dep(Pool *pool, char *s)
259 if ((n = strchr(s, '|')) != 0)
261 id = testcase_str2dep(pool, n + 1);
263 id = pool_rel2id(pool, testcase_str2dep(pool, s), id, REL_OR, 1);
267 while (*s == ' ' || *s == '\t')
270 while (*s && *s != ' ' && *s != '\t' && *s != '<' && *s != '=' && *s != '>')
274 while (*s && *s != ')')
280 if ((a = strchr(n, '.')) != 0 && a + 1 < s && s[-1] != ')')
282 Id archid = pool_strn2id(pool, a + 1, s - (a + 1), 0);
283 if (pool_isknownarch(pool, archid))
285 id = pool_strn2id(pool, n, a - n, 1);
286 id = pool_rel2id(pool, id, archid, REL_ARCH, 1);
289 id = pool_strn2id(pool, n, s - n, 1);
292 id = pool_strn2id(pool, n, s - n, 1);
295 while (*s == ' ' || *s == '\t')
311 while (*s == ' ' || *s == '\t')
314 while (*s && *s != ' ' && *s != '\t')
316 return pool_rel2id(pool, id, pool_strn2id(pool, n, s - n, 1), flags, 1);
320 testcase_repoid2str(Pool *pool, Id repoid)
322 Repo *repo = pool_id2repo(pool, repoid);
325 char *r = pool_tmpjoin(pool, repo->name, 0, 0);
327 for (rp = r; *rp; rp++)
328 if (*rp == ' ' || *rp == '\t')
335 sprintf(buf, "#%d", repoid);
336 return pool_tmpjoin(pool, buf, 0, 0);
341 testcase_solvid2str(Pool *pool, Id p)
343 Solvable *s = pool->solvables + p;
347 if (p == SYSTEMSOLVABLE)
349 str = pool_solvid2str(pool, p);
351 return pool_tmpappend(pool, str, "@", 0);
355 char *str2 = pool_tmpappend(pool, str, "@", s->repo->name);
357 if (str2[l] == ' ' || str2[l] == '\t')
361 sprintf(buf, "@#%d", s->repo->repoid);
362 return pool_tmpappend(pool, str, buf, 0);
366 testcase_str2repo(Pool *pool, const char *str)
370 if (str[0] == '#' && (str[1] >= '0' && str[1] <= '9'))
374 for (j = 1; str[j] >= '0' && str[j] <= '9'; j++)
375 repoid = repoid * 10 + (str[j] - '0');
376 if (!str[j] && repoid > 0 && repoid < pool->nrepos)
377 repo = pool_id2repo(pool, repoid);
381 FOR_REPOS(repoid, repo)
386 l = strlen(repo->name);
387 for (i = 0; i < l; i++)
389 int c = repo->name[i];
390 if (c == ' ' || c == '\t')
395 if (i == l && !str[l])
398 if (repoid >= pool->nrepos)
405 testcase_str2solvid(Pool *pool, const char *str)
407 int i, l = strlen(str);
414 if (*str == '@' && !strcmp(str, "@SYSTEM"))
415 return SYSTEMSOLVABLE;
417 for (i = l - 1; i >= 0; i--)
418 if (str[i] == '@' && (repo = testcase_str2repo(pool, str + i + 1)) != 0)
423 /* now find the arch (if present) */
425 for (i = repostart - 1; i > 0; i--)
428 arch = pool_strn2id(pool, str + i + 1, repostart - (i + 1), 0);
433 /* now find the name */
434 for (i = repostart - 1; i > 0; i--)
438 Id nid, evrid, p, pp;
439 nid = pool_strn2id(pool, str, i, 0);
442 evrid = pool_strn2id(pool, str + i + 1, repostart - (i + 1), 0);
445 FOR_PROVIDES(p, pp, nid)
447 Solvable *s = pool->solvables + p;
448 if (s->name != nid || s->evr != evrid)
450 if (repo && s->repo != repo)
452 if (arch && s->arch != arch)
462 testcase_job2str(Pool *pool, Id how, Id what)
469 Id select = how & SOLVER_SELECTMASK;
471 for (i = 0; job2str[i].str; i++)
472 if ((how & SOLVER_JOBMASK) == job2str[i].job)
474 jobstr = job2str[i].str ? job2str[i].str : "unknown";
475 if (select == SOLVER_SOLVABLE)
478 pkgstr = testcase_solvid2str(pool, what);
480 else if (select == SOLVER_SOLVABLE_NAME)
483 pkgstr = pool_dep2str(pool, what);
485 else if (select == SOLVER_SOLVABLE_PROVIDES)
487 selstr = " provides ";
488 pkgstr = pool_dep2str(pool, what);
490 else if (select == SOLVER_SOLVABLE_ONE_OF)
495 while ((p = pool->whatprovidesdata[what++]) != 0)
497 const char *s = testcase_solvid2str(pool, p);
500 pkgstr = pool_tmpappend(pool, pkgstr, " ", s);
501 pool_freetmpspace(pool, s);
509 else if (select == SOLVER_SOLVABLE_REPO)
511 Repo *repo = pool_id2repo(pool, what);
516 sprintf(buf, "#%d", repo->repoid);
517 pkgstr = pool_tmpjoin(pool, buf, 0, 0);
520 pkgstr = pool_tmpjoin(pool, repo->name, 0, 0);
522 else if (select == SOLVER_SOLVABLE_ALL)
529 selstr = " unknown ";
532 ret = pool_tmpjoin(pool, jobstr, selstr, pkgstr);
534 ret = pool_tmpappend(pool, ret, " ", 0);
535 for (i = 0; jobflags2str[i].str; i++)
536 if ((how & jobflags2str[i].flag) != 0)
537 ret = pool_tmpappend(pool, ret, ",", jobflags2str[i].str);
543 ret = pool_tmpappend(pool, ret, "]", 0);
549 testcase_str2job(Pool *pool, const char *str, Id *whatp)
559 /* so we can patch it */
560 s = pool_tmpjoin(pool, str, 0, 0);
561 /* split it in pieces */
564 while (*s == ' ' || *s == '\t')
568 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
569 pieces[npieces++] = s;
570 while (*s && *s != ' ' && *s != '\t')
577 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
581 for (i = 0; job2str[i].str; i++)
582 if (!strcmp(pieces[0], job2str[i].str))
586 pool_debug(pool, SOLV_ERROR, "str2job: unknown job '%s'\n", str);
589 job = job2str[i].job;
592 char *flags = pieces[npieces - 1];
594 if (*flags == '[' && flags[strlen(flags) - 1] == ']')
598 flags[strlen(flags) - 1] = ',';
601 for (nf = flags; *nf != ','; nf++)
604 for (i = 0; jobflags2str[i].str; i++)
605 if (!strcmp(flags, jobflags2str[i].str))
607 if (!jobflags2str[i].str)
609 pool_debug(pool, SOLV_ERROR, "str2job: unknown jobflags in '%s'\n", str);
612 job |= jobflags2str[i].flag;
617 if (!strcmp(pieces[1], "pkg"))
621 pool_debug(pool, SOLV_ERROR, "str2job: bad pkg selector in '%s'\n", str);
624 job |= SOLVER_SOLVABLE;
625 what = testcase_str2solvid(pool, pieces[2]);
628 pool_debug(pool, SOLV_ERROR, "str2job: unknown package '%s'\n", pieces[2]);
632 else if (!strcmp(pieces[1], "name") || !strcmp(pieces[1], "provides"))
634 /* join em again for dep2str... */
636 for (sp = pieces[2]; sp < pieces[npieces - 1]; sp++)
639 what = testcase_str2dep(pool, pieces[2]);
640 if (pieces[1][0] == 'n')
641 job |= SOLVER_SOLVABLE_NAME;
643 job |= SOLVER_SOLVABLE_PROVIDES;
645 else if (!strcmp(pieces[1], "oneof"))
648 job |= SOLVER_SOLVABLE_ONE_OF;
650 if (npieces > 3 && strcmp(pieces[2], "nothing") != 0)
652 for (i = 2; i < npieces; i++)
654 Id p = testcase_str2solvid(pool, pieces[i]);
657 pool_debug(pool, SOLV_ERROR, "str2job: unknown package '%s'\n", pieces[i]);
664 what = pool_queuetowhatprovides(pool, &q);
667 else if (!strcmp(pieces[1], "repo"))
672 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
675 repo = testcase_str2repo(pool, pieces[2]);
678 pool_debug(pool, SOLV_ERROR, "str2job: unknown repo '%s'\n", pieces[2]);
681 job |= SOLVER_SOLVABLE_REPO;
684 else if (!strcmp(pieces[1], "all"))
686 if (npieces != 3 && strcmp(pieces[2], "packages") != 0)
688 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
691 job |= SOLVER_SOLVABLE_ALL;
696 pool_debug(pool, SOLV_ERROR, "str2job: unknown selection in '%s'\n", str);
704 writedeps(Repo *repo, FILE *fp, const char *tag, Id key, Solvable *s, Offset off)
706 Pool *pool = repo->pool;
713 dp = repo->idarraydata + off;
715 while ((id = *dp++) != 0)
717 if (key == SOLVABLE_REQUIRES && id == SOLVABLE_PREREQMARKER)
720 fprintf(fp, "-%s\n", tag);
725 if (key == SOLVABLE_PROVIDES && id == SOLVABLE_FILEMARKER)
730 idstr = pool_dep2str(pool, id);
733 Reldep *rd = GETRELDEP(pool, id);
734 if (key == SOLVABLE_CONFLICTS && rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
736 if (!strncmp(idstr, "namespace:", 10))
739 if (key == SOLVABLE_SUPPLEMENTS)
741 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_FILESYSTEM)
743 if (!strncmp(idstr, "namespace:", 10))
746 else if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_MODALIAS)
748 if (!strncmp(idstr, "namespace:", 10))
751 else if (rd->flags == REL_AND)
753 /* either packageand chain or modalias */
755 if (ISRELDEP(rd->evr))
757 Reldep *mrd = GETRELDEP(pool, rd->evr);
758 if (mrd->flags == REL_NAMESPACE && mrd->name == NAMESPACE_MODALIAS)
760 idstr = pool_tmpjoin(pool, "modalias(", pool_dep2str(pool, rd->name), ":");
761 idstr = pool_tmpappend(pool, idstr, pool_dep2str(pool, mrd->evr), ")");
763 else if (mrd->flags >= 8)
768 /* must be and chain */
769 idstr = pool_dep2str(pool, rd->evr);
775 rd = GETRELDEP(pool, id);
776 if (rd->flags != REL_AND)
778 idstr = pool_tmpjoin(pool, pool_dep2str(pool, rd->evr), ":", idstr);
780 idstr = pool_tmpjoin(pool, pool_dep2str(pool, id), ":", idstr);
781 idstr = pool_tmpjoin(pool, "packageand(", idstr, ")");
784 else if (rd->flags >= 8)
790 fprintf(fp, "+%s\n", tag);
793 fprintf(fp, "%s\n", idstr);
795 if (key == SOLVABLE_PROVIDES)
797 /* add the filelist */
799 dataiterator_init(&di, pool, repo, s - pool->solvables, SOLVABLE_FILELIST, 0, 0);
800 while (dataiterator_step(&di))
802 const char *s = repodata_dir2str(di.data, di.kv.id, di.kv.str);
805 Id id = pool_str2id(pool, s, 0);
808 for (dp = prvdp; *dp; dp++)
812 continue; /* already included */
817 fprintf(fp, "+%s", tag);
820 fprintf(fp, "%s\n", s);
824 fprintf(fp, "-%s\n", tag);
828 testcase_write_susetags(Repo *repo, FILE *fp)
830 Pool *pool = repo->pool;
840 fprintf(fp, "=Ver: 2.0\n");
841 FOR_REPO_SOLVABLES(repo, p, s)
843 name = pool_id2str(pool, s->name);
844 evr = pool_id2str(pool, s->evr);
845 arch = pool_id2str(pool, s->arch);
846 release = strrchr(evr, '-');
848 release = evr + strlen(evr);
849 fprintf(fp, "=Pkg: %s %.*s %s %s\n", name, release - evr, evr, *release && release[1] ? release + 1 : "-", arch);
850 tmp = solvable_lookup_str(s, SOLVABLE_SUMMARY);
852 fprintf(fp, "=Sum: %s\n", tmp);
853 writedeps(repo, fp, "Req:", SOLVABLE_REQUIRES, s, s->requires);
854 writedeps(repo, fp, "Prv:", SOLVABLE_PROVIDES, s, s->provides);
855 writedeps(repo, fp, "Obs:", SOLVABLE_OBSOLETES, s, s->obsoletes);
856 writedeps(repo, fp, "Con:", SOLVABLE_CONFLICTS, s, s->conflicts);
857 writedeps(repo, fp, "Rec:", SOLVABLE_RECOMMENDS, s, s->recommends);
858 writedeps(repo, fp, "Sup:", SOLVABLE_SUPPLEMENTS, s, s->supplements);
859 writedeps(repo, fp, "Sug:", SOLVABLE_SUGGESTS, s, s->suggests);
860 writedeps(repo, fp, "Enh:", SOLVABLE_ENHANCES, s, s->enhances);
862 fprintf(fp, "=Vnd: %s\n", pool_id2str(pool, s->vendor));
863 ti = solvable_lookup_num(s, SOLVABLE_BUILDTIME, 0);
865 fprintf(fp, "=Tim: %u\n", ti);
870 #ifndef ENABLE_SUSEREPO
873 adddep(Repo *repo, Offset olddeps, char *str, Id marker)
875 Id id = *str == '/' ? pool_str2id(repo->pool, str, 1) : testcase_str2dep(repo->pool, str);
876 return repo_addid_dep(repo, olddeps, id, marker);
880 finish_solvable(Pool *pool, Repodata *data, Solvable *s, char *filelist, int nfilelist)
886 for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1)
888 char *p = strrchr(filelist + l, '/');
892 did = repodata_str2dir(data, filelist + l, 1);
895 did = repodata_str2dir(data, "/", 1);
896 repodata_add_dirstr(data, s - pool->solvables, SOLVABLE_FILELIST, did, p);
899 if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
900 s->provides = repo_addid_dep(s->repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
901 s->supplements = repo_fix_supplements(s->repo, s->provides, s->supplements, 0);
902 s->conflicts = repo_fix_conflicts(s->repo, s->conflicts);
905 /* stripped down version of susetags parser used for testcases */
907 testcase_add_susetags(Repo *repo, FILE *fp, int flags)
909 Pool *pool = repo->pool;
922 data = repo_add_repodata(repo, flags);
927 line = solv_malloc(aline);
931 if (linep - line + 16 > aline)
933 aline = linep - line;
934 line = solv_realloc(line, aline + 512);
935 linep = line + aline;
938 if (!fgets(linep, aline - (linep - line), fp))
940 linep += strlen(linep);
941 if (linep == line || linep[-1] != '\n')
944 linep = line + intag;
947 if (line[intag] == '-' && !strncmp(line + 1, line + intag + 1, intag - 2))
954 else if (line[0] == '+' && line[1] && line[1] != ':')
956 char *tagend = strchr(line, ':');
961 intag = tagend + 2 - line;
962 linep = line + intag;
965 if (*line != '=' || !line[1] || !line[2] || !line[3] || line[4] != ':')
967 tag = line[1] << 16 | line[2] << 8 | line[3];
970 case 'P' << 16 | 'k' << 8 | 'g':
972 finish_solvable(pool, data, s, filelist, nfilelist);
974 if (split(line + 5, sp, 5) != 4)
976 s = pool_id2solvable(pool, repo_add_solvable(repo));
977 s->name = pool_str2id(pool, sp[0], 1);
978 /* join back version and release */
979 if (sp[2] && !(sp[2][0] == '-' && !sp[2][1]))
981 s->evr = makeevr(pool, sp[1]);
982 s->arch = pool_str2id(pool, sp[3], 1);
984 case 'S' << 16 | 'u' << 8 | 'm':
985 repodata_set_str(data, s - pool->solvables, SOLVABLE_SUMMARY, line + 6);
987 case 'V' << 16 | 'n' << 8 | 'd':
988 s->vendor = pool_str2id(pool, line + 6, 1);
990 case 'T' << 16 | 'i' << 8 | 'm':
993 repodata_set_num(data, s - pool->solvables, SOLVABLE_BUILDTIME, t);
995 case 'R' << 16 | 'e' << 8 | 'q':
996 s->requires = adddep(repo, s->requires, line + 6, -SOLVABLE_PREREQMARKER);
998 case 'P' << 16 | 'r' << 8 | 'q':
999 s->requires = adddep(repo, s->requires, line + 6, SOLVABLE_PREREQMARKER);
1001 case 'P' << 16 | 'r' << 8 | 'v':
1004 int l = strlen(line + 6) + 1;
1005 if (nfilelist + l > afilelist)
1007 afilelist = nfilelist + l + 512;
1008 filelist = solv_realloc(filelist, afilelist);
1010 memcpy(filelist + nfilelist, line + 6, l);
1017 for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1)
1018 s->provides = repo_addid_dep(repo, s->provides, pool_str2id(pool, filelist + l, 1), 0);
1021 s->provides = adddep(repo, s->provides, line + 6, 0);
1023 case 'O' << 16 | 'b' << 8 | 's':
1024 s->obsoletes = adddep(repo, s->obsoletes, line + 6, 0);
1026 case 'C' << 16 | 'o' << 8 | 'n':
1027 s->conflicts = adddep(repo, s->conflicts, line + 6, 0);
1029 case 'R' << 16 | 'e' << 8 | 'c':
1030 s->recommends = adddep(repo, s->recommends, line + 6, 0);
1032 case 'S' << 16 | 'u' << 8 | 'p':
1033 s->supplements = adddep(repo, s->supplements, line + 6, 0);
1035 case 'S' << 16 | 'u' << 8 | 'g':
1036 s->suggests = adddep(repo, s->suggests, line + 6, 0);
1038 case 'E' << 16 | 'n' << 8 | 'h':
1039 s->enhances = adddep(repo, s->enhances, line + 6, 0);
1046 finish_solvable(pool, data, s, filelist, nfilelist);
1048 solv_free(filelist);
1049 repodata_free_dircache(data);
1050 if (!(flags & REPO_NO_INTERNALIZE))
1051 repodata_internalize(data);
1058 testcase_add_susetags(Repo *repo, FILE *fp, int flags)
1060 return repo_add_susetags(repo, fp, 0, 0, flags);
1066 testcase_getpoolflags(Pool *pool)
1068 const char *str = 0;
1070 for (i = 0; poolflags2str[i].str; i++)
1072 v = pool_get_flag(pool, poolflags2str[i].flag);
1073 if (v == poolflags2str[i].def)
1075 str = pool_tmpappend(pool, str, v ? " " : " !", poolflags2str[i].str);
1077 return str ? str + 1 : "";
1081 testcase_setpoolflags(Pool *pool, const char *str)
1083 const char *p = str, *s;
1087 while (*p == ' ' || *p == '\t' || *p == ',')
1098 while (*p && *p != ' ' && *p != '\t' && *p != ',')
1100 for (i = 0; poolflags2str[i].str; i++)
1101 if (!strncmp(poolflags2str[i].str, s, p - s) && poolflags2str[i].str[p - s] == 0)
1103 if (!poolflags2str[i].str)
1105 pool_debug(pool, SOLV_ERROR, "setpoolflags: unknown flag '%.*s'\n", p - s, s);
1108 pool_set_flag(pool, poolflags2str[i].flag, v);
1114 testcase_resetpoolflags(Pool *pool)
1117 for (i = 0; poolflags2str[i].str; i++)
1118 pool_set_flag(pool, poolflags2str[i].flag, poolflags2str[i].def);
1122 testcase_getsolverflags(Solver *solv)
1124 Pool *pool = solv->pool;
1125 const char *str = 0;
1127 for (i = 0; solverflags2str[i].str; i++)
1129 v = solver_get_flag(solv, solverflags2str[i].flag);
1130 if (v == solverflags2str[i].def)
1132 str = pool_tmpappend(pool, str, v ? " " : " !", solverflags2str[i].str);
1134 return str ? str + 1 : "";
1138 testcase_setsolverflags(Solver *solv, const char *str)
1140 const char *p = str, *s;
1144 while (*p == ' ' || *p == '\t' || *p == ',')
1155 while (*p && *p != ' ' && *p != '\t' && *p != ',')
1157 for (i = 0; solverflags2str[i].str; i++)
1158 if (!strncmp(solverflags2str[i].str, s, p - s) && solverflags2str[i].str[p - s] == 0)
1160 if (!solverflags2str[i].str)
1162 pool_debug(solv->pool, SOLV_ERROR, "setsolverflags: unknown flag '%.*s'\n", p - s, s);
1165 solver_set_flag(solv, solverflags2str[i].flag, v);
1171 testcase_resetsolverflags(Solver *solv)
1174 for (i = 0; solverflags2str[i].str; i++)
1175 solver_set_flag(solv, solverflags2str[i].flag, solverflags2str[i].def);
1179 testcase_ruleid(Solver *solv, Id rid)
1185 const unsigned char *md5;
1191 solver_ruleliterals(solv, rid, &q);
1192 for (i = 0; i < q.count; i++)
1194 Id p = q.elements[i];
1195 s = testcase_solvid2str(solv->pool, p > 0 ? p : -p);
1197 s = pool_tmpjoin(solv->pool, "!", s, 0);
1198 strqueue_push(&sq, s);
1201 strqueue_sort_u(&sq);
1202 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1203 for (i = 0; i < sq.nstr; i++)
1204 solv_chksum_add(chk, sq.str[i], strlen(sq.str[i]) + 1);
1205 md5 = solv_chksum_get(chk, &md5l);
1206 s = pool_bin2hex(solv->pool, md5, md5l);
1207 chk = solv_chksum_free(chk, 0);
1213 testcase_problemid(Solver *solv, Id problem)
1218 const unsigned char *md5;
1222 /* we build a hash of all rules that define the problem */
1225 solver_findallproblemrules(solv, problem, &q);
1226 for (i = 0; i < q.count; i++)
1227 strqueue_push(&sq, testcase_ruleid(solv, q.elements[i]));
1229 strqueue_sort_u(&sq);
1230 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1231 for (i = 0; i < sq.nstr; i++)
1232 solv_chksum_add(chk, sq.str[i], strlen(sq.str[i]) + 1);
1233 md5 = solv_chksum_get(chk, &md5l);
1234 s = pool_bin2hex(solv->pool, md5, 4);
1235 chk = solv_chksum_free(chk, 0);
1241 testcase_solutionid(Solver *solv, Id problem, Id solution)
1245 const unsigned char *md5;
1249 intid = solver_solutionelement_internalid(solv, problem, solution);
1250 /* internal stuff! handle with care! */
1254 s = testcase_job2str(solv->pool, solv->job.elements[-intid - 1], solv->job.elements[-intid]);
1259 s = testcase_ruleid(solv, intid);
1261 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1262 solv_chksum_add(chk, s, strlen(s) + 1);
1263 md5 = solv_chksum_get(chk, &md5l);
1264 s = pool_bin2hex(solv->pool, md5, 4);
1265 chk = solv_chksum_free(chk, 0);
1269 static struct class2str {
1273 { SOLVER_TRANSACTION_ERASE, "erase" },
1274 { SOLVER_TRANSACTION_INSTALL, "install" },
1275 { SOLVER_TRANSACTION_REINSTALLED, "reinstall" },
1276 { SOLVER_TRANSACTION_DOWNGRADED, "downgrade" },
1277 { SOLVER_TRANSACTION_CHANGED, "change" },
1278 { SOLVER_TRANSACTION_UPGRADED, "upgrade" },
1279 { SOLVER_TRANSACTION_OBSOLETED, "obsolete" },
1280 { SOLVER_TRANSACTION_MULTIINSTALL, "multiinstall" },
1281 { SOLVER_TRANSACTION_MULTIREINSTALL, "multireinstall" },
1286 testcase_solverresult(Solver *solv, int resultflags)
1288 Pool *pool = solv->pool;
1296 if ((resultflags & TESTCASE_RESULT_TRANSACTION) != 0)
1298 Transaction *trans = solver_create_transaction(solv);
1302 for (i = 0; class2str[i].str; i++)
1305 transaction_classify_pkgs(trans, SOLVER_TRANSACTION_KEEP_PSEUDO, class2str[i].class, 0, 0, &q);
1306 for (j = 0; j < q.count; j++)
1310 if (pool->installed && pool->solvables[p].repo == pool->installed)
1311 op = transaction_obs_pkg(trans, p);
1312 s = pool_tmpjoin(pool, class2str[i].str, " ", testcase_solvid2str(pool, p));
1314 s = pool_tmpjoin(pool, s, " ", testcase_solvid2str(pool, op));
1315 strqueue_push(&sq, s);
1319 transaction_free(trans);
1321 if ((resultflags & TESTCASE_RESULT_PROBLEMS) != 0)
1323 char *probprefix, *solprefix;
1324 int problem, solution, element;
1327 pcnt = solver_problem_count(solv);
1328 for (problem = 1; problem <= pcnt; problem++)
1330 Id rid, from, to, dep;
1331 SolverRuleinfo rinfo;
1332 rid = solver_findproblemrule(solv, problem);
1333 s = testcase_problemid(solv, problem);
1334 probprefix = solv_dupjoin("problem ", s, 0);
1335 rinfo = solver_ruleinfo(solv, rid, &from, &to, &dep);
1336 s = pool_tmpjoin(pool, probprefix, " info ", solver_problemruleinfo2str(solv, rinfo, from, to, dep));
1337 strqueue_push(&sq, s);
1338 scnt = solver_solution_count(solv, problem);
1339 for (solution = 1; solution <= scnt; solution++)
1341 s = testcase_solutionid(solv, problem, solution);
1342 solprefix = solv_dupjoin(probprefix, " solution ", s);
1344 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &op)) != 0)
1346 if (p == SOLVER_SOLUTION_JOB)
1347 s = pool_tmpjoin(pool, solprefix, " deljob ", testcase_job2str(pool, solv->job.elements[op - 1], solv->job.elements[op]));
1348 else if (p > 0 && op == 0)
1349 s = pool_tmpjoin(pool, solprefix, " erase ", testcase_solvid2str(pool, p));
1350 else if (p > 0 && op > 0)
1352 s = pool_tmpjoin(pool, solprefix, " replace ", testcase_solvid2str(pool, p));
1353 s = pool_tmpappend(pool, s, " ", testcase_solvid2str(pool, op));
1355 else if (p < 0 && op > 0)
1356 s = pool_tmpjoin(pool, solprefix, " allow ", testcase_solvid2str(pool, op));
1358 s = pool_tmpjoin(pool, solprefix, " unknown", 0);
1359 strqueue_push(&sq, s);
1361 solv_free(solprefix);
1363 solv_free(probprefix);
1367 if ((resultflags & TESTCASE_RESULT_ORPHANED) != 0)
1372 solver_get_orphaned(solv, &q);
1373 for (i = 0; i < q.count; i++)
1375 s = pool_tmpjoin(pool, "orphaned ", testcase_solvid2str(pool, q.elements[i]), 0);
1376 strqueue_push(&sq, s);
1381 if ((resultflags & TESTCASE_RESULT_RECOMMENDED) != 0)
1387 solver_get_recommendations(solv, &qr, &qs, 0);
1388 for (i = 0; i < qr.count; i++)
1390 s = pool_tmpjoin(pool, "recommended ", testcase_solvid2str(pool, qr.elements[i]), 0);
1391 strqueue_push(&sq, s);
1393 for (i = 0; i < qs.count; i++)
1395 s = pool_tmpjoin(pool, "suggested ", testcase_solvid2str(pool, qs.elements[i]), 0);
1396 strqueue_push(&sq, s);
1402 if ((resultflags & TESTCASE_RESULT_UNNEEDED) != 0)
1407 solver_get_unneeded(solv, &q, 0);
1408 for (i = 0; i < q.count; i++)
1410 s = pool_tmpjoin(pool, "unneeded ", testcase_solvid2str(pool, q.elements[i]), 0);
1411 strqueue_push(&sq, s);
1417 result = strqueue_join(&sq);
1424 testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasename, const char *resultname)
1426 Pool *pool = solv->pool;
1437 testcasename = "testcase.t";
1439 resultname = "solver.result";
1441 if (mkdir(dir, 0777) && errno != EEXIST)
1443 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not create directory '%s'\n", dir);
1447 FOR_REPOS(repoid, repo)
1449 const char *name = testcase_repoid2str(pool, repoid);
1451 if (repo->subpriority)
1452 sprintf(priobuf, "%d.%d", repo->priority, repo->subpriority);
1454 sprintf(priobuf, "%d", repo->priority);
1455 out = pool_tmpjoin(pool, name, ".repo", ".gz");
1456 cmd = pool_tmpjoin(pool, "repo ", name, " ");
1457 cmd = pool_tmpappend(pool, cmd, priobuf, " ");
1458 cmd = pool_tmpappend(pool, cmd, "susetags ", out);
1459 strqueue_push(&sq, cmd);
1460 out = pool_tmpjoin(pool, dir, "/", out);
1461 if (!(fp = solv_xfopen(out, "w")))
1463 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
1467 testcase_write_susetags(repo, fp);
1470 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1475 /* hmm, this is not optimal... we currently search for the lowest score */
1478 for (i = 0; i < pool->lastarch; i++)
1480 if (pool->id2arch[i] == 1 && !lowscore)
1482 if (pool->id2arch[i] > 0x10000 && (!lowscore || pool->id2arch[i] < lowscore))
1485 lowscore = pool->id2arch[i];
1488 cmd = pool_tmpjoin(pool, "system ", pool_id2str(pool, arch), pool->disttype == DISTTYPE_DEB ? " deb" : " rpm");
1489 if (pool->installed)
1490 cmd = pool_tmpappend(pool, cmd, " ", testcase_repoid2str(pool, pool->installed->repoid));
1491 strqueue_push(&sq, cmd);
1492 s = testcase_getpoolflags(solv->pool);
1495 cmd = pool_tmpjoin(pool, "poolflags ", s, 0);
1496 strqueue_push(&sq, cmd);
1499 if (pool->vendorclasses)
1502 for (i = 0; pool->vendorclasses[i]; i++)
1504 cmd = pool_tmpappend(pool, cmd ? cmd : "vendorclass", " ", pool->vendorclasses[i]);
1505 if (!pool->vendorclasses[i + 1])
1507 strqueue_push(&sq, cmd);
1514 s = testcase_getsolverflags(solv);
1517 cmd = pool_tmpjoin(pool, "solverflags ", s, 0);
1518 strqueue_push(&sq, cmd);
1521 /* now dump all the ns callback values we know */
1522 if (pool->nscallback)
1526 for (rid = 1; rid < pool->nrels; rid++)
1528 Reldep *rd = pool->rels + rid;
1529 if (rd->flags != REL_NAMESPACE || rd->name == NAMESPACE_OTHERPROVIDERS)
1531 /* check if we evaluated it, also skip empty results */
1532 if (!(d = pool->whatprovides_rel[rid]) || !pool->whatprovidesdata[d])
1534 cmd = pool_tmpjoin(pool, "namespace ", pool_id2str(pool, rd->name), "(");
1535 cmd = pool_tmpappend(pool, cmd, pool_id2str(pool, rd->evr), ")");
1536 for (; pool->whatprovidesdata[d]; d++)
1537 cmd = pool_tmpappend(pool, cmd, " ", testcase_solvid2str(pool, pool->whatprovidesdata[d]));
1538 strqueue_push(&sq, cmd);
1542 for (i = 0; i < solv->job.count; i += 2)
1544 cmd = (char *)testcase_job2str(pool, solv->job.elements[i], solv->job.elements[i + 1]);
1545 cmd = pool_tmpjoin(pool, "job ", cmd, 0);
1546 strqueue_push(&sq, cmd);
1553 for (i = 0; resultflags2str[i].str; i++)
1554 if ((resultflags & resultflags2str[i].flag) != 0)
1555 cmd = pool_tmpappend(pool, cmd, cmd ? "," : 0, resultflags2str[i].str);
1556 cmd = pool_tmpjoin(pool, "result ", cmd ? cmd : "?", 0);
1557 cmd = pool_tmpappend(pool, cmd, " ", resultname);
1558 strqueue_push(&sq, cmd);
1559 result = testcase_solverresult(solv, resultflags);
1560 if (!strcmp(resultname, "<inline>"))
1564 strqueue_init(&rsq);
1565 strqueue_split(&rsq, result);
1566 for (i = 0; i < rsq.nstr; i++)
1568 cmd = pool_tmpjoin(pool, "#>", rsq.str[i], 0);
1569 strqueue_push(&sq, cmd);
1571 strqueue_free(&rsq);
1575 out = pool_tmpjoin(pool, dir, "/", resultname);
1576 if (!(fp = fopen(out, "w")))
1578 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
1583 if (result && *result && fwrite(result, strlen(result), 1, fp) != 1)
1585 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1592 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1600 cmd = strqueue_join(&sq);
1601 out = pool_tmpjoin(pool, dir, "/", testcasename);
1602 if (!(fp = fopen(out, "w")))
1604 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
1608 if (*cmd && fwrite(cmd, strlen(cmd), 1, fp) != 1)
1610 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1616 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1626 testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp, int *resultflagsp)
1631 char *testcasedir, *s;
1637 int poolflagsreset = 0;
1639 if (!fp && !(fp = fopen(testcase, "r")))
1641 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", testcase);
1644 testcasedir = solv_strdup(testcase);
1645 if ((s = strrchr(testcasedir, '/')) != 0)
1650 buf = solv_malloc(bufl);
1655 if (bufp - buf + 16 > bufl)
1658 buf = solv_realloc(buf, bufl + 512);
1662 if (!fgets(bufp, bufl - (bufp - buf), fp))
1666 if (!l || buf[l - 1] != '\n')
1673 while (*s && (*s == ' ' || *s == '\t'))
1675 if (!*s || *s == '#')
1678 /* split it in pieces */
1681 while (*s == ' ' || *s == '\t')
1685 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
1686 pieces[npieces++] = s;
1687 while (*s && *s != ' ' && *s != '\t')
1692 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
1693 pieces[npieces] = 0;
1694 if (!strcmp(pieces[0], "repo") && npieces >= 4)
1696 Repo *repo = repo_create(pool, pieces[1]);
1702 if (!poolflagsreset)
1705 testcase_resetpoolflags(pool); /* hmm */
1707 if (sscanf(pieces[2], "%d.%d", &prio, &subprio) != 2)
1710 prio = atoi(pieces[2]);
1712 repo->priority = prio;
1713 repo->subpriority = subprio;
1714 if (strcmp(pieces[3], "empty") != 0)
1716 rdata = pool_tmpjoin(pool, testcasedir, pieces[4], 0);
1717 if ((rfp = solv_xfopen(rdata, "r")) == 0)
1719 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata);
1721 else if (!strcmp(pieces[3], "susetags"))
1723 testcase_add_susetags(repo, rfp, 0);
1726 else if (!strcmp(pieces[3], "solv"))
1728 repo_add_solv(repo, rfp, 0);
1734 pool_debug(pool, SOLV_ERROR, "testcase_read: unknown repo type for repo '%s'\n", repo->name);
1738 else if (!strcmp(pieces[0], "system") && npieces >= 3)
1741 pool_setarch(pool, pieces[1]);
1744 Repo *repo = testcase_str2repo(pool, pieces[3]);
1746 pool_debug(pool, SOLV_ERROR, "testcase_read: system: unknown repo '%s'\n", pieces[3]);
1748 pool_set_installed(pool, repo);
1751 else if (!strcmp(pieces[0], "job") && npieces > 1)
1757 pool_addfileprovides(pool);
1758 pool_createwhatprovides(pool);
1762 for (sp = pieces[1]; sp < pieces[npieces - 1]; sp++)
1765 how = testcase_str2job(pool, pieces[1], &what);
1766 if (how >= 0 && job)
1767 queue_push2(job, how, what);
1769 else if (!strcmp(pieces[0], "vendorclass") && npieces > 1)
1771 pool_addvendorclass(pool, (const char **)(pieces + 1));
1773 else if (!strcmp(pieces[0], "namespace") && npieces > 1)
1775 int i = strlen(pieces[1]);
1776 s = strchr(pieces[1], '(');
1777 if (!s && pieces[1][i - 1] != ')')
1779 pool_debug(pool, SOLV_ERROR, "testcase_read: bad namespace '%s'\n", pieces[1]);
1787 pieces[1][i - 1] = 0;
1788 name = pool_str2id(pool, pieces[1], 1);
1789 evr = pool_str2id(pool, s + 1, 1);
1791 pieces[1][i - 1] = ')';
1792 id = pool_rel2id(pool, name, evr, REL_NAMESPACE, 1);
1793 for (i = 2; i < npieces; i++)
1794 queue_push(&q, testcase_str2solvid(pool, pieces[i]));
1795 /* now do the callback */
1798 pool_addfileprovides(pool);
1799 pool_createwhatprovides(pool);
1802 pool->whatprovides_rel[GETRELID(id)] = pool_queuetowhatprovides(pool, &q);
1806 else if (!strcmp(pieces[0], "poolflags"))
1809 if (!poolflagsreset)
1812 testcase_resetpoolflags(pool); /* hmm */
1814 for (i = 1; i < npieces; i++)
1815 testcase_setpoolflags(pool, pieces[i]);
1817 else if (!strcmp(pieces[0], "solverflags") && npieces > 1)
1822 solv = solver_create(pool);
1823 testcase_resetsolverflags(solv);
1825 for (i = 1; i < npieces; i++)
1826 testcase_setsolverflags(solv, pieces[i]);
1828 else if (!strcmp(pieces[0], "result") && npieces > 2)
1832 int resultflags = 0;
1833 char *s = pieces[1];
1837 char *se = strchr(s, ',');
1840 for (i = 0; resultflags2str[i].str; i++)
1841 if (!strcmp(s, resultflags2str[i].str))
1843 resultflags |= resultflags2str[i].flag;
1846 if (!resultflags2str[i].str)
1847 pool_debug(pool, SOLV_ERROR, "result: unknown flag '%s'\n", s);
1851 rdata = pool_tmpjoin(pool, testcasedir, pieces[2], 0);
1852 if (!strcmp(pieces[2], "<inline>"))
1855 rfp = fopen(rdata, "r");
1858 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata);
1862 /* slurp it in... */
1863 char *result = solv_malloc(1024);
1869 if (rp - result + 256 >= resultl)
1871 resultl = rp - result;
1872 result = solv_realloc(result, resultl + 1024);
1873 rp = result + resultl;
1878 if (!fgets(rp, resultl - (rp - result), fp))
1883 if (rl && (rp == result || rp[-1] == '\n'))
1885 if (rl > 1 && rp[0] == '#' && rp[1] == '>')
1887 memmove(rp, rp + 2, rl - 2);
1892 while (rl + 16 > bufl)
1894 buf = solv_realloc(buf, bufl + 512);
1897 memmove(buf, rp, rl);
1898 if (buf[rl - 1] == '\n')
1910 rl = fread(rp, 1, resultl - (rp - result), rfp);
1925 *resultflagsp = resultflags;
1928 else if (!strcmp(pieces[0], "nextjob") && npieces == 1)
1934 pool_debug(pool, SOLV_ERROR, "testcase_read: cannot parse command '%s'\n", pieces[0]);
1937 buf = solv_free(buf);
1938 pieces = solv_free(pieces);
1939 solv_free(testcasedir);
1942 pool_addfileprovides(pool);
1943 pool_createwhatprovides(pool);
1947 solv = solver_create(pool);
1948 testcase_resetsolverflags(solv);
1956 testcase_resultdiff(char *result1, char *result2)
1958 Strqueue sq1, sq2, osq;
1960 strqueue_init(&sq1);
1961 strqueue_init(&sq2);
1962 strqueue_init(&osq);
1963 strqueue_split(&sq1, result1);
1964 strqueue_split(&sq2, result2);
1965 strqueue_sort(&sq1);
1966 strqueue_sort(&sq2);
1967 strqueue_diff(&sq1, &sq2, &osq);
1968 r = osq.nstr ? strqueue_join(&osq) : 0;
1969 strqueue_free(&sq1);
1970 strqueue_free(&sq2);
1971 strqueue_free(&osq);