@@ -3,7 +3,6 @@ package main
33import (
44 "cmp"
55 "encoding/json"
6- "fmt"
76 "os"
87 "regexp"
98
@@ -125,8 +124,7 @@ func DumpJSON(result ResolvedResult, targets []string, cmdline []string) ([]byte
125124 }
126125
127126 alreadyInstalled := make (map [string ]bool )
128- packageNames := sortedKeys (allPackages )
129- for _ , name := range packageNames {
127+ for _ , name := range maps .Keys (allPackages ) {
130128 if _ , ignored := forceIgnored [name ]; ignored {
131129 continue
132130 }
@@ -152,6 +150,10 @@ func DumpJSON(result ResolvedResult, targets []string, cmdline []string) ([]byte
152150 allPackages [name ] = entry
153151 }
154152
153+ allPackages , forceIgnored = garbageCollect (targets , forceIgnored , allPackages )
154+
155+ packageNames := sortedKeys (allPackages )
156+
155157 sortedPackages := make ([]InstalledPackage , 0 , len (packageNames ))
156158 for _ , name := range packageNames {
157159 sortedPackages = append (sortedPackages , allPackages [name ])
@@ -189,7 +191,8 @@ func computeDependencies(requires []string, providers map[string]string, ignored
189191 logrus .Debugf ("Resolving dependency %s" , req )
190192 provider , ok := providers [req ]
191193 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
193196 }
194197 logrus .Debugf ("Found provider %s for %s" , provider , req )
195198 if ignored [provider ] {
@@ -223,10 +226,7 @@ func exploreAllDependencies(input *api.Package, allPackages map[string]*api.Pack
223226 current := pending [0 ]
224227 pending = pending [1 :]
225228
226- logrus .Debugf ("exploring %s" , current .Name )
227-
228229 if _ , explored := previouslyExplored [current .Name ]; explored {
229- logrus .Debugf ("previously explored %s" , current .Name )
230230 continue
231231 }
232232
@@ -295,13 +295,12 @@ func filterIgnores(rpmsRequested []string, allAvailable []*api.Package, ignoreRe
295295 pending := []* api.Package {target }
296296 for len (pending ) > 0 {
297297 current := pending [0 ]
298- logrus .Debugf ("processing %s" , current .Name )
299298 pending = pending [1 :]
300299 if _ , alreadyExplored := explored [current .Name ]; alreadyExplored {
301- logrus .Debugf ("already iterated" )
302300 continue
303301 }
304302
303+ logrus .Debugf ("processing %s" , current .Name )
305304 if ! shouldInclude (current .Name , ignoreRegex ) {
306305 toIgnore := exploreAllDependencies (current , allAvailablePerName , explored )
307306 for _ , d := range toIgnore {
@@ -320,7 +319,6 @@ func filterIgnores(rpmsRequested []string, allAvailable []*api.Package, ignoreRe
320319
321320 toInstall = append (toInstall , current )
322321 for _ , dep := range current .Format .Requires .Entries {
323- logrus .Debugf ("finding dependency provider for %s" , dep .Name )
324322 p , ok := allAvailablePerName [dep .Name ]
325323 if ok {
326324 pending = append (pending , p )
@@ -337,45 +335,36 @@ func filterIgnores(rpmsRequested []string, allAvailable []*api.Package, ignoreRe
337335 return toInstall , ignoredPackages
338336}
339337
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 {}
345340
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+ }
350346 }
351347
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
366351 }
367352 }
368353
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 )
376356 }
377357
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
379368}
380369
381370func (opts * BzlmodOpts ) RunE (cmd * cobra.Command , rpms []string ) error {
@@ -401,13 +390,13 @@ func (opts *BzlmodOpts) RunE(cmd *cobra.Command, rpms []string) error {
401390 }
402391
403392 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 ) )
405394 err = solver .LoadInvolvedPackages (involved , []string {}, resolvehelperopts .onlyAllowRegex )
406395 if err != nil {
407396 return err
408397 }
409398
410- logrus .Info ("Adding required packages to the rpmtreer." )
399+ logrus .Infof ("Adding required packages to the rpmtreer: %d" , len ( matched ) )
411400 err = solver .ConstructRequirements (matched )
412401 if err != nil {
413402 return err
@@ -419,15 +408,11 @@ func (opts *BzlmodOpts) RunE(cmd *cobra.Command, rpms []string) error {
419408 return err
420409 }
421410
422- logrus .Debugf ("install: %v" , install )
411+ logrus .Debugf ("resolver install: %v" , install )
423412
424413 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 ))
431416
432417 result := ResolvedResult {Install : actualInstall , ForceIgnored : forceIgnored }
433418
0 commit comments