@@ -74,9 +74,10 @@ type Resolver struct {
7474
7575 bestPackages map [string ]* api.Package
7676
77- ands []bf.Formula
78- unresolvable []unresolvable
79- nobest bool
77+ ands []bf.Formula
78+ unresolvable []unresolvable
79+ forceIgnoreWithDependencies map [string ]* api.Package
80+ nobest bool
8081}
8182
8283type unresolvable struct {
@@ -87,13 +88,14 @@ type unresolvable struct {
8788
8889func NewResolver (nobest bool ) * Resolver {
8990 return & Resolver {
90- varsCount : 0 ,
91- provides : map [string ][]* Var {},
92- packages : map [string ][]* Var {},
93- vars : map [string ]* Var {},
94- pkgProvides : map [VarContext ][]* Var {},
95- nobest : nobest ,
96- bestPackages : map [string ]* api.Package {},
91+ varsCount : 0 ,
92+ provides : map [string ][]* Var {},
93+ packages : map [string ][]* Var {},
94+ vars : map [string ]* Var {},
95+ pkgProvides : map [VarContext ][]* Var {},
96+ nobest : nobest ,
97+ bestPackages : map [string ]* api.Package {},
98+ forceIgnoreWithDependencies : map [string ]* api.Package {},
9799 }
98100}
99101
@@ -102,14 +104,30 @@ func (r *Resolver) ticket() string {
102104 return "x" + strconv .Itoa (r .varsCount )
103105}
104106
105- func (r * Resolver ) LoadInvolvedPackages (packages []* api.Package ) error {
106- // Deduplicate entries
107+ //LoadInvolvedPackages takes a list of all involved packages to install, as well as a list of regular
108+ // expressions which denoe packages which should be taken into account for solving the problem, but they
109+ // should then be ignored together with their requirements in the provided list of installed packages.
110+ func (r * Resolver ) LoadInvolvedPackages (packages []* api.Package , ignoreRegex []string ) error {
111+ // Deduplicate and detect excludes
107112 deduplicated := map [string ]* api.Package {}
108113 for i , pkg := range packages {
109114 if _ , exists := deduplicated [pkg .String ()]; exists {
110115 logrus .Infof ("Removing duplicate of %v." , pkg .String ())
111116 }
112- deduplicated [pkg .String ()] = packages [i ]
117+ fullName := pkg .String ()
118+ if _ , exists := deduplicated [fullName ]; ! exists {
119+ for _ , rex := range ignoreRegex {
120+ if match , err := regexp .MatchString (rex , fullName ); err != nil {
121+ return fmt .Errorf ("failed to match package with regex '%v': %v" , rex , err )
122+ } else if match {
123+ packages [i ].Format .Requires .Entries = nil
124+ logrus .Warnf ("Package %v is forcefully ignored by regex '%v'." , pkg .String (), rex )
125+ r .forceIgnoreWithDependencies [pkg .String ()] = packages [i ]
126+ break
127+ }
128+ }
129+ deduplicated [pkg .String ()] = packages [i ]
130+ }
113131 }
114132 packages = nil
115133 for k , _ := range deduplicated {
@@ -182,7 +200,7 @@ func (r *Resolver) ConstructRequirements(packages []string) error {
182200 return nil
183201}
184202
185- func (res * Resolver ) Resolve () (install []* api.Package , excluded []* api.Package , err error ) {
203+ func (res * Resolver ) Resolve () (install []* api.Package , excluded []* api.Package , forceIgnoredWithDependencies [] * api. Package , err error ) {
186204 logrus .WithField ("bf" , bf .And (res .ands ... )).Debug ("Formula to solve" )
187205
188206 satReader , satWriter := io .Pipe ()
@@ -253,13 +271,13 @@ func (res *Resolver) Resolve() (install []*api.Package, excluded []*api.Package,
253271 logrus .Info ("Loading the Partial weighted MAXSAT problem." )
254272 s , err := maxsat .ParseWCNF (pwMaxSatReader )
255273 if err != nil {
256- return nil , nil , err
274+ return nil , nil , nil , err
257275 }
258276 if err := <- satErrChan ; err != nil {
259- return nil , nil , err
277+ return nil , nil , nil , err
260278 }
261279 if err := <- pwMaxSatErrChan ; err != nil {
262- return nil , nil , err
280+ return nil , nil , nil , err
263281 }
264282 satVars := <- varsChan
265283
@@ -270,12 +288,17 @@ func (res *Resolver) Resolve() (install []*api.Package, excluded []*api.Package,
270288 logrus .Infof ("Solution with weight %v found." , solution .Weight )
271289 installMap := map [VarContext ]* api.Package {}
272290 excludedMap := map [VarContext ]* api.Package {}
291+ forceIgnoreMap := map [VarContext ]* api.Package {}
273292 for k , v := range solution .Model {
274293 // Offset of `1`. The model index starts with 0, but the variable sequence starts with 1, since 0 is not allowed
275294 resVar := res .vars [satVars .satToPkg [strconv .Itoa (k + 1 )]]
276295 if resVar != nil && resVar .varType == VarTypePackage {
277296 if v {
278- installMap [resVar .Context ] = resVar .Package
297+ if _ , exists := res .forceIgnoreWithDependencies [resVar .Package .String ()]; ! exists {
298+ installMap [resVar .Context ] = resVar .Package
299+ } else {
300+ forceIgnoreMap [resVar .Context ] = resVar .Package
301+ }
279302 } else {
280303 excludedMap [resVar .Context ] = resVar .Package
281304 }
@@ -291,10 +314,13 @@ func (res *Resolver) Resolve() (install []*api.Package, excluded []*api.Package,
291314 for _ , v := range excludedMap {
292315 excluded = append (excluded , v )
293316 }
294- return install , excluded , nil
317+ for _ , v := range forceIgnoreMap {
318+ forceIgnoredWithDependencies = append (forceIgnoredWithDependencies , v )
319+ }
320+ return install , excluded , forceIgnoredWithDependencies , nil
295321 }
296322 logrus .Info ("No solution found." )
297- return nil , nil , fmt .Errorf ("no solution found" )
323+ return nil , nil , nil , fmt .Errorf ("no solution found" )
298324}
299325
300326func (res * Resolver ) MUS () (mus * explain.Problem , err error ) {
0 commit comments