From affb566d4caa4b14cdccc0db5f977a0343aaccb8 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: squash later Signed-off-by: Fabio Utzig --- newt/cli/project_cmds.go | 6 +++++- newt/deprepo/deprepo.go | 8 ++++---- newt/install/install.go | 10 +++++----- newt/newtutil/newtutil.go | 1 + newt/project/project.go | 5 +++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/newt/cli/project_cmds.go b/newt/cli/project_cmds.go index e7508f8cd..67e908abf 100644 --- a/newt/cli/project_cmds.go +++ b/newt/cli/project_cmds.go @@ -128,7 +128,8 @@ func upgradeRunCmd(cmd *cobra.Command, args []string) { pred := makeRepoPredicate(args) if err := proj.UpgradeIf( - newtutil.NewtForce, newtutil.NewtAsk, args, pred); err != nil { + newtutil.NewtForce, newtutil.NewtAsk, newtutil.NewtNoDeps, + args, pred); err != nil { NewtUsage(nil, err) } @@ -207,6 +208,9 @@ func AddProjectCommands(cmd *cobra.Command) { "Force upgrade of the repositories to latest state in project.yml") upgradeCmd.PersistentFlags().BoolVarP(&newtutil.NewtAsk, "ask", "a", false, "Prompt user before upgrading any repos") + upgradeCmd.PersistentFlags().BoolVarP(&newtutil.NewtNoDeps, + "no-deps", "n", false, + "Don't upgrade dependencies when repos are provided") cmd.AddCommand(upgradeCmd) 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/newtutil/newtutil.go b/newt/newtutil/newtutil.go index 85fe22527..0fef2a46a 100644 --- a/newt/newtutil/newtutil.go +++ b/newt/newtutil/newtutil.go @@ -39,6 +39,7 @@ var NewtBlinkyTag string = "mynewt_1_11_0_tag" var NewtNumJobs int var NewtForce bool var NewtAsk bool +var NewtNoDeps bool const CORE_REPO_NAME string = "apache-mynewt-core" const ARDUINO_ZERO_REPO_NAME string = "mynewt_arduino_zero" diff --git a/newt/project/project.go b/newt/project/project.go index bb6b69f84..882890431 100644 --- a/newt/project/project.go +++ b/newt/project/project.go @@ -314,7 +314,8 @@ func (proj *Project) SelectRepos(pred func(r *repo.Repo) bool) []*repo.Repo { // Installs or upgrades repos matching the specified predicate. func (proj *Project) UpgradeIf( - force bool, ask bool, okRepos []string, predicate func(r *repo.Repo) bool) error { + force bool, ask bool, noDeps bool, okRepos []string, + predicate func(r *repo.Repo) bool) error { // Make sure we have an up to date copy of all `repository.yml` files. if err := proj.downloadRepositoryYmlFiles(okRepos); err != nil { @@ -332,7 +333,7 @@ func (proj *Project) UpgradeIf( return err } - return inst.Upgrade(specifiedRepoList, force, ask) + return inst.Upgrade(specifiedRepoList, force, ask, noDeps && len(okRepos) > 0) } func (proj *Project) InfoIf(predicate func(r *repo.Repo) bool,