@@ -3,7 +3,6 @@ package main
3
3
import (
4
4
"cmp"
5
5
"encoding/json"
6
- "fmt"
7
6
"os"
8
7
"regexp"
9
8
@@ -125,8 +124,7 @@ func DumpJSON(result ResolvedResult, targets []string, cmdline []string) ([]byte
125
124
}
126
125
127
126
alreadyInstalled := make (map [string ]bool )
128
- packageNames := sortedKeys (allPackages )
129
- for _ , name := range packageNames {
127
+ for _ , name := range maps .Keys (allPackages ) {
130
128
if _ , ignored := forceIgnored [name ]; ignored {
131
129
continue
132
130
}
@@ -152,6 +150,10 @@ func DumpJSON(result ResolvedResult, targets []string, cmdline []string) ([]byte
152
150
allPackages [name ] = entry
153
151
}
154
152
153
+ allPackages , forceIgnored = garbageCollect (targets , forceIgnored , allPackages )
154
+
155
+ packageNames := sortedKeys (allPackages )
156
+
155
157
sortedPackages := make ([]InstalledPackage , 0 , len (packageNames ))
156
158
for _ , name := range packageNames {
157
159
sortedPackages = append (sortedPackages , allPackages [name ])
@@ -189,7 +191,8 @@ func computeDependencies(requires []string, providers map[string]string, ignored
189
191
logrus .Debugf ("Resolving dependency %s" , req )
190
192
provider , ok := providers [req ]
191
193
if ! ok {
192
- return nil , fmt .Errorf ("could not find provider for %s" , req )
194
+ logrus .Warnf ("could not find provider for %s" , req )
195
+ continue
193
196
}
194
197
logrus .Debugf ("Found provider %s for %s" , provider , req )
195
198
if ignored [provider ] {
@@ -223,10 +226,7 @@ func exploreAllDependencies(input *api.Package, allPackages map[string]*api.Pack
223
226
current := pending [0 ]
224
227
pending = pending [1 :]
225
228
226
- logrus .Debugf ("exploring %s" , current .Name )
227
-
228
229
if _ , explored := previouslyExplored [current .Name ]; explored {
229
- logrus .Debugf ("previously explored %s" , current .Name )
230
230
continue
231
231
}
232
232
@@ -295,13 +295,12 @@ func filterIgnores(rpmsRequested []string, allAvailable []*api.Package, ignoreRe
295
295
pending := []* api.Package {target }
296
296
for len (pending ) > 0 {
297
297
current := pending [0 ]
298
- logrus .Debugf ("processing %s" , current .Name )
299
298
pending = pending [1 :]
300
299
if _ , alreadyExplored := explored [current .Name ]; alreadyExplored {
301
- logrus .Debugf ("already iterated" )
302
300
continue
303
301
}
304
302
303
+ logrus .Debugf ("processing %s" , current .Name )
305
304
if ! shouldInclude (current .Name , ignoreRegex ) {
306
305
toIgnore := exploreAllDependencies (current , allAvailablePerName , explored )
307
306
for _ , d := range toIgnore {
@@ -320,7 +319,6 @@ func filterIgnores(rpmsRequested []string, allAvailable []*api.Package, ignoreRe
320
319
321
320
toInstall = append (toInstall , current )
322
321
for _ , dep := range current .Format .Requires .Entries {
323
- logrus .Debugf ("finding dependency provider for %s" , dep .Name )
324
322
p , ok := allAvailablePerName [dep .Name ]
325
323
if ok {
326
324
pending = append (pending , p )
@@ -337,45 +335,36 @@ func filterIgnores(rpmsRequested []string, allAvailable []*api.Package, ignoreRe
337
335
return toInstall , ignoredPackages
338
336
}
339
337
340
- func garbageCollect (rpmsRequested []string , toInstall []* api.Package , ignored []* api.Package ) ([]* api.Package , []* api.Package ) {
341
- requested := map [string ]bool {}
342
- for _ , rpm := range rpmsRequested {
343
- requested [rpm ] = true
344
- }
338
+ func garbageCollect (targets []string , forceIgnored map [string ]bool , packages map [string ]InstalledPackage ) (map [string ]InstalledPackage , map [string ]bool ) {
339
+ reachedPackages := map [string ]bool {}
345
340
346
- directDependencies := make (map [string ]bool )
347
- allPackages := make (map [string ]* api.Package , 0 )
348
- for _ , rpm := range toInstall {
349
- allPackages [rpm .Name ] = rpm
341
+ for _ , target := range targets {
342
+ reachedPackages [target ] = true
343
+ for _ , dep := range packages [target ].Dependencies {
344
+ reachedPackages [dep ] = true
345
+ }
350
346
}
351
347
352
- emptyMap := make (map [string ]bool , 0 )
353
-
354
- for _ , rpm := range toInstall {
355
- if _ , isDirectDependency := requested [rpm .Name ]; ! isDirectDependency {
356
- continue
357
- }
358
- directDependencies [rpm .Name ] = true
359
- deps := exploreAllDependencies (rpm , allPackages , emptyMap )
360
- for _ , dep := range deps {
361
- if _ , available := allPackages [dep .Name ]; ! available {
362
- // this one was filtered out by the ignore regex
363
- continue
364
- }
365
- directDependencies [dep .Name ] = true
348
+ for _ , pkg := range packages {
349
+ if _ , isReached := reachedPackages [pkg .Name ]; ! isReached {
350
+ forceIgnored [pkg .Name ] = true
366
351
}
367
352
}
368
353
369
- toKeep := make ([]* api.Package , 0 )
370
- for _ , rpm := range toInstall {
371
- if _ , keep := directDependencies [rpm .Name ]; keep {
372
- toKeep = append (toKeep , rpm )
373
- } else {
374
- ignored = append (ignored , rpm )
375
- }
354
+ for pkg , _ := range forceIgnored {
355
+ delete (packages , pkg )
376
356
}
377
357
378
- return toKeep , ignored
358
+ return packages , forceIgnored
359
+ }
360
+
361
+ func packageNames (packages []* api.Package ) []string {
362
+ output := make ([]string , 0 )
363
+ for _ , p := range packages {
364
+ output = append (output , p .Name )
365
+ }
366
+ slices .Sort (output )
367
+ return output
379
368
}
380
369
381
370
func (opts * BzlmodOpts ) RunE (cmd * cobra.Command , rpms []string ) error {
@@ -401,13 +390,13 @@ func (opts *BzlmodOpts) RunE(cmd *cobra.Command, rpms []string) error {
401
390
}
402
391
403
392
solver := sat .NewResolver (resolvehelperopts .nobest )
404
- logrus .Info ("Loading involved packages into the rpmtreer." )
393
+ logrus .Infof ("Loading involved packages into the rpmtreer: %d" , len ( involved ) )
405
394
err = solver .LoadInvolvedPackages (involved , []string {}, resolvehelperopts .onlyAllowRegex )
406
395
if err != nil {
407
396
return err
408
397
}
409
398
410
- logrus .Info ("Adding required packages to the rpmtreer." )
399
+ logrus .Infof ("Adding required packages to the rpmtreer: %d" , len ( matched ) )
411
400
err = solver .ConstructRequirements (matched )
412
401
if err != nil {
413
402
return err
@@ -419,15 +408,11 @@ func (opts *BzlmodOpts) RunE(cmd *cobra.Command, rpms []string) error {
419
408
return err
420
409
}
421
410
422
- logrus .Debugf ("install: %v" , install )
411
+ logrus .Debugf ("resolver install: %v" , install )
423
412
424
413
actualInstall , forceIgnored := filterIgnores (rpms , install , resolvehelperopts .forceIgnoreRegex )
425
- logrus .Debugf ("before GC actual install: %d" , len (actualInstall ))
426
- logrus .Debugf ("before GC actual ignored: %d" , len (forceIgnored ))
427
-
428
- actualInstall , forceIgnored = garbageCollect (rpms , actualInstall , forceIgnored )
429
- logrus .Debugf ("actualInstall: %v" , actualInstall )
430
- logrus .Debugf ("forceIgnored: %v" , forceIgnored )
414
+ logrus .Debugf ("before GC actual install(%d): %+v" , len (actualInstall ), packageNames (actualInstall ))
415
+ logrus .Debugf ("before GC actual ignored(%d): %+v" , len (forceIgnored ), packageNames (forceIgnored ))
431
416
432
417
result := ResolvedResult {Install : actualInstall , ForceIgnored : forceIgnored }
433
418
0 commit comments