You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/03/08 22:50:51 UTC
incubator-mynewt-newt git commit: add upgrade command. next step is
cleanup & status messages.
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/rename_project_app 53ca8db65 -> 5aecc66fd
add upgrade command. next step is cleanup & status messages.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/5aecc66f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/5aecc66f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/5aecc66f
Branch: refs/heads/rename_project_app
Commit: 5aecc66fddafefa3140ee2d2c380cf5a2d1d0e53
Parents: 53ca8db
Author: Sterling Hughes <st...@apache.org>
Authored: Tue Mar 8 13:50:42 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Mar 8 13:50:42 2016 -0800
----------------------------------------------------------------------
newt/builder/build.go | 2 ++
newt/project/cmds.go | 35 +++++++++++++++++++++++++++++++++--
newt/project/project.go | 37 ++++++++++++++++++++-----------------
newt/project/projectstate.go | 2 +-
newt/repo/repo.go | 12 +++++++++---
newt/target/target.go | 5 +++++
6 files changed, 70 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5aecc66f/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 890be8b..ee265fb 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -20,6 +20,7 @@
package builder
import (
+ "fmt"
"os"
"path/filepath"
@@ -355,6 +356,7 @@ func (b *Builder) PrepBuild() error {
func (b *Builder) Build() error {
if b.target.App() == nil {
+ fmt.Println(b.target)
return util.NewNewtError("app package not specified")
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5aecc66f/newt/project/cmds.go
----------------------------------------------------------------------
diff --git a/newt/project/cmds.go b/newt/project/cmds.go
index 8e61f85..b9a8923 100644
--- a/newt/project/cmds.go
+++ b/newt/project/cmds.go
@@ -29,17 +29,30 @@ import (
"mynewt.apache.org/newt/util"
)
+var Force bool = false
+
func installRunCmd(cmd *cobra.Command, args []string) {
proj := GetProject()
interfaces.SetProject(proj)
- if err := proj.Install(false); err != nil {
+ if err := proj.Install(false, Force); err != nil {
panic(err.Error())
}
fmt.Println("Repos successfully installed")
}
+func upgradeRunCmd(cmd *cobra.Command, args []string) {
+ proj := GetProject()
+ interfaces.SetProject(proj)
+
+ if err := proj.Upgrade(Force); err != nil {
+ panic(err.Error())
+ }
+
+ fmt.Println("Repos successfully upgrade")
+}
+
func projectRunCmd(cmd *cobra.Command, args []string) {
wd, err := os.Getwd()
if err != nil {
@@ -73,6 +86,7 @@ func AddCommands(cmd *cobra.Command) {
Example: projectHelpEx,
Run: projectRunCmd,
}
+ cmd.AddCommand(projectCmd)
installHelpText := ""
installHelpEx := ""
@@ -83,7 +97,24 @@ func AddCommands(cmd *cobra.Command) {
Example: installHelpEx,
Run: installRunCmd,
}
+ installCmd.PersistentFlags().BoolVarP(&Force, "force", "f", false,
+ "Force install of the repositories in project, regardless of what "+
+ "exists in repos directory")
+
cmd.AddCommand(installCmd)
- cmd.AddCommand(projectCmd)
+ upgradeHelpText := ""
+ upgradeHelpEx := ""
+ upgradeCmd := &cobra.Command{
+ Use: "upgrade",
+ Short: "Command to upgrade project dependencies from project.yml",
+ Long: upgradeHelpText,
+ Example: upgradeHelpEx,
+ Run: upgradeRunCmd,
+ }
+ upgradeCmd.PersistentFlags().BoolVarP(&Force, "force", "f", false,
+ "Force upgrade of the repositories to latest state in project.yml")
+
+ cmd.AddCommand(upgradeCmd)
+
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5aecc66f/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index 5194cd5..5c79d2e 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -138,7 +138,7 @@ func (proj *Project) PackageSearchDirs() []string {
return proj.packageSearchDirs
}
-func (proj *Project) Install(force bool) error {
+func (proj *Project) Install(upgrade bool, force bool) error {
repoList := proj.Repos()
for rname, r := range repoList {
// Ignore the local repo on install
@@ -163,29 +163,28 @@ func (proj *Project) Install(force bool) error {
// Project is already installed, let's see if we match the version
// requirements. If we don't print a warning.
// Either way, continue processing.
- _, _, ok := rdesc.MatchVersion(vers)
- if !ok {
+ ok := vers.SatisfiesVersion(r.VersionRequirements())
+ if !ok && !upgrade {
fmt.Printf("WARNING: Installed version %s of repository %s "+
"does not match desired versions %s in project.yml\n",
vers, rname, r.VersionRequirementsString())
- }
- } else {
-
- _, _, ok := rdesc.Match(r)
- if !ok {
- fmt.Printf("WARNING: No matching repository version found for repository "+
- "%s specified in project.yml, skipping...\n", r.Name())
continue
}
+ }
+ _, _, ok := rdesc.Match(r)
+ if !ok {
+ fmt.Printf("WARNING: No matching repository version found for repository "+
+ "%s specified in project.yml, skipping...\n", r.Name())
+ continue
+ }
- rvers, err := r.Install(rdesc, force)
- if err != nil {
- return err
- }
+ rvers, err := r.Install(rdesc, upgrade || force)
+ if err != nil {
+ return err
+ }
- if rvers != nil {
- proj.projState.Add(rname, rvers)
- }
+ if rvers != nil {
+ proj.projState.Replace(rname, rvers)
}
}
@@ -196,6 +195,10 @@ func (proj *Project) Install(force bool) error {
return nil
}
+func (proj *Project) Upgrade(force bool) error {
+ return proj.Install(true, force)
+}
+
func (proj *Project) loadRepo(rname string, v *viper.Viper) error {
varName := fmt.Sprintf("repository.%s", rname)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5aecc66f/newt/project/projectstate.go
----------------------------------------------------------------------
diff --git a/newt/project/projectstate.go b/newt/project/projectstate.go
index 9e07207..cf710a2 100644
--- a/newt/project/projectstate.go
+++ b/newt/project/projectstate.go
@@ -42,7 +42,7 @@ func (ps *ProjectState) GetInstalledVersion(rname string) *repo.Version {
return v
}
-func (ps *ProjectState) Add(rname string, rvers *repo.Version) {
+func (ps *ProjectState) Replace(rname string, rvers *repo.Version) {
ps.installedRepos[rname] = rvers
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5aecc66f/newt/repo/repo.go
----------------------------------------------------------------------
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index c67561a..5f78314 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -144,9 +144,15 @@ func (r *Repo) repoFilePath() string {
func (r *Repo) Install(rdesc *RepoDesc, force bool) (*Version, error) {
// Copy the git repo into /repos/, error'ing out if the repo already exists
- if cli.NodeExist(r.Path()) && !force {
- return nil, util.NewNewtError(fmt.Sprintf("Repository %s already "+
- "exists in local tree, cannot install. Provide -f to override.", r.Path()))
+ if cli.NodeExist(r.Path()) {
+ if force {
+ if err := os.RemoveAll(r.Path()); err != nil {
+ return nil, util.NewNewtError(err.Error())
+ }
+ } else {
+ return nil, util.NewNewtError(fmt.Sprintf("Repository %s already "+
+ "exists in local tree, cannot install. Provide -f to override.", r.Path()))
+ }
}
branchName, vers, found := rdesc.Match(r)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5aecc66f/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 32727f5..128ea9b 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -20,6 +20,7 @@
package target
import (
+ "fmt"
"io/ioutil"
"os"
"path/filepath"
@@ -115,11 +116,15 @@ func (target *Target) Compiler() *pkg.LocalPackage {
func (target *Target) App() *pkg.LocalPackage {
dep, err := pkg.NewDependency(nil, target.AppName)
if err != nil {
+ fmt.Println("app name = %s\n", target.AppName)
+ fmt.Println("dep is nil")
return nil
}
appPkg := project.GetProject().ResolveDependency(dep)
if appPkg == nil {
+ fmt.Printf("app name = %s\n", target.AppName)
+ fmt.Println("dep is not resolved")
return nil
}