Skip to content

Commit

Permalink
[TESTING] Fix dependency graph when no repos given
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
utzig committed Aug 21, 2023
1 parent 944b1b5 commit 5f32ab8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions newt/deprepo/deprepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]
Expand Down
10 changes: 5 additions & 5 deletions newt/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion newt/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5f32ab8

Please sign in to comment.