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: squash later

Signed-off-by: Fabio Utzig <[email protected]>
  • Loading branch information
utzig committed Aug 21, 2023
1 parent 66be85f commit affb566
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
6 changes: 5 additions & 1 deletion newt/cli/project_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)

Expand Down
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
1 change: 1 addition & 0 deletions newt/newtutil/newtutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions newt/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down

0 comments on commit affb566

Please sign in to comment.