Skip to content

Commit 6adcbee

Browse files
committed
Add support for conda constrains
1 parent 5205c56 commit 6adcbee

6 files changed

Lines changed: 73 additions & 0 deletions

File tree

ext/repo_conda.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ parse_deps(struct parsedata *pd, struct solv_jsonparser *jp, Offset *depp)
4242
return type;
4343
}
4444

45+
static int
46+
parse_otherdeps(struct parsedata *pd, struct solv_jsonparser *jp, Id handle, Id keyname)
47+
{
48+
int type = JP_ARRAY;
49+
while (type > 0 && (type = jsonparser_parse(jp)) > 0 && type != JP_ARRAY_END)
50+
{
51+
if (type == JP_STRING)
52+
{
53+
Id id = pool_conda_matchspec(pd->pool, jp->value);
54+
if (id)
55+
repodata_add_idarray(pd->data, handle, keyname, id);
56+
}
57+
else
58+
type = jsonparser_skip(jp, type);
59+
}
60+
return type;
61+
}
62+
4563
static int
4664
parse_package(struct parsedata *pd, struct solv_jsonparser *jp, char *kfn)
4765
{
@@ -64,6 +82,8 @@ parse_package(struct parsedata *pd, struct solv_jsonparser *jp, char *kfn)
6482
type = parse_deps(pd, jp, &s->requires);
6583
else if (type == JP_ARRAY && !strcmp(jp->key, "requires"))
6684
type = parse_deps(pd, jp, &s->requires);
85+
else if (type == JP_ARRAY && !strcmp(jp->key, "constrains"))
86+
type = parse_otherdeps(pd, jp, handle, SOLVABLE_CONSTRAINS);
6787
else if (type == JP_STRING && !strcmp(jp->key, "license"))
6888
repodata_add_poolstr_array(data, handle, SOLVABLE_LICENSE, jp->value);
6989
else if (type == JP_STRING && !strcmp(jp->key, "md5"))

ext/repo_testcase.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,14 @@ testcase_write_testtags(Repo *repo, FILE *fp)
461461
fprintf(fp, "%s\n", testcase_dep2str(pool, q.elements[i]));
462462
fprintf(fp, "-Ipr:\n");
463463
}
464+
if (solvable_lookup_idarray(s, SOLVABLE_CONSTRAINS, &q))
465+
{
466+
int i;
467+
fprintf(fp, "+Cns:\n");
468+
for (i = 0; i < q.count; i++)
469+
fprintf(fp, "%s\n", testcase_dep2str(pool, q.elements[i]));
470+
fprintf(fp, "-Cns:\n");
471+
}
464472
if (s->vendor)
465473
fprintf(fp, "=Vnd: %s\n", pool_id2str(pool, s->vendor));
466474
if (solvable_lookup_idarray(s, SOLVABLE_BUILDFLAVOR, &q))
@@ -690,6 +698,9 @@ testcase_add_testtags(Repo *repo, FILE *fp, int flags)
690698
repodata_add_idarray(data, s - pool->solvables, SOLVABLE_PREREQ_IGNOREINST, id);
691699
break;
692700
}
701+
case 'C' << 16 | 'n' << 8 | 's':
702+
repodata_add_idarray(data, s - pool->solvables, SOLVABLE_CONSTRAINS, testcase_str2dep(pool, line + 6));
703+
break;
693704
case 'F' << 16 | 'l' << 8 | 'v':
694705
repodata_add_poolstr_array(data, s - pool->solvables, SOLVABLE_BUILDFLAVOR, line + 6);
695706
break;

src/knownid.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ KNOWNID(UPDATE_STATUS, "update:status"), /* "stable", "testing", ...*/
265265

266266
KNOWNID(LIBSOLV_SELF_DESTRUCT_PKG, "libsolv-self-destruct-pkg()"), /* this package will self-destruct on installation */
267267

268+
KNOWNID(SOLVABLE_CONSTRAINS, "solvable:constrains"), /* conda */
269+
268270
KNOWNID(ID_NUM_INTERNAL, 0)
269271

270272
#ifdef KNOWNID_INITIALIZE

src/problems.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,10 @@ solver_problemruleinfo2str(Solver *solv, SolverRuleinfo type, Id source, Id targ
13411341
return pool_tmpappend(pool, s, pool_dep2str(pool, dep), 0);
13421342
case SOLVER_RULE_BLACK:
13431343
return pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), " can only be installed by a direct request");
1344+
case SOLVER_RULE_PKG_CONSTRAINS:
1345+
s = pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), 0);
1346+
s = pool_tmpappend(pool, s, " has a constraint ", pool_dep2str(pool, dep));
1347+
return pool_tmpappend(pool, s, " conflicting with ", pool_solvid2str(pool, target));
13441348
default:
13451349
return "bad problem rule type";
13461350
}

src/rules.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,30 @@ add_complex_deprules(Solver *solv, Id p, Id dep, int type, int dontfix, Queue *w
665665

666666
#endif
667667

668+
#ifdef ENABLE_CONDA
669+
void
670+
add_conda_constrains_rule(Solver *solv, Id n, Id dep)
671+
{
672+
Pool *pool = solv->pool;
673+
Reldep *rd;
674+
Id p, pp, pdep;
675+
if (!ISRELDEP(dep))
676+
return;
677+
rd = GETRELDEP(pool, dep);
678+
pdep = pool_whatprovides(pool, dep);
679+
FOR_PROVIDES(p, pp, rd->name)
680+
{
681+
Id p2;
682+
while ((p2 = pool->whatprovidesdata[pdep]) != 0 && p2 < p)
683+
pdep++;
684+
if (p == p2)
685+
pdep++;
686+
else
687+
addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_CONSTRAINS, dep);
688+
}
689+
}
690+
#endif
691+
668692
/*-------------------------------------------------------------------
669693
*
670694
* add dependency rules for solvable
@@ -896,6 +920,17 @@ solver_addpkgrulesforsolvable(Solver *solv, Solvable *s, Map *m)
896920
}
897921
}
898922

923+
#ifdef ENABLE_CONDA
924+
if (pool->disttype == DISTTYPE_CONDA)
925+
{
926+
if (prereqq.count) /* reuse the prereq queue */
927+
queue_empty(&prereqq);
928+
solvable_lookup_idarray(s, SOLVABLE_CONSTRAINS, &prereqq);
929+
for (i = 0; i < prereqq.count; i++)
930+
add_conda_constrains_rule(solv, n, prereqq.elements[i]);
931+
}
932+
#endif
933+
899934
/* that's all we check for src packages */
900935
if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
901936
continue;

src/rules.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ typedef enum {
5959
SOLVER_RULE_PKG_IMPLICIT_OBSOLETES,
6060
SOLVER_RULE_PKG_INSTALLED_OBSOLETES,
6161
SOLVER_RULE_PKG_RECOMMENDS,
62+
SOLVER_RULE_PKG_CONSTRAINS,
6263
SOLVER_RULE_UPDATE = 0x200,
6364
SOLVER_RULE_FEATURE = 0x300,
6465
SOLVER_RULE_JOB = 0x400,

0 commit comments

Comments
 (0)