From f2b3f04f31a1489d40ff77661da8c254f204a82e Mon Sep 17 00:00:00 2001 From: Michael Kelly Date: Tue, 7 Jan 2025 22:16:01 -0800 Subject: [PATCH 1/7] Seperate RepoReducer from CacheHelper implementation Separating ourselves from the concrete implementation of the CacheHelper via an interface makes it easier to write tests against RepoReducer. --- pkg/reducer/reducer.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/reducer/reducer.go b/pkg/reducer/reducer.go index a791504..21021cd 100644 --- a/pkg/reducer/reducer.go +++ b/pkg/reducer/reducer.go @@ -12,6 +12,10 @@ import ( "github.com/sirupsen/logrus" ) +type RepoCache interface { + CurrentPrimaries(repos *bazeldnf.Repositories, arch string) (primaries []*api.Repository, err error) +} + type RepoReducer struct { packages []api.Package lang string @@ -21,7 +25,7 @@ type RepoReducer struct { arch string architectures []string repos *bazeldnf.Repositories - cacheHelper *repo.CacheHelper + cacheHelper RepoCache } func (r *RepoReducer) Load() error { From a50651fe68e09664e26dd1c1d617cea9f84be991 Mon Sep 17 00:00:00 2001 From: Michael Kelly Date: Tue, 7 Jan 2025 22:22:24 -0800 Subject: [PATCH 2/7] Remove unused `lang` option for reducer The lang option never gets used anywhere (and is not even hooked up as a proper argument!) so we can safely prune it. --- cmd/reduce.go | 3 +-- cmd/resolve.go | 3 +-- cmd/rpmtree.go | 3 +-- pkg/reducer/reducer.go | 4 +--- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/cmd/reduce.go b/cmd/reduce.go index 6cd8c91..9e6b6d5 100644 --- a/cmd/reduce.go +++ b/cmd/reduce.go @@ -17,7 +17,6 @@ type reduceOpts struct { in []string repofiles []string out string - lang string nobest bool arch string baseSystem string @@ -43,7 +42,7 @@ which allow reducing huge rpm repos to a smaller problem set for debugging, remo return err } } - repo := reducer.NewRepoReducer(repos, reduceopts.in, reduceopts.lang, reduceopts.baseSystem, reduceopts.arch, ".bazeldnf") + repo := reducer.NewRepoReducer(repos, reduceopts.in, reduceopts.baseSystem, reduceopts.arch, ".bazeldnf") logrus.Info("Loading packages.") if err := repo.Load(); err != nil { return err diff --git a/cmd/resolve.go b/cmd/resolve.go index 2f8ff40..3eb923d 100644 --- a/cmd/resolve.go +++ b/cmd/resolve.go @@ -14,7 +14,6 @@ import ( type resolveOpts struct { in []string - lang string nobest bool arch string baseSystem string @@ -40,7 +39,7 @@ func NewResolveCmd() *cobra.Command { return err } } - repo := reducer.NewRepoReducer(repos, resolveopts.in, resolveopts.lang, resolveopts.baseSystem, resolveopts.arch, ".bazeldnf") + repo := reducer.NewRepoReducer(repos, resolveopts.in, resolveopts.baseSystem, resolveopts.arch, ".bazeldnf") logrus.Info("Loading packages.") if err := repo.Load(); err != nil { return err diff --git a/cmd/rpmtree.go b/cmd/rpmtree.go index c34ffe0..2db822c 100644 --- a/cmd/rpmtree.go +++ b/cmd/rpmtree.go @@ -14,7 +14,6 @@ import ( ) type rpmtreeOpts struct { - lang string nobest bool arch string baseSystem string @@ -42,7 +41,7 @@ func NewRpmTreeCmd() *cobra.Command { if err != nil { return err } - repoReducer := reducer.NewRepoReducer(repos, nil, rpmtreeopts.lang, rpmtreeopts.baseSystem, rpmtreeopts.arch, ".bazeldnf") + repoReducer := reducer.NewRepoReducer(repos, nil, rpmtreeopts.baseSystem, rpmtreeopts.arch, ".bazeldnf") logrus.Info("Loading packages.") if err := repoReducer.Load(); err != nil { return err diff --git a/pkg/reducer/reducer.go b/pkg/reducer/reducer.go index 21021cd..afc34a2 100644 --- a/pkg/reducer/reducer.go +++ b/pkg/reducer/reducer.go @@ -18,7 +18,6 @@ type RepoCache interface { type RepoReducer struct { packages []api.Package - lang string repoFiles []string provides map[string][]*api.Package implicitRequires []string @@ -178,10 +177,9 @@ func (r *RepoReducer) requires(p *api.Package) (wants []*api.Package) { return wants } -func NewRepoReducer(repos *bazeldnf.Repositories, repoFiles []string, lang string, baseSystem string, arch string, cachDir string) *RepoReducer { +func NewRepoReducer(repos *bazeldnf.Repositories, repoFiles []string, baseSystem string, arch string, cachDir string) *RepoReducer { return &RepoReducer{ packages: nil, - lang: lang, implicitRequires: []string{baseSystem}, repoFiles: repoFiles, provides: map[string][]*api.Package{}, From e505566a91acd244339af72444c9fcda32d6c58a Mon Sep 17 00:00:00 2001 From: Michael Kelly Date: Tue, 7 Jan 2025 22:30:25 -0800 Subject: [PATCH 3/7] Extract Resolve() function for reducer All of the uses of the reducer have the exact same sequence. We can capture this sequence and then use it as our model for testing the reducer. --- cmd/reduce.go | 8 +------- cmd/resolve.go | 8 +------- cmd/rpmtree.go | 8 +------- pkg/reducer/reducer.go | 10 ++++++++++ 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/cmd/reduce.go b/cmd/reduce.go index 9e6b6d5..86f719d 100644 --- a/cmd/reduce.go +++ b/cmd/reduce.go @@ -42,13 +42,7 @@ which allow reducing huge rpm repos to a smaller problem set for debugging, remo return err } } - repo := reducer.NewRepoReducer(repos, reduceopts.in, reduceopts.baseSystem, reduceopts.arch, ".bazeldnf") - logrus.Info("Loading packages.") - if err := repo.Load(); err != nil { - return err - } - logrus.Info("Reduction of involved packages.") - _, involved, err := repo.Resolve(required) + _, involved, err := reducer.Resolve(repos, reduceopts.in, reduceopts.baseSystem, reduceopts.arch, required) if err != nil { return err } diff --git a/cmd/resolve.go b/cmd/resolve.go index 3eb923d..87cc037 100644 --- a/cmd/resolve.go +++ b/cmd/resolve.go @@ -39,13 +39,7 @@ func NewResolveCmd() *cobra.Command { return err } } - repo := reducer.NewRepoReducer(repos, resolveopts.in, resolveopts.baseSystem, resolveopts.arch, ".bazeldnf") - logrus.Info("Loading packages.") - if err := repo.Load(); err != nil { - return err - } - logrus.Info("Initial reduction of involved packages.") - matched, involved, err := repo.Resolve(required) + matched, involved, err := reducer.Resolve(repos, resolveopts.in, resolveopts.baseSystem, resolveopts.arch, required) if err != nil { return err } diff --git a/cmd/rpmtree.go b/cmd/rpmtree.go index 2db822c..527b0ec 100644 --- a/cmd/rpmtree.go +++ b/cmd/rpmtree.go @@ -41,13 +41,7 @@ func NewRpmTreeCmd() *cobra.Command { if err != nil { return err } - repoReducer := reducer.NewRepoReducer(repos, nil, rpmtreeopts.baseSystem, rpmtreeopts.arch, ".bazeldnf") - logrus.Info("Loading packages.") - if err := repoReducer.Load(); err != nil { - return err - } - logrus.Info("Initial reduction of involved packages.") - matched, involved, err := repoReducer.Resolve(required) + matched, involved, err := reducer.Resolve(repos, nil, rpmtreeopts.baseSystem, rpmtreeopts.arch, required) if err != nil { return err } diff --git a/pkg/reducer/reducer.go b/pkg/reducer/reducer.go index afc34a2..fad4228 100644 --- a/pkg/reducer/reducer.go +++ b/pkg/reducer/reducer.go @@ -218,3 +218,13 @@ func FixPackages(p *api.Package) { p.Format.Requires.Entries = requires } } + +func Resolve(repos *bazeldnf.Repositories, repoFiles []string, baseSystem, arch string, packages []string) (matched []string, involved []*api.Package, err error) { + repoReducer := NewRepoReducer(repos, repoFiles, baseSystem, arch, ".bazeldnf") + logrus.Info("Loading packages.") + if err := repoReducer.Load(); err != nil { + return nil, nil, err + } + logrus.Info("Initial reduction of involved packages.") + return repoReducer.Resolve(packages) +} From c84e3ac7c66c6fb830e0bdc0cb7c3b160bbf663f Mon Sep 17 00:00:00 2001 From: Michael Kelly Date: Tue, 7 Jan 2025 23:16:38 -0800 Subject: [PATCH 4/7] reducer: pull out loadRepos() from Load() This is the first step in de-couple the repo data loading from the reducer itself to enable easier testing of the reducer. --- pkg/reducer/reducer.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/reducer/reducer.go b/pkg/reducer/reducer.go index fad4228..8840fba 100644 --- a/pkg/reducer/reducer.go +++ b/pkg/reducer/reducer.go @@ -27,7 +27,7 @@ type RepoReducer struct { cacheHelper RepoCache } -func (r *RepoReducer) Load() error { +func (r *RepoReducer) loadRepos() error { for _, rpmrepo := range r.repoFiles { repoFile := &api.Repository{} f, err := os.Open(rpmrepo) @@ -46,6 +46,7 @@ func (r *RepoReducer) Load() error { r.packages = append(r.packages, repoFile.Packages[i]) } } + repos, err := r.cacheHelper.CurrentPrimaries(r.repos, r.arch) if err != nil { return err @@ -58,10 +59,19 @@ func (r *RepoReducer) Load() error { r.packages = append(r.packages, rpmrepo.Packages[i]) } } + for i, _ := range r.packages { FixPackages(&r.packages[i]) } + return nil +} + +func (r *RepoReducer) Load() error { + if err := r.loadRepos(); err != nil { + return err + } + for i, p := range r.packages { requires := []api.Entry{} for _, requirement := range p.Format.Requires.Entries { From 710f6b088f3a1c1b9eb02b12bc7fc243ec5cccb2 Mon Sep 17 00:00:00 2001 From: Michael Kelly Date: Tue, 7 Jan 2025 23:25:52 -0800 Subject: [PATCH 5/7] reducer: Decouple loadRepos() from RepoReducer In order to completely decouple the loading process from the general reducer algorithm we need to decouple it from the RepoReducer itself. This change converts to returning the package list and accepting the inputs as parameters to enable this decoupling. --- pkg/reducer/reducer.go | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/pkg/reducer/reducer.go b/pkg/reducer/reducer.go index 8840fba..aadd4bf 100644 --- a/pkg/reducer/reducer.go +++ b/pkg/reducer/reducer.go @@ -27,51 +27,56 @@ type RepoReducer struct { cacheHelper RepoCache } -func (r *RepoReducer) loadRepos() error { - for _, rpmrepo := range r.repoFiles { +func loadRepos(repoFiles, architectures []string, arch string, repos *bazeldnf.Repositories, cacheHelper RepoCache) ([]api.Package, error) { + packages := []api.Package{} + + for _, rpmrepo := range repoFiles { repoFile := &api.Repository{} f, err := os.Open(rpmrepo) if err != nil { - return err + return packages, err } defer f.Close() err = xml.NewDecoder(f).Decode(repoFile) if err != nil { - return err + return packages, err } for i, p := range repoFile.Packages { - if skip(p.Arch, r.architectures) { + if skip(p.Arch, architectures) { continue } - r.packages = append(r.packages, repoFile.Packages[i]) + packages = append(packages, repoFile.Packages[i]) } } - repos, err := r.cacheHelper.CurrentPrimaries(r.repos, r.arch) + cachedRepos, err := cacheHelper.CurrentPrimaries(repos, arch) if err != nil { - return err + return packages, err } - for _, rpmrepo := range repos { + for _, rpmrepo := range cachedRepos { for i, p := range rpmrepo.Packages { - if skip(p.Arch, r.architectures) { + if skip(p.Arch, architectures) { continue } - r.packages = append(r.packages, rpmrepo.Packages[i]) + packages = append(packages, rpmrepo.Packages[i]) } } - for i, _ := range r.packages { - FixPackages(&r.packages[i]) + for i, _ := range packages { + FixPackages(&packages[i]) } - return nil + return packages, nil } func (r *RepoReducer) Load() error { - if err := r.loadRepos(); err != nil { + packages, err := loadRepos(r.repoFiles, r.architectures, r.arch, r.repos, r.cacheHelper) + if err != nil { return err } + r.packages = packages + for i, p := range r.packages { requires := []api.Entry{} for _, requirement := range p.Format.Requires.Entries { From 325d64db69e6e59c5c27986f14e7e9afe273d342 Mon Sep 17 00:00:00 2001 From: Michael Kelly Date: Tue, 7 Jan 2025 23:33:15 -0800 Subject: [PATCH 6/7] reducer: Factor our separate loader RepoLoader captures the repository package loading process separately from the reducer and introduces an interface between them to make testing the reducer easier. --- pkg/reducer/BUILD.bazel | 1 + pkg/reducer/loader.go | 96 ++++++++++++++++++++++++++++++++++++++++ pkg/reducer/reducer.go | 97 ++++------------------------------------- 3 files changed, 106 insertions(+), 88 deletions(-) create mode 100644 pkg/reducer/loader.go diff --git a/pkg/reducer/BUILD.bazel b/pkg/reducer/BUILD.bazel index 9678537..9c24e8c 100644 --- a/pkg/reducer/BUILD.bazel +++ b/pkg/reducer/BUILD.bazel @@ -4,6 +4,7 @@ go_library( name = "reducer", srcs = [ "doc.go", + "loader.go", "reducer.go", ], importpath = "github.com/rmohr/bazeldnf/pkg/reducer", diff --git a/pkg/reducer/loader.go b/pkg/reducer/loader.go new file mode 100644 index 0000000..06832fe --- /dev/null +++ b/pkg/reducer/loader.go @@ -0,0 +1,96 @@ +package reducer + +import ( + "encoding/xml" + "os" + + "github.com/rmohr/bazeldnf/pkg/api" + "github.com/rmohr/bazeldnf/pkg/api/bazeldnf" +) + +type RepoCache interface { + CurrentPrimaries(repos *bazeldnf.Repositories, arch string) (primaries []*api.Repository, err error) +} + +type ReducerPackageLoader interface { + Load() ([]api.Package, error) +} + +type RepoLoader struct { + repoFiles []string + arch string + architectures []string + repos *bazeldnf.Repositories + cacheHelper RepoCache +} + +func (r RepoLoader) Load() ([]api.Package, error) { + packages := []api.Package{} + + for _, rpmrepo := range r.repoFiles { + repoFile := &api.Repository{} + f, err := os.Open(rpmrepo) + if err != nil { + return packages, err + } + defer f.Close() + err = xml.NewDecoder(f).Decode(repoFile) + if err != nil { + return packages, err + } + for i, p := range repoFile.Packages { + if skip(p.Arch, r.architectures) { + continue + } + packages = append(packages, repoFile.Packages[i]) + } + } + + cachedRepos, err := r.cacheHelper.CurrentPrimaries(r.repos, r.arch) + if err != nil { + return packages, err + } + for _, rpmrepo := range cachedRepos { + for i, p := range rpmrepo.Packages { + if skip(p.Arch, r.architectures) { + continue + } + packages = append(packages, rpmrepo.Packages[i]) + } + } + + for i, _ := range packages { + FixPackages(&packages[i]) + } + + return packages, nil +} + +// FixPackages contains hacks which should probably not have to exist +func FixPackages(p *api.Package) { + // FIXME: This is not a proper modules support for python. We should properly resolve `alternative(python)` and + // not have to add such a hack. On the other hand this seems to have been reverted in fedora and only exists in centos stream. + if p.Name == "platform-python" { + p.Format.Provides.Entries = append(p.Format.Provides.Entries, api.Entry{ + Name: "/usr/libexec/platform-python", + }) + var requires []api.Entry + for _, entry := range p.Format.Requires.Entries { + if entry.Name != "/usr/libexec/platform-python" { + requires = append(requires, entry) + } + } + p.Format.Requires.Entries = requires + } +} + +func skip(arch string, arches []string) bool { + skip := true + for _, a := range arches { + if a == arch { + skip = false + break + } + } + return skip +} diff --git a/pkg/reducer/reducer.go b/pkg/reducer/reducer.go index aadd4bf..f92cf6c 100644 --- a/pkg/reducer/reducer.go +++ b/pkg/reducer/reducer.go @@ -1,9 +1,7 @@ package reducer import ( - "encoding/xml" "fmt" - "os" "strings" "github.com/rmohr/bazeldnf/pkg/api" @@ -12,65 +10,15 @@ import ( "github.com/sirupsen/logrus" ) -type RepoCache interface { - CurrentPrimaries(repos *bazeldnf.Repositories, arch string) (primaries []*api.Repository, err error) -} - type RepoReducer struct { packages []api.Package - repoFiles []string provides map[string][]*api.Package implicitRequires []string - arch string - architectures []string - repos *bazeldnf.Repositories - cacheHelper RepoCache -} - -func loadRepos(repoFiles, architectures []string, arch string, repos *bazeldnf.Repositories, cacheHelper RepoCache) ([]api.Package, error) { - packages := []api.Package{} - - for _, rpmrepo := range repoFiles { - repoFile := &api.Repository{} - f, err := os.Open(rpmrepo) - if err != nil { - return packages, err - } - defer f.Close() - err = xml.NewDecoder(f).Decode(repoFile) - if err != nil { - return packages, err - } - for i, p := range repoFile.Packages { - if skip(p.Arch, architectures) { - continue - } - packages = append(packages, repoFile.Packages[i]) - } - } - - cachedRepos, err := cacheHelper.CurrentPrimaries(repos, arch) - if err != nil { - return packages, err - } - for _, rpmrepo := range cachedRepos { - for i, p := range rpmrepo.Packages { - if skip(p.Arch, architectures) { - continue - } - packages = append(packages, rpmrepo.Packages[i]) - } - } - - for i, _ := range packages { - FixPackages(&packages[i]) - } - - return packages, nil + loader ReducerPackageLoader } func (r *RepoReducer) Load() error { - packages, err := loadRepos(r.repoFiles, r.architectures, r.arch, r.repos, r.cacheHelper) + packages, err := r.loader.Load() if err != nil { return err } @@ -196,41 +144,14 @@ func NewRepoReducer(repos *bazeldnf.Repositories, repoFiles []string, baseSystem return &RepoReducer{ packages: nil, implicitRequires: []string{baseSystem}, - repoFiles: repoFiles, provides: map[string][]*api.Package{}, - architectures: []string{"noarch", arch}, - arch: arch, - repos: repos, - cacheHelper: &repo.CacheHelper{CacheDir: cachDir}, - } -} - -func skip(arch string, arches []string) bool { - skip := true - for _, a := range arches { - if a == arch { - skip = false - break - } - } - return skip -} - -// FixPackages contains hacks which should probably not have to exist -func FixPackages(p *api.Package) { - // FIXME: This is not a proper modules support for python. We should properly resolve `alternative(python)` and - // not have to add such a hack. On the other hand this seems to have been reverted in fedora and only exists in centos stream. - if p.Name == "platform-python" { - p.Format.Provides.Entries = append(p.Format.Provides.Entries, api.Entry{ - Name: "/usr/libexec/platform-python", - }) - var requires []api.Entry - for _, entry := range p.Format.Requires.Entries { - if entry.Name != "/usr/libexec/platform-python" { - requires = append(requires, entry) - } - } - p.Format.Requires.Entries = requires + loader: RepoLoader{ + repoFiles: repoFiles, + architectures: []string{"noarch", arch}, + arch: arch, + repos: repos, + cacheHelper: &repo.CacheHelper{CacheDir: cachDir}, + }, } } From b9918d57956e685f8bbf0d11ea8f6a8ccf0ac722 Mon Sep 17 00:00:00 2001 From: Michael Kelly Date: Tue, 7 Jan 2025 23:33:15 -0800 Subject: [PATCH 7/7] Refine loader interface The loader should also capture the provide-map builder so as to keep the reducer itself fairly simple. This change pulls the remainder of the reducer's Load() method into the loader and refines the interface to the loader to help with this. --- pkg/reducer/loader.go | 52 +++++++++++++++++++++++++++++++++--------- pkg/reducer/reducer.go | 36 +++++++---------------------- 2 files changed, 49 insertions(+), 39 deletions(-) diff --git a/pkg/reducer/loader.go b/pkg/reducer/loader.go index 06832fe..a880801 100644 --- a/pkg/reducer/loader.go +++ b/pkg/reducer/loader.go @@ -3,6 +3,7 @@ package reducer import ( "encoding/xml" "os" + "strings" "github.com/rmohr/bazeldnf/pkg/api" "github.com/rmohr/bazeldnf/pkg/api/bazeldnf" @@ -13,7 +14,16 @@ type RepoCache interface { } type ReducerPackageLoader interface { - Load() ([]api.Package, error) + Load() (*packageInfo, error) +} + +// packageInfo captures the package information required by the reducer +type packageInfo struct { + // the list of available packages + packages []api.Package + + // mapping of provisions to a list of associated packages + provides map[string][]*api.Package } type RepoLoader struct { @@ -24,46 +34,66 @@ type RepoLoader struct { cacheHelper RepoCache } -func (r RepoLoader) Load() ([]api.Package, error) { - packages := []api.Package{} +func (r RepoLoader) Load() (*packageInfo, error) { + packageInfo := &packageInfo{ + packages: []api.Package{}, + provides: map[string][]*api.Package{}, + } for _, rpmrepo := range r.repoFiles { repoFile := &api.Repository{} f, err := os.Open(rpmrepo) if err != nil { - return packages, err + return packageInfo, err } defer f.Close() err = xml.NewDecoder(f).Decode(repoFile) if err != nil { - return packages, err + return packageInfo, err } for i, p := range repoFile.Packages { if skip(p.Arch, r.architectures) { continue } - packages = append(packages, repoFile.Packages[i]) + packageInfo.packages = append(packageInfo.packages, repoFile.Packages[i]) } } cachedRepos, err := r.cacheHelper.CurrentPrimaries(r.repos, r.arch) if err != nil { - return packages, err + return packageInfo, err } for _, rpmrepo := range cachedRepos { for i, p := range rpmrepo.Packages { if skip(p.Arch, r.architectures) { continue } - packages = append(packages, rpmrepo.Packages[i]) + packageInfo.packages = append(packageInfo.packages, rpmrepo.Packages[i]) } } - for i, _ := range packages { - FixPackages(&packages[i]) + for i, _ := range packageInfo.packages { + FixPackages(&packageInfo.packages[i]) + } + + for i, p := range packageInfo.packages { + requires := []api.Entry{} + for _, requirement := range p.Format.Requires.Entries { + if !strings.HasPrefix(requirement.Name, "(") { + requires = append(requires, requirement) + } + } + packageInfo.packages[i].Format.Requires.Entries = requires + + for _, p := range p.Format.Provides.Entries { + packageInfo.provides[p.Name] = append(packageInfo.provides[p.Name], &packageInfo.packages[i]) + } + for _, file := range p.Format.Files { + packageInfo.provides[file.Text] = append(packageInfo.provides[file.Text], &packageInfo.packages[i]) + } } - return packages, nil + return packageInfo, nil } // FixPackages contains hacks which should probably not have to exist diff --git a/pkg/reducer/reducer.go b/pkg/reducer/reducer.go index f92cf6c..a757bce 100644 --- a/pkg/reducer/reducer.go +++ b/pkg/reducer/reducer.go @@ -11,36 +11,17 @@ import ( ) type RepoReducer struct { - packages []api.Package - provides map[string][]*api.Package + packageInfo *packageInfo implicitRequires []string loader ReducerPackageLoader } func (r *RepoReducer) Load() error { - packages, err := r.loader.Load() + packageInfo, err := r.loader.Load() if err != nil { return err } - - r.packages = packages - - for i, p := range r.packages { - requires := []api.Entry{} - for _, requirement := range p.Format.Requires.Entries { - if !strings.HasPrefix(requirement.Name, "(") { - requires = append(requires, requirement) - } - } - r.packages[i].Format.Requires.Entries = requires - - for _, provides := range p.Format.Provides.Entries { - r.provides[provides.Name] = append(r.provides[provides.Name], &r.packages[i]) - } - for _, file := range p.Format.Files { - r.provides[file.Text] = append(r.provides[file.Text], &r.packages[i]) - } - } + r.packageInfo = packageInfo return nil } @@ -52,15 +33,15 @@ func (r *RepoReducer) Resolve(packages []string) (matched []string, involved []* found := false name := "" var candidates []*api.Package - for i, p := range r.packages { + for i, p := range r.packageInfo.packages { if strings.HasPrefix(p.String(), req) { if strings.HasPrefix(req, p.Name) { if !found || len(p.Name) < len(name) { - candidates = []*api.Package{&r.packages[i]} + candidates = []*api.Package{&r.packageInfo.packages[i]} name = p.Name found = true } else if p.Name == name { - candidates = append(candidates, &r.packages[i]) + candidates = append(candidates, &r.packageInfo.packages[i]) } } } @@ -125,7 +106,7 @@ func (r *RepoReducer) Resolve(packages []string) (matched []string, involved []* func (r *RepoReducer) requires(p *api.Package) (wants []*api.Package) { for _, requires := range p.Format.Requires.Entries { - if val, exists := r.provides[requires.Name]; exists { + if val, exists := r.packageInfo.provides[requires.Name]; exists { var packages []string for _, p := range val { @@ -142,9 +123,8 @@ func (r *RepoReducer) requires(p *api.Package) (wants []*api.Package) { func NewRepoReducer(repos *bazeldnf.Repositories, repoFiles []string, baseSystem string, arch string, cachDir string) *RepoReducer { return &RepoReducer{ - packages: nil, + packageInfo: nil, implicitRequires: []string{baseSystem}, - provides: map[string][]*api.Package{}, loader: RepoLoader{ repoFiles: repoFiles, architectures: []string{"noarch", arch},