diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/CMakeLists.txt | 5 | ||||
-rw-r--r-- | ext/libsolvext.ver | 2 | ||||
-rw-r--r-- | ext/pool_parserpmrichdep.c | 138 | ||||
-rw-r--r-- | ext/pool_parserpmrichdep.h | 15 | ||||
-rw-r--r-- | ext/repo_deb.c | 96 | ||||
-rw-r--r-- | ext/repo_deb.h | 1 | ||||
-rw-r--r-- | ext/repo_rpmdb.c | 26 | ||||
-rw-r--r-- | ext/repo_rpmmd.c | 22 | ||||
-rw-r--r-- | ext/repo_susetags.c | 14 | ||||
-rw-r--r-- | ext/testcase.c | 668 | ||||
-rw-r--r-- | ext/testcase.h | 2 |
11 files changed, 765 insertions, 224 deletions
diff --git a/ext/CMakeLists.txt b/ext/CMakeLists.txt index 5f017f2..bdf949d 100644 --- a/ext/CMakeLists.txt +++ b/ext/CMakeLists.txt @@ -43,6 +43,11 @@ IF (ENABLE_SUSEREPO) repo_susetags.h repo_zyppdb.h) ENDIF (ENABLE_SUSEREPO) +IF (ENABLE_COMPLEX_DEPS AND (ENABLE_SUSEREPO OR ENABLE_RPMMD OR ENABLE_RPMDB)) + SET (libsolvext_SRCS ${libsolvext_SRCS} + pool_parserpmrichdep.c) +ENDIF (ENABLE_COMPLEX_DEPS AND (ENABLE_SUSEREPO OR ENABLE_RPMMD OR ENABLE_RPMDB)) + IF (SUSE) SET (libsolvext_SRCS ${libsolvext_SRCS} repo_autopattern.c) diff --git a/ext/libsolvext.ver b/ext/libsolvext.ver index 5c176e2..654469b 100644 --- a/ext/libsolvext.ver +++ b/ext/libsolvext.ver @@ -1,5 +1,6 @@ SOLV_1.0 { global: + pool_deb_get_autoinstalled; pool_findfileconflicts; repo_add_appdata; repo_add_appdata_dir; @@ -58,6 +59,7 @@ SOLV_1.0 { solvsig_free; solvsig_verify; testcase_add_testtags; + testcase_dep2str; testcase_job2str; testcase_solvid2str; testcase_str2dep; diff --git a/ext/pool_parserpmrichdep.c b/ext/pool_parserpmrichdep.c new file mode 100644 index 0000000..742823a --- /dev/null +++ b/ext/pool_parserpmrichdep.c @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2015, SUSE Inc. + * + * This program is licensed under the BSD license, read LICENSE.BSD + * for further information + */ + +/* this is used by repo_rpmmd, repo_rpmdb, and repo_susetags */ + +#include <stdio.h> + +#include "pool.h" +#include "pool_parserpmrichdep.h" + +#define REL_THEN 0 +#define REL_ELSE 0 + +static struct RichOpComp { + const char *n; + int l; + Id fl; +} RichOps[] = { + { "&&", 2, REL_AND }, + { "&", 1, REL_AND }, + { "AND", 3, REL_AND }, + { "||", 2, REL_OR }, + { "|", 1, REL_OR }, + { "OR", 2, REL_OR }, + { "IF", 2, REL_COND }, + { "THEN", 4, REL_THEN }, + { "?", 1, REL_THEN }, + { "ELSE", 4, REL_ELSE }, + { ":", 1, REL_ELSE }, + { NULL, 0, 0}, +}; + +static Id +parseRichDep(Pool *pool, const char **depp, Id chainfl) +{ + const char *p = *depp; + const char *n; + Id id, evr; + int fl, bl; + struct RichOpComp *op; + + if (!chainfl && *p++ != '(') + return 0; + while (*p == ' ') + p++; + if (*p == ')') + return 0; + if (*p == '(') + { + id = parseRichDep(pool, &p, 0); + if (!id) + return 0; + } + else + { + n = p; + bl = 0; + while (*p && !(*p == ' ' || *p == ',' || (*p == ')' && bl-- <= 0))) + if (*p++ == '(') + bl++; + if (n == p) + return 0; + id = pool_strn2id(pool, n, p - n, 1); + while (*p == ' ') + p++; + if (*p) + { + fl = 0; + for (;; p++) + { + if (*p == '<') + fl |= REL_LT; + else if (*p == '=') + fl |= REL_EQ; + else if (*p == '>') + fl |= REL_GT; + else + break; + } + if (fl) + { + while (*p == ' ') + p++; + n = p; + bl = 0; + while (*p && !(*p == ' ' || *p == ',' || (*p == ')' && bl-- <= 0))) + if (*p++ == '(') + bl++; + if (p - n > 2 && n[0] == '0' && n[1] == ':') + n += 2; /* strip zero epoch */ + if (n == p) + return 0; + id = pool_rel2id(pool, id, pool_strn2id(pool, n, p - n, 1), fl, 1); + } + } + } + while (*p == ' ') + p++; + if (!*p) + return 0; + if (*p == ')') + { + *depp = p + 1; + return id; + } + n = p; + while (*p && *p != ' ') + p++; + for (op = RichOps; op->n; op++) + if (p - n == op->l && !strncmp(n, op->n, op->l)) + break; + fl = op->fl; + if (!fl) + return 0; + if (chainfl == REL_THEN && fl == REL_ELSE) + chainfl = 0; + if (chainfl && fl != chainfl) + return 0; + evr = parseRichDep(pool, &p, fl); + if (!evr) + return 0; + *depp = p; + return pool_rel2id(pool, id, evr, fl, 1); +} + +Id +pool_parserpmrichdep(Pool *pool, const char *dep) +{ + Id id = parseRichDep(pool, &dep, 0); + if (id && *dep) + id = 0; + return id; +} + diff --git a/ext/pool_parserpmrichdep.h b/ext/pool_parserpmrichdep.h new file mode 100644 index 0000000..09dce2c --- /dev/null +++ b/ext/pool_parserpmrichdep.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2014, SUSE Inc. + * + * This program is licensed under the BSD license, read LICENSE.BSD + * for further information + */ + +#ifndef POOL_PARSERPMRICHDEP_H +#define POOL_PARSERPMRICHDEP_H + +#include "pool.h" + +extern Id pool_parserpmrichdep(Pool *pool, const char *dep); + +#endif diff --git a/ext/repo_deb.c b/ext/repo_deb.c index 5af0c70..05d731b 100644 --- a/ext/repo_deb.c +++ b/ext/repo_deb.c @@ -17,6 +17,7 @@ #include "pool.h" #include "repo.h" #include "util.h" +#include "solver.h" /* for GET_USERINSTALLED_ flags */ #include "chksum.h" #include "repo_deb.h" @@ -204,7 +205,7 @@ control2solvable(Solvable *s, Repodata *data, char *control) if (*p) *p++ = 0; /* strip trailing space */ - while (end >= control && *end == ' ' && *end == '\t') + while (end >= control && (*end == ' ' || *end == '\t')) *end-- = 0; tag = control; control = p; @@ -313,6 +314,10 @@ control2solvable(Solvable *s, Repodata *data, char *control) havesource = 1; } break; + case 'S' << 8 | 'T': + if (!strcasecmp(tag, "status")) + repodata_set_poolstr(data, s - pool->solvables, SOLVABLE_INSTALLSTATUS, q); + break; case 'S' << 8 | 'U': if (!strcasecmp(tag, "suggests")) s->suggests = makedeps(repo, q, s->suggests, 0); @@ -613,3 +618,92 @@ repo_add_deb(Repo *repo, const char *deb, int flags) repodata_internalize(data); return s - pool->solvables; } + +void +pool_deb_get_autoinstalled(Pool *pool, FILE *fp, Queue *q, int flags) +{ + Id name = 0, arch = 0; + int autoinstalled = -1; + char *buf, *bp; + int x, l, bufl, eof = 0; + Id p, pp; + + queue_empty(q); + buf = solv_malloc(4096); + bufl = 4096; + l = 0; + while (!eof) + { + while (bufl - l < 1024) + { + bufl += 4096; + if (bufl > 1024 * 64) + break; /* hmm? */ + buf = solv_realloc(buf, bufl); + } + if (!fgets(buf + l, bufl - l, fp)) + { + eof = 1; + buf[l] = '\n'; + buf[l + 1] = 0; + } + l = strlen(buf); + if (l && buf[l - 1] == '\n') + buf[--l] = 0; + if (!*buf || eof) + { + l = 0; + if (name && autoinstalled > 0) + { + if ((flags & GET_USERINSTALLED_NAMES) != 0) + queue_push(q, name); + else + { + FOR_PROVIDES(p, pp, name) + { + Solvable *s = pool->solvables + p; + if (s->name != name) + continue; + if (arch && s->arch != arch) + continue; + queue_push(q, p); + } + } + } + name = arch = 0; + autoinstalled = -1; + continue; + } + /* strip trailing space */ + while (l && (buf[l - 1] == ' ' || buf[l - 1] == '\t')) + buf[--l] = 0; + l = 0; + + bp = strchr(buf, ':'); + if (!bp || bp - buf < 4) + continue; + *bp++ = 0; + while (*bp == ' ' || *bp == '\t') + bp++; + x = '@' + (buf[0] & 0x1f); + x = (x << 8) + '@' + (buf[1] & 0x1f); + switch(x) + { + case 'P' << 8 | 'A': + if (!strcasecmp(buf, "package")) + name = pool_str2id(pool, bp, 1); + break; + case 'A' << 8 | 'R': + if (!strcasecmp(buf, "architecture")) + arch = pool_str2id(pool, bp, 1); + break; + case 'A' << 8 | 'U': + if (!strcasecmp(buf, "auto-installed")) + autoinstalled = atoi(bp); + break; + default: + break; + } + } +} + diff --git a/ext/repo_deb.h b/ext/repo_deb.h index 7057da6..5993991 100644 --- a/ext/repo_deb.h +++ b/ext/repo_deb.h @@ -8,5 +8,6 @@ extern int repo_add_debpackages(Repo *repo, FILE *fp, int flags); extern int repo_add_debdb(Repo *repo, int flags); extern Id repo_add_deb(Repo *repo, const char *deb, int flags); +extern void pool_deb_get_autoinstalled(Pool *pool, FILE *fp, Queue *q, int flags); #define DEBS_ADD_WITH_PKGID (1 << 8) diff --git a/ext/repo_rpmdb.c b/ext/repo_rpmdb.c index b4541c3..71c69ab 100644 --- a/ext/repo_rpmdb.c +++ b/ext/repo_rpmdb.c @@ -47,6 +47,9 @@ #include "chksum.h" #include "repo_rpmdb.h" #include "repo_solv.h" +#ifdef ENABLE_COMPLEX_DEPS +#include "pool_parserpmrichdep.h" +#endif /* 3: added triggers */ /* 4: fixed triggers */ @@ -147,6 +150,7 @@ #define DEP_STRONG (1 << 27) #define DEP_PRE_IN ((1 << 6) | (1 << 9) | (1 << 10)) #define DEP_PRE_UN ((1 << 6) | (1 << 11) | (1 << 12)) +#define DEP_RICH (1 << 29) #define FILEFLAG_GHOST (1 << 6) @@ -404,7 +408,6 @@ setutf8string(Repodata *repodata, Id handle, Id tag, const char *str) repodata_set_str(repodata, handle, tag, str); } - /* * strong: 0: ignore strongness * 1: filter to strong @@ -512,6 +515,7 @@ makedeps(Pool *pool, Repo *repo, RpmHead *rpmhead, int tagn, int tagv, int tagf, ida = repo->idarraydata + olddeps; for (i = 0; ; i++) { + Id id; if (i == nc) { if (haspre != 1) @@ -532,9 +536,21 @@ makedeps(Pool *pool, Repo *repo, RpmHead *rpmhead, int tagn, int tagv, int tagf, if ((flags & RPM_ADD_NO_RPMLIBREQS) != 0) if (!strncmp(n[i], "rpmlib(", 7)) continue; +#ifdef ENABLE_COMPLEX_DEPS + if ((f[i] & (DEP_RICH|DEP_LESS| DEP_EQUAL|DEP_GREATER)) == DEP_RICH && n[i][0] == '(') + { + id = pool_parserpmrichdep(pool, n[i]); + if (id) + *ida++ = id; + else + cc--; + continue; + } +#endif + id = pool_str2id(pool, n[i], 1); if (f[i] & (DEP_LESS|DEP_GREATER|DEP_EQUAL)) { - Id name, evr; + Id evr; int fl = 0; if ((f[i] & DEP_LESS) != 0) fl |= REL_LT; @@ -542,15 +558,13 @@ makedeps(Pool *pool, Repo *repo, RpmHead *rpmhead, int tagn, int tagv, int tagf, fl |= REL_EQ; if ((f[i] & DEP_GREATER) != 0) fl |= REL_GT; - name = pool_str2id(pool, n[i], 1); if (v[i][0] == '0' && v[i][1] == ':' && v[i][2]) evr = pool_str2id(pool, v[i] + 2, 1); else evr = pool_str2id(pool, v[i], 1); - *ida++ = pool_rel2id(pool, name, evr, fl, 1); + id = pool_rel2id(pool, id, evr, fl, 1); } - else - *ida++ = pool_str2id(pool, n[i], 1); + *ida++ = id; } *ida++ = 0; repo->idarraysize += cc + 1; diff --git a/ext/repo_rpmmd.c b/ext/repo_rpmmd.c index 21dd913..4272b6f 100644 --- a/ext/repo_rpmmd.c +++ b/ext/repo_rpmmd.c @@ -19,7 +19,9 @@ #include "tools_util.h" #include "repo_rpmmd.h" #include "chksum.h" - +#ifdef ENABLE_COMPLEX_DEPS +#include "pool_parserpmrichdep.h" +#endif enum state { STATE_START, @@ -466,7 +468,7 @@ static char *flagtab[] = { static unsigned int adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, const char **atts, int isreq) { - Id id, name, marker; + Id id, marker; const char *n, *f, *k; const char **a; @@ -496,10 +498,18 @@ adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, const char **atts pd->acontent = l + 256; } sprintf(pd->content, "%s:%s", k, n); - name = pool_str2id(pool, pd->content, 1); + id = pool_str2id(pool, pd->content, 1); + } +#ifdef ENABLE_COMPLEX_DEPS + else if (!f && n[0] == '(') + { + id = pool_parserpmrichdep(pool, n); + if (!id) + return olddeps; } +#endif else - name = pool_str2id(pool, (char *)n, 1); + id = pool_str2id(pool, (char *)n, 1); if (f) { Id evr = makeevr_atts(pool, pd, atts); @@ -508,10 +518,8 @@ adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, const char **atts if (!strcmp(f, flagtab[flags])) break; flags = flags < 6 ? flags + 1 : 0; - id = pool_rel2id(pool, name, evr, flags, 1); + id = pool_rel2id(pool, id, evr, flags, 1); } - else - id = name; #if 0 fprintf(stderr, "new dep %s\n", pool_dep2str(pool, id)); #endif diff --git a/ext/repo_susetags.c b/ext/repo_susetags.c index 440e2d5..a96ba97 100644 --- a/ext/repo_susetags.c +++ b/ext/repo_susetags.c @@ -18,6 +18,9 @@ #include "chksum.h" #include "tools_util.h" #include "repo_susetags.h" +#ifdef ENABLE_COMPLEX_DEPS +#include "pool_parserpmrichdep.h" +#endif struct datashare { Id name; @@ -87,6 +90,17 @@ adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, Id ma /* A file dependency. Do not try to parse it */ id = pool_str2id(pool, line + 6, 1); } +#ifdef ENABLE_COMPLEX_DEPS + else if (line[6] == '(') + { + id = pool_parserpmrichdep(pool, line + 6); + if (!id) + { + pd->ret = pool_error(pool, -1, "susetags: line %d: bad dependency: '%s'\n", pd->lineno, line); + return olddeps; + } + } +#endif else { i = split(line + 6, sp, 4); /* name, <op>, evr, ? */ diff --git a/ext/testcase.c b/ext/testcase.c index fa9c807..f0057e6 100644 --- a/ext/testcase.c +++ b/ext/testcase.c @@ -77,6 +77,7 @@ static struct resultflags2str { { TESTCASE_RESULT_ORPHANED, "orphaned" }, { TESTCASE_RESULT_RECOMMENDED, "recommended" }, { TESTCASE_RESULT_UNNEEDED, "unneeded" }, + { TESTCASE_RESULT_ALTERNATIVES, "alternatives" }, { 0, 0 } }; @@ -284,151 +285,339 @@ strqueue_diff(Strqueue *sq1, Strqueue *sq2, Strqueue *osq) strqueue_pushjoin(osq, "+", sq2->str[j++], 0); } -static inline int -pool_isknownarch(Pool *pool, Id id) -{ - if (!id || id == ID_EMPTY) - return 0; - if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH) - return 1; - if (!pool->id2arch || (id > pool->lastarch || !pool->id2arch[id])) - return 0; - return 1; -} -static Id -testcase_str2dep_simple(Pool *pool, const char **sp) +static const char * +testcase_id2str(Pool *pool, Id id, int isname) { - const char *s = *sp; - const char *n, *a; - Id id, evr; - int flags; - - while (*s == ' ' || *s == '\t') - s++; - n = s; - while (*s && *s != ' ' && *s != '\t' && *s != '<' && *s != '=' && *s != '>') - { - if (*s == '(') + const char *s = pool_id2str(pool, id); + const char *ss; + char *s2, *s2p; + int bad = 0, paren = 0, parenbad = 0; + + if (id == 0) + return "<NULL>"; + if (id == 1) + return "\\00"; + if (strchr("[(<=>!", *s)) + bad++; + if (!strncmp(s, "namespace:", 10)) + bad++; + for (ss = s + bad; *ss; ss++) + { + if (*ss == ' ' || *ss == '\\' || *(unsigned char *)ss < 32 || *ss == '(' || *ss == ')') + bad++; + if (*ss == '(') + paren = paren == 0 ? 1 : -1; + else if (*ss == ')') { - while (*s && *s != ')') - s++; - continue; + paren = paren == 1 ? 0 : -1; + if (!paren) + parenbad += 2; } - s++; } - if ((a = strchr(n, '.')) != 0 && a + 1 < s && s[-1] != ')') + if (isname && ss - s > 4 && !strcmp(ss - 4, ":any")) + bad++; + if (!paren && !(bad - parenbad)) + return s; + + /* we need escaping! */ + s2 = s2p = pool_alloctmpspace(pool, strlen(s) + bad * 2 + 1); + ss = s; + if (!strncmp(s, "namespace:", 10)) { - Id archid = pool_strn2id(pool, a + 1, s - (a + 1), 0); - if (pool_isknownarch(pool, archid)) + strcpy(s2p, "namespace\\3a"); + s2p += 12; + s += 10; + } + for (; *ss; ss++) + { + *s2p++ = *ss; + if ((ss == s && strchr("[(<=>!", *s)) || *ss == ' ' || *ss == '\\' || *(unsigned char *)ss < 32 || *ss == '(' || *ss == ')') { - id = pool_strn2id(pool, n, a - n, 1); - id = pool_rel2id(pool, id, archid, REL_ARCH, 1); + s2p[-1] = '\\'; + solv_bin2hex((unsigned char *)ss, 1, s2p); + s2p += 2; } - else - id = pool_strn2id(pool, n, s - n, 1); } - else if (s - n > 4 && s[-4] == ':' && !strncmp(s - 4, ":any", 4)) + *s2p = 0; + if (isname && s2p - s2 > 4 && !strcmp(s2p - 4, ":any")) + strcpy(s2p - 4, "\\3aany"); + return s2; +} + +struct oplist { + Id flags; + const char *opname; +} oplist[] = { + { REL_EQ, "=" }, + { REL_GT | REL_LT | REL_EQ, "<=>" }, + { REL_LT | REL_EQ, "<=" }, + { REL_GT | REL_EQ, ">=" }, + { REL_GT, ">" }, + { REL_GT | REL_LT, "<>" }, + { REL_AND, "&" }, + { REL_OR , "|" }, + { REL_WITH , "+" }, + { REL_NAMESPACE , "<NAMESPACE>" }, + { REL_ARCH, "." }, + { REL_MULTIARCH, "<MULTIARCH>" }, + { REL_FILECONFLICT, "<FILECONFLICT>" }, + { REL_COND, "<IF>" }, + { REL_COMPAT, "compat >=" }, + { REL_KIND, "<KIND>" }, + { REL_LT, "<" }, + { 0, 0 } +}; + +static const char * +testcase_dep2str_complex(Pool *pool, Id id, int addparens) +{ + Reldep *rd; + char *s; + const char *s2; + int needparens; + struct oplist *op; + + if (!ISRELDEP(id)) + return testcase_id2str(pool, id, 1); + rd = GETRELDEP(pool, id); + + /* check for special shortcuts */ + if (rd->flags == REL_NAMESPACE && !ISRELDEP(rd->name) && !strncmp(pool_id2str(pool, rd->name), "namespace:", 10)) { - id = pool_strn2id(pool, n, s - n - 4, 1); - id = pool_rel2id(pool, id, ARCH_ANY, REL_MULTIARCH, 1); + const char *ns = pool_id2str(pool, rd->name); + int nslen = strlen(ns); + /* special namespace formatting */ + const char *evrs = testcase_dep2str_complex(pool, rd->evr, 0); + s = pool_tmpappend(pool, evrs, ns, "()"); + memmove(s + nslen + 1, s, strlen(s) - nslen - 2); + memcpy(s, ns, nslen); + s[nslen] = '('; + return s; + } + if (rd->flags == REL_MULTIARCH && !ISRELDEP(rd->name) && rd->evr == ARCH_ANY) + { + /* special :any suffix */ + const char *ns = testcase_id2str(pool, rd->name, 1); + return pool_tmpappend(pool, ns, ":any", 0); + } + + needparens = 0; + if (ISRELDEP(rd->name)) + { + Reldep *rd2 = GETRELDEP(pool, rd->name); + needparens = 1; + if (rd->flags > 7 && rd->flags != REL_COMPAT && rd2->flags && rd2->flags <= 7) + needparens = 0; + } + s = (char *)testcase_dep2str_complex(pool, rd->name, needparens); + + if (addparens) + { + s = pool_tmpappend(pool, s, "(", 0); + memmove(s + 1, s, strlen(s + 1)); + s[0] = '('; + } + for (op = oplist; op->flags; op++) + if (rd->flags == op->flags) + break; + if (op->flags) + { + s = pool_tmpappend(pool, s, " ", op->opname); + s = pool_tmpappend(pool, s, " ", 0); } else - id = pool_strn2id(pool, n, s - n, 1); - if (!*s) { - *sp = s; - return id; + char buf[64]; + sprintf(buf, " <%u> ", rd->flags); + s = pool_tmpappend(pool, s, buf, 0); } - while (*s == ' ' || *s == '\t') - s++; - flags = 0; - if (*s == '!' && s[1] == '=') /* support != as synonym for <> */ + + needparens = 0; + if (ISRELDEP(rd->evr)) + { + Reldep *rd2 = GETRELDEP(pool, rd->evr); + needparens = 1; + if (rd->flags > 7 && rd2->flags && rd2->flags <= 7) + needparens = 0; + if (rd->flags == REL_AND && rd2->flags == REL_AND) + needparens = 0; /* chain */ + if (rd->flags == REL_OR && rd2->flags == REL_OR) + needparens = 0; /* chain */ + if (rd->flags > 0 && rd->flags < 8 && rd2->flags == REL_COMPAT) + needparens = 0; /* chain */ + } + if (!ISRELDEP(rd->evr)) + s2 = testcase_id2str(pool, rd->evr, 0); + else + s2 = testcase_dep2str_complex(pool, rd->evr, needparens); + if (addparens) + s = pool_tmpappend(pool, s, s2, ")"); + else + s = pool_tmpappend(pool, s, s2, 0); + pool_freetmpspace(pool, s2); + return s; +} + +const char * +testcase_dep2str(Pool *pool, Id id) +{ + return testcase_dep2str_complex(pool, id, 0); +} + + +/* Convert a simple string. Also handle the :any suffix */ +static Id +testcase_str2dep_simple(Pool *pool, const char **sp, int isname) +{ + int haveesc = 0; + int paren = 0; + int isany = 0; + Id id; + const char *s; + for (s = *sp; *s; s++) { - flags = REL_LT | REL_GT; - s += 2; + if (*s == '\\') + haveesc++; + if (*s == ' ' || *(unsigned char *)s < 32) + break; + if (*s == '(') + paren++; + if (*s == ')' && paren-- <= 0) + break; } - for (;;s++) + if (isname && s - *sp > 4 && !strncmp(s - 4, ":any", 4)) { - if (*s == '<') - flags |= REL_LT; - else if (*s == '=') - flags |= REL_EQ; - else if (*s == '>') - flags |= REL_GT; + isany = 1; + s -= 4; + } + if (!haveesc) + { + if (s - *sp == 6 && !strncmp(*sp, "<NULL>", 6)) + id = 0; else - break; + id = pool_strn2id(pool, *sp, s - *sp, 1); } - if (!flags) + else if (s - *sp == 3 && !strncmp(*sp, "\\00", 3)) + id = 1; + else { - *sp = s; - return id; + char buf[128], *bp, *bp2; + const char *sp2; + bp = s - *sp >= 128 ? solv_malloc(s - *sp + 1) : buf; + for (bp2 = bp, sp2 = *sp; sp2 < s;) + { + *bp2++ = *sp2++; + if (bp2[-1] == '\\') + solv_hex2bin(&sp2, (unsigned char *)bp2 - 1, 1); + } + *bp2 = 0; + id = pool_str2id(pool, bp, 1); + if (bp != buf) + solv_free(bp); } - while (*s == ' ' || *s == '\t') - s++; - n = s; - while (*s && *s != ' ' && *s != '\t') - s++; - evr = pool_strn2id(pool, n, s - n, 1); - if (*s == ' ' && !strcmp(s, " compat >= ")) + if (isany) { - s += 11; - while (*s == ' ' || *s == '\t') - s++; - n = s; - while (*s && *s != ' ' && *s != '\t') - s++; - evr = pool_rel2id(pool, evr, pool_strn2id(pool, n, s - n, 1), REL_COMPAT, 1); + id = pool_rel2id(pool, id, ARCH_ANY, REL_MULTIARCH, 1); + s += 4; } *sp = s; - return pool_rel2id(pool, id, evr, flags, 1); + return id; } + static Id -testcase_str2dep_complex(Pool *pool, const char **sp) +testcase_str2dep_complex(Pool *pool, const char **sp, int relop) { const char *s = *sp; - Id id; -#ifdef ENABLE_COMPLEX_DEPS + Id flags, id, id2, namespaceid = 0; + struct oplist *op; + while (*s == ' ' || *s == '\t') s++; - if (*s == '(') + if (!strncmp(s, "namespace:", 10)) { - s++; - id = testcase_str2dep_complex(pool, &s); - if (*s == ')') - s++; - while (*s == ' ' || *s == '\t') - s++; + /* special namespace hack */ + const char *s2; + for (s2 = s + 10; *s2 && *s2 != '('; s2++) + ; + if (*s2 == '(') + { + namespaceid = pool_strn2id(pool, s, s2 - s, 1); + s = s2; + } } - else -#endif - id = testcase_str2dep_simple(pool, &s); - if (*s == '|') + if (*s == '(') { s++; - id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_OR, 1); - } - else if (*s == '&') - { + id = testcase_str2dep_complex(pool, &s, 0); + if (!s || *s != ')') + { + *sp = 0; + return 0; + } s++; - id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_AND, 1); } - else if (*s == 'I' && s[1] == 'F' && (s[2] == ' ' || s[2] == '\t')) + else + id = testcase_str2dep_simple(pool, &s, relop ? 0 : 1); + if (namespaceid) + id = pool_rel2id(pool, namespaceid, id, REL_NAMESPACE, 1); + + for (;;) { - s += 2; - id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_COND, 1); + while (*s == ' ' || *s == '\t') + s++; + if (!*s || *s == ')' || (relop && strncmp(s, "compat >= ", 10) != 0)) + { + *sp = s; + return id; + } + + /* we have an op! Find the end */ + flags = -1; + if (s[0] == '<' && (s[1] >= '0' && s[1] <= '9')) + { + const char *s2; + for (s2 = s + 1; *s2 >= '0' && *s2 <= '9'; s2++) + ; + if (*s2 == '>') + { + flags = strtoul(s + 1, 0, 10); + s = s2 + 1; + } + } + if (flags == -1) + { + for (op = oplist; op->flags; op++) + if (!strncmp(s, op->opname, strlen(op->opname))) + break; + if (!op->flags) + { + *sp = 0; + return 0; + } + flags = op->flags; + s += strlen(op->opname); + } + id2 = testcase_str2dep_complex(pool, &s, flags > 0 && flags < 8); + if (!s) + { + *sp = 0; + return 0; + } + id = pool_rel2id(pool, id, id2, flags, 1); } - *sp = s; - return id; } Id testcase_str2dep(Pool *pool, const char *s) { - return testcase_str2dep_complex(pool, &s); + Id id = testcase_str2dep_complex(pool, &s, 0); + return s && !*s ? id : 0; } +/**********************************************************/ + const char * testcase_repoid2str(Pool *pool, Id repoid) { @@ -597,12 +786,12 @@ testcase_job2str(Pool *pool, Id how, Id what) else if (select == SOLVER_SOLVABLE_NAME) { selstr = " name "; - pkgstr = pool_dep2str(pool, what); + pkgstr = testcase_dep2str(pool, what); } else if (select == SOLVER_SOLVABLE_PROVIDES) { selstr = " provides "; - pkgstr = pool_dep2str(pool, what); + pkgstr = testcase_dep2str(pool, what); } else if (select == SOLVER_SOLVABLE_ONE_OF) { @@ -920,14 +1109,13 @@ static void writedeps(Repo *repo, FILE *fp, const char *tag, Id key, Solvable *s, Offset off) { Pool *pool = repo->pool; - Id id, *dp, *prvdp; + Id id, *dp; int tagwritten = 0; const char *idstr; if (!off) return; dp = repo->idarraydata + off; - prvdp = 0; while ((id = *dp++) != 0) { if (key == SOLVABLE_REQUIRES && id == SOLVABLE_PREREQMARKER) @@ -939,68 +1127,8 @@ writedeps(Repo *repo, FILE *fp, const char *tag, Id key, Solvable *s, Offset off continue; } if (key == SOLVABLE_PROVIDES && id == SOLVABLE_FILEMARKER) - { - prvdp = dp; - continue; - } - idstr = pool_dep2str(pool, id); - if (ISRELDEP(id)) - { - Reldep *rd = GETRELDEP(pool, id); - if (key == SOLVABLE_CONFLICTS && rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS) - { - if (!strncmp(idstr, "namespace:", 10)) - idstr += 10; - } - if (key == SOLVABLE_SUPPLEMENTS) - { - if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_FILESYSTEM) - { - if (!strncmp(idstr, "namespace:", 10)) - idstr += 10; - } - else if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_MODALIAS) - { - if (!strncmp(idstr, "namespace:", 10)) - idstr += 10; - } - else if (rd->flags == REL_AND) - { - /* either packageand chain or modalias */ - idstr = 0; - if (ISRELDEP(rd->evr)) - { - Reldep *mrd = GETRELDEP(pool, rd->evr); - if (mrd->flags == REL_NAMESPACE && mrd->name == NAMESPACE_MODALIAS) - { - idstr = pool_tmpjoin(pool, "modalias(", pool_dep2str(pool, rd->name), ":"); - idstr = pool_tmpappend(pool, idstr, pool_dep2str(pool, mrd->evr), ")"); - } - else if (mrd->flags >= 8) - continue; - } - if (!idstr) - { - /* must be and chain */ - idstr = pool_dep2str(pool, rd->evr); - for (;;) - { - id = rd->name; - if (!ISRELDEP(id)) - break; - rd = GETRELDEP(pool, id); - if (rd->flags != REL_AND) - break; - idstr = pool_tmpjoin(pool, pool_dep2str(pool, rd->evr), ":", idstr); - } - idstr = pool_tmpjoin(pool, pool_dep2str(pool, id), ":", idstr); - idstr = pool_tmpjoin(pool, "packageand(", idstr, ")"); - } - } - else if (rd->flags >= 8) - continue; - } - } + continue; + idstr = testcase_dep2str(pool, id); if (!tagwritten) { fprintf(fp, "+%s\n", tag); @@ -1008,36 +1136,31 @@ writedeps(Repo *repo, FILE *fp, const char *tag, Id key, Solvable *s, Offset off } fprintf(fp, "%s\n", idstr); } - if (key == SOLVABLE_PROVIDES) + if (tagwritten) + fprintf(fp, "-%s\n", tag); +} + +static void +writefilelist(Repo *repo, FILE *fp, const char *tag, Solvable *s) +{ + Pool *pool = repo->pool; + int tagwritten = 0; + Dataiterator di; + + dataiterator_init(&di, pool, repo, s - pool->solvables, SOLVABLE_FILELIST, 0, 0); + while (dataiterator_step(&di)) { - /* add the filelist */ - Dataiterator di; - dataiterator_init(&di, pool, repo, s - pool->solvables, SOLVABLE_FILELIST, 0, 0); - while (dataiterator_step(&di)) + const char *s = repodata_dir2str(di.data, di.kv.id, di.kv.str); + if (!tagwritten) { - const char *s = repodata_dir2str(di.data, di.kv.id, di.kv.str); - if (prvdp) - { - Id id = pool_str2id(pool, s, 0); - if (id) - { - for (dp = prvdp; *dp; dp++) - if (*dp == id) - break; - if (*dp) - continue; /* already included */ - } - } - if (!tagwritten) - { - fprintf(fp, "+%s", tag); - tagwritten = 1; - } - fprintf(fp, "%s\n", s); + fprintf(fp, "+%s\n", tag); + tagwritten = 1; } + fprintf(fp, "%s\n", s); } if (tagwritten) fprintf(fp, "-%s\n", tag); + dataiterator_free(&di); } int @@ -1053,7 +1176,7 @@ testcase_write_testtags(Repo *repo, FILE *fp) const char *tmp; unsigned int ti; - fprintf(fp, "=Ver: 2.0\n"); + fprintf(fp, "=Ver: 3.0\n"); FOR_REPO_SOLVABLES(repo, p, s) { name = pool_id2str(pool, s->name); @@ -1079,6 +1202,7 @@ testcase_write_testtags(Repo *repo, FILE *fp) ti = solvable_lookup_num(s, SOLVABLE_BUILDTIME, 0); if (ti) fprintf(fp, "=Tim: %u\n", ti); + writefilelist(repo, fp, "Fls:", s); } return 0; } @@ -1091,7 +1215,7 @@ adddep(Repo *repo, Offset olddeps, char *str, Id marker) } static void -finish_solvable(Pool *pool, Repodata *data, Solvable *s, char *filelist, int nfilelist) +finish_v2_solvable(Pool *pool, Repodata *data, Solvable *s, char *filelist, int nfilelist) { if (nfilelist) { @@ -1110,8 +1234,6 @@ finish_solvable(Pool *pool, Repodata *data, Solvable *s, char *filelist, int nfi repodata_add_dirstr(data, s - pool->solvables, SOLVABLE_FILELIST, did, p); } } - if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC) - s->provides = repo_addid_dep(s->repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0); s->supplements = repo_fix_supplements(s->repo, s->provides, s->supplements, 0); s->conflicts = repo_fix_conflicts(s->repo, s->conflicts); } @@ -1132,6 +1254,8 @@ testcase_add_testtags(Repo *repo, FILE *fp, int flags) char *filelist = 0; int afilelist = 0; int nfilelist = 0; + int tagsversion = 0; + int addselfprovides = 1; /* for compat reasons */ data = repo_add_repodata(repo, flags); s = 0; @@ -1181,9 +1305,18 @@ testcase_add_testtags(Repo *repo, FILE *fp, int flags) tag = line[1] << 16 | line[2] << 8 | line[3]; switch(tag) { + case 'V' << 16 | 'e' << 8 | 'r': + tagsversion = atoi(line + 6); + addselfprovides = tagsversion < 3 || strstr(line + 6, "addselfprovides") != 0; + break; case 'P' << 16 | 'k' << 8 | 'g': if (s) - finish_solvable(pool, data, s, filelist, nfilelist); + { + if (tagsversion == 2) + finish_v2_solvable(pool, data, s, filelist, nfilelist); + if (addselfprovides && s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC) + s->provides = repo_addid_dep(s->repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0); + } nfilelist = 0; if (split(line + 5, sp, 5) != 4) break; @@ -1213,27 +1346,44 @@ testcase_add_testtags(Repo *repo, FILE *fp, int flags) s->requires = adddep(repo, s->requires, line + 6, SOLVABLE_PREREQMARKER); break; case 'P' << 16 | 'r' << 8 | 'v': - if (line[6] == '/') + /* version 2 had the file list at the end of the provides */ + if (tagsversion == 2) { - int l = strlen(line + 6) + 1; - if (nfilelist + l > afilelist) + if (line[6] == '/') { - afilelist = nfilelist + l + 512; - filelist = solv_realloc(filelist, afilelist); + int l = strlen(line + 6) + 1; + if (nfilelist + l > afilelist) + { + afilelist = nfilelist + l + 512; + filelist = solv_realloc(filelist, afilelist); + } + memcpy(filelist + nfilelist, line + 6, l); + nfilelist += l; + break; + } + if (nfilelist) + { + int l; + for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1) + s->provides = repo_addid_dep(repo, s->provides, pool_str2id(pool, filelist + l, 1), 0); + nfilelist = 0; } - memcpy(filelist + nfilelist, line + 6, l); - nfilelist += l; - break; - } - if (nfilelist) - { - int l; - for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1) - s->provides = repo_addid_dep(repo, s->provides, pool_str2id(pool, filelist + l, 1), 0); - nfilelist = 0; } s->provides = adddep(repo, s->provides, line + 6, 0); break; + case 'F' << 16 | 'l' << 8 | 's': + { + char *p = strrchr(line + 6, '/'); + Id did; + if (!p) + break; + *p++ = 0; + did = repodata_str2dir(data, line + 6, 1); + if (!did) + did = repodata_str2dir(data, "/", 1); + repodata_add_dirstr(data, s - pool->solvables, SOLVABLE_FILELIST, did, p); + break; + } case 'O' << 16 | 'b' << 8 | 's': s->obsoletes = adddep(repo, s->obsoletes, line + 6, 0); break; @@ -1257,7 +1407,12 @@ testcase_add_testtags(Repo *repo, FILE *fp, int flags) } } if (s) - finish_solvable(pool, data, s, filelist, nfilelist); + { + if (tagsversion == 2) + finish_v2_solvable(pool, data, s, filelist, nfilelist); + if (addselfprovides && s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC) + s->provides = repo_addid_dep(s->repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0); + } solv_free(line); solv_free(filelist); repodata_free_dircache(data); @@ -1470,6 +1625,33 @@ testcase_solutionid(Solver *solv, Id problem, Id solution) return s; } +static const char * +testcase_alternativeid(Solver *solv, int type, Id id, Id from) +{ + const char *s; + Pool *pool = solv->pool; + Chksum *chk; + const unsigned char *md5; + int md5l; + chk = solv_chksum_create(REPOKEY_TYPE_MD5); + if (type == SOLVER_ALTERNATIVE_TYPE_RECOMMENDS) + { + s = testcase_solvid2str(pool, from); + solv_chksum_add(chk, s, strlen(s) + 1); + s = testcase_dep2str(pool, id); + solv_chksum_add(chk, s, strlen(s) + 1); + } + else if (type == SOLVER_ALTERNATIVE_TYPE_RULE) + { + s = testcase_ruleid(solv, id); + solv_chksum_add(chk, s, strlen(s) + 1); + } + md5 = solv_chksum_get(chk, &md5l); + s = pool_bin2hex(pool, md5, 4); + chk = solv_chksum_free(chk, 0); + return s; +} + static struct class2str { Id class; const char *str; @@ -1626,6 +1808,72 @@ testcase_solverresult(Solver *solv, int resultflags) queue_free(&q); queue_free(&qf); } + if ((resultflags & TESTCASE_RESULT_ALTERNATIVES) != 0) + { + char *altprefix; + Queue q, rq; + int cnt; + Id alternative; + queue_init(&q); + queue_init(&rq); + cnt = solver_alternatives_count(solv); + for (alternative = 1; alternative <= cnt; alternative++) + { + Id id, from, chosen; + char num[20]; + int type = solver_get_alternative(solv, alternative, &id, &from, &chosen, &q, 0); + altprefix = solv_dupjoin("alternative ", testcase_alternativeid(solv, type, id, from), " "); + strcpy(num, " 0 "); + if (type == SOLVER_ALTERNATIVE_TYPE_RECOMMENDS) + { + char *s = pool_tmpjoin(pool, altprefix, num, testcase_solvid2str(pool, from)); + s = pool_tmpappend(pool, s, " recommends ", testcase_dep2str(pool, id)); + strqueue_push(&sq, s); + } + else if (type == SOLVER_ALTERNATIVE_TYPE_RULE) + { + /* map choice rules back to pkg rules */ + if (solver_ruleclass(solv, id) == SOLVER_RULE_CHOICE) + id = solver_rule2pkgrule(solv, id); + solver_allruleinfos(solv, id, &rq); + for (i = 0; i < rq.count; i += 4) + { + int rtype = rq.elements[i]; + if ((rtype & SOLVER_RULE_TYPEMASK) == SOLVER_RULE_JOB) + { + const char *js = testcase_job2str(pool, rq.elements[i + 2], rq.elements[i + 3]); + char *s = pool_tmpjoin(pool, altprefix, num, " job "); + s = pool_tmpappend(pool, s, js, 0); + strqueue_push(&sq, s); + } + else if (rtype == SOLVER_RULE_PKG_REQUIRES) + { + char *s = pool_tmpjoin(pool, altprefix, num, testcase_solvid2str(pool, rq.elements[i + 1])); + s = pool_tmpappend(pool, s, " requires ", testcase_dep2str(pool, rq.elements[i + 3])); + strqueue_push(&sq, s); + } + } + } + for (i = 0; i < q.count; i++) + { + Id p = q.elements[i]; + if (i >= 9) + num[0] = '0' + (i + 1) / 10; + num[1] = '0' + (i + 1) % 10; + if (-p == chosen) + s = pool_tmpjoin(pool, altprefix, num, "+ "); + else if (p < 0) + s = pool_tmpjoin(pool, altprefix, num, "- "); + else if (p >= 0) + s = pool_tmpjoin(pool, altprefix, num, " "); + s = pool_tmpappend(pool, s, testcase_solvid2str(pool, p < 0 ? -p : p), 0); + strqueue_push(&sq, s); + } + solv_free(altprefix); + } + queue_free(&q); + queue_free(&rq); + } strqueue_sort(&sq); result = strqueue_join(&sq); diff --git a/ext/testcase.h b/ext/testcase.h index 4243e4f..14a2cca 100644 --- a/ext/testcase.h +++ b/ext/testcase.h @@ -14,8 +14,10 @@ #define TESTCASE_RESULT_ORPHANED (1 << 2) #define TESTCASE_RESULT_RECOMMENDED (1 << 3) #define TESTCASE_RESULT_UNNEEDED (1 << 4) +#define TESTCASE_RESULT_ALTERNATIVES (1 << 5) extern Id testcase_str2dep(Pool *pool, const char *s); +extern const char *testcase_dep2str(Pool *pool, Id id); extern const char *testcase_repoid2str(Pool *pool, Id repoid); extern const char *testcase_solvid2str(Pool *pool, Id p); extern Repo *testcase_str2repo(Pool *pool, const char *str); |