1818#include <string.h>
1919#include <sys/types.h>
2020#include <regex.h>
21- #include <ctype.h>
2221
2322#include "pool.h"
2423#include "repo.h"
@@ -225,7 +224,6 @@ pool_evrcmp_conda_int(const char *evr1, const char *evr1e, const char *evr2, con
225224int
226225pool_evrcmp_conda (const Pool * pool , const char * evr1 , const char * evr2 , int mode )
227226{
228- // printf("EVR CMP conda: %s, %s", evr1, evr2);
229227 if (evr1 == evr2 )
230228 return 0 ;
231229 return pool_evrcmp_conda_int (evr1 , evr1 + strlen (evr1 ), evr2 , evr2 + strlen (evr2 ), 0 );
@@ -680,242 +678,3 @@ pool_conda_matchspec(Pool *pool, const char *name)
680678 return pool_rel2id (pool , nameid , evrid , REL_CONDA , 1 );
681679}
682680
683- int find_lower_upper_bound (const char * c ,
684- char * lower , int * lowerflag , char * upper , int * upperflag )
685- {
686- lower [0 ] = '\0' ;
687- upper [0 ] = '\0' ;
688- * lowerflag = 0 ;
689- * upperflag = 0 ;
690-
691- if (!c )
692- {
693- // Infinity bound => lower[0] == '\0' && flag == REL_GT | REL_EQ
694- // return infinity lower & upper
695- * lowerflag = REL_GT | REL_EQ ;
696- * upperflag = REL_GT | REL_EQ ;
697- return 1 ;
698- }
699-
700- int len = strlen (c );
701- const char * lowerbegin = NULL ;
702- const char * lowerend ;
703- const char * upperbegin = NULL ;
704- const char * upperend ;
705- const char * p ;
706- const char * * toend = NULL ;
707- int has_star = 0 ;
708-
709- for (int i = 0 ; i < len ; ++ i )
710- {
711- if (c [i ] == ' ' ) break ;
712- if (c [i ] == '>' )
713- {
714- * lowerflag = REL_GT ;
715- ++ i ;
716- if (len > i && c [i ] == '=' )
717- {
718- * lowerflag |= REL_EQ ;
719- ++ i ;
720- }
721- p = lowerbegin = & c [i ];
722- toend = & lowerend ;
723- }
724- else if (c [i ] == '<' )
725- {
726- * upperflag = REL_LT ;
727- ++ i ;
728- if (len > i && c [i ] == '=' )
729- {
730- * upperflag |= REL_EQ ;
731- ++ i ;
732- }
733- p = upperbegin = & c [i ];
734- toend = & upperend ;
735- }
736- else if (c [i ] == '=' )
737- {
738- ++ i ;
739- if (c [i ] == '=' )
740- {
741- ++ i ;
742- * lowerflag = REL_EQ ;
743- * upperflag = REL_EQ ;
744- }
745- else
746- {
747- * lowerflag = REL_EQ | REL_LT | REL_GT ;
748- * upperflag = REL_EQ | REL_LT | REL_GT ;
749- has_star = 1 ;
750- }
751- p = lowerbegin = & c [i ];
752- toend = & lowerend ;
753- }
754- else if (c [i ] == ',' || c [i ] == '|' )
755- {
756- // ignore
757- }
758- else
759- {
760- * lowerflag = REL_EQ ;
761- * upperflag = REL_EQ ;
762- p = lowerbegin = & c [i ];
763- toend = & lowerend ;
764- }
765- if (toend )
766- {
767- while (* p && * p != ',' && * p != '|' && * p != ' ' )
768- ++ p , ++ i ;
769- * toend = p ;
770- toend = NULL ;
771- if (* p == ' ' ) break ;
772- }
773- }
774-
775- if (!upperbegin )
776- {
777- if (* (lowerend - 1 ) == '*' || has_star )
778- {
779- * upperflag = REL_GT | REL_LT | REL_EQ ;
780- * lowerflag = REL_GT | REL_LT | REL_EQ ;
781- const char * p = lowerend - 1 ;
782- while (p > lowerbegin && (* p == '*' || * p == '.' )) p -- ;
783- lowerend = p + 1 ;
784- }
785- upperbegin = lowerbegin ;
786- upperend = lowerend ;
787- }
788-
789- if (lowerbegin != NULL )
790- strncat (lower , lowerbegin , lowerend - lowerbegin );
791-
792- if (upperbegin != NULL && upperbegin != upper )
793- strncat (upper , upperbegin , upperend - upperbegin );
794-
795- return 1 ;
796- }
797-
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-
869- int conda_compare_bounds (const char * b1 , const char * b2 )
870- {
871- if (!b1 || !b2 )
872- {
873- if (!b1 && !b2 ) return 0 ;
874- if (b1 && !b2 ) return 1 ;
875- if (!b1 && b2 ) return -1 ;
876- }
877-
878- // TODO handle infty bounds
879- int lf1 , uf1 , lf2 , uf2 ;
880- char l1 [100 ] = "" , u1 [100 ] = "" ;
881- char l2 [100 ] = "" , u2 [100 ] = "" ;
882- find_lower_upper_bound (b1 , l1 , & lf1 , u1 , & uf1 );
883- find_lower_upper_bound (b2 , l2 , & lf2 , u2 , & uf2 );
884-
885- // if lower bound different, prefer package with higher lower bound
886- // if upper bound different, prefer package with higher upper bound
887-
888- // edge cases `=3.7, >=3.7 --> lower bound equal, upper bound different
889- // edge cases `==3.7, =3.7 --> lower bound equal, upper bound different
890-
891- // printf("compare: %s vs %s", l1, l2);
892-
893- // both lower pin with * at end
894- if (lf1 == lf2 )
895- {
896- printf ("compare: %s vs %s\n" , l1 , l2 );
897- int l_evr_cmp = pool_evrcmp_conda (NULL , l1 , l2 , 0 );
898- if (l_evr_cmp != 0 )
899- {
900- return - l_evr_cmp ;
901- }
902- }
903- else
904- {
905- normalize_bound (& lf1 , l1 );
906- normalize_bound (& lf2 , l2 );
907-
908- int l_evr_cmp = pool_evrcmp_conda (NULL , l1 , l2 , 0 );
909- // TODO
910- // need some logic here to normalize the bounds
911- // depending on the comparison function
912- return - l_evr_cmp ;
913- }
914-
915- int u_evr_cmp = pool_evrcmp_conda (NULL , u1 , u2 , 0 );
916- if (u_evr_cmp != 0 )
917- {
918- return u_evr_cmp ;
919- }
920- return u_evr_cmp ;
921- }
0 commit comments