Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Enable upgrading only specified repos #527

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions newt/cli/project_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,15 @@ func makeRepoPredicate(repoNames []string) func(r *repo.Repo) bool {
}

func upgradeRunCmd(cmd *cobra.Command, args []string) {
proj := TryGetOrDownloadProject()
proj := TryGetOrDownloadProject(newtutil.NewtNoDeps, args)
interfaces.SetProject(proj)

proj.GetPkgRepos()
proj.GetPkgRepos(newtutil.NewtNoDeps, args)

pred := makeRepoPredicate(args)
if err := proj.UpgradeIf(
newtutil.NewtForce, newtutil.NewtAsk, 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
4 changes: 2 additions & 2 deletions newt/cli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ func TryGetProject() *project.Project {
return p
}

func TryGetOrDownloadProject() *project.Project {
func TryGetOrDownloadProject(noDeps bool, okRepos []string) *project.Project {
var p *project.Project
var err error

if p, err = project.TryGetOrDownloadProject(); err != nil {
if p, err = project.TryGetOrDownloadProject(noDeps, okRepos); err != nil {
NewtUsage(nil, err)
}

Expand Down
21 changes: 18 additions & 3 deletions newt/deprepo/deprepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,26 @@ func (vm VersionMap) String() string {
return s
}

func isInReqs(repo string, reqs RequirementMap) bool {
for r, _ := range reqs {
if repo == r {
return true
}
}
return false
}

// 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 := repos[repoName]
repo, ok := repos[repoName]
if !ok && noDeps {
continue
}
normalizedReq, err := repo.NormalizeVerReq(verReq)
if err != nil {
return nil, err
Expand All @@ -128,13 +140,16 @@ 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 {
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 noDeps && !isInReqs(d.Name, rootReqs) {
continue
}
depRepo := repos[d.Name]
verReqs, err := depRepo.NormalizeVerReq(d.VerReqs)
if err != nil {
Expand Down
22 changes: 13 additions & 9 deletions newt/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,10 @@ func (inst *Installer) ensureDepsInList(repos []*repo.Repo,
deps = r.DepsForVersion(vm[r.Name()])
}
for _, d := range deps {
depRepo := inst.repos[d.Name]
result = append(result, recurse(depRepo)...)
depRepo, ok := inst.repos[d.Name]
if ok {
result = append(result, recurse(depRepo)...)
}
}

return result
Expand Down Expand Up @@ -414,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 @@ -461,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 @@ -548,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 @@ -680,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 All @@ -706,12 +708,14 @@ func (inst *Installer) remoteRepoInfo(r *repo.Repo, vm *deprepo.VersionMap) {
ri := inst.gatherInfo(r, vm)
s := fmt.Sprintf(" * %s:", r.Name())

s += fmt.Sprintf(" %s", ri.commitHash)
if ri.installedVer == nil {
s += fmt.Sprintf(" ?")
s += ", (not installed)"
} else if ri.errorText != "" {
s += fmt.Sprintf(" %s", ri.commitHash)
s += fmt.Sprintf(", (unknown: %s)", ri.errorText)
} else {
s += fmt.Sprintf(" %s", ri.commitHash)
if ri.installedVer.Commit == "" {
s += fmt.Sprintf(", %s", ri.installedVer.String())
}
Expand All @@ -725,7 +729,7 @@ func (inst *Installer) remoteRepoInfo(r *repo.Repo, vm *deprepo.VersionMap) {
util.StatusMessage(util.VERBOSITY_DEFAULT, "%s\n", s)
}

// remoteRepoInfo prints information about the specified local repo (i.e., the
// localRepoInfo prints information about the specified local repo (i.e., the
// project itself). It does nothing if the project is not a git repo.
func (inst *Installer) localRepoInfo(r *repo.Repo) {
ri := inst.gatherInfo(r, nil)
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
Loading
Loading