From 0f29d1ce7392ba1c37c8eb90433f58169b959551 Mon Sep 17 00:00:00 2001 From: Fabio Utzig Date: Mon, 21 Aug 2023 17:22:19 -0300 Subject: [PATCH] [TESTING] Fix dependency graph when no repos given Fix dependency graph build when no repos were given to `upgrade`. FIXME: if this works must still add a `--no-deps` or such flag to enable compatibility with previous versions if deemed so... FIXME: squash later Signed-off-by: Fabio Utzig --- newt/deprepo/deprepo.go | 8 ++++---- newt/install/install.go | 10 +++++----- newt/project/project.go | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/newt/deprepo/deprepo.go b/newt/deprepo/deprepo.go index 0edab8c1e..542df6e76 100644 --- a/newt/deprepo/deprepo.go +++ b/newt/deprepo/deprepo.go @@ -118,13 +118,13 @@ func isInReqs(repo string, reqs RequirementMap) bool { // Builds a repo dependency graph from the repo requirements expressed in the // `project.yml` file. -func BuildDepGraph(repos RepoMap, rootReqs RequirementMap) (DepGraph, error) { +func BuildDepGraph(repos RepoMap, rootReqs RequirementMap, noDeps bool) (DepGraph, error) { dg := DepGraph{} // First, add the hard dependencies expressed in `project.yml`. for repoName, verReq := range rootReqs { repo, ok := repos[repoName] - if !ok { + if !ok && noDeps { continue } normalizedReq, err := repo.NormalizeVerReq(verReq) @@ -140,14 +140,14 @@ func BuildDepGraph(repos RepoMap, rootReqs RequirementMap) (DepGraph, error) { // Add inter-repo dependencies to the graph. for _, r := range repos.Sorted() { nvers, err := r.NormalizedVersions() - if err != nil && isInReqs(r.Name(), rootReqs) { + if err != nil && noDeps && isInReqs(r.Name(), rootReqs) { return nil, err } for _, v := range nvers { deps := r.DepsForVersion(v) reqMap := RequirementMap{} for _, d := range deps { - if !isInReqs(d.Name, rootReqs) { + if noDeps && !isInReqs(d.Name, rootReqs) { continue } depRepo := repos[d.Name] diff --git a/newt/install/install.go b/newt/install/install.go index c3be104c5..26a4222da 100644 --- a/newt/install/install.go +++ b/newt/install/install.go @@ -416,7 +416,7 @@ func (inst *Installer) versionMapRepos( // Calculates a map of repos and version numbers that should be included in an // install or upgrade operation. -func (inst *Installer) calcVersionMap(candidates []*repo.Repo) ( +func (inst *Installer) calcVersionMap(candidates []*repo.Repo, noDeps bool) ( deprepo.VersionMap, error) { // Repos that depend on any specified repos must also be considered during @@ -463,7 +463,7 @@ func (inst *Installer) calcVersionMap(candidates []*repo.Repo) ( // Construct a repo dependency graph from the `project.yml` version // requirements and from each repo's dependency list. - dg, err := deprepo.BuildDepGraph(inst.repos, inst.reqs) + dg, err := deprepo.BuildDepGraph(inst.repos, inst.reqs, noDeps) if err != nil { return nil, err } @@ -550,13 +550,13 @@ func verifyNewtCompat(repos []*repo.Repo, vm deprepo.VersionMap) error { // Installs or upgrades the specified set of repos. func (inst *Installer) Upgrade(candidates []*repo.Repo, force bool, - ask bool) error { + ask bool, noDeps bool) error { if err := verifyRepoDirtyState(candidates, force); err != nil { return err } - vm, err := inst.calcVersionMap(candidates) + vm, err := inst.calcVersionMap(candidates, noDeps) if err != nil { return err } @@ -682,7 +682,7 @@ func (inst *Installer) Info(repos []*repo.Repo, remote bool) error { } } - vm, err := inst.calcVersionMap(repos) + vm, err := inst.calcVersionMap(repos, false) if err != nil { return err } diff --git a/newt/project/project.go b/newt/project/project.go index bb6b69f84..7a8805663 100644 --- a/newt/project/project.go +++ b/newt/project/project.go @@ -332,7 +332,7 @@ func (proj *Project) UpgradeIf( return err } - return inst.Upgrade(specifiedRepoList, force, ask) + return inst.Upgrade(specifiedRepoList, force, ask, len(okRepos) > 0) } func (proj *Project) InfoIf(predicate func(r *repo.Repo) bool,