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
224225int
225226pool_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+
797869int 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
0 commit comments