Skip to content

Commit 92d9d87

Browse files
committed
second try at fixing all this
1 parent a769f33 commit 92d9d87

4 files changed

Lines changed: 408 additions & 39 deletions

File tree

src/conda.c

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <string.h>
1919
#include <sys/types.h>
2020
#include <regex.h>
21+
#include <ctype.h>
2122

2223
#include "pool.h"
2324
#include "repo.h"
@@ -224,6 +225,7 @@ pool_evrcmp_conda_int(const char *evr1, const char *evr1e, const char *evr2, con
224225
int
225226
pool_evrcmp_conda(const Pool *pool, const char *evr1, const char *evr2, int mode)
226227
{
228+
// printf("EVR CMP conda: %s, %s", evr1, evr2);
227229
if (evr1 == evr2)
228230
return 0;
229231
return pool_evrcmp_conda_int(evr1, evr1 + strlen(evr1), evr2, evr2 + strlen(evr2), 0);
@@ -790,10 +792,80 @@ int find_lower_upper_bound(const char* c,
790792
if (upperbegin != NULL && upperbegin != upper)
791793
strncat(upper, upperbegin, upperend - upperbegin);
792794

793-
printf("\nLower: %s\nUpper: %s\nFlags: %d\n", lower, upper, *upperflag);
794795
return 1;
795796
}
796797

798+
void normalize_bound(int* flags, char* bound)
799+
{
800+
if ((*flags & (REL_GT | REL_EQ)) == (REL_GT | REL_EQ)) return;
801+
if (*flags & REL_GT)
802+
{
803+
size_t len = strlen(bound);
804+
if (len == 0) return;
805+
806+
char snum[100] = "\0";
807+
char sbef[100] = "\0", saft[100] = "\0";
808+
809+
const char* end = &bound[len - 1];
810+
const char* start;
811+
812+
for (;end >= bound; --end) {
813+
if (*end == '.') {
814+
end++;
815+
break;
816+
}
817+
}
818+
819+
start = end;
820+
821+
while ((*end != '\0') && isdigit(*end))
822+
++end;
823+
824+
memcpy(sbef, bound, start - bound);
825+
sbef[start - bound ] = '\0';
826+
memcpy(saft, end, &bound[len] - end);
827+
strncpy(snum, start, end - start);
828+
829+
size_t num;
830+
if (1 == sscanf(snum, "%zu", &num))
831+
{
832+
sprintf(bound, "%s%zu%s", sbef, num + 1, saft);
833+
}
834+
else
835+
{
836+
return;
837+
}
838+
}
839+
}
840+
841+
// given a list of bounds, selects the highest lowest
842+
// for a given solvable, e.g.
843+
// - python =3.4
844+
// - python >=3.3
845+
// -- will return reldep for `python =3.4` etc.
846+
Reldep* select_best_bound(Pool* pool, Queue* q, Id name)
847+
{
848+
Reldep* res = NULL;
849+
for (int i = 0; i < q->count; ++i)
850+
{
851+
Id x1 = q->elements[i];
852+
Reldep *rd1 = GETRELDEP(pool, x1);
853+
if (rd1->name == name)
854+
{
855+
if (res)
856+
{
857+
// check if this has a higher lower bound than rd1
858+
int cmp = conda_compare_bounds(pool_id2str(pool, res->evr),
859+
pool_id2str(pool, rd1->evr));
860+
if (cmp > 0) res = rd1;
861+
}
862+
else
863+
res = rd1;
864+
}
865+
}
866+
return res;
867+
}
868+
797869
int conda_compare_bounds(const char* b1, const char* b2)
798870
{
799871
if (!b1 || !b2)
@@ -816,9 +888,12 @@ int conda_compare_bounds(const char* b1, const char* b2)
816888
// edge cases `=3.7, >=3.7 --> lower bound equal, upper bound different
817889
// edge cases `==3.7, =3.7 --> lower bound equal, upper bound different
818890

891+
// printf("compare: %s vs %s", l1, l2);
892+
819893
// both lower pin with * at end
820894
if (lf1 == lf2)
821895
{
896+
printf("compare: %s vs %s\n", l1, l2);
822897
int l_evr_cmp = pool_evrcmp_conda(NULL, l1, l2, 0);
823898
if (l_evr_cmp != 0)
824899
{
@@ -827,6 +902,9 @@ int conda_compare_bounds(const char* b1, const char* b2)
827902
}
828903
else
829904
{
905+
normalize_bound(&lf1, l1);
906+
normalize_bound(&lf2, l2);
907+
830908
int l_evr_cmp = pool_evrcmp_conda(NULL, l1, l2, 0);
831909
// TODO
832910
// need some logic here to normalize the bounds

src/conda.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313
#ifndef LIBSOLV_CONDA_H
1414
#define LIBSOLV_CONDA_H
1515

16+
#include "queue.h"
17+
#include "pool.h"
18+
1619
int pool_evrcmp_conda(const Pool *pool, const char *evr1, const char *evr2, int mode);
1720
int solvable_conda_matchversion(Solvable *s, const char *version);
1821
Id pool_addrelproviders_conda(Pool *pool, Id name, Id evr, Queue *plist);
1922
Id pool_conda_matchspec(Pool *pool, const char *name);
2023
int conda_compare_bounds(const char* b1, const char* b2);
24+
void normalize_bound(int* f, char* b);
25+
Reldep* select_best_bound(Pool* pool, Queue* q, Id name);
2126

2227
#endif /* LIBSOLV_CONDA_H */
2328

0 commit comments

Comments
 (0)