You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/03/09 21:23:16 UTC
[01/50] incubator-mynewt-newt git commit: Fix mismerge.
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/develop 487dce611 -> 2b15801ba
Fix mismerge.
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/58967ec0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/58967ec0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/58967ec0
Branch: refs/heads/develop
Commit: 58967ec06fb565bb2a89aec77123fe5d2e5bd3a4
Parents: 5dba749
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Mar 7 16:46:32 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 7 16:46:32 2016 -0800
----------------------------------------------------------------------
newt/builder/build.go | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/58967ec0/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 5bbe82c..83e59b4 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -279,7 +279,6 @@ func (b *Builder) linkApp(baseCi *toolchain.CompilerInfo,
if b.Bsp.LinkerScript != "" {
c.LinkerScript = b.Bsp.BasePath() + b.Bsp.LinkerScript
}
- elfFile := binDir + "/" + appPackage.Name()
err = c.CompileElf(b.elfPath(), pkgNames)
if err != nil {
return err
[29/50] incubator-mynewt-newt git commit: Improve some messages.
Posted by ma...@apache.org.
Improve some 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/65b5bb39
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/65b5bb39
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/65b5bb39
Branch: refs/heads/develop
Commit: 65b5bb39f61e500b6e1d8f635942862c0932cb30
Parents: 4920e1e
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 16:38:17 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 17:35:02 2016 -0800
----------------------------------------------------------------------
newt/builder/build.go | 23 +++++++++++++++++++----
newt/builder/cmds.go | 33 ++++++++++++++++++---------------
newt/cli/util.go | 2 ++
newt/target/target.go | 18 ++++++++++--------
util/util.go | 11 ++---------
5 files changed, 51 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/65b5bb39/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 1f149af..7b3a35a 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -270,13 +270,23 @@ func (b *Builder) PrepBuild() error {
// Collect the seed packages.
bspPkg := b.target.Bsp()
if bspPkg == nil {
- return util.NewNewtError("bsp package not specified")
+ if b.target.BspName == "" {
+ return util.NewNewtError("BSP package not specified by target")
+ } else {
+ return util.NewNewtError("BSP package not found: " +
+ b.target.BspName)
+ }
}
b.Bsp = pkg.NewBspPackage(bspPkg)
compilerPkg := b.resolveCompiler()
if compilerPkg == nil {
- return util.NewNewtError("compiler package not specified")
+ if b.Bsp.CompilerName == "" {
+ return util.NewNewtError("Compiler package not specified by BSP")
+ } else {
+ return util.NewNewtError("Compiler package not found: " +
+ b.Bsp.CompilerName)
+ }
}
// An app package is not required (e.g., unit tests).
@@ -362,7 +372,12 @@ func (b *Builder) PrepBuild() error {
func (b *Builder) Build() error {
if b.target.App() == nil {
- return util.NewNewtError("app package not specified")
+ if b.target.AppName == "" {
+ return util.NewNewtError("App package not specified by target")
+ } else {
+ return util.NewNewtError("App package not found: " +
+ b.target.AppName)
+ }
}
// Populate the package and feature sets and calculate the base compiler
@@ -445,7 +460,7 @@ func (b *Builder) Test(p *pkg.LocalPackage) error {
cli.StatusMessage(cli.VERBOSITY_DEFAULT, "%s", string(o))
// Always terminate on test failure since only one test is being run.
- return util.NewtErrorNoTrace("Test failed: " + testFilename)
+ return util.NewNewtError("Test failed: " + testFilename)
}
cli.StatusMessage(cli.VERBOSITY_VERBOSE, "%s", string(o))
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/65b5bb39/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index 1b52c41..24299a8 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -44,12 +44,15 @@ func buildRunCmd(cmd *cobra.Command, args []string) {
b, err := NewBuilder(t)
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
}
err = b.Build()
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
}
+
+ cli.StatusMessage(cli.VERBOSITY_DEFAULT, "App successfully built: %s\n",
+ b.AppElfPath())
}
func cleanRunCmd(cmd *cobra.Command, args []string) {
@@ -64,11 +67,11 @@ func cleanRunCmd(cmd *cobra.Command, args []string) {
b, err := NewBuilder(t)
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
}
err = b.Clean()
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
}
}
@@ -85,7 +88,7 @@ func testRunCmd(cmd *cobra.Command, args []string) {
b, err := NewBuilder(t)
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
}
// Verify and resolve each specified package.
@@ -93,16 +96,16 @@ func testRunCmd(cmd *cobra.Command, args []string) {
for _, pkgName := range args {
dep, err := pkg.NewDependency(nil, pkgName)
if err != nil {
- cli.NewtUsage(cmd, util.NewtErrorNoTrace(fmt.Sprintf("invalid "+
+ cli.NewtUsage(cmd, util.NewNewtError(fmt.Sprintf("invalid "+
"package name: %s (%s)", pkgName, err.Error())))
}
if dep == nil {
- cli.NewtUsage(cmd, util.NewtErrorNoTrace("invalid package name: "+
+ cli.NewtUsage(cmd, util.NewNewtError("invalid package name: "+
pkgName))
}
pack := project.GetProject().ResolveDependency(dep)
if pack == nil {
- cli.NewtUsage(cmd, util.NewtErrorNoTrace("unknown package: "+
+ cli.NewtUsage(cmd, util.NewNewtError("unknown package: "+
pkgName))
}
@@ -113,7 +116,7 @@ func testRunCmd(cmd *cobra.Command, args []string) {
for _, pack := range packs {
err = b.Test(pack)
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
}
}
}
@@ -130,12 +133,12 @@ func downloadRunCmd(cmd *cobra.Command, args []string) {
b, err := NewBuilder(t)
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
}
err = b.Download()
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
}
}
@@ -151,12 +154,12 @@ func debugRunCmd(cmd *cobra.Command, args []string) {
b, err := NewBuilder(t)
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
}
err = b.Debug()
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
}
}
@@ -186,7 +189,7 @@ func AddCommands(cmd *cobra.Command) {
buildHelpEx := ""
buildCmd := &cobra.Command{
Use: "build",
- Short: "Command for building target",
+ Short: "Builds one or more apps.",
Long: buildHelpText,
Example: buildHelpEx,
Run: buildRunCmd,
@@ -198,7 +201,7 @@ func AddCommands(cmd *cobra.Command) {
cleanHelpEx := ""
cleanCmd := &cobra.Command{
Use: "clean",
- Short: "Command for cleaning target",
+ Short: "Deletes app build artifacts.",
Long: cleanHelpText,
Example: cleanHelpEx,
Run: cleanRunCmd,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/65b5bb39/newt/cli/util.go
----------------------------------------------------------------------
diff --git a/newt/cli/util.go b/newt/cli/util.go
index 0794cc1..fde67f3 100644
--- a/newt/cli/util.go
+++ b/newt/cli/util.go
@@ -61,6 +61,8 @@ func NewtUsage(cmd *cobra.Command, err error) {
}
if cmd != nil {
+ fmt.Printf("\n")
+ fmt.Printf("%s - ", cmd.Name())
cmd.Help()
}
os.Exit(1)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/65b5bb39/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 6a520c3..90b7afa 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -109,24 +109,26 @@ func (target *Target) ShortName() string {
return filepath.Base(target.Name())
}
-func (target *Target) App() *pkg.LocalPackage {
- dep, err := pkg.NewDependency(nil, target.AppName)
+func resolvePackageName(name string) *pkg.LocalPackage {
+ dep, err := pkg.NewDependency(nil, name)
if err != nil {
return nil
}
- appPkg := project.GetProject().ResolveDependency(dep)
- if appPkg == nil {
+ pack, ok := project.GetProject().ResolveDependency(dep).(*pkg.LocalPackage)
+ if !ok {
return nil
}
- return appPkg.(*pkg.LocalPackage)
+ return pack
+}
+
+func (target *Target) App() *pkg.LocalPackage {
+ return resolvePackageName(target.AppName)
}
func (target *Target) Bsp() *pkg.LocalPackage {
- dep, _ := pkg.NewDependency(nil, target.BspName)
- mypkg := project.GetProject().ResolveDependency(dep).(*pkg.LocalPackage)
- return mypkg
+ return resolvePackageName(target.BspName)
}
func (target *Target) BinBasePath() string {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/65b5bb39/util/util.go
----------------------------------------------------------------------
diff --git a/util/util.go b/util/util.go
index 8ac4e60..4ac925d 100644
--- a/util/util.go
+++ b/util/util.go
@@ -20,10 +20,10 @@
package util
import (
- "mynewt.apache.org/newt/viper"
- "github.com/hashicorp/logutils"
"fmt"
+ "github.com/hashicorp/logutils"
"log"
+ "mynewt.apache.org/newt/viper"
"os"
"path/filepath"
"runtime"
@@ -66,13 +66,6 @@ func NewNewtError(msg string) *NewtError {
return err
}
-func NewtErrorNoTrace(msg string) *NewtError {
- return &NewtError{
- Text: msg,
- StackTrace: nil,
- }
-}
-
func Min(x, y int) int {
if x < y {
return x
[06/50] incubator-mynewt-newt git commit: Rearrange some code;
build.go was getting confusing.
Posted by ma...@apache.org.
Rearrange some code; build.go was getting confusing.
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/c8a0ed95
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/c8a0ed95
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/c8a0ed95
Branch: refs/heads/develop
Commit: c8a0ed9592fb31ad85d9d9232a88d5271ca9a44e
Parents: 928e034
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Mar 7 21:25:48 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Mar 7 21:28:10 2016 -0800
----------------------------------------------------------------------
newt/builder/build.go | 121 +++++++----------------------------------
newt/builder/buildutil.go | 108 ++++++++++++++++++++++++++++++++++++
2 files changed, 128 insertions(+), 101 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/c8a0ed95/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 46e8133..b256a53 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -20,13 +20,11 @@
package builder
import (
- "bytes"
"os"
"path/filepath"
"mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/newt/pkg"
- "mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/newt/target"
"mynewt.apache.org/newt/newt/toolchain"
"mynewt.apache.org/newt/util"
@@ -44,6 +42,26 @@ type Builder struct {
target *target.Target
}
+func NewBuilder(target *target.Target) (*Builder, error) {
+ b := &Builder{}
+
+ if err := b.Init(target); err != nil {
+ return nil, err
+ }
+
+ return b, nil
+}
+
+func (b *Builder) Init(target *target.Target) error {
+ b.target = target
+
+ b.Packages = map[*pkg.LocalPackage]*BuildPackage{}
+ b.features = map[string]bool{}
+ b.apis = map[string]*BuildPackage{}
+
+ return nil
+}
+
func (b *Builder) Features() map[string]bool {
return b.features
}
@@ -83,25 +101,6 @@ func (b *Builder) AddApi(apiString string, bpkg *BuildPackage) bool {
}
}
-func (b *Builder) logFeatures() {
- var buffer bytes.Buffer
- buffer.WriteString("Building with the following feature set: [")
-
- first := true
- for feature, _ := range b.Features() {
- if !first {
- buffer.WriteString(" ")
- } else {
- first = false
- }
-
- buffer.WriteString(feature)
- }
- buffer.WriteString("]\n")
-
- cli.StatusMessage(cli.VERBOSITY_VERBOSE, buffer.String())
-}
-
func (b *Builder) loadDeps() error {
// Circularly resolve dependencies, identities, APIs, and required APIs
// until no new ones exist.
@@ -128,44 +127,6 @@ func (b *Builder) loadDeps() error {
return nil
}
-// Makes sure all packages with required APIs have been augmented a dependency
-// which satisfies that requirement. If there are any unsatisfied
-// requirements, an error is returned.
-func (b *Builder) verifyApisSatisfied() error {
- unsatisfied := map[*BuildPackage][]string{}
-
- for _, bpkg := range b.Packages {
- for api, status := range bpkg.reqApiMap {
- if status == REQ_API_STATUS_UNSATISFIED {
- slice := unsatisfied[bpkg]
- if slice == nil {
- unsatisfied[bpkg] = []string{api}
- } else {
- slice = append(slice, api)
- }
- }
- }
- }
-
- if len(unsatisfied) != 0 {
- var buffer bytes.Buffer
- for bpkg, apis := range unsatisfied {
- buffer.WriteString("Package " + bpkg.Name() +
- " has unsatisfied required APIs: ")
- for i, api := range apis {
- if i != 0 {
- buffer.WriteString(", ")
- }
- buffer.WriteString(api)
- }
- buffer.WriteString("\n")
- }
- return util.NewNewtError(buffer.String())
- }
-
- return nil
-}
-
// Recursively compiles all the .c and .s files in the specified directory.
// Architecture-specific files are also compiled.
func buildDir(srcDir string, c *toolchain.Compiler, arch string,
@@ -223,28 +184,6 @@ func buildDir(srcDir string, c *toolchain.Compiler, arch string,
return nil
}
-func (b *Builder) binDir() string {
- return project.GetProject().Path() + "/bin/" + b.target.ShortName()
-}
-
-func (b *Builder) pkgBinDir(pkgName string) string {
- return b.binDir() + "/" + pkgName
-}
-
-// Generates the path+filename of the specified package's .a file.
-func (b *Builder) archivePath(pkgName string) string {
- return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".a"
-}
-
-func (b *Builder) appElfPath() string {
- pkgName := b.target.App().Name()
- return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".elf"
-}
-
-func (b *Builder) testExePath(pkgName string) string {
- return b.pkgBinDir(pkgName) + "/test_" + filepath.Base(pkgName)
-}
-
// Compiles and archives a package.
func (b *Builder) buildPackage(bpkg *BuildPackage) error {
srcDir := bpkg.BasePath() + "/src"
@@ -514,23 +453,3 @@ func (b *Builder) Clean() error {
err := os.RemoveAll(path)
return err
}
-
-func (b *Builder) Init(target *target.Target) error {
- b.target = target
-
- b.Packages = map[*pkg.LocalPackage]*BuildPackage{}
- b.features = map[string]bool{}
- b.apis = map[string]*BuildPackage{}
-
- return nil
-}
-
-func NewBuilder(target *target.Target) (*Builder, error) {
- b := &Builder{}
-
- if err := b.Init(target); err != nil {
- return nil, err
- }
-
- return b, nil
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/c8a0ed95/newt/builder/buildutil.go
----------------------------------------------------------------------
diff --git a/newt/builder/buildutil.go b/newt/builder/buildutil.go
new file mode 100644
index 0000000..06de849
--- /dev/null
+++ b/newt/builder/buildutil.go
@@ -0,0 +1,108 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package builder
+
+import (
+ "bytes"
+ "path/filepath"
+
+ "mynewt.apache.org/newt/newt/cli"
+ "mynewt.apache.org/newt/newt/project"
+ "mynewt.apache.org/newt/util"
+)
+
+func (b *Builder) binDir() string {
+ return project.GetProject().Path() + "/bin/" + b.target.ShortName()
+}
+
+func (b *Builder) pkgBinDir(pkgName string) string {
+ return b.binDir() + "/" + pkgName
+}
+
+// Generates the path+filename of the specified package's .a file.
+func (b *Builder) archivePath(pkgName string) string {
+ return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".a"
+}
+
+func (b *Builder) appElfPath() string {
+ pkgName := b.target.App().Name()
+ return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".elf"
+}
+
+func (b *Builder) testExePath(pkgName string) string {
+ return b.pkgBinDir(pkgName) + "/test_" + filepath.Base(pkgName)
+}
+
+func (b *Builder) logFeatures() {
+ var buffer bytes.Buffer
+ buffer.WriteString("Building with the following feature set: [")
+
+ first := true
+ for feature, _ := range b.Features() {
+ if !first {
+ buffer.WriteString(" ")
+ } else {
+ first = false
+ }
+
+ buffer.WriteString(feature)
+ }
+ buffer.WriteString("]\n")
+
+ cli.StatusMessage(cli.VERBOSITY_VERBOSE, buffer.String())
+}
+
+// Makes sure all packages with required APIs have been augmented a dependency
+// which satisfies that requirement. If there are any unsatisfied
+// requirements, an error is returned.
+func (b *Builder) verifyApisSatisfied() error {
+ unsatisfied := map[*BuildPackage][]string{}
+
+ for _, bpkg := range b.Packages {
+ for api, status := range bpkg.reqApiMap {
+ if status == REQ_API_STATUS_UNSATISFIED {
+ slice := unsatisfied[bpkg]
+ if slice == nil {
+ unsatisfied[bpkg] = []string{api}
+ } else {
+ slice = append(slice, api)
+ }
+ }
+ }
+ }
+
+ if len(unsatisfied) != 0 {
+ var buffer bytes.Buffer
+ for bpkg, apis := range unsatisfied {
+ buffer.WriteString("Package " + bpkg.Name() +
+ " has unsatisfied required APIs: ")
+ for i, api := range apis {
+ if i != 0 {
+ buffer.WriteString(", ")
+ }
+ buffer.WriteString(api)
+ }
+ buffer.WriteString("\n")
+ }
+ return util.NewNewtError(buffer.String())
+ }
+
+ return nil
+}
[23/50] incubator-mynewt-newt git commit: add prompt for upgrade.
remove debug text from previous version. use proper define for version
stability
Posted by ma...@apache.org.
add prompt for upgrade. remove debug text from previous version. use proper define for version stability
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/9351ecf9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/9351ecf9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/9351ecf9
Branch: refs/heads/develop
Commit: 9351ecf970e4eacf800a16f5a33df3eae75e0365
Parents: ec23685
Author: Sterling Hughes <st...@apache.org>
Authored: Tue Mar 8 17:28:08 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Mar 8 17:28:08 2016 -0800
----------------------------------------------------------------------
newt/project/project.go | 15 ++++++++++++++-
newt/repo/repo.go | 2 +-
newt/target/target.go | 1 -
3 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9351ecf9/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index 7e3e5e1..a53fd06 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -20,6 +20,7 @@
package project
import (
+ "bufio"
"fmt"
"log"
"os"
@@ -190,9 +191,21 @@ func (proj *Project) Install(upgrade bool, force bool) error {
str += "(" + branch + ")"
}
- fmt.Printf("Would you like to upgrade repository %s from %s to %s %s",
+ fmt.Printf("Would you like to upgrade repository %s from %s to %s %s? [Yn] ",
r.Name(), vers.String(), newVers.String(), str)
+ line, more, err := bufio.NewReader(os.Stdin).ReadLine()
+ if more || err != nil {
+ return util.NewNewtError(fmt.Sprintf(
+ "Couldn't read upgrade response: %s\n", err.Error()))
+ }
+ answer := strings.ToUpper(strings.Trim(string(line), " "))
+ if answer == "N" || answer == "NO" {
+ fmt.Printf("Users says don't upgrade, skipping upgrade of %s\n",
+ r.Name())
+ continue
+ }
+
}
} else {
fmt.Printf("Repository %s doesn't need to be upgraded, latest "+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9351ecf9/newt/repo/repo.go
----------------------------------------------------------------------
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index 35f7507..0419e38 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -65,7 +65,7 @@ func (rd *RepoDesc) Match(r *Repo) (string, *Version, bool) {
if vers.SatisfiesVersion(r.VersionRequirements()) {
log.Printf("[DEBUG] Found matching version %s for repo %s",
vers.String(), r.Name())
- if vers.Stability() != "none" {
+ if vers.Stability() != VERSION_STABILITY_NONE {
searchVers, err := LoadVersion(branch)
if err != nil {
return "", nil, false
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9351ecf9/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 19e55ac..643035e 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -125,7 +125,6 @@ func (target *Target) App() *pkg.LocalPackage {
appPkg := project.GetProject().ResolveDependency(dep)
if appPkg == nil {
fmt.Printf("app name = %s\n", target.AppName)
- fmt.Println("dep is not resolved")
return nil
}
[39/50] incubator-mynewt-newt git commit: Add 'newt run' command.
Posted by ma...@apache.org.
Add 'newt run' command.
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/f46ff311
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/f46ff311
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/f46ff311
Branch: refs/heads/develop
Commit: f46ff3118e296611a159f295dc80bad3a1f5418d
Parents: 1049e22
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Mar 8 20:47:04 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Mar 8 20:47:04 2016 -0800
----------------------------------------------------------------------
newt/builder/build.go | 4 ++
newt/builder/cmds.go | 4 +-
newt/builder/download.go | 7 +++
newt/newt.go | 2 +
newt/run/cmds.go | 106 ++++++++++++++++++++++++++++++++++++++++++
5 files changed, 121 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f46ff311/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 009a598..6f6ea75 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -266,6 +266,10 @@ func (b *Builder) link(elfName string) error {
// configures each package's build settings. After this function executes,
// packages are ready to be built.
func (b *Builder) PrepBuild() error {
+ if b.Bsp != nil {
+ // Already prepped
+ return nil
+ }
// Collect the seed packages.
bspPkg := b.target.Bsp()
if bspPkg == nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f46ff311/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index 2744127..6298a92 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -175,12 +175,12 @@ func sizeRunCmd(cmd *cobra.Command, args []string) {
b, err := NewBuilder(t)
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
}
err = b.Size()
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f46ff311/newt/builder/download.go
----------------------------------------------------------------------
diff --git a/newt/builder/download.go b/newt/builder/download.go
index 9a4c512..cab02c8 100644
--- a/newt/builder/download.go
+++ b/newt/builder/download.go
@@ -41,6 +41,13 @@ func (b *Builder) Download() error {
return err
}
+ if b.Bsp.DownloadScript == "" {
+ /*
+ *
+ */
+ return nil
+ }
+
bspPath := b.Bsp.BasePath()
downloadScript := filepath.Join(bspPath, b.Bsp.DownloadScript)
binBaseName := b.appBinBasePath()
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f46ff311/newt/newt.go
----------------------------------------------------------------------
diff --git a/newt/newt.go b/newt/newt.go
index 103f52f..ce89ad5 100644
--- a/newt/newt.go
+++ b/newt/newt.go
@@ -28,6 +28,7 @@ import (
"mynewt.apache.org/newt/newt/image"
"mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/project"
+ "mynewt.apache.org/newt/newt/run"
"mynewt.apache.org/newt/newt/target"
"mynewt.apache.org/newt/util"
@@ -113,6 +114,7 @@ func main() {
target.AddCommands(cmd)
builder.AddCommands(cmd)
image.AddCommands(cmd)
+ run.AddCommands(cmd)
cmd.Execute()
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f46ff311/newt/run/cmds.go
----------------------------------------------------------------------
diff --git a/newt/run/cmds.go b/newt/run/cmds.go
new file mode 100644
index 0000000..4f133ef
--- /dev/null
+++ b/newt/run/cmds.go
@@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package run
+
+import (
+ "os"
+
+ "github.com/spf13/cobra"
+ "mynewt.apache.org/newt/newt/builder"
+ "mynewt.apache.org/newt/newt/cli"
+ "mynewt.apache.org/newt/newt/image"
+ "mynewt.apache.org/newt/newt/target"
+ "mynewt.apache.org/newt/util"
+)
+
+func runRunCmd(cmd *cobra.Command, args []string) {
+ if len(args) < 1 {
+ cli.NewtUsage(cmd, util.NewNewtError("Must specify target"))
+ }
+
+ t := target.ResolveTargetName(args[0])
+ if t == nil {
+ cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"+args[0]))
+ }
+
+ b, err := builder.NewBuilder(t)
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+
+ err = b.Build()
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+
+ /*
+ * Run create-image if version number is specified. If no version number,
+ * remove .img which would'be been created. This so that download script will
+ * barf if it needs an image for this type of target, instead of downloading
+ * an older version.
+ */
+ if len(args) > 1 {
+ image, err := image.NewImage(b)
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+ err = image.SetVersion(args[1])
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+ err = image.Generate()
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+ err = image.CreateManifest(t)
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+ } else {
+ os.Remove(b.AppImgPath())
+ }
+ err = b.Download()
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+ err = b.Debug()
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+}
+
+func AddCommands(cmd *cobra.Command) {
+ runHelpText := "Same as running\n" +
+ " - build <target>\n" +
+ " - create-image <target> <version>\n" +
+ " - download <target>\n" +
+ " - debug <target>\n\n" +
+ "Note if version number is omitted, create-image step is skipped\n"
+ runHelpEx := " newt run <target-name> [<version>]\n"
+
+ runCmd := &cobra.Command{
+ Use: "run",
+ Short: "build/create-image/download/debug <target>",
+ Long: runHelpText,
+ Example: runHelpEx,
+ Run: runRunCmd,
+ }
+ cmd.AddCommand(runCmd)
+}
[24/50] incubator-mynewt-newt git commit: Allow multiple targets in
delete command.
Posted by ma...@apache.org.
Allow multiple targets in delete command.
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/aef3d397
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/aef3d397
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/aef3d397
Branch: refs/heads/develop
Commit: aef3d397c82de355fa8a2511af204f9770af523d
Parents: d2d5ef1
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 15:18:15 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 17:31:54 2016 -0800
----------------------------------------------------------------------
newt/target/cmds.go | 67 +++++++++++++++++++++++++++---------------------
1 file changed, 38 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/aef3d397/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index c55fd39..d831063 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -33,12 +33,14 @@ import (
"mynewt.apache.org/newt/util"
)
-// Type for sorting an array of target pointers alphabetically by name.
-type ByName []*Target
+func parseTargetName(arg string) (*Target, error) {
+ t := ResolveTargetName(arg)
+ if t == nil {
+ return nil, util.NewNewtError("Unknown target: " + arg)
+ }
-func (a ByName) Len() int { return len(a) }
-func (a ByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
-func (a ByName) Less(i, j int) bool { return a[i].Package().Name() < a[j].Package().Name() }
+ return t, nil
+}
func targetShowCmd(cmd *cobra.Command, args []string) {
proj := project.GetProject()
@@ -108,12 +110,10 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
}
// Parse target name.
- tName := args[0]
- t := ResolveTargetName(tName)
- if t == nil {
- cli.NewtUsage(cmd, util.NewNewtError("Unknown target: "+tName))
+ t, err := parseTargetName(args[0])
+ if err != nil {
+ cli.NewtUsage(cmd, err)
}
- tName = t.Name()
// Parse series of k=v pairs. If an argument doesn't contain a '='
// character, display the valid values for the variable and quit.
@@ -155,10 +155,11 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
for _, kv := range vars {
if kv[1] == "" {
cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Target %s successfully unset %s\n", tName, kv[0])
+ "Target %s successfully unset %s\n", t.Name(), kv[0])
} else {
cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Target %s successfully set %s to %s\n", tName, kv[0], kv[1])
+ "Target %s successfully set %s to %s\n", t.Name(), kv[0],
+ kv[1])
}
}
}
@@ -198,22 +199,13 @@ func targetCreateCmd(cmd *cobra.Command, args []string) {
}
}
-func targetDelCmd(cmd *cobra.Command, args []string) {
- if len(args) < 1 {
- cli.NewtUsage(cmd, util.NewNewtError("Must specify target to delete"))
- }
-
- t := ResolveTargetName(args[0])
- if t == nil {
- cli.NewtUsage(cmd, util.NewNewtError("Target does not exist"))
- }
-
+func targetDelOne(t *Target) error {
if !cli.Force {
// Determine if the target directory contains extra user files. If it
// does, a prompt (or force) is required to delete it.
userFiles, err := t.ContainsUserFiles()
if err != nil {
- cli.NewtUsage(cmd, err)
+ return err
}
if userFiles {
@@ -222,20 +214,37 @@ func targetDelCmd(cmd *cobra.Command, args []string) {
"delete anyway? (y/N): ", t.basePkg.Name())
rc := scanner.Scan()
if !rc || strings.ToLower(scanner.Text()) != "y" {
- return
+ return nil
}
}
}
- // Clean target prior to deletion; ignore errors during clean.
- //t.BuildClean(false)
-
if err := t.Delete(); err != nil {
- cli.NewtUsage(cmd, err)
+ return err
}
cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Target %s successfully removed\n", args[0])
+ "Target %s successfully removed\n", t.Name())
+
+ return nil
+}
+
+func targetDelCmd(cmd *cobra.Command, args []string) {
+ if len(args) < 1 {
+ cli.NewtUsage(cmd, util.NewNewtError("Must specify at least one "+
+ "target to delete"))
+ }
+
+ targets, err := ResolveTargetNames(args...)
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+
+ for _, t := range targets {
+ if err := targetDelOne(t); err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+ }
}
func AddCommands(cmd *cobra.Command) {
[36/50] incubator-mynewt-newt git commit: Handle targets from
non-local repos.
Posted by ma...@apache.org.
Handle targets from non-local repos.
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/5c7d6ff4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/5c7d6ff4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/5c7d6ff4
Branch: refs/heads/develop
Commit: 5c7d6ff4a8210eec06d52a54dbd0eeffd3b2f95c
Parents: 8815613
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 18:34:53 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 19:39:09 2016 -0800
----------------------------------------------------------------------
newt/builder/cmds.go | 2 +-
newt/target/cmds.go | 12 +++++++-----
newt/target/target.go | 44 ++++++++++++++++++++++++++++++--------------
3 files changed, 38 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5c7d6ff4/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index aaf4836..2744127 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -57,7 +57,7 @@ func buildRunCmd(cmd *cobra.Command, args []string) {
func cleanRunCmd(cmd *cobra.Command, args []string) {
if len(args) < 1 {
- cli.NewtUsage(cmd, nil)
+ cli.NewtUsage(cmd, util.NewNewtError("Must specify target"))
}
t := target.ResolveTargetName(args[0])
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5c7d6ff4/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index 1cfe18a..7480c0f 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -61,7 +61,7 @@ func targetShowCmd(cmd *cobra.Command, args []string) {
}
for _, t := range targetSlice {
- targetNames = append(targetNames, t.Name())
+ targetNames = append(targetNames, t.FullName())
}
}
@@ -155,10 +155,10 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
for _, kv := range vars {
if kv[1] == "" {
util.StatusMessage(util.VERBOSITY_DEFAULT,
- "Target %s successfully unset %s\n", t.Name(), kv[0])
+ "Target %s successfully unset %s\n", t.FullName(), kv[0])
} else {
util.StatusMessage(util.VERBOSITY_DEFAULT,
- "Target %s successfully set %s to %s\n", t.Name(), kv[0],
+ "Target %s successfully set %s to %s\n", t.FullName(), kv[0],
kv[1])
}
}
@@ -176,6 +176,8 @@ func targetCreateCmd(cmd *cobra.Command, args []string) {
tName = "targets/" + tName
}
+ // XXX: Deal with repo name at start of target string.
+
util.StatusMessage(util.VERBOSITY_DEFAULT, "Creating target "+tName+"\n")
t := ResolveTargetName(tName)
@@ -211,7 +213,7 @@ func targetDelOne(t *Target) error {
if userFiles {
scanner := bufio.NewScanner(os.Stdin)
fmt.Printf("Target directory %s contains some extra content; "+
- "delete anyway? (y/N): ", t.basePkg.Name())
+ "delete anyway? (y/N): ", t.basePkg.BasePath())
rc := scanner.Scan()
if !rc || strings.ToLower(scanner.Text()) != "y" {
return nil
@@ -224,7 +226,7 @@ func targetDelOne(t *Target) error {
}
util.StatusMessage(util.VERBOSITY_DEFAULT,
- "Target %s successfully removed\n", t.Name())
+ "Target %s successfully removed\n", t.FullName())
return nil
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5c7d6ff4/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 72e1e1d..661df43 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -32,14 +32,11 @@ import (
"mynewt.apache.org/newt/yaml"
)
-const TARGET_FILE_NAME string = "target.yml"
+const TARGET_FILENAME string = "target.yml"
+const TARGET_DEFAULT_DIR string = "targets"
var globalTargetMap map[string]*Target
-var targetSearchDirs = []string{
- "targets",
-}
-
type Target struct {
basePkg *pkg.LocalPackage
@@ -76,7 +73,7 @@ func (target *Target) Init(basePkg *pkg.LocalPackage) {
func (target *Target) Load(basePkg *pkg.LocalPackage) error {
v, err := util.ReadConfig(basePkg.BasePath(),
- strings.TrimSuffix(TARGET_FILE_NAME, ".yml"))
+ strings.TrimSuffix(TARGET_FILENAME, ".yml"))
if err != nil {
return err
}
@@ -104,6 +101,10 @@ func (target *Target) Name() string {
return target.basePkg.Name()
}
+func (target *Target) FullName() string {
+ return target.basePkg.FullName()
+}
+
func (target *Target) ShortName() string {
return filepath.Base(target.Name())
}
@@ -155,7 +156,7 @@ func (t *Target) Save() error {
}
dirpath := t.basePkg.BasePath()
- filepath := dirpath + "/" + TARGET_FILE_NAME
+ filepath := dirpath + "/" + TARGET_FILENAME
file, err := os.Create(filepath)
if err != nil {
return util.NewNewtError(err.Error())
@@ -189,7 +190,7 @@ func (t *Target) ContainsUserFiles() (bool, error) {
for _, node := range contents {
name := node.Name()
if name != "." && name != ".." &&
- name != pkg.PACKAGE_FILE_NAME && name != TARGET_FILE_NAME {
+ name != pkg.PACKAGE_FILE_NAME && name != TARGET_FILENAME {
userFiles = true
break
@@ -220,7 +221,7 @@ func buildTargetMap() error {
"Warning: failed to load target \"%s\": %s\n", pack.Name,
nerr.Text)
} else {
- globalTargetMap[pack.Name()] = target
+ globalTargetMap[pack.FullName()] = target
}
}
@@ -241,13 +242,28 @@ func GetTargets() map[string]*Target {
func ResolveTargetName(name string) *Target {
targetMap := GetTargets()
- t := targetMap[name]
- for i := 0; t == nil && i < len(targetSearchDirs); i++ {
- guess := targetSearchDirs[i] + "/" + name
- t = targetMap[guess]
+ // Check for fully-qualified name.
+ if t := targetMap[name]; t != nil {
+ return t
+ }
+
+ // Check the local "targets" directory.
+ if t := targetMap[TARGET_DEFAULT_DIR+"/"+name]; t != nil {
+ return t
}
- return t
+ // Check each repo alphabetically.
+ fullNames := []string{}
+ for fullName, _ := range targetMap {
+ fullNames = append(fullNames, fullName)
+ }
+ for _, fullName := range util.SortFields(fullNames...) {
+ if name == filepath.Base(fullName) {
+ return targetMap[fullName]
+ }
+ }
+
+ return nil
}
func ResolveTargetNames(names ...string) ([]*Target, error) {
[27/50] incubator-mynewt-newt git commit: Remove compiler fields from
target.
Posted by ma...@apache.org.
Remove compiler fields from target.
Now they are in the bsp.
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/4920e1e4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/4920e1e4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/4920e1e4
Branch: refs/heads/develop
Commit: 4920e1e47b368a3aadcd5d30d315f7c9c07aec72
Parents: a54695c
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 15:28:13 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 17:32:48 2016 -0800
----------------------------------------------------------------------
newt/target/target.go | 4 ----
1 file changed, 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4920e1e4/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 2a4f781..6a520c3 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -47,7 +47,6 @@ type Target struct {
// XXX: Probably don't need the below four fields; they can just be
// retrieved from the viper object. Keep them here for now for easy
// initializiation of dummy targets.
- CompilerName string
BspName string
AppName string
Arch string
@@ -90,14 +89,11 @@ func (target *Target) Load(basePkg *pkg.LocalPackage) error {
target.Vars[k] = v.(string)
}
- target.CompilerName = target.Vars["target.compiler"]
target.BspName = target.Vars["target.bsp"]
target.AppName = target.Vars["target.app"]
target.Arch = target.Vars["target.arch"]
target.BuildProfile = target.Vars["target.build_profile"]
- // XXX: Verify required fields set?
-
return nil
}
[41/50] incubator-mynewt-newt git commit: fix build
Posted by ma...@apache.org.
fix build
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/057cef16
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/057cef16
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/057cef16
Branch: refs/heads/develop
Commit: 057cef1615b3fb681b4148e3f247c432d5e3bb57
Parents: e9ff877
Author: Sterling Hughes <st...@apache.org>
Authored: Wed Mar 9 08:02:28 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Wed Mar 9 08:02:28 2016 -0800
----------------------------------------------------------------------
newt/image/cmds.go | 2 --
1 file changed, 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/057cef16/newt/image/cmds.go
----------------------------------------------------------------------
diff --git a/newt/image/cmds.go b/newt/image/cmds.go
index d8f00b7..75b6805 100644
--- a/newt/image/cmds.go
+++ b/newt/image/cmds.go
@@ -20,8 +20,6 @@
package image
import (
- "fmt"
-
"github.com/spf13/cobra"
"mynewt.apache.org/newt/newt/builder"
"mynewt.apache.org/newt/newt/cli"
[07/50] incubator-mynewt-newt git commit: Allow multiple packages for
test command.
Posted by ma...@apache.org.
Allow multiple packages for test command.
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/88fe5653
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/88fe5653
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/88fe5653
Branch: refs/heads/develop
Commit: 88fe56537e190a5a05739a281da7a9ed3421a067
Parents: c8a0ed9
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Mar 7 21:36:52 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Mar 7 21:36:52 2016 -0800
----------------------------------------------------------------------
newt/builder/cmds.go | 41 +++++++++++++++++++++++++----------------
1 file changed, 25 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/88fe5653/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index 5cb3889..a6f2c89 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -90,22 +90,31 @@ func testRunCmd(cmd *cobra.Command, args []string) {
fmt.Println(err)
}
- pkgString := args[0]
- dep, err := pkg.NewDependency(nil, pkgString)
- if err != nil {
- cli.NewtUsage(cmd, err)
- }
- if dep == nil {
- cli.NewtUsage(cmd, util.NewNewtError("invalid package name"))
- }
- pack := project.GetProject().ResolveDependency(dep)
- if pack == nil {
- cli.NewtUsage(cmd, util.NewNewtError("invalid package name"))
- }
-
- err = b.Test(pack.(*pkg.LocalPackage))
- if err != nil {
- fmt.Println(err)
+ // Verify and resolve each specified package.
+ packs := []*pkg.LocalPackage{}
+ for _, pkgName := range args {
+ dep, err := pkg.NewDependency(nil, pkgName)
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+ if dep == nil {
+ cli.NewtUsage(cmd, util.NewNewtError("invalid package name: "+
+ pkgName))
+ }
+ pack := project.GetProject().ResolveDependency(dep)
+ if pack == nil {
+ cli.NewtUsage(cmd, util.NewNewtError("unknown package: "+pkgName))
+ }
+
+ packs = append(packs, pack.(*pkg.LocalPackage))
+ }
+
+ // Test each package.
+ for _, pack := range packs {
+ err = b.Test(pack)
+ if err != nil {
+ fmt.Println(err)
+ }
}
}
[04/50] incubator-mynewt-newt git commit: Ignore emacs autosave files.
Posted by ma...@apache.org.
Ignore emacs autosave files.
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/516dd1eb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/516dd1eb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/516dd1eb
Branch: refs/heads/develop
Commit: 516dd1ebe4069b8b5c1c6cff0a3ccabdc29ddb4d
Parents: ae87703
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Mar 7 18:11:20 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 7 18:11:20 2016 -0800
----------------------------------------------------------------------
.gitignore | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/516dd1eb/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 090d89e..8ec1006 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,7 +18,8 @@
#
*.swp
-*.swo
+*.swo
+*~
tags
newt/newt
newtmgr/newtmgr
[37/50] incubator-mynewt-newt git commit: Don't allow repo name in
target create command.
Posted by ma...@apache.org.
Don't allow repo name in target create command.
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/7a3d6913
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/7a3d6913
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/7a3d6913
Branch: refs/heads/develop
Commit: 7a3d6913815b62ce011b0bf0244b1838c82ea5c9
Parents: 5c7d6ff
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 19:08:18 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 19:39:09 2016 -0800
----------------------------------------------------------------------
newt/cli/util.go | 28 ++++++++++++++++++++++++++++
newt/pkg/dependency.go | 27 +++++++++++----------------
newt/pkg/localpackage.go | 6 +++---
newt/target/cmds.go | 42 ++++++++++++++++++++++++------------------
newt/target/vars.go | 7 +++++--
5 files changed, 71 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/7a3d6913/newt/cli/util.go
----------------------------------------------------------------------
diff --git a/newt/cli/util.go b/newt/cli/util.go
index 89ee6ae..ce2b671 100644
--- a/newt/cli/util.go
+++ b/newt/cli/util.go
@@ -117,3 +117,31 @@ func GetStringSliceFeatures(v *viper.Viper, features map[string]bool,
return result
}
+
+// Parses a string of the following form:
+// [@repo]<path/to/package>
+//
+// @return string repo name ("" if no repo)
+// string package name
+// error if invalid package string
+func ParsePackageString(pkgStr string) (string, string, error) {
+ if strings.HasPrefix(pkgStr, "@") {
+ nameParts := strings.SplitN(pkgStr[1:], "/", 2)
+ if len(nameParts) == 1 {
+ return "", "", util.NewNewtError(fmt.Sprintf("Invalid package "+
+ "string; contains repo but no package name: %s", pkgStr))
+ } else {
+ return nameParts[0], nameParts[1], nil
+ }
+ } else {
+ return "", pkgStr, nil
+ }
+}
+
+func BuildPackageString(repoName string, pkgName string) string {
+ if repoName != "" {
+ return "@" + repoName + "/" + pkgName
+ } else {
+ return pkgName
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/7a3d6913/newt/pkg/dependency.go
----------------------------------------------------------------------
diff --git a/newt/pkg/dependency.go b/newt/pkg/dependency.go
index ee57655..bd586c0 100644
--- a/newt/pkg/dependency.go
+++ b/newt/pkg/dependency.go
@@ -20,12 +20,9 @@
package pkg
import (
- "fmt"
- "strings"
-
+ "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/newt/interfaces"
"mynewt.apache.org/newt/newt/repo"
- "mynewt.apache.org/newt/util"
)
type Dependency struct {
@@ -34,8 +31,7 @@ type Dependency struct {
}
func (dep *Dependency) String() string {
- str := fmt.Sprintf("@%s/%s", dep.Repo, dep.Name)
- return str
+ return cli.BuildPackageString(dep.Repo, dep.Name)
}
func (dep *Dependency) SatisfiesDependency(pkg interfaces.PackageInterface) bool {
@@ -52,17 +48,16 @@ func (dep *Dependency) SatisfiesDependency(pkg interfaces.PackageInterface) bool
func (dep *Dependency) setRepoAndName(parentRepo interfaces.RepoInterface, str string) error {
// First part is always repo/dependency name combination.
- // If repo is present, string will always begin with a $ sign
+ // If repo is present, string will always begin with a @ sign
// representing the repo name, followed by 'n' slashes.
- if strings.HasPrefix(str, "@") {
- nameParts := strings.SplitN(str[1:], "/", 2)
- if len(nameParts) == 1 {
- return util.NewNewtError(fmt.Sprintf(
- "Must specify both repo and package name, no package detected: %s",
- str))
- }
- dep.Repo = nameParts[0]
- dep.Name = nameParts[1]
+ repoName, pkgName, err := cli.ParsePackageString(str)
+ if err != nil {
+ return err
+ }
+
+ if repoName != "" {
+ dep.Repo = repoName
+ dep.Name = pkgName
} else {
if parentRepo != nil {
dep.Repo = parentRepo.Name()
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/7a3d6913/newt/pkg/localpackage.go
----------------------------------------------------------------------
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index 6a89563..f7ab295 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -28,11 +28,11 @@ import (
"path/filepath"
"strings"
- "mynewt.apache.org/newt/viper"
-
+ "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/newt/interfaces"
"mynewt.apache.org/newt/newt/repo"
"mynewt.apache.org/newt/util"
+ "mynewt.apache.org/newt/viper"
"mynewt.apache.org/newt/yaml"
)
@@ -84,7 +84,7 @@ func (pkg *LocalPackage) FullName() string {
if r.IsLocal() {
return pkg.Name()
} else {
- return "@" + r.Name() + "/" + pkg.Name()
+ return cli.BuildPackageString(r.Name(), pkg.Name())
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/7a3d6913/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index 7480c0f..98f0df6 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -33,7 +33,7 @@ import (
"mynewt.apache.org/newt/util"
)
-func parseTargetName(arg string) (*Target, error) {
+func resolveTargetArg(arg string) (*Target, error) {
t := ResolveTargetName(arg)
if t == nil {
return nil, util.NewNewtError("Unknown target: " + arg)
@@ -110,7 +110,7 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
}
// Parse target name.
- t, err := parseTargetName(args[0])
+ t, err := resolveTargetArg(args[0])
if err != nil {
cli.NewtUsage(cmd, err)
}
@@ -169,35 +169,41 @@ func targetCreateCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, util.NewNewtError("Missing target name"))
}
- tName := args[0]
+ repoName, pkgName, err := cli.ParsePackageString(args[0])
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
- // "Naked" target names go in the "targets/" directory.
- if !strings.Contains(tName, "/") {
- tName = "targets/" + tName
+ if repoName != "" {
+ cli.NewtUsage(cmd, util.NewNewtError("Target name cannot contain "+
+ "repo; must be local"))
}
- // XXX: Deal with repo name at start of target string.
+ // "Naked" target names go in the "targets/" directory.
+ if !strings.Contains(pkgName, "/") {
+ pkgName = "targets/" + pkgName
+ }
- util.StatusMessage(util.VERBOSITY_DEFAULT, "Creating target "+tName+"\n")
+ util.StatusMessage(util.VERBOSITY_DEFAULT, "Creating target "+
+ pkgName+"\n")
- t := ResolveTargetName(tName)
- if t != nil {
- cli.NewtUsage(cmd, util.NewNewtError(
- "Target already exists; cannot create target with same name."))
+ if GetTargets()[pkgName] != nil {
+ cli.NewtUsage(cmd, util.NewNewtError("Target already exists: "+
+ pkgName))
}
repo := project.GetProject().LocalRepo()
- pack := pkg.NewLocalPackage(repo, repo.Path()+"/"+tName)
- pack.SetName(tName)
+ pack := pkg.NewLocalPackage(repo, repo.Path()+"/"+pkgName)
+ pack.SetName(pkgName)
pack.SetType(pkg.PACKAGE_TYPE_TARGET)
- t = NewTarget(pack)
- err := t.Save()
+ t := NewTarget(pack)
+ err = t.Save()
if err != nil {
cli.NewtUsage(nil, err)
} else {
util.StatusMessage(util.VERBOSITY_DEFAULT,
- "Target %s successfully created!\n", tName)
+ "Target %s successfully created!\n", pkgName)
}
}
@@ -226,7 +232,7 @@ func targetDelOne(t *Target) error {
}
util.StatusMessage(util.VERBOSITY_DEFAULT,
- "Target %s successfully removed\n", t.FullName())
+ "Target %s successfully deleted.\n", t.FullName())
return nil
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/7a3d6913/newt/target/vars.go
----------------------------------------------------------------------
diff --git a/newt/target/vars.go b/newt/target/vars.go
index 71f4bed..5b29b41 100644
--- a/newt/target/vars.go
+++ b/newt/target/vars.go
@@ -24,6 +24,7 @@ import (
"path/filepath"
"strings"
+ "mynewt.apache.org/newt/newt/cli"
. "mynewt.apache.org/newt/newt/interfaces"
"mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/project"
@@ -51,8 +52,10 @@ func varsFromChildDirs(key string, fullPath bool) ([]string, error) {
project.GetProject().Path()+"/")
}
if strings.HasPrefix(value, repo.REPOS_DIR+"/") {
- value = "@" +
- strings.TrimPrefix(value, repo.REPOS_DIR+"/")
+ parts := strings.SplitN(value, "/", 2)
+ if len(parts) > 1 {
+ value = cli.BuildPackageString(parts[0], parts[1])
+ }
}
valueSlice = append(valueSlice, value)
}
[49/50] incubator-mynewt-newt git commit: os error for opening the
file already has filename. Don't repeat it.
Posted by ma...@apache.org.
os error for opening the file already has filename. Don't repeat it.
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/7671e5ed
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/7671e5ed
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/7671e5ed
Branch: refs/heads/develop
Commit: 7671e5ed91f4d29805b69b4273f7dd8b50f5d7f7
Parents: e5eaa6a
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Mar 9 09:59:59 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Mar 9 10:02:33 2016 -0800
----------------------------------------------------------------------
newt/image/image.go | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/7671e5ed/newt/image/image.go
----------------------------------------------------------------------
diff --git a/newt/image/image.go b/newt/image/image.go
index 7aba96f..fe76540 100644
--- a/newt/image/image.go
+++ b/newt/image/image.go
@@ -177,14 +177,14 @@ func (image *Image) SetVersion(versStr string) error {
func (image *Image) Generate() error {
binFile, err := os.Open(image.sourceBin)
if err != nil {
- return util.NewNewtError(fmt.Sprintf("Can't open target binary %s: %s",
- image.sourceBin, err.Error()))
+ return util.NewNewtError(fmt.Sprintf("Can't open app binary: %s",
+ err.Error()))
}
defer binFile.Close()
binInfo, err := binFile.Stat()
if err != nil {
- return util.NewNewtError(fmt.Sprintf("Can't stat target binary %s: %s",
+ return util.NewNewtError(fmt.Sprintf("Can't stat app binary %s: %s",
image.sourceBin, err.Error()))
}
[02/50] incubator-mynewt-newt git commit: Clean up bin / obj
directories.
Posted by ma...@apache.org.
Clean up bin / obj directories.
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/0a68684d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/0a68684d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/0a68684d
Branch: refs/heads/develop
Commit: 0a68684de0c5fad056083bcbc7ae70568ddfb11e
Parents: 58967ec
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Mar 7 16:17:03 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Mar 7 17:04:31 2016 -0800
----------------------------------------------------------------------
newt/builder/build.go | 96 ++++++++---------------------------------
newt/target/target.go | 9 ++++
newt/toolchain/compiler.go | 47 +++++++++-----------
newt/toolchain/deps.go | 20 +++------
4 files changed, 55 insertions(+), 117 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0a68684d/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 83e59b4..11221b6 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -21,12 +21,12 @@ package builder
import (
"bytes"
- "io/ioutil"
"os"
"path/filepath"
"mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/newt/pkg"
+ "mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/newt/target"
"mynewt.apache.org/newt/newt/toolchain"
"mynewt.apache.org/newt/util"
@@ -190,11 +190,17 @@ func buildDir(srcDir string, c *toolchain.Compiler, t *target.Target,
return nil
}
+func (b *Builder) binDir() string {
+ return project.GetProject().Path() + "/bin/" + b.target.ShortName()
+}
+
+func (b *Builder) pkgBinDir(pkgName string) string {
+ return b.binDir() + "/" + pkgName
+}
+
// Generates the path+filename of the specified package's .a file.
func (b *Builder) archivePath(bpkg *BuildPackage) string {
- binDir := bpkg.BasePath() + "/bin/" + b.target.Package().Name()
- archiveFile := binDir + "/lib" + filepath.Base(bpkg.Name()) + ".a"
- return archiveFile
+ return b.pkgBinDir(bpkg.Name()) + "/" + filepath.Base(bpkg.Name()) + ".a"
}
func (b *Builder) elfPath() string {
@@ -203,8 +209,8 @@ func (b *Builder) elfPath() string {
return ""
}
- return appPkg.BasePath() + "/bin/" + b.target.Package().Name() + "/" +
- appPkg.Name() + ".elf"
+ return b.pkgBinDir(appPkg.Name()) + "/" +
+ filepath.Base(appPkg.Name()) + ".elf"
}
// Compiles and archives a package.
@@ -218,8 +224,7 @@ func (b *Builder) buildPackage(bpkg *BuildPackage,
}
c, err := toolchain.NewCompiler(compilerPkg.BasePath(),
- "default", // XXX
- b.target.Package().Name())
+ b.pkgBinDir(bpkg.Name()), "default") // XXX Use correct compiler def
if err != nil {
return err
}
@@ -262,8 +267,7 @@ func (b *Builder) linkApp(baseCi *toolchain.CompilerInfo,
compilerPkg *pkg.LocalPackage) error {
c, err := toolchain.NewCompiler(compilerPkg.BasePath(),
- "default", // XXX
- b.target.Package().Name())
+ b.pkgBinDir(b.target.App().Name()), "default") // XXX
if err != nil {
return err
}
@@ -346,75 +350,11 @@ func (b *Builder) Build() error {
return nil
}
-func cleanTree(rootPath string, tName string) error {
- // Find all the subdirectories of path that contain an "obj/" directory,
- // and remove that directory either altogether, or just the arch specific
- // directory.
- dirList, err := ioutil.ReadDir(rootPath)
- if err != nil {
- return util.NewNewtError(err.Error())
- }
-
- for _, node := range dirList {
- if node.IsDir() {
- if node.Name() == "obj" || node.Name() == "bin" {
- fullPath := filepath.Clean(rootPath + "/" + node.Name() + "/" +
- tName + "/")
- cli.StatusMessage(util.VERBOSITY_VERBOSE,
- "Cleaning directory %s\n", fullPath)
- os.RemoveAll(fullPath)
- } else {
- // recurse into the directory.
- err = cleanTree(rootPath+"/"+node.Name(), tName)
- if err != nil {
- return err
- }
- }
- }
- }
-
- return nil
-}
-
func (b *Builder) Clean() error {
- bspPkg := b.target.Bsp()
- if bspPkg != nil {
- b.AddPackage(bspPkg)
- }
-
- appPkg := b.target.App()
- if appPkg != nil {
- b.AddPackage(appPkg)
- }
-
- compilerPkg := b.target.Compiler()
- if compilerPkg != nil {
- b.AddPackage(compilerPkg)
- }
-
- if err := b.loadDeps(); err != nil {
- return err
- }
-
- for _, bpkg := range b.Packages {
- err := cleanTree(bpkg.BasePath(), b.target.Package().Name())
- if err != nil {
- return err
- }
- }
-
- binPath := b.elfPath()
- if binPath != "" {
- binDir := filepath.Dir(binPath)
- cli.StatusMessage(util.VERBOSITY_VERBOSE, "Cleaning directory %s\n",
- binDir)
- err := os.RemoveAll(binDir)
- if err != nil {
- return err
- }
- }
-
- return nil
+ path := b.binDir()
+ cli.StatusMessage(util.VERBOSITY_VERBOSE, "Cleaning directory %s\n", path)
+ err := os.RemoveAll(path)
+ return err
}
func (b *Builder) Init(target *target.Target) error {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0a68684d/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index a2113e3..3b6dfc6 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -22,6 +22,7 @@ package target
import (
"io/ioutil"
"os"
+ "path/filepath"
"sort"
"strings"
@@ -96,6 +97,14 @@ func (target *Target) Package() *pkg.LocalPackage {
return target.basePkg
}
+func (target *Target) Name() string {
+ return target.basePkg.Name()
+}
+
+func (target *Target) ShortName() string {
+ return filepath.Base(target.Name())
+}
+
func (target *Target) Compiler() *pkg.LocalPackage {
dep, _ := pkg.NewDependency(nil, target.CompilerName)
mypkg := project.GetProject().ResolveDependency(dep).(*pkg.LocalPackage)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0a68684d/newt/toolchain/compiler.go
----------------------------------------------------------------------
diff --git a/newt/toolchain/compiler.go b/newt/toolchain/compiler.go
index 3a3571a..cb3017c 100644
--- a/newt/toolchain/compiler.go
+++ b/newt/toolchain/compiler.go
@@ -46,7 +46,6 @@ type CompilerInfo struct {
}
type Compiler struct {
- TargetName string
ObjPathList map[string]bool
LinkerScript string
@@ -59,6 +58,7 @@ type Compiler struct {
ocPath string
ldResolveCircularDeps bool
ldMapFile bool
+ dstDir string
info CompilerInfo
}
@@ -80,18 +80,18 @@ func (ci *CompilerInfo) AddCompilerInfo(newCi *CompilerInfo) {
ci.Aflags = append(ci.Aflags, newCi.Aflags...)
}
-func NewCompiler(compilerDir string, cDef string,
- tName string) (*Compiler, error) {
+func NewCompiler(compilerDir string, dstDir string,
+ cDef string) (*Compiler, error) {
c := &Compiler{
- TargetName: tName,
ObjPathList: map[string]bool{},
+ dstDir: filepath.Clean(dstDir),
}
c.depTracker = NewDepTracker(c)
cli.StatusMessage(cli.VERBOSITY_VERBOSE,
- "Loading compiler %s, target %s, def %s\n", compilerDir, tName, cDef)
+ "Loading compiler %s, def %s\n", compilerDir, cDef)
err := c.load(compilerDir, cDef)
if err != nil {
return nil, err
@@ -137,6 +137,10 @@ func (c *Compiler) AddInfo(info *CompilerInfo) {
c.info.AddCompilerInfo(info)
}
+func (c *Compiler) DstDir() string {
+ return c.dstDir
+}
+
// Skips compilation of the specified C or assembly file, but adds the name of
// the object file that would have been generated to the compiler's list of
// object files. This function is used when the object file is already up to
@@ -144,10 +148,8 @@ func (c *Compiler) AddInfo(info *CompilerInfo) {
// still be remembered so that it gets linked in to the final library or
// executable.
func (c *Compiler) SkipSourceFile(srcFile string) error {
- wd, _ := os.Getwd()
- objDir := wd + "/obj/" + c.TargetName + "/"
- objFile := objDir + strings.TrimSuffix(srcFile, filepath.Ext(srcFile)) +
- ".o"
+ objFile := c.dstDir + "/" +
+ strings.TrimSuffix(srcFile, filepath.Ext(srcFile)) + ".o"
c.ObjPathList[filepath.ToSlash(objFile)] = true
// Update the dependency tracker with the object file's modification time.
@@ -192,10 +194,8 @@ func (c *Compiler) lflagsString() string {
func (c *Compiler) CompileFileCmd(file string,
compilerType int) (string, error) {
- wd, _ := os.Getwd()
- objDir := wd + "/obj/" + c.TargetName + "/"
objFile := strings.TrimSuffix(file, filepath.Ext(file)) + ".o"
- objPath := filepath.ToSlash(objDir + objFile)
+ objPath := filepath.ToSlash(c.dstDir + "/" + objFile)
var cmd string
@@ -218,14 +218,12 @@ func (c *Compiler) CompileFileCmd(file string,
//
// @param file The name of the source file.
func (c *Compiler) GenDepsForFile(file string) error {
- wd, _ := os.Getwd()
- objDir := wd + "/obj/" + c.TargetName + "/"
-
- if cli.NodeNotExist(objDir) {
- os.MkdirAll(objDir, 0755)
+ if cli.NodeNotExist(c.dstDir) {
+ os.MkdirAll(c.dstDir, 0755)
}
- depFile := objDir + strings.TrimSuffix(file, filepath.Ext(file)) + ".d"
+ depFile := c.dstDir + "/" +
+ strings.TrimSuffix(file, filepath.Ext(file)) + ".d"
depFile = filepath.ToSlash(depFile)
var cmd string
@@ -263,16 +261,13 @@ func writeCommandFile(dstFile string, cmd string) error {
// @param file The filename of the source file to compile.
// @param compilerType One of the COMPILER_TYPE_[...] constants.
func (c *Compiler) CompileFile(file string, compilerType int) error {
- wd, _ := os.Getwd()
- objDir := wd + "/obj/" + c.TargetName + "/"
-
- if cli.NodeNotExist(objDir) {
- os.MkdirAll(objDir, 0755)
+ if cli.NodeNotExist(c.dstDir) {
+ os.MkdirAll(c.dstDir, 0755)
}
objFile := strings.TrimSuffix(file, filepath.Ext(file)) + ".o"
- objPath := objDir + objFile
+ objPath := c.dstDir + "/" + objFile
c.ObjPathList[filepath.ToSlash(objPath)] = true
cmd, err := c.CompileFileCmd(file, compilerType)
@@ -418,9 +413,9 @@ func (c *Compiler) RecursiveCompile(cType int, ignDirs []string) error {
}
switch cType {
- case 0:
+ case COMPILER_TYPE_C:
return c.CompileC()
- case 1:
+ case COMPILER_TYPE_ASM:
return c.CompileAs()
default:
return NewNewtError("Wrong compiler type specified to RecursiveCompile")
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0a68684d/newt/toolchain/deps.go
----------------------------------------------------------------------
diff --git a/newt/toolchain/deps.go b/newt/toolchain/deps.go
index b2ddc06..01e74de 100644
--- a/newt/toolchain/deps.go
+++ b/newt/toolchain/deps.go
@@ -22,7 +22,6 @@ package toolchain
import (
"bytes"
"io/ioutil"
- "os"
"path/filepath"
"strings"
"time"
@@ -115,11 +114,7 @@ func commandHasChanged(dstFile string, cmd string) bool {
return true
}
- rc := bytes.Compare(prevCmd, []byte(cmd)) != 0
- if rc {
- cli.StatusMessage(util.VERBOSITY_VERBOSE, "oldcmd=%s\nnewcmd=%s\n", prevCmd, cmd)
- }
- return rc
+ return bytes.Compare(prevCmd, []byte(cmd)) != 0
}
// Determines if the specified C or assembly file needs to be built. A compile
@@ -132,13 +127,11 @@ func commandHasChanged(dstFile string, cmd string) bool {
// the object file.
func (tracker *DepTracker) CompileRequired(srcFile string,
compilerType int) (bool, error) {
- wd, _ := os.Getwd()
- objDir := wd + "/obj/" + tracker.compiler.TargetName + "/"
- objFile := objDir + strings.TrimSuffix(srcFile, filepath.Ext(srcFile)) +
- ".o"
- depFile := objDir + strings.TrimSuffix(srcFile, filepath.Ext(srcFile)) +
- ".d"
+ objFile := tracker.compiler.DstDir() + "/" +
+ strings.TrimSuffix(srcFile, filepath.Ext(srcFile)) + ".o"
+ depFile := tracker.compiler.DstDir() + "/" +
+ strings.TrimSuffix(srcFile, filepath.Ext(srcFile)) + ".d"
// If the object was previously built with a different set of options, a
// rebuild is necessary.
@@ -165,7 +158,8 @@ func (tracker *DepTracker) CompileRequired(srcFile string,
// If the object doesn't exist or is older than the source file, a build is
// required; no need to check dependencies.
if srcModTime.After(objModTime) {
- cli.StatusMessage(util.VERBOSITY_VERBOSE, "%s - rebuild required; source newer than obj\n", srcFile)
+ cli.StatusMessage(util.VERBOSITY_VERBOSE, "%s - rebuild required; "+
+ "source newer than obj\n", srcFile)
return true, nil
}
[28/50] incubator-mynewt-newt git commit: Fix valid app list for
"newt target set <...> app"
Posted by ma...@apache.org.
Fix valid app list for "newt target set <...> app"
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/f3842f09
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/f3842f09
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/f3842f09
Branch: refs/heads/develop
Commit: f3842f09a9dad8a35f6d837944ccdcf2f6a338dc
Parents: dc1e947
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 16:38:32 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 17:35:02 2016 -0800
----------------------------------------------------------------------
newt/interfaces/interfaces.go | 2 ++
newt/pkg/localpackage.go | 9 +++++++++
newt/pkg/package.go | 16 +++++++++------
newt/project/project.go | 15 ++++++++++++++
newt/repo/repo.go | 4 ++++
newt/target/target.go | 25 +++++++++++-------------
newt/target/vars.go | 40 +++++++++++++++++++++++++++-----------
7 files changed, 80 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f3842f09/newt/interfaces/interfaces.go
----------------------------------------------------------------------
diff --git a/newt/interfaces/interfaces.go b/newt/interfaces/interfaces.go
index 16cd3c6..56b5cba 100644
--- a/newt/interfaces/interfaces.go
+++ b/newt/interfaces/interfaces.go
@@ -21,6 +21,7 @@ package interfaces
type PackageInterface interface {
Name() string
+ FullName() string
Repo() RepoInterface
Type() PackageType
}
@@ -29,6 +30,7 @@ type PackageType int
type RepoInterface interface {
Name() string
+ IsLocal() bool
}
type VersionReqInterface interface {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f3842f09/newt/pkg/localpackage.go
----------------------------------------------------------------------
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index 1738b4c..9f14561 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -80,6 +80,15 @@ func (pkg *LocalPackage) Name() string {
return pkg.name
}
+func (pkg *LocalPackage) FullName() string {
+ r := pkg.Repo()
+ if r.IsLocal() {
+ return pkg.Name()
+ } else {
+ return "@" + r.Name() + "/" + pkg.Name()
+ }
+}
+
func (pkg *LocalPackage) BasePath() string {
return pkg.basePath
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f3842f09/newt/pkg/package.go
----------------------------------------------------------------------
diff --git a/newt/pkg/package.go b/newt/pkg/package.go
index 38be9f4..7b30f69 100644
--- a/newt/pkg/package.go
+++ b/newt/pkg/package.go
@@ -34,17 +34,19 @@ const (
)
const (
- PACKAGE_TYPE_LIB interfaces.PackageType = iota
+ PACKAGE_TYPE_APP interfaces.PackageType = iota
PACKAGE_TYPE_BSP
+ PACKAGE_TYPE_COMPILER
+ PACKAGE_TYPE_LIB
PACKAGE_TYPE_TARGET
- PACKAGE_TYPE_APP
)
var PackageTypeNames = map[interfaces.PackageType]string{
- PACKAGE_TYPE_LIB: "lib",
- PACKAGE_TYPE_BSP: "bsp",
- PACKAGE_TYPE_APP: "app",
- PACKAGE_TYPE_TARGET: "target",
+ PACKAGE_TYPE_APP: "app",
+ PACKAGE_TYPE_BSP: "bsp",
+ PACKAGE_TYPE_COMPILER: "compiler",
+ PACKAGE_TYPE_LIB: "lib",
+ PACKAGE_TYPE_TARGET: "target",
}
// An interface, representing information about a Package
@@ -59,6 +61,8 @@ type Package interface {
Repo() *repo.Repo
// The name of this package
Name() string
+ // The full name of this package, including repo
+ FullName() string
// The type of package (lib, target, bsp, etc.)
Type() interfaces.PackageType
// Hash of the contents of the package
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f3842f09/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index a53fd06..990ba51 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -382,6 +382,21 @@ func (proj *Project) PackageList() interfaces.PackageList {
return proj.packages
}
+func (proj *Project) PackagesOfType(pkgType interfaces.PackageType) []interfaces.PackageInterface {
+ matches := []interfaces.PackageInterface{}
+
+ packs := proj.PackageList()
+ for _, packHash := range packs {
+ for _, pack := range *packHash {
+ if pack.Type() == pkgType {
+ matches = append(matches, pack)
+ }
+ }
+ }
+
+ return matches
+}
+
func LoadProject(dir string) (*Project, error) {
projDir, err := findProjectDir(dir)
if err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f3842f09/newt/repo/repo.go
----------------------------------------------------------------------
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index 0419e38..93fd31a 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -158,6 +158,10 @@ func (r *Repo) Path() string {
return r.localPath
}
+func (r *Repo) IsLocal() bool {
+ return r.name == REPO_NAME_LOCAL
+}
+
func (r *Repo) VersionRequirements() []interfaces.VersionReqInterface {
return r.versreq
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f3842f09/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 90b7afa..7b79176 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -211,20 +211,17 @@ func (t *Target) Delete() error {
func buildTargetMap() error {
globalTargetMap = map[string]*Target{}
- packs := project.GetProject().PackageList()
- for _, packHash := range packs {
- for name, pack := range *packHash {
- if pack.Type() == pkg.PACKAGE_TYPE_TARGET {
- target, err := LoadTarget(pack.(*pkg.LocalPackage))
- if err != nil {
- nerr := err.(*util.NewtError)
- cli.ErrorMessage(cli.VERBOSITY_QUIET,
- "Warning: failed to load target \"%s\": %s\n", name,
- nerr.Text)
- } else {
- globalTargetMap[name] = target
- }
- }
+ packs := project.GetProject().PackagesOfType(pkg.PACKAGE_TYPE_TARGET)
+ for _, packItf := range packs {
+ pack := packItf.(*pkg.LocalPackage)
+ target, err := LoadTarget(pack)
+ if err != nil {
+ nerr := err.(*util.NewtError)
+ cli.ErrorMessage(cli.VERBOSITY_QUIET,
+ "Warning: failed to load target \"%s\": %s\n", pack.Name,
+ nerr.Text)
+ } else {
+ globalTargetMap[pack.Name()] = target
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f3842f09/newt/target/vars.go
----------------------------------------------------------------------
diff --git a/newt/target/vars.go b/newt/target/vars.go
index fee7bcf..a4b1cac 100644
--- a/newt/target/vars.go
+++ b/newt/target/vars.go
@@ -21,9 +21,12 @@ package target
import (
"fmt"
+ "path/filepath"
"strings"
"mynewt.apache.org/newt/newt/cli"
+ . "mynewt.apache.org/newt/newt/interfaces"
+ "mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/newt/repo"
"mynewt.apache.org/newt/util"
@@ -37,17 +40,20 @@ func varsFromChildDirs(key string, fullPath bool) ([]string, error) {
for _, r := range repos {
for _, pkgDir := range searchDirs {
pkgBaseDir := r.Path() + "/" + pkgDir
- values, err := cli.DescendantDirsOfParent(pkgBaseDir, key, fullPath)
+ values, err := cli.DescendantDirsOfParent(pkgBaseDir, key,
+ fullPath)
if err != nil {
return nil, util.NewNewtError(err.Error())
}
for _, value := range values {
if fullPath {
- value = strings.TrimPrefix(value, project.GetProject().Path()+"/")
+ value = strings.TrimPrefix(value,
+ project.GetProject().Path()+"/")
}
if strings.HasPrefix(value, repo.REPOS_DIR+"/") {
- value = "$" + strings.TrimPrefix(value, repo.REPOS_DIR+"/")
+ value = "@" +
+ strings.TrimPrefix(value, repo.REPOS_DIR+"/")
}
valueSlice = append(valueSlice, value)
}
@@ -57,21 +63,33 @@ func varsFromChildDirs(key string, fullPath bool) ([]string, error) {
return cli.SortFields(valueSlice...), nil
}
+func varsFromPackageType(pt PackageType, fullPath bool) ([]string, error) {
+ values := []string{}
+
+ packs := project.GetProject().PackagesOfType(pt)
+ for _, pack := range packs {
+ value := pack.FullName()
+ if !fullPath {
+ value = filepath.Base(value)
+ }
+
+ values = append(values, value)
+ }
+
+ return values, nil
+}
+
var varsMap = map[string]func() ([]string, error){
- "arch": func() ([]string, error) {
+ "target.arch": func() ([]string, error) {
return varsFromChildDirs("arch", false)
},
- "bsp": func() ([]string, error) {
+ "target.bsp": func() ([]string, error) {
return varsFromChildDirs("bsp", true)
},
- "compiler": func() ([]string, error) {
- return varsFromChildDirs("compiler", true)
- },
-
- "project": func() ([]string, error) {
- return varsFromChildDirs("project", true)
+ "target.app": func() ([]string, error) {
+ return varsFromPackageType(pkg.PACKAGE_TYPE_APP, true)
},
}
[32/50] incubator-mynewt-newt git commit: Create manifest.json during
create-image.
Posted by ma...@apache.org.
Create manifest.json during create-image.
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/57cb34a4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/57cb34a4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/57cb34a4
Branch: refs/heads/develop
Commit: 57cb34a4a82ba8b465b32d490a0a4999a68d24b1
Parents: 35e2e6f
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Mar 8 18:00:33 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Mar 8 18:01:34 2016 -0800
----------------------------------------------------------------------
newt/builder/buildutil.go | 5 +++++
newt/image/cmds.go | 9 +++++++++
newt/image/image.go | 24 +++++++++++-------------
3 files changed, 25 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/57cb34a4/newt/builder/buildutil.go
----------------------------------------------------------------------
diff --git a/newt/builder/buildutil.go b/newt/builder/buildutil.go
index 83ed623..2654477 100644
--- a/newt/builder/buildutil.go
+++ b/newt/builder/buildutil.go
@@ -51,6 +51,11 @@ func (b *Builder) AppImgPath() string {
return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".img"
}
+func (b *Builder) AppPath() string {
+ pkgName := b.target.App().Name()
+ return b.pkgBinDir(pkgName) + "/"
+}
+
func (b *Builder) appBinBasePath() string {
pkgName := b.target.App().Name()
return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/57cb34a4/newt/image/cmds.go
----------------------------------------------------------------------
diff --git a/newt/image/cmds.go b/newt/image/cmds.go
index 1ced272..1d12f20 100644
--- a/newt/image/cmds.go
+++ b/newt/image/cmds.go
@@ -67,6 +67,15 @@ func createImageRunCmd(cmd *cobra.Command, args []string) {
if err != nil {
fmt.Println(err)
}
+
+ err = image.CreateManifest(t)
+ if err != nil {
+ fmt.Println(err)
+ }
+ cli.StatusMessage(cli.VERBOSITY_DEFAULT, "App image succesfully generated: %s\n",
+ image.targetImg)
+ cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Build manifest: %s\n",
+ image.manifestFile)
}
func AddCommands(cmd *cobra.Command) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/57cb34a4/newt/image/image.go
----------------------------------------------------------------------
diff --git a/newt/image/image.go b/newt/image/image.go
index 6c0dfdb..7aba96f 100644
--- a/newt/image/image.go
+++ b/newt/image/image.go
@@ -47,12 +47,11 @@ type ImageVersion struct {
}
type Image struct {
- target *builder.Builder
builder *builder.Builder
sourceBin string
targetImg string
- ManifestFile string
+ manifestFile string
version ImageVersion
hash []byte
}
@@ -110,15 +109,16 @@ type ImageManifest struct {
type ImageManifestPkg struct {
Name string `json:"name"`
- Version string `json:"version,omitempty"`
- Hash string `json:"hash"`
}
func NewImage(b *builder.Builder) (*Image, error) {
- image := &Image{}
+ image := &Image{
+ builder: b,
+ }
image.sourceBin = b.AppElfPath() + ".bin"
image.targetImg = b.AppImgPath()
+ image.manifestFile = b.AppPath() + "manifest.json"
return image, nil
}
@@ -287,16 +287,14 @@ func (image *Image) CreateManifest(t *target.Target) error {
Image: filepath.Base(image.targetImg),
Date: timeStr,
}
-/*
- for _, builtPkg := range BuiltPkgs {
+
+ for _, builtPkg := range image.builder.Packages {
imgPkg := &ImageManifestPkg{
- Name: builtPkg.Name,
- Version: builtPkg.Version,
- Hash: builtPkg.Hash,
+ Name: builtPkg.Name(),
}
manifest.Pkgs = append(manifest.Pkgs, imgPkg)
}
-*/
+
vars := t.Vars
var keys []string
for k := range vars {
@@ -306,10 +304,10 @@ func (image *Image) CreateManifest(t *target.Target) error {
for _, k := range keys {
manifest.TgtVars = append(manifest.TgtVars, k+"="+vars[k])
}
- file, err := os.Create(image.ManifestFile)
+ file, err := os.Create(image.manifestFile)
if err != nil {
return util.NewNewtError(fmt.Sprintf("Cannot create manifest file %s: %s",
- image.ManifestFile, err.Error()))
+ image.manifestFile, err.Error()))
}
defer file.Close()
[34/50] incubator-mynewt-newt git commit: refactor of the install
code to make it a bit more maintainable. still needs work,
as it was written quite quickly.
Posted by ma...@apache.org.
refactor of the install code to make it a bit more maintainable. still needs work, as it was written quite quickly.
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/37bd71fb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/37bd71fb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/37bd71fb
Branch: refs/heads/develop
Commit: 37bd71fb9c1594d20ac876931420d532e66628bf
Parents: 35e2e6f
Author: Sterling Hughes <st...@apache.org>
Authored: Tue Mar 8 19:16:42 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Mar 8 19:16:42 2016 -0800
----------------------------------------------------------------------
newt/project/project.go | 189 +++++++++++++++++++++++++++----------------
newt/repo/repo.go | 30 ++++++-
2 files changed, 145 insertions(+), 74 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/37bd71fb/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index 990ba51..1967481 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -139,99 +139,146 @@ func (proj *Project) PackageSearchDirs() []string {
return proj.packageSearchDirs
}
-func (proj *Project) Install(upgrade bool, force bool) error {
- repoList := proj.Repos()
- for rname, r := range repoList {
- // Ignore the local repo on install
- if rname == repo.REPO_NAME_LOCAL {
- continue
- }
- // Download repository description. Try and resolve this
- // repository out of the repo list (repodesc for each repo.)
- // If matching repository is found, then prompt for install and install
- // that repository.
- if err := r.DownloadDesc(); err != nil {
- return err
- }
+func (proj *Project) upgradeCheck(r *repo.Repo, vers *repo.Version,
+ upgrade bool, force bool) (bool, error) {
+ rdesc, err := r.GetRepoDesc()
+ if err != nil {
+ return false, err
+ }
- rdesc, err := r.ReadDesc()
- if err != nil {
- return err
+ if !upgrade {
+ cli.StatusMessage(cli.VERBOSITY_DEFAULT,
+ fmt.Sprintf("Installed repository %s has version %s, "+
+ "which meets project requirements. Moving on to next repository.\n",
+ r.Name(), vers))
+ return true, nil
+ } else {
+ _, newVers, _ := rdesc.Match(r)
+ if newVers == nil {
+ cli.StatusMessage(cli.VERBOSITY_DEFAULT,
+ "No matching version to upgrade to "+
+ "found for %s. Please check your project requirements, and use the "+
+ "project show-repo command to see available repository versions.",
+ r.Name())
+ return false, util.NewNewtError(fmt.Sprintf("Cannot find a "+
+ "version of repository %s that matches project requirements.",
+ r.Name()))
}
- vers := proj.projState.GetInstalledVersion(rname)
- if vers != nil {
- ok := rdesc.SatisfiesVersion(vers, r.VersionRequirements())
- if !ok && !upgrade {
- fmt.Printf("WARNING: Installed version %s of repository %s "+
- "does not match desired versions %s in project\n",
- vers, rname, r.VersionRequirementsString())
- continue
- }
+ // If the change between the old repository and the new repository would cause
+ // and upgrade. Then prompt for an upgrade response, unless the force option
+ // is present.
+ if vers.CompareVersions(newVers, vers) != 0 ||
+ vers.Stability() != newVers.Stability() {
+ if !force {
+ branch, newVers, _ := rdesc.Match(r)
+
+ str := ""
+ if newVers.Stability() != repo.VERSION_STABILITY_NONE {
+ str += "(" + branch + ")"
+ }
+
+ fmt.Printf("Would you like to upgrade repository %s from %s to %s %s? [Yn] ",
+ r.Name(), vers.String(), newVers.String(), str)
- if !upgrade {
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- fmt.Sprintf("Installed repository %s matches project requirements, "+
- "moving on to next repository.\n", r.Name()))
- continue
- } else {
- _, newVers, _ := rdesc.Match(r)
- if newVers == nil {
- return util.NewNewtError(fmt.Sprintf(
- "No matching version for repository %s\n", r.Name()))
+ line, more, err := bufio.NewReader(os.Stdin).ReadLine()
+ if more || err != nil {
+ return false, util.NewNewtError(fmt.Sprintf(
+ "Couldn't read upgrade response: %s\n", err.Error()))
}
- if vers.CompareVersions(newVers, vers) != 0 ||
- vers.Stability() != newVers.Stability() {
- // Prompt for upgrade, unless force option present
- if !force {
- branch, newVers, _ := rdesc.Match(r)
-
- str := ""
- if newVers.Stability() != repo.VERSION_STABILITY_NONE {
- str += "(" + branch + ")"
- }
-
- fmt.Printf("Would you like to upgrade repository %s from %s to %s %s? [Yn] ",
- r.Name(), vers.String(), newVers.String(), str)
-
- line, more, err := bufio.NewReader(os.Stdin).ReadLine()
- if more || err != nil {
- return util.NewNewtError(fmt.Sprintf(
- "Couldn't read upgrade response: %s\n", err.Error()))
- }
- answer := strings.ToUpper(strings.Trim(string(line), " "))
- if answer == "N" || answer == "NO" {
- fmt.Printf("Users says don't upgrade, skipping upgrade of %s\n",
- r.Name())
- continue
- }
-
- }
- } else {
- fmt.Printf("Repository %s doesn't need to be upgraded, latest "+
- "version installed.\n", r.Name())
- continue
+ // Anything but no means yes.
+ answer := strings.ToUpper(strings.Trim(string(line), " "))
+ if answer == "N" || answer == "NO" {
+ fmt.Printf("Users says don't upgrade, skipping upgrade of %s\n",
+ r.Name())
+ return true, nil
}
}
+ } else {
+ cli.StatusMessage(cli.VERBOSITY_DEFAULT,
+ "Repository %s doesn't need to be upgraded, latest "+
+ "version installed.\n", r.Name())
+ return true, nil
}
+ }
+
+ return false, nil
+}
+func (proj *Project) checkVersionRequirements(r *repo.Repo, upgrade bool, force bool) (bool, error) {
+ rdesc, err := r.GetRepoDesc()
+ if err != nil {
+ return false, err
+ }
+
+ rname := r.Name()
+
+ vers := proj.projState.GetInstalledVersion(rname)
+ if vers != nil {
+ ok := rdesc.SatisfiesVersion(vers, r.VersionRequirements())
+ if !ok && !upgrade {
+ cli.StatusMessage(cli.VERBOSITY_DEFAULT, "WARNING: Installed"+
+ "version %s of repository %s does not match desired "+
+ "version %s in project file. You can fix this by either upgrading"+
+ " your repository, or modifying the project.yml file.\n",
+ vers, rname, r.VersionRequirementsString())
+ return true, err
+ } else {
+ skip, err := proj.upgradeCheck(r, vers, upgrade, force)
+ return skip, err
+ }
+ } else {
+ // Fallthrough and perform the installation.
+ // Check to make sure that this repository contains a version
+ // that can satisfy.
_, _, ok := rdesc.Match(r)
if !ok {
fmt.Printf("WARNING: No matching repository version found for repository "+
- "%s specified in project, skipping...\n", r.Name())
+ "%s specified in project. To find available versions for a repository"+
+ " issue the project show-repo command.\n", r.Name())
+ return true, err
+ }
+ }
+
+ return false, nil
+}
+
+func (proj *Project) Install(upgrade bool, force bool) error {
+ repoList := proj.Repos()
+
+ for rname, r := range repoList {
+ // Ignore the local repo on install
+ if rname == repo.REPO_NAME_LOCAL {
continue
}
+ // First thing we do is update repository description. This
+ // will get us available branches and versions in the repository.
+ if err := r.UpdateDesc(); err != nil {
+ return err
+ }
- rvers, err := r.Install(rdesc, upgrade || force)
+ // Check the version requirements on this repository, and see
+ // whether or not we need to install/upgrade it.
+ skip, err := proj.checkVersionRequirements(r, upgrade, force)
if err != nil {
return err
}
+ if skip {
+ continue
+ }
- if rvers != nil {
- proj.projState.Replace(rname, rvers)
+ // Do the hard work of actually copying and installing the repository.
+ rvers, err := r.Install(upgrade || force)
+ if err != nil {
+ return err
}
+
+ // Update the project state with the new repository version information.
+ proj.projState.Replace(rname, rvers)
}
+ // Save the project state, including any updates or changes to the project
+ // information that either install or upgrade caused.
if err := proj.projState.Save(); err != nil {
return err
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/37bd71fb/newt/repo/repo.go
----------------------------------------------------------------------
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index 93fd31a..a41a0b7 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -150,6 +150,16 @@ func NewRepoDesc(name string, versBranchMap map[string]string) (*RepoDesc, error
return rd, nil
}
+func (r *Repo) GetRepoDesc() (*RepoDesc, error) {
+ if r.rdesc == nil {
+ return nil, util.NewNewtError(fmt.Sprintf(
+ "Repository description for %s not yet initailized. Must "+
+ "download it first. ", r.Name()))
+ } else {
+ return r.rdesc, nil
+ }
+}
+
func (r *Repo) Name() string {
return r.name
}
@@ -180,7 +190,7 @@ func (r *Repo) repoFilePath() string {
".configs/" + r.name + "/"
}
-func (r *Repo) Install(rdesc *RepoDesc, force bool) (*Version, error) {
+func (r *Repo) Install(force bool) (*Version, error) {
// Copy the git repo into /repos/, error'ing out if the repo already exists
if cli.NodeExist(r.Path()) {
if force {
@@ -193,10 +203,10 @@ func (r *Repo) Install(rdesc *RepoDesc, force bool) (*Version, error) {
}
}
- branchName, vers, found := rdesc.Match(r)
+ branchName, vers, found := r.rdesc.Match(r)
if !found {
return nil, util.NewNewtError(fmt.Sprintf("No repository matching description %s found",
- rdesc.String()))
+ r.rdesc.String()))
}
dl := r.downloader
@@ -219,6 +229,20 @@ func (r *Repo) Install(rdesc *RepoDesc, force bool) (*Version, error) {
return vers, nil
}
+func (r *Repo) UpdateDesc() error {
+ var err error
+
+ if err = r.DownloadDesc(); err != nil {
+ return err
+ }
+
+ _, err = r.ReadDesc()
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
// Download the repository description.
func (r *Repo) DownloadDesc() error {
dl := r.downloader
[40/50] incubator-mynewt-newt git commit: Use NewtUsage() when
reporting errors.
Posted by ma...@apache.org.
Use NewtUsage() when reporting errors.
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/e9ff8773
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/e9ff8773
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/e9ff8773
Branch: refs/heads/develop
Commit: e9ff87735cfa47fddc084e1f4904e27a7b5304d3
Parents: f46ff31
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Mar 9 07:55:04 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Mar 9 07:55:04 2016 -0800
----------------------------------------------------------------------
newt/image/cmds.go | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e9ff8773/newt/image/cmds.go
----------------------------------------------------------------------
diff --git a/newt/image/cmds.go b/newt/image/cmds.go
index 0e1128c..d8f00b7 100644
--- a/newt/image/cmds.go
+++ b/newt/image/cmds.go
@@ -37,24 +37,24 @@ func createImageRunCmd(cmd *cobra.Command, args []string) {
targetName := args[0]
t := target.GetTargets()[targetName]
if t == nil {
- cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"))
+ cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"+targetName))
}
b, err := builder.NewBuilder(t)
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
return
}
err = b.PrepBuild()
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
return
}
image, err := NewImage(b)
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
return
}
@@ -65,12 +65,12 @@ func createImageRunCmd(cmd *cobra.Command, args []string) {
err = image.Generate()
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
}
err = image.CreateManifest(t)
if err != nil {
- fmt.Println(err)
+ cli.NewtUsage(cmd, err)
}
util.StatusMessage(util.VERBOSITY_DEFAULT, "App image succesfully generated: %s\n",
image.targetImg)
[47/50] incubator-mynewt-newt git commit: Print status message when
asked to download with BSP with no download script.
Posted by ma...@apache.org.
Print status message when asked to download with BSP with no
download script.
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/bdf361df
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/bdf361df
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/bdf361df
Branch: refs/heads/develop
Commit: bdf361df55bf9d8f317d565ccfbe6edc4ac2e8f7
Parents: 7671e5e
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Mar 9 10:00:36 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Mar 9 10:02:33 2016 -0800
----------------------------------------------------------------------
newt/builder/download.go | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/bdf361df/newt/builder/download.go
----------------------------------------------------------------------
diff --git a/newt/builder/download.go b/newt/builder/download.go
index 0cb0258..75d3639 100644
--- a/newt/builder/download.go
+++ b/newt/builder/download.go
@@ -45,6 +45,8 @@ func (b *Builder) Download() error {
/*
*
*/
+ util.StatusMessage(util.VERBOSITY_DEFAULT,
+ "No download script for BSP %s\n", b.Bsp.Name())
return nil
}
[15/50] incubator-mynewt-newt git commit: Allow "naked" target names
as arguements.
Posted by ma...@apache.org.
Allow "naked" target names as arguements.
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/19fea21b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/19fea21b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/19fea21b
Branch: refs/heads/develop
Commit: 19fea21bcbd73b568e5abc0ae86c8ff13107cf27
Parents: a3d68ef
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 14:31:24 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 14:31:24 2016 -0800
----------------------------------------------------------------------
newt/builder/cmds.go | 22 +++++++++-------------
newt/target/cmds.go | 6 +++---
2 files changed, 12 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/19fea21b/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index f2e8668..8cbd984 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -37,10 +37,9 @@ func buildRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, nil)
}
- targetName := args[0]
- t := target.GetTargets()[targetName]
+ t := target.ResolveTargetName(args[0])
if t == nil {
- cli.NewtUsage(cmd, util.NewNewtError("invalid target name"))
+ cli.NewtUsage(cmd, util.NewNewtError("invalid target name: "+args[0]))
}
b, err := NewBuilder(t)
@@ -58,10 +57,9 @@ func cleanRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, nil)
}
- targetName := args[0]
- t := target.GetTargets()[targetName]
+ t := target.ResolveTargetName(args[0])
if t == nil {
- cli.NewtUsage(cmd, util.NewNewtError("invalid target name"))
+ cli.NewtUsage(cmd, util.NewNewtError("invalid target name"+args[0]))
}
b, err := NewBuilder(t)
@@ -79,7 +77,7 @@ func testRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, nil)
}
- t := target.GetTargets()[TARGET_TEST_NAME]
+ t := target.ResolveTargetName(TARGET_TEST_NAME)
if t == nil {
cli.NewtUsage(cmd, util.NewNewtError("can't find unit test target: "+
TARGET_TEST_NAME))
@@ -125,10 +123,9 @@ func downloadRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, util.NewNewtError("Must specify target"))
}
- targetName := args[0]
- t := target.GetTargets()[targetName]
+ t := target.ResolveTargetName(args[0])
if t == nil {
- cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"))
+ cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"+args[0]))
}
b, err := NewBuilder(t)
@@ -147,10 +144,9 @@ func debugRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, util.NewNewtError("Must specify target"))
}
- targetName := args[0]
- t := target.GetTargets()[targetName]
+ t := target.ResolveTargetName(args[0])
if t == nil {
- cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"))
+ cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"+args[0]))
}
b, err := NewBuilder(t)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/19fea21b/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index 018b713..5049886 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -107,7 +107,7 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
"(target-name & k=v) to set"))
}
- t := GetTargets()[args[0]]
+ t := ResolveTargetName(args[0])
if t == nil {
cli.NewtUsage(cmd, util.NewNewtError("Unknown target"))
}
@@ -154,7 +154,7 @@ func targetCreateCmd(cmd *cobra.Command, args []string) {
cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Creating target "+args[0]+"\n")
- t := GetTargets()[args[0]]
+ t := ResolveTargetName(args[0])
if t != nil {
cli.NewtUsage(cmd, util.NewNewtError(
"Target already exists, cannot create target with same name."))
@@ -180,7 +180,7 @@ func targetDelCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, util.NewNewtError("Must specify target to delete"))
}
- t := GetTargets()[args[0]]
+ t := ResolveTargetName(args[0])
if t == nil {
cli.NewtUsage(cmd, util.NewNewtError("Target does not exist"))
}
[20/50] incubator-mynewt-newt git commit: Add newt size command.
Posted by ma...@apache.org.
Add newt size command.
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/91fac93d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/91fac93d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/91fac93d
Branch: refs/heads/develop
Commit: 91fac93ddf4fab2e8d1bdc06c1edd7e9552bf3bd
Parents: 9468c1b
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Mar 8 16:21:54 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Mar 8 16:21:54 2016 -0800
----------------------------------------------------------------------
newt/builder/cmds.go | 42 +++++-
newt/builder/size.go | 340 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 378 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/91fac93d/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index 8cbd984..1b52c41 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -160,12 +160,33 @@ func debugRunCmd(cmd *cobra.Command, args []string) {
}
}
+func sizeRunCmd(cmd *cobra.Command, args []string) {
+ if len(args) < 1 {
+ cli.NewtUsage(cmd, util.NewNewtError("Must specify target"))
+ }
+
+ t := target.ResolveTargetName(args[0])
+ if t == nil {
+ cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"+args[0]))
+ }
+
+ b, err := NewBuilder(t)
+ if err != nil {
+ fmt.Println(err)
+ }
+
+ err = b.Size()
+ if err != nil {
+ fmt.Println(err)
+ }
+}
+
func AddCommands(cmd *cobra.Command) {
buildHelpText := ""
buildHelpEx := ""
buildCmd := &cobra.Command{
Use: "build",
- Short: "Commands for building targets",
+ Short: "Command for building target",
Long: buildHelpText,
Example: buildHelpEx,
Run: buildRunCmd,
@@ -177,7 +198,7 @@ func AddCommands(cmd *cobra.Command) {
cleanHelpEx := ""
cleanCmd := &cobra.Command{
Use: "clean",
- Short: "Commands for cleaning targets",
+ Short: "Command for cleaning target",
Long: cleanHelpText,
Example: cleanHelpEx,
Run: cleanRunCmd,
@@ -197,7 +218,7 @@ func AddCommands(cmd *cobra.Command) {
cmd.AddCommand(testCmd)
- downloadHelpText := "Download project image to target for <target-name>."
+ downloadHelpText := "Download app image to target for <target-name>."
downloadHelpEx := " newt download <target-name>\n"
downloadCmd := &cobra.Command{
@@ -209,7 +230,7 @@ func AddCommands(cmd *cobra.Command) {
}
cmd.AddCommand(downloadCmd)
- debugHelpText := "Download project image to target for <target-name>."
+ debugHelpText := "Open debugger session for <target-name>."
debugHelpEx := " newt debug <target-name>\n"
debugCmd := &cobra.Command{
@@ -220,4 +241,17 @@ func AddCommands(cmd *cobra.Command) {
Run: debugRunCmd,
}
cmd.AddCommand(debugCmd)
+
+ sizeHelpText := "Calculate the size of target components specified by " +
+ "<target-name>."
+ sizeHelpEx := " newt size <target-name>\n"
+
+ sizeCmd := &cobra.Command{
+ Use: "size",
+ Short: "Size of target components",
+ Long: sizeHelpText,
+ Example: sizeHelpEx,
+ Run: sizeRunCmd,
+ }
+ cmd.AddCommand(sizeCmd)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/91fac93d/newt/builder/size.go
----------------------------------------------------------------------
diff --git a/newt/builder/size.go b/newt/builder/size.go
new file mode 100644
index 0000000..3579d77
--- /dev/null
+++ b/newt/builder/size.go
@@ -0,0 +1,340 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package builder
+
+import (
+ "bufio"
+ "fmt"
+ "os"
+ "path/filepath"
+ "sort"
+ "strconv"
+ "strings"
+
+ "mynewt.apache.org/newt/newt/cli"
+ "mynewt.apache.org/newt/util"
+)
+
+/*
+ * These are different memory regions as specified in linker script.
+ */
+type MemSection struct {
+ Name string
+ Offset uint64
+ EndOff uint64
+}
+type MemSectionArray []*MemSection
+
+func (array MemSectionArray) Len() int {
+ return len(array)
+}
+
+func (array MemSectionArray) Less(i, j int) bool {
+ return array[i].Offset < array[j].Offset
+}
+
+func (array MemSectionArray) Swap(i, j int) {
+ array[i], array[j] = array[j], array[i]
+}
+
+func MakeMemSection(name string, off uint64, size uint64) *MemSection {
+ memsection := &MemSection{
+ Name: name,
+ Offset: off,
+ EndOff: off + size,
+ }
+ return memsection
+}
+
+func (m *MemSection) PartOf(addr uint64) bool {
+ if addr >= m.Offset && addr < m.EndOff {
+ return true
+ } else {
+ return false
+ }
+}
+
+/*
+ * We accumulate the size of libraries to elements in this.
+ */
+type PkgSize struct {
+ Name string
+ Sizes map[string]uint32 /* Sizes indexed by mem section name */
+}
+
+type PkgSizeArray []*PkgSize
+
+func (array PkgSizeArray) Len() int {
+ return len(array)
+}
+
+func (array PkgSizeArray) Less(i, j int) bool {
+ return array[i].Name < array[j].Name
+}
+
+func (array PkgSizeArray) Swap(i, j int) {
+ array[i], array[j] = array[j], array[i]
+}
+
+func MakePkgSize(name string, memSections map[string]*MemSection) *PkgSize {
+ pkgSize := &PkgSize{
+ Name: name,
+ }
+ pkgSize.Sizes = make(map[string]uint32)
+ for secName, _ := range memSections {
+ pkgSize.Sizes[secName] = 0
+ }
+ return pkgSize
+}
+
+/*
+ * Go through GCC generated mapfile, and collect info about symbol sizes
+ */
+func ParseMapFileSizes(fileName string) (map[string]*PkgSize, map[string]*MemSection,
+ error) {
+ var state int = 0
+
+ file, err := os.Open(fileName)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ memSections := make(map[string]*MemSection)
+ pkgSizes := make(map[string]*PkgSize)
+
+ scanner := bufio.NewScanner(file)
+ for scanner.Scan() {
+ switch state {
+ case 0:
+ if strings.Contains(scanner.Text(), "Memory Configuration") {
+ state = 1
+ }
+ case 1:
+ if strings.Contains(scanner.Text(), "Origin") {
+ state = 2
+ }
+ case 2:
+ if strings.Contains(scanner.Text(), "*default*") {
+ state = 3
+ continue
+ }
+ array := strings.Fields(scanner.Text())
+ offset, err := strconv.ParseUint(array[1], 0, 64)
+ if err != nil {
+ return nil, nil, util.NewNewtError("Can't parse mem info")
+ }
+ size, err := strconv.ParseUint(array[2], 0, 64)
+ if err != nil {
+ return nil, nil, util.NewNewtError("Can't parse mem info")
+ }
+ memSections[array[0]] = MakeMemSection(array[0], offset,
+ size)
+ case 3:
+ if strings.Contains(scanner.Text(),
+ "Linker script and memory map") {
+ state = 4
+ }
+ case 4:
+ var addrStr string = ""
+ var sizeStr string = ""
+ var srcFile string = ""
+
+ if strings.Contains(scanner.Text(), "/DISCARD/") ||
+ strings.HasPrefix(scanner.Text(), "OUTPUT(") {
+ /*
+ * After this there is only discarded symbols
+ */
+ state = 5
+ continue
+ }
+
+ array := strings.Fields(scanner.Text())
+ switch len(array) {
+ case 1:
+ /*
+ * section name on it's own, e.g.
+ * *(.text*)
+ *
+ * section name + symbol name, e.g.
+ * .text.Reset_Handler
+ *
+ * ignore these for now
+ */
+ continue
+ case 2:
+ /*
+ * Either stuff from beginning to first useful data e.g.
+ * END GROUP
+ *
+ * or address of symbol + symbol name, e.g.
+ * 0x00000000080002c8 SystemInit
+ *
+ * or section names with multiple input things, e.g.
+ * *(.ARM.extab* .gnu.linkonce.armextab.*)
+ *
+ * or space set aside in linker script e.g.
+ * 0x0000000020002e80 0x400
+ * (that's the initial stack)
+ *
+ * ignore these for now
+ */
+ continue
+ case 3:
+ /*
+ * address, size, and name of file, e.g.
+ * 0x000000000800bb04 0x1050 /Users/marko/foo/tadpole/hw//mcu/stm/stm32f3xx/bin/blinky_f3/libstm32f3xx.a(stm32f30x_syscfg.o)
+ *
+ * padding, or empty areas defined in linker script:
+ * *fill* 0x000000000800cb71 0x3
+ *
+ * output section name, location, size, e.g.:
+ * .bss 0x0000000020000ab0 0x23d0
+ */
+ /*
+ * Record addr, size and name to find library.
+ */
+ if array[0] == "*fill*" {
+ addrStr = array[1]
+ sizeStr = array[2]
+ srcFile = array[0]
+ } else {
+ addrStr = array[0]
+ sizeStr = array[1]
+ srcFile = array[2]
+ }
+ case 4:
+ /*
+ * section, address, size, name of file, e.g.
+ * COMMON 0x0000000020002d28 0x8 /Users/marko/foo/tadpole/libs//os/bin/blinky_f3/libos.a(os_arch_arm.o)
+ *
+ * linker script symbol definitions:
+ * 0x0000000020002e80 _ebss = .
+ *
+ * crud, e.g.:
+ * 0x8 (size before relaxing)
+ */
+ addrStr = array[1]
+ sizeStr = array[2]
+ srcFile = array[3]
+ default:
+ continue
+ }
+ addr, err := strconv.ParseUint(addrStr, 0, 64)
+ if err != nil {
+ continue
+ }
+ size, err := strconv.ParseUint(sizeStr, 0, 64)
+ if err != nil {
+ continue
+ }
+ if size == 0 {
+ continue
+ }
+ tmpStrArr := strings.Split(srcFile, "(")
+ srcLib := filepath.Base(tmpStrArr[0])
+ for name, section := range memSections {
+ if section.PartOf(addr) {
+ pkgSize := pkgSizes[srcLib]
+ if pkgSize == nil {
+ pkgSize =
+ MakePkgSize(srcLib, memSections)
+ pkgSizes[srcLib] = pkgSize
+ }
+ pkgSize.Sizes[name] += uint32(size)
+ break
+ }
+ }
+ default:
+ }
+ }
+ file.Close()
+ for name, section := range memSections {
+ cli.StatusMessage(cli.VERBOSITY_VERBOSE, "Mem %s: 0x%x-0x%x\n",
+ name, section.Offset, section.EndOff)
+ }
+
+ return pkgSizes, memSections, nil
+}
+
+/*
+ * Return a printable string containing size data for the libraries
+ */
+func PrintSizes(libs map[string]*PkgSize,
+ sectMap map[string]*MemSection) (string, error) {
+ ret := ""
+
+ /*
+ * Order sections by offset, and display lib sizes in that order.
+ */
+ memSections := make(MemSectionArray, len(sectMap))
+ var i int = 0
+ for _, sec := range sectMap {
+ memSections[i] = sec
+ i++
+ }
+ sort.Sort(memSections)
+
+ /*
+ * Order libraries by name, and display them in that order.
+ */
+ pkgSizes := make(PkgSizeArray, len(libs))
+ i = 0
+ for _, es := range libs {
+ pkgSizes[i] = es
+ i++
+ }
+ sort.Sort(pkgSizes)
+
+ for _, sec := range memSections {
+ ret += fmt.Sprintf("%7s ", sec.Name)
+ }
+ ret += "\n"
+ for _, es := range pkgSizes {
+ for i := 0; i < len(memSections); i++ {
+ ret += fmt.Sprintf("%7d ", es.Sizes[memSections[i].Name])
+ }
+ ret += fmt.Sprintf("%s\n", es.Name)
+ }
+ return ret, nil
+}
+
+func (b *Builder) Size() error {
+ if b.target.App() == nil {
+ return util.NewNewtError("app package not specified for this target")
+ }
+
+ err := b.PrepBuild()
+ if err != nil {
+ return err
+ }
+
+ mapFile := b.AppElfPath() + ".map"
+
+ pkgSizes, memSections, err := ParseMapFileSizes(mapFile)
+ if err != nil {
+ return err
+ }
+ output, err := PrintSizes(pkgSizes, memSections)
+ if err != nil {
+ return err
+ }
+ fmt.Printf("%s", output)
+ return nil
+}
[33/50] incubator-mynewt-newt git commit: Remove code duplication
among cli and util.
Posted by ma...@apache.org.
Remove code duplication among cli and util.
Everything in cli/util.go should now be newt-tool-specific.
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/cc41f163
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/cc41f163
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/cc41f163
Branch: refs/heads/develop
Commit: cc41f1639f6fe6dbe4d099697033a198277bb8d3
Parents: 57cb34a
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 18:08:25 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 18:11:04 2016 -0800
----------------------------------------------------------------------
newt/builder/build.go | 29 ++--
newt/builder/buildpackage.go | 2 +-
newt/builder/cmds.go | 2 +-
newt/builder/download.go | 5 +-
newt/builder/size.go | 3 +-
newt/cli/util.go | 283 -------------------------------------
newt/downloader/downloader.go | 5 +-
newt/image/cmds.go | 4 +-
newt/newt.go | 11 +-
newt/pkg/localpackage.go | 5 +-
newt/project/project.go | 5 +-
newt/project/projectstate.go | 3 +-
newt/repo/repo.go | 15 +-
newt/target/cmds.go | 14 +-
newt/target/target.go | 3 +-
newt/target/vars.go | 5 +-
newt/toolchain/compiler.go | 59 ++++----
newt/toolchain/deps.go | 27 ++--
util/util.go | 272 ++++++++++++++++++++++++++++++++---
19 files changed, 348 insertions(+), 404 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 7b3a35a..009a598 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -23,7 +23,6 @@ import (
"os"
"path/filepath"
- "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/target"
"mynewt.apache.org/newt/newt/toolchain"
@@ -93,7 +92,7 @@ func (b *Builder) AddApi(apiString string, bpkg *BuildPackage) bool {
return true
} else {
if curBpkg != bpkg {
- cli.StatusMessage(util.VERBOSITY_QUIET,
+ util.StatusMessage(util.VERBOSITY_QUIET,
"Warning: API conflict: %s <-> %s\n", curBpkg.Name(),
bpkg.Name())
}
@@ -122,7 +121,7 @@ func (b *Builder) loadDeps() error {
}
}
- cli.StatusMessage(cli.VERBOSITY_VERBOSE, "Building with the following "+
+ util.StatusMessage(util.VERBOSITY_VERBOSE, "Building with the following "+
"feature set: ["+b.featureString()+"]\n")
return nil
@@ -134,11 +133,11 @@ func buildDir(srcDir string, c *toolchain.Compiler, arch string,
ignDirs []string) error {
// Quietly succeed if the source directory doesn't exist.
- if cli.NodeNotExist(srcDir) {
+ if util.NodeNotExist(srcDir) {
return nil
}
- cli.StatusMessage(util.VERBOSITY_VERBOSE,
+ util.StatusMessage(util.VERBOSITY_VERBOSE,
"compiling src in base directory: %s\n", srcDir)
// Start from the source directory.
@@ -160,11 +159,11 @@ func buildDir(srcDir string, c *toolchain.Compiler, arch string,
}
archDir := srcDir + "/arch/" + arch + "/"
- cli.StatusMessage(util.VERBOSITY_VERBOSE,
+ util.StatusMessage(util.VERBOSITY_VERBOSE,
"compiling architecture specific src pkgs in directory: %s\n",
archDir)
- if cli.NodeExist(archDir) {
+ if util.NodeExist(archDir) {
if err := os.Chdir(archDir); err != nil {
return util.NewNewtError(err.Error())
}
@@ -188,7 +187,7 @@ func buildDir(srcDir string, c *toolchain.Compiler, arch string,
// Compiles and archives a package.
func (b *Builder) buildPackage(bpkg *BuildPackage) error {
srcDir := bpkg.BasePath() + "/src"
- if cli.NodeNotExist(srcDir) {
+ if util.NodeNotExist(srcDir) {
// Nothing to compile.
return nil
}
@@ -247,7 +246,7 @@ func (b *Builder) link(elfName string) error {
pkgNames := []string{}
for _, bpkg := range b.Packages {
archivePath := b.archivePath(bpkg.Name())
- if cli.NodeExist(archivePath) {
+ if util.NodeExist(archivePath) {
pkgNames = append(pkgNames, archivePath)
}
}
@@ -449,29 +448,29 @@ func (b *Builder) Test(p *pkg.LocalPackage) error {
}
// Run the tests.
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Testing package %s\n", p.Name())
+ util.StatusMessage(util.VERBOSITY_DEFAULT, "Testing package %s\n", p.Name())
if err := os.Chdir(filepath.Dir(testFilename)); err != nil {
return err
}
- o, err := cli.ShellCommand(testFilename)
+ o, err := util.ShellCommand(testFilename)
if err != nil {
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "%s", string(o))
+ util.StatusMessage(util.VERBOSITY_DEFAULT, "%s", string(o))
// Always terminate on test failure since only one test is being run.
return util.NewNewtError("Test failed: " + testFilename)
}
- cli.StatusMessage(cli.VERBOSITY_VERBOSE, "%s", string(o))
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Test %s ok!\n", testFilename)
+ util.StatusMessage(util.VERBOSITY_VERBOSE, "%s", string(o))
+ util.StatusMessage(util.VERBOSITY_DEFAULT, "Test %s ok!\n", testFilename)
return nil
}
func (b *Builder) Clean() error {
path := b.binDir()
- cli.StatusMessage(util.VERBOSITY_VERBOSE, "Cleaning directory %s\n", path)
+ util.StatusMessage(util.VERBOSITY_VERBOSE, "Cleaning directory %s\n", path)
err := os.RemoveAll(path)
return err
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/builder/buildpackage.go
----------------------------------------------------------------------
diff --git a/newt/builder/buildpackage.go b/newt/builder/buildpackage.go
index a303693..93a59aa 100644
--- a/newt/builder/buildpackage.go
+++ b/newt/builder/buildpackage.go
@@ -276,7 +276,7 @@ func (bpkg *BuildPackage) privateIncludeDirs(b *Builder) []string {
incls = append(incls, srcDir)
incls = append(incls, srcDir+"/arch/"+b.target.Arch)
- if cli.CheckBoolMap(b.Features(), "test") {
+ if b.Features()["test"] {
testSrcDir := srcDir + "/test"
incls = append(incls, testSrcDir)
incls = append(incls, testSrcDir+"/arch/"+b.target.Arch)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index 24299a8..aaf4836 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -51,7 +51,7 @@ func buildRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, err)
}
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "App successfully built: %s\n",
+ util.StatusMessage(util.VERBOSITY_DEFAULT, "App successfully built: %s\n",
b.AppElfPath())
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/builder/download.go
----------------------------------------------------------------------
diff --git a/newt/builder/download.go b/newt/builder/download.go
index 32b4290..9a4c512 100644
--- a/newt/builder/download.go
+++ b/newt/builder/download.go
@@ -24,7 +24,6 @@ import (
"os"
"path/filepath"
- "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/util"
)
@@ -50,7 +49,7 @@ func (b *Builder) Download() error {
downloadCmd := fmt.Sprintf("%s %s %s %s",
downloadScript, bspPath, binBaseName, featureString)
- rsp, err := cli.ShellCommand(downloadCmd)
+ rsp, err := util.ShellCommand(downloadCmd)
fmt.Printf("%s", rsp)
return err
@@ -77,5 +76,5 @@ func (b *Builder) Debug() error {
os.Chdir(project.GetProject().Path())
cmdLine := []string{debugScript, bspPath, binBaseName, featureString}
- return cli.ShellInteractiveCommand(cmdLine)
+ return util.ShellInteractiveCommand(cmdLine)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/builder/size.go
----------------------------------------------------------------------
diff --git a/newt/builder/size.go b/newt/builder/size.go
index 3579d77..769dba4 100644
--- a/newt/builder/size.go
+++ b/newt/builder/size.go
@@ -28,7 +28,6 @@ import (
"strconv"
"strings"
- "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/util"
)
@@ -266,7 +265,7 @@ func ParseMapFileSizes(fileName string) (map[string]*PkgSize, map[string]*MemSec
}
file.Close()
for name, section := range memSections {
- cli.StatusMessage(cli.VERBOSITY_VERBOSE, "Mem %s: 0x%x-0x%x\n",
+ util.StatusMessage(util.VERBOSITY_VERBOSE, "Mem %s: 0x%x-0x%x\n",
name, section.Offset, section.EndOff)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/cli/util.go
----------------------------------------------------------------------
diff --git a/newt/cli/util.go b/newt/cli/util.go
index a48de90..89ee6ae 100644
--- a/newt/cli/util.go
+++ b/newt/cli/util.go
@@ -20,36 +20,19 @@
package cli
import (
- "bufio"
"fmt"
- "io/ioutil"
"log"
"os"
- "os/exec"
- "os/signal"
- "path"
- "path/filepath"
"regexp"
"sort"
"strings"
- "syscall"
- "time"
- "github.com/hashicorp/logutils"
"github.com/spf13/cobra"
"mynewt.apache.org/newt/util"
"mynewt.apache.org/newt/viper"
)
-const (
- VERBOSITY_SILENT = 0
- VERBOSITY_QUIET = 1
- VERBOSITY_DEFAULT = 2
- VERBOSITY_VERBOSE = 3
-)
-
var Logger *log.Logger
-var Verbosity int = VERBOSITY_DEFAULT
var Force bool
var OK_STRING = " ok!\n"
@@ -87,28 +70,6 @@ func FormatHelp(text string) string {
return fmtText
}
-// Initialize the CLI module
-func Init(level string, verbosity int) {
- if level == "" {
- level = "WARN"
- }
-
- filter := &logutils.LevelFilter{
- Levels: []logutils.LogLevel{"DEBUG", "VERBOSE", "INFO",
- "WARN", "ERROR"},
- MinLevel: logutils.LogLevel(level),
- Writer: os.Stderr,
- }
-
- log.SetOutput(filter)
- Verbosity = verbosity
-}
-
-func CheckBoolMap(mapVar map[string]bool, item string) bool {
- v, ok := mapVar[item]
- return v && ok
-}
-
func GetStringFeatures(v *viper.Viper, features map[string]bool,
key string) string {
val := v.GetString(key)
@@ -156,247 +117,3 @@ func GetStringSliceFeatures(v *viper.Viper, features map[string]bool,
return result
}
-
-func NodeExist(path string) bool {
- if _, err := os.Stat(path); err == nil {
- return true
- } else {
- return false
- }
-}
-
-// Check whether the node (either dir or file) specified by path exists
-func NodeNotExist(path string) bool {
- if _, err := os.Stat(path); os.IsNotExist(err) {
- return true
- } else {
- return false
- }
-}
-
-func FileModificationTime(path string) (time.Time, error) {
- fileInfo, err := os.Stat(path)
- if err != nil {
- epoch := time.Unix(0, 0)
- if os.IsNotExist(err) {
- return epoch, nil
- } else {
- return epoch, util.NewNewtError(err.Error())
- }
- }
-
- return fileInfo.ModTime(), nil
-}
-
-func ChildDirs(path string) ([]string, error) {
- children, err := ioutil.ReadDir(path)
- if err != nil {
- return nil, util.NewNewtError(err.Error())
- }
-
- childDirs := []string{}
- for _, child := range children {
- name := child.Name()
- if !filepath.HasPrefix(name, ".") &&
- !filepath.HasPrefix(name, "..") &&
- child.IsDir() {
-
- childDirs = append(childDirs, name)
- }
- }
-
- return childDirs, nil
-}
-
-func DescendantDirsOfParent(rootPath string, parentName string, fullPath bool) ([]string, error) {
- rootPath = path.Clean(rootPath)
-
- if NodeNotExist(rootPath) {
- return []string{}, nil
- }
-
- children, err := ChildDirs(rootPath)
- if err != nil {
- return nil, err
- }
-
- dirs := []string{}
- if path.Base(rootPath) == parentName {
- for _, child := range children {
- if fullPath {
- child = rootPath + "/" + child
- }
-
- dirs = append(dirs, child)
- }
- } else {
- for _, child := range children {
- childPath := rootPath + "/" + child
- subDirs, err := DescendantDirsOfParent(childPath, parentName,
- fullPath)
- if err != nil {
- return nil, err
- }
-
- dirs = append(dirs, subDirs...)
- }
- }
-
- return dirs, nil
-}
-
-// Execute the command specified by cmdStr on the shell and return results
-func ShellCommand(cmdStr string) ([]byte, error) {
- log.Print("[VERBOSE] " + cmdStr)
- cmd := exec.Command("sh", "-c", cmdStr)
-
- o, err := cmd.CombinedOutput()
- log.Print("[VERBOSE] o=" + string(o))
- if err != nil {
- return o, util.NewNewtError(err.Error())
- } else {
- return o, nil
- }
-}
-
-// Run interactive shell command
-func ShellInteractiveCommand(cmdStr []string) error {
- log.Print("[VERBOSE] " + cmdStr[0])
-
- //
- // Block SIGINT, at least.
- // Otherwise Ctrl-C meant for gdb would kill newt.
- //
- c := make(chan os.Signal, 1)
- signal.Notify(c, os.Interrupt)
- signal.Notify(c, syscall.SIGTERM)
- go func() {
- <-c
- }()
-
- // Transfer stdin, stdout, and stderr to the new process
- // and also set target directory for the shell to start in.
- pa := os.ProcAttr{
- Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
- }
-
- // Start up a new shell.
- proc, err := os.StartProcess(cmdStr[0], cmdStr, &pa)
- if err != nil {
- signal.Stop(c)
- return util.NewNewtError(err.Error())
- }
-
- // Release and exit
- _, err = proc.Wait()
- if err != nil {
- signal.Stop(c)
- return util.NewNewtError(err.Error())
- }
- signal.Stop(c)
- return nil
-}
-
-func CopyFile(srcFile string, destFile string) error {
- _, err := ShellCommand(fmt.Sprintf("mkdir -p %s", filepath.Dir(destFile)))
- if err != nil {
- return err
- }
- if _, err := ShellCommand(fmt.Sprintf("cp -Rf %s %s", srcFile,
- destFile)); err != nil {
- return err
- }
- return nil
-}
-
-func CopyDir(srcDir, destDir string) error {
- return CopyFile(srcDir, destDir)
-}
-
-// Print Silent, Quiet and Verbose aware status messages to stdout.
-func StatusMessage(level int, message string, args ...interface{}) {
- if Verbosity >= level {
- fmt.Printf(message, args...)
- }
-}
-
-// Print Silent, Quiet and Verbose aware status messages to stderr.
-func ErrorMessage(level int, message string, args ...interface{}) {
- if Verbosity >= level {
- fmt.Fprintf(os.Stderr, message, args...)
- }
-}
-
-// Reads each line from the specified text file into an array of strings. If a
-// line ends with a backslash, it is concatenated with the following line.
-func ReadLines(path string) ([]string, error) {
- file, err := os.Open(path)
- if err != nil {
- return nil, util.NewNewtError(err.Error())
- }
- defer file.Close()
-
- lines := []string{}
- scanner := bufio.NewScanner(file)
-
- for scanner.Scan() {
- line := scanner.Text()
- concatted := false
-
- if len(lines) != 0 {
- prevLine := lines[len(lines)-1]
- if len(prevLine) > 0 && prevLine[len(prevLine)-1:] == "\\" {
- prevLine = prevLine[:len(prevLine)-1]
- prevLine += line
- lines[len(lines)-1] = prevLine
-
- concatted = true
- }
- }
-
- if !concatted {
- lines = append(lines, line)
- }
- }
-
- if scanner.Err() != nil {
- return lines, util.NewNewtError(scanner.Err().Error())
- }
-
- return lines, nil
-}
-
-// Removes all duplicate strings from the specified array, while preserving
-// order.
-func UniqueStrings(elems []string) []string {
- set := make(map[string]bool)
- result := make([]string, 0)
-
- for _, elem := range elems {
- if !set[elem] {
- result = append(result, elem)
- set[elem] = true
- }
- }
-
- return result
-}
-
-// Sorts whitespace-delimited lists of strings.
-//
-// @param wsSepStrings A list of strings; each string contains one or
-// more whitespace-delimited tokens.
-//
-// @return A slice containing all the input tokens, sorted
-// alphabetically.
-func SortFields(wsSepStrings ...string) []string {
- slice := []string{}
-
- for _, s := range wsSepStrings {
- slice = append(slice, strings.Fields(s)...)
- }
-
- slice = UniqueStrings(slice)
- sort.Strings(slice)
- return slice
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/downloader/downloader.go
----------------------------------------------------------------------
diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index ee396bb..a4e0197 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -28,7 +28,6 @@ import (
"os"
"os/exec"
- "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/util"
)
@@ -93,7 +92,7 @@ func (gd *GithubDownloader) DownloadRepo(branch string) (string, error) {
}
url := fmt.Sprintf("https://github.com/%s/%s.git", gd.User, gd.Repo)
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, fmt.Sprintf("Downloading "+
+ util.StatusMessage(util.VERBOSITY_DEFAULT, fmt.Sprintf("Downloading "+
"repository %s (branch: %s) at %s\n", gd.Repo, branch, url))
gitPath, err := exec.LookPath("git")
@@ -112,7 +111,7 @@ func (gd *GithubDownloader) DownloadRepo(branch string) (string, error) {
tmpdir,
}
- if err := cli.ShellInteractiveCommand(cmds); err != nil {
+ if err := util.ShellInteractiveCommand(cmds); err != nil {
os.RemoveAll(tmpdir)
return "", err
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/image/cmds.go
----------------------------------------------------------------------
diff --git a/newt/image/cmds.go b/newt/image/cmds.go
index 1d12f20..0e1128c 100644
--- a/newt/image/cmds.go
+++ b/newt/image/cmds.go
@@ -72,9 +72,9 @@ func createImageRunCmd(cmd *cobra.Command, args []string) {
if err != nil {
fmt.Println(err)
}
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "App image succesfully generated: %s\n",
+ util.StatusMessage(util.VERBOSITY_DEFAULT, "App image succesfully generated: %s\n",
image.targetImg)
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Build manifest: %s\n",
+ util.StatusMessage(util.VERBOSITY_DEFAULT, "Build manifest: %s\n",
image.manifestFile)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/newt.go
----------------------------------------------------------------------
diff --git a/newt/newt.go b/newt/newt.go
index a18d507..103f52f 100644
--- a/newt/newt.go
+++ b/newt/newt.go
@@ -29,6 +29,7 @@ import (
"mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/newt/target"
+ "mynewt.apache.org/newt/util"
"github.com/spf13/cobra"
)
@@ -63,16 +64,16 @@ func newtCmd() *cobra.Command {
PersistentPreRun: func(cmd *cobra.Command, args []string) {
NewtLogLevel = strings.ToUpper(NewtLogLevel)
- verbosity := cli.VERBOSITY_DEFAULT
+ verbosity := util.VERBOSITY_DEFAULT
if newtSilent {
- verbosity = cli.VERBOSITY_SILENT
+ verbosity = util.VERBOSITY_SILENT
} else if newtQuiet {
- verbosity = cli.VERBOSITY_QUIET
+ verbosity = util.VERBOSITY_QUIET
} else if newtVerbose {
- verbosity = cli.VERBOSITY_VERBOSE
+ verbosity = util.VERBOSITY_VERBOSE
}
- cli.Init(NewtLogLevel, verbosity)
+ util.Init(NewtLogLevel, verbosity)
},
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/pkg/localpackage.go
----------------------------------------------------------------------
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index 9f14561..6a89563 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -30,7 +30,6 @@ import (
"mynewt.apache.org/newt/viper"
- "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/newt/interfaces"
"mynewt.apache.org/newt/newt/repo"
"mynewt.apache.org/newt/util"
@@ -299,7 +298,7 @@ func ReadLocalPackageRecursive(repo *repo.Repo,
}
}
- if cli.NodeNotExist(basePath + "/" + pkgName + "/" + PACKAGE_FILE_NAME) {
+ if util.NodeNotExist(basePath + "/" + pkgName + "/" + PACKAGE_FILE_NAME) {
return nil
}
@@ -320,7 +319,7 @@ func ReadLocalPackages(repo *repo.Repo, basePath string,
for _, path := range searchPaths {
pkgDir := basePath + "/" + path
- if cli.NodeNotExist(pkgDir) {
+ if util.NodeNotExist(pkgDir) {
continue
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index 990ba51..a7438cd 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -27,7 +27,6 @@ import (
"path"
"strings"
- "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/newt/downloader"
"mynewt.apache.org/newt/newt/interfaces"
"mynewt.apache.org/newt/newt/pkg"
@@ -170,7 +169,7 @@ func (proj *Project) Install(upgrade bool, force bool) error {
}
if !upgrade {
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
+ util.StatusMessage(util.VERBOSITY_DEFAULT,
fmt.Sprintf("Installed repository %s matches project requirements, "+
"moving on to next repository.\n", r.Name()))
continue
@@ -344,7 +343,7 @@ func findProjectDir(dir string) (string, error) {
projFile := path.Clean(dir) + "/" + PROJECT_FILE_NAME
log.Printf("[DEBUG] Searching for project file %s", projFile)
- if cli.NodeExist(projFile) {
+ if util.NodeExist(projFile) {
log.Printf("[INFO] Project file found at %s", projFile)
break
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/project/projectstate.go
----------------------------------------------------------------------
diff --git a/newt/project/projectstate.go b/newt/project/projectstate.go
index cf710a2..2c14359 100644
--- a/newt/project/projectstate.go
+++ b/newt/project/projectstate.go
@@ -25,7 +25,6 @@ import (
"os"
"strings"
- "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/newt/interfaces"
"mynewt.apache.org/newt/newt/repo"
"mynewt.apache.org/newt/util"
@@ -72,7 +71,7 @@ func (ps *ProjectState) Init() error {
// Read project state file. If doesn't exist, it will be empty until somebody
// installs a repo
- if cli.NodeNotExist(path) {
+ if util.NodeNotExist(path) {
return nil
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/repo/repo.go
----------------------------------------------------------------------
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index 93fd31a..eb8d596 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -26,7 +26,6 @@ import (
"path/filepath"
"strings"
- "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/newt/downloader"
"mynewt.apache.org/newt/newt/interfaces"
"mynewt.apache.org/newt/util"
@@ -182,7 +181,7 @@ 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()) {
+ if util.NodeExist(r.Path()) {
if force {
if err := os.RemoveAll(r.Path()); err != nil {
return nil, util.NewNewtError(err.Error())
@@ -209,7 +208,7 @@ func (r *Repo) Install(rdesc *RepoDesc, force bool) (*Version, error) {
}
// Copy the Git repo into the the desired local path of the repo
- if err := cli.CopyDir(tmpdir, r.Path()); err != nil {
+ if err := util.CopyDir(tmpdir, r.Path()); err != nil {
// Cleanup any directory that might have been created if we error out
// here.
os.RemoveAll(r.Path())
@@ -223,12 +222,12 @@ func (r *Repo) Install(rdesc *RepoDesc, force bool) (*Version, error) {
func (r *Repo) DownloadDesc() error {
dl := r.downloader
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, fmt.Sprintf("Downloading "+
+ util.StatusMessage(util.VERBOSITY_DEFAULT, fmt.Sprintf("Downloading "+
"repository description for %s...", r.Name()))
// Configuration path
cpath := r.repoFilePath()
- if cli.NodeNotExist(cpath) {
+ if util.NodeNotExist(cpath) {
if err := os.MkdirAll(cpath, REPO_DEFAULT_PERMS); err != nil {
return util.NewNewtError(err.Error())
}
@@ -237,17 +236,17 @@ func (r *Repo) DownloadDesc() error {
dl.SetBranch("master")
if err := dl.FetchFile("repository.yml",
cpath+"/"+"repository.yml"); err != nil {
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, " failed\n")
+ util.StatusMessage(util.VERBOSITY_DEFAULT, " failed\n")
return err
}
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, " success!\n")
+ util.StatusMessage(util.VERBOSITY_DEFAULT, " success!\n")
return nil
}
func (r *Repo) ReadDesc() (*RepoDesc, error) {
- if cli.NodeNotExist(r.repoFilePath() + REPO_FILE_NAME) {
+ if util.NodeNotExist(r.repoFilePath() + REPO_FILE_NAME) {
return nil,
util.NewNewtError("No configuration exists for repository " + r.name)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index d831063..1cfe18a 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -68,7 +68,7 @@ func targetShowCmd(cmd *cobra.Command, args []string) {
sort.Strings(targetNames)
for _, name := range targetNames {
- cli.StatusMessage(cli.VERBOSITY_QUIET, name+"\n")
+ util.StatusMessage(util.VERBOSITY_QUIET, name+"\n")
target := GetTargets()[name]
keys := []string{}
@@ -78,7 +78,7 @@ func targetShowCmd(cmd *cobra.Command, args []string) {
sort.Strings(keys)
for _, k := range keys {
- cli.StatusMessage(cli.VERBOSITY_QUIET, " %s=%s\n", k,
+ util.StatusMessage(util.VERBOSITY_QUIET, " %s=%s\n", k,
target.Vars[k])
}
}
@@ -154,10 +154,10 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
for _, kv := range vars {
if kv[1] == "" {
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
+ util.StatusMessage(util.VERBOSITY_DEFAULT,
"Target %s successfully unset %s\n", t.Name(), kv[0])
} else {
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
+ util.StatusMessage(util.VERBOSITY_DEFAULT,
"Target %s successfully set %s to %s\n", t.Name(), kv[0],
kv[1])
}
@@ -176,7 +176,7 @@ func targetCreateCmd(cmd *cobra.Command, args []string) {
tName = "targets/" + tName
}
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Creating target "+tName+"\n")
+ util.StatusMessage(util.VERBOSITY_DEFAULT, "Creating target "+tName+"\n")
t := ResolveTargetName(tName)
if t != nil {
@@ -194,7 +194,7 @@ func targetCreateCmd(cmd *cobra.Command, args []string) {
if err != nil {
cli.NewtUsage(nil, err)
} else {
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
+ util.StatusMessage(util.VERBOSITY_DEFAULT,
"Target %s successfully created!\n", tName)
}
}
@@ -223,7 +223,7 @@ func targetDelOne(t *Target) error {
return err
}
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
+ util.StatusMessage(util.VERBOSITY_DEFAULT,
"Target %s successfully removed\n", t.Name())
return nil
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 7b79176..72e1e1d 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -26,7 +26,6 @@ import (
"sort"
"strings"
- "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/util"
@@ -217,7 +216,7 @@ func buildTargetMap() error {
target, err := LoadTarget(pack)
if err != nil {
nerr := err.(*util.NewtError)
- cli.ErrorMessage(cli.VERBOSITY_QUIET,
+ util.ErrorMessage(util.VERBOSITY_QUIET,
"Warning: failed to load target \"%s\": %s\n", pack.Name,
nerr.Text)
} else {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/target/vars.go
----------------------------------------------------------------------
diff --git a/newt/target/vars.go b/newt/target/vars.go
index a4b1cac..71f4bed 100644
--- a/newt/target/vars.go
+++ b/newt/target/vars.go
@@ -24,7 +24,6 @@ import (
"path/filepath"
"strings"
- "mynewt.apache.org/newt/newt/cli"
. "mynewt.apache.org/newt/newt/interfaces"
"mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/project"
@@ -40,7 +39,7 @@ func varsFromChildDirs(key string, fullPath bool) ([]string, error) {
for _, r := range repos {
for _, pkgDir := range searchDirs {
pkgBaseDir := r.Path() + "/" + pkgDir
- values, err := cli.DescendantDirsOfParent(pkgBaseDir, key,
+ values, err := util.DescendantDirsOfParent(pkgBaseDir, key,
fullPath)
if err != nil {
return nil, util.NewNewtError(err.Error())
@@ -60,7 +59,7 @@ func varsFromChildDirs(key string, fullPath bool) ([]string, error) {
}
}
- return cli.SortFields(valueSlice...), nil
+ return util.SortFields(valueSlice...), nil
}
func varsFromPackageType(pt PackageType, fullPath bool) ([]string, error) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/toolchain/compiler.go
----------------------------------------------------------------------
diff --git a/newt/toolchain/compiler.go b/newt/toolchain/compiler.go
index 34c2e51..bada60b 100644
--- a/newt/toolchain/compiler.go
+++ b/newt/toolchain/compiler.go
@@ -29,7 +29,6 @@ import (
"strings"
"time"
- "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/util"
)
@@ -90,7 +89,7 @@ func NewCompiler(compilerDir string, dstDir string,
c.depTracker = NewDepTracker(c)
- cli.StatusMessage(cli.VERBOSITY_VERBOSE,
+ util.StatusMessage(util.VERBOSITY_VERBOSE,
"Loading compiler %s, def %s\n", compilerDir, buildProfile)
err := c.load(compilerDir, buildProfile)
if err != nil {
@@ -170,17 +169,17 @@ func (c *Compiler) includesString() string {
return ""
}
- includes := cli.SortFields(c.info.Includes...)
+ includes := util.SortFields(c.info.Includes...)
return "-I" + strings.Join(includes, " -I")
}
func (c *Compiler) cflagsString() string {
- cflags := cli.SortFields(c.info.Cflags...)
+ cflags := util.SortFields(c.info.Cflags...)
return strings.Join(cflags, " ")
}
func (c *Compiler) lflagsString() string {
- lflags := cli.SortFields(c.info.Lflags...)
+ lflags := util.SortFields(c.info.Lflags...)
return strings.Join(lflags, " ")
}
@@ -218,7 +217,7 @@ func (c *Compiler) CompileFileCmd(file string,
//
// @param file The name of the source file.
func (c *Compiler) GenDepsForFile(file string) error {
- if cli.NodeNotExist(c.dstDir) {
+ if util.NodeNotExist(c.dstDir) {
os.MkdirAll(c.dstDir, 0755)
}
@@ -231,7 +230,7 @@ func (c *Compiler) GenDepsForFile(file string) error {
cmd = c.ccPath + " " + c.cflagsString() + " " + c.includesString() +
" -MM -MG " + file + " > " + depFile
- _, err = cli.ShellCommand(cmd)
+ _, err = util.ShellCommand(cmd)
if err != nil {
return err
}
@@ -261,7 +260,7 @@ func writeCommandFile(dstFile string, cmd string) error {
// @param file The filename of the source file to compile.
// @param compilerType One of the COMPILER_TYPE_[...] constants.
func (c *Compiler) CompileFile(file string, compilerType int) error {
- if cli.NodeNotExist(c.dstDir) {
+ if util.NodeNotExist(c.dstDir) {
os.MkdirAll(c.dstDir, 0755)
}
@@ -277,16 +276,16 @@ func (c *Compiler) CompileFile(file string, compilerType int) error {
switch compilerType {
case COMPILER_TYPE_C:
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Compiling %s\n", file)
+ util.StatusMessage(util.VERBOSITY_DEFAULT, "Compiling %s\n", file)
case COMPILER_TYPE_ASM:
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Assembling %s\n", file)
+ util.StatusMessage(util.VERBOSITY_DEFAULT, "Assembling %s\n", file)
default:
return util.NewNewtError("Unknown compiler type")
}
- rsp, err := cli.ShellCommand(cmd)
+ rsp, err := util.ShellCommand(cmd)
if err != nil {
- cli.StatusMessage(cli.VERBOSITY_QUIET, string(rsp))
+ util.StatusMessage(util.VERBOSITY_QUIET, string(rsp))
return err
}
@@ -445,7 +444,7 @@ func (c *Compiler) getObjFiles(baseObjFiles []string) string {
func (c *Compiler) CompileBinaryCmd(dstFile string, options map[string]bool,
objFiles []string) string {
- objList := c.getObjFiles(cli.UniqueStrings(objFiles))
+ objList := c.getObjFiles(util.UniqueStrings(objFiles))
cmd := c.ccPath + " -o " + dstFile + " " + " " + c.cflagsString()
if c.ldResolveCircularDeps {
@@ -459,7 +458,7 @@ func (c *Compiler) CompileBinaryCmd(dstFile string, options map[string]bool,
if c.LinkerScript != "" {
cmd += " -T " + c.LinkerScript
}
- if cli.CheckBoolMap(options, "mapFile") {
+ if options["mapFile"] {
cmd += " -Wl,-Map=" + dstFile + ".map"
}
@@ -476,16 +475,16 @@ func (c *Compiler) CompileBinaryCmd(dstFile string, options map[string]bool,
func (c *Compiler) CompileBinary(dstFile string, options map[string]bool,
objFiles []string) error {
- objList := c.getObjFiles(cli.UniqueStrings(objFiles))
+ objList := c.getObjFiles(util.UniqueStrings(objFiles))
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Linking %s\n", path.Base(dstFile))
- cli.StatusMessage(cli.VERBOSITY_VERBOSE, "Linking %s with input files %s\n",
+ util.StatusMessage(util.VERBOSITY_DEFAULT, "Linking %s\n", path.Base(dstFile))
+ util.StatusMessage(util.VERBOSITY_VERBOSE, "Linking %s with input files %s\n",
dstFile, objList)
cmd := c.CompileBinaryCmd(dstFile, options, objFiles)
- rsp, err := cli.ShellCommand(cmd)
+ rsp, err := util.ShellCommand(cmd)
if err != nil {
- cli.StatusMessage(cli.VERBOSITY_QUIET, string(rsp))
+ util.StatusMessage(util.VERBOSITY_QUIET, string(rsp))
return err
}
@@ -511,17 +510,17 @@ func (c *Compiler) generateExtras(elfFilename string,
var cmd string
- if cli.CheckBoolMap(options, "listFile") {
+ if options["listFile"] {
listFile := elfFilename + ".lst"
// if list file exists, remove it
- if cli.NodeExist(listFile) {
+ if util.NodeExist(listFile) {
if err := os.RemoveAll(listFile); err != nil {
return err
}
}
cmd = c.odPath + " -wxdS " + elfFilename + " >> " + listFile
- _, err := cli.ShellCommand(cmd)
+ _, err := util.ShellCommand(cmd)
if err != nil {
// XXX: gobjdump appears to always crash. Until we get that sorted
// out, don't fail the link process if lst generation fails.
@@ -532,21 +531,21 @@ func (c *Compiler) generateExtras(elfFilename string,
for _, sect := range sects {
cmd = c.odPath + " -s -j " + sect + " " + elfFilename + " >> " +
listFile
- cli.ShellCommand(cmd)
+ util.ShellCommand(cmd)
}
cmd = c.osPath + " " + elfFilename + " >> " + listFile
- _, err = cli.ShellCommand(cmd)
+ _, err = util.ShellCommand(cmd)
if err != nil {
return err
}
}
- if cli.CheckBoolMap(options, "binFile") {
+ if options["binFile"] {
binFile := elfFilename + ".bin"
cmd = c.ocPath + " -R .bss -R .bss.core -R .bss.core.nz -O binary " +
elfFilename + " " + binFile
- _, err := cli.ShellCommand(cmd)
+ _, err := util.ShellCommand(cmd)
if err != nil {
return err
}
@@ -622,10 +621,10 @@ func (c *Compiler) CompileArchive(archiveFile string) error {
return util.NewNewtError(err.Error())
}
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Archiving %s\n",
+ util.StatusMessage(util.VERBOSITY_DEFAULT, "Archiving %s\n",
path.Base(archiveFile))
objList := c.getObjFiles([]string{})
- cli.StatusMessage(cli.VERBOSITY_VERBOSE, "Archiving %s with object "+
+ util.StatusMessage(util.VERBOSITY_VERBOSE, "Archiving %s with object "+
"files %s\n", archiveFile, objList)
// Delete the old archive, if it exists.
@@ -635,9 +634,9 @@ func (c *Compiler) CompileArchive(archiveFile string) error {
}
cmd := c.CompileArchiveCmd(archiveFile, objFiles)
- rsp, err := cli.ShellCommand(cmd)
+ rsp, err := util.ShellCommand(cmd)
if err != nil {
- cli.StatusMessage(cli.VERBOSITY_QUIET, string(rsp))
+ util.StatusMessage(util.VERBOSITY_QUIET, string(rsp))
return err
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/newt/toolchain/deps.go
----------------------------------------------------------------------
diff --git a/newt/toolchain/deps.go b/newt/toolchain/deps.go
index 01e74de..fa639a5 100644
--- a/newt/toolchain/deps.go
+++ b/newt/toolchain/deps.go
@@ -26,7 +26,6 @@ import (
"strings"
"time"
- "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/util"
)
@@ -55,7 +54,7 @@ func NewDepTracker(c *Compiler) DepTracker {
//
// This function ignores all lines except for the first.
func ParseDepsFile(filename string) ([]string, error) {
- lines, err := cli.ReadLines(filename)
+ lines, err := util.ReadLines(filename)
if err != nil {
return nil, err
}
@@ -84,7 +83,7 @@ func ParseDepsFile(filename string) ([]string, error) {
// modification time of the specified file. If the specified file is older
// than the tracker's currently most-recent time, this function has no effect.
func (tracker *DepTracker) ProcessFileTime(file string) error {
- modTime, err := cli.FileModificationTime(file)
+ modTime, err := util.FileModificationTime(file)
if err != nil {
return err
}
@@ -140,17 +139,17 @@ func (tracker *DepTracker) CompileRequired(srcFile string,
return false, err
}
if commandHasChanged(objFile, cmd) {
- cli.StatusMessage(util.VERBOSITY_VERBOSE, "%s - rebuild required; "+
+ util.StatusMessage(util.VERBOSITY_VERBOSE, "%s - rebuild required; "+
"different command\n", srcFile)
return true, nil
}
- srcModTime, err := cli.FileModificationTime(srcFile)
+ srcModTime, err := util.FileModificationTime(srcFile)
if err != nil {
return false, err
}
- objModTime, err := cli.FileModificationTime(objFile)
+ objModTime, err := util.FileModificationTime(objFile)
if err != nil {
return false, err
}
@@ -158,7 +157,7 @@ func (tracker *DepTracker) CompileRequired(srcFile string,
// If the object doesn't exist or is older than the source file, a build is
// required; no need to check dependencies.
if srcModTime.After(objModTime) {
- cli.StatusMessage(util.VERBOSITY_VERBOSE, "%s - rebuild required; "+
+ util.StatusMessage(util.VERBOSITY_VERBOSE, "%s - rebuild required; "+
"source newer than obj\n", srcFile)
return true, nil
}
@@ -166,7 +165,7 @@ func (tracker *DepTracker) CompileRequired(srcFile string,
// Determine if the dependency (.d) file needs to be generated. If it
// doesn't exist or is older than the source file, it is out of date and
// needs to be created.
- depModTime, err := cli.FileModificationTime(depFile)
+ depModTime, err := util.FileModificationTime(depFile)
if err != nil {
return false, err
}
@@ -186,7 +185,7 @@ func (tracker *DepTracker) CompileRequired(srcFile string,
// Check if any dependencies are newer than the destination object file.
for _, dep := range deps {
- if cli.NodeNotExist(dep) {
+ if util.NodeNotExist(dep) {
// The dependency has been deleted; the .d file is out of date.
// Recreate the dependency file and repeat this entire function.
err := tracker.compiler.GenDepsForFile(srcFile)
@@ -196,14 +195,14 @@ func (tracker *DepTracker) CompileRequired(srcFile string,
return tracker.CompileRequired(srcFile, compilerType)
} else {
- depModTime, err = cli.FileModificationTime(dep)
+ depModTime, err = util.FileModificationTime(dep)
if err != nil {
return false, err
}
}
if depModTime.After(objModTime) {
- cli.StatusMessage(util.VERBOSITY_VERBOSE, "%s - rebuild required; obj older than dependency (%s)\n", srcFile, dep)
+ util.StatusMessage(util.VERBOSITY_VERBOSE, "%s - rebuild required; obj older than dependency (%s)\n", srcFile, dep)
return true, nil
}
}
@@ -230,7 +229,7 @@ func (tracker *DepTracker) ArchiveRequired(archiveFile string,
// If the archive doesn't exist or is older than any object file, a rebuild
// is required.
- aModTime, err := cli.FileModificationTime(archiveFile)
+ aModTime, err := util.FileModificationTime(archiveFile)
if err != nil {
return false, err
}
@@ -264,7 +263,7 @@ func (tracker *DepTracker) LinkRequired(dstFile string,
// If the elf file doesn't exist or is older than any input file, a rebuild
// is required.
- dstModTime, err := cli.FileModificationTime(dstFile)
+ dstModTime, err := util.FileModificationTime(dstFile)
if err != nil {
return false, err
}
@@ -279,7 +278,7 @@ func (tracker *DepTracker) LinkRequired(dstFile string,
objFiles = append(objFiles, tracker.compiler.LinkerScript)
}
for _, obj := range objFiles {
- objModTime, err := cli.FileModificationTime(obj)
+ objModTime, err := util.FileModificationTime(obj)
if err != nil {
return false, err
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cc41f163/util/util.go
----------------------------------------------------------------------
diff --git a/util/util.go b/util/util.go
index 4ac925d..dc439ac 100644
--- a/util/util.go
+++ b/util/util.go
@@ -20,14 +20,22 @@
package util
import (
+ "bufio"
"fmt"
"github.com/hashicorp/logutils"
+ "io/ioutil"
"log"
"mynewt.apache.org/newt/viper"
"os"
+ "os/exec"
+ "os/signal"
+ "path"
"path/filepath"
"runtime"
+ "sort"
"strings"
+ "syscall"
+ "time"
)
var Logger *log.Logger
@@ -66,6 +74,71 @@ func NewNewtError(msg string) *NewtError {
return err
}
+// Print Silent, Quiet and Verbose aware status messages to stdout.
+func StatusMessage(level int, message string, args ...interface{}) {
+ if Verbosity >= level {
+ fmt.Printf(message, args...)
+ }
+}
+
+// Print Silent, Quiet and Verbose aware status messages to stderr.
+func ErrorMessage(level int, message string, args ...interface{}) {
+ if Verbosity >= level {
+ fmt.Fprintf(os.Stderr, message, args...)
+ }
+}
+
+func NodeExist(path string) bool {
+ if _, err := os.Stat(path); err == nil {
+ return true
+ } else {
+ return false
+ }
+}
+
+// Check whether the node (either dir or file) specified by path exists
+func NodeNotExist(path string) bool {
+ if _, err := os.Stat(path); os.IsNotExist(err) {
+ return true
+ } else {
+ return false
+ }
+}
+
+func FileModificationTime(path string) (time.Time, error) {
+ fileInfo, err := os.Stat(path)
+ if err != nil {
+ epoch := time.Unix(0, 0)
+ if os.IsNotExist(err) {
+ return epoch, nil
+ } else {
+ return epoch, NewNewtError(err.Error())
+ }
+ }
+
+ return fileInfo.ModTime(), nil
+}
+
+func ChildDirs(path string) ([]string, error) {
+ children, err := ioutil.ReadDir(path)
+ if err != nil {
+ return nil, NewNewtError(err.Error())
+ }
+
+ childDirs := []string{}
+ for _, child := range children {
+ name := child.Name()
+ if !filepath.HasPrefix(name, ".") &&
+ !filepath.HasPrefix(name, "..") &&
+ child.IsDir() {
+
+ childDirs = append(childDirs, name)
+ }
+ }
+
+ return childDirs, nil
+}
+
func Min(x, y int) int {
if x < y {
return x
@@ -80,8 +153,8 @@ func Max(x, y int) int {
return y
}
-// Initialize the CLI module
-func Init(level string, silent bool, quiet bool, verbose bool) {
+// Initialize the util module
+func Init(level string, verbosity int) {
if level == "" {
level = "WARN"
}
@@ -94,21 +167,7 @@ func Init(level string, silent bool, quiet bool, verbose bool) {
}
log.SetOutput(filter)
-
- if silent {
- Verbosity = VERBOSITY_SILENT
- } else if quiet {
- Verbosity = VERBOSITY_QUIET
- } else if verbose {
- Verbosity = VERBOSITY_VERBOSE
- } else {
- Verbosity = VERBOSITY_DEFAULT
- }
-}
-
-func CheckBoolMap(mapVar map[string]bool, item string) bool {
- v, ok := mapVar[item]
- return v && ok
+ Verbosity = verbosity
}
// Read in the configuration file specified by name, in path
@@ -127,3 +186,182 @@ func ReadConfig(path string, name string) (*viper.Viper, error) {
return v, nil
}
}
+
+func DescendantDirsOfParent(rootPath string, parentName string, fullPath bool) ([]string, error) {
+ rootPath = path.Clean(rootPath)
+
+ if NodeNotExist(rootPath) {
+ return []string{}, nil
+ }
+
+ children, err := ChildDirs(rootPath)
+ if err != nil {
+ return nil, err
+ }
+
+ dirs := []string{}
+ if path.Base(rootPath) == parentName {
+ for _, child := range children {
+ if fullPath {
+ child = rootPath + "/" + child
+ }
+
+ dirs = append(dirs, child)
+ }
+ } else {
+ for _, child := range children {
+ childPath := rootPath + "/" + child
+ subDirs, err := DescendantDirsOfParent(childPath, parentName,
+ fullPath)
+ if err != nil {
+ return nil, err
+ }
+
+ dirs = append(dirs, subDirs...)
+ }
+ }
+
+ return dirs, nil
+}
+
+// Execute the command specified by cmdStr on the shell and return results
+func ShellCommand(cmdStr string) ([]byte, error) {
+ log.Print("[VERBOSE] " + cmdStr)
+ cmd := exec.Command("sh", "-c", cmdStr)
+
+ o, err := cmd.CombinedOutput()
+ log.Print("[VERBOSE] o=" + string(o))
+ if err != nil {
+ return o, NewNewtError(err.Error())
+ } else {
+ return o, nil
+ }
+}
+
+// Run interactive shell command
+func ShellInteractiveCommand(cmdStr []string) error {
+ log.Print("[VERBOSE] " + cmdStr[0])
+
+ //
+ // Block SIGINT, at least.
+ // Otherwise Ctrl-C meant for gdb would kill newt.
+ //
+ c := make(chan os.Signal, 1)
+ signal.Notify(c, os.Interrupt)
+ signal.Notify(c, syscall.SIGTERM)
+ go func() {
+ <-c
+ }()
+
+ // Transfer stdin, stdout, and stderr to the new process
+ // and also set target directory for the shell to start in.
+ pa := os.ProcAttr{
+ Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
+ }
+
+ // Start up a new shell.
+ proc, err := os.StartProcess(cmdStr[0], cmdStr, &pa)
+ if err != nil {
+ signal.Stop(c)
+ return NewNewtError(err.Error())
+ }
+
+ // Release and exit
+ _, err = proc.Wait()
+ if err != nil {
+ signal.Stop(c)
+ return NewNewtError(err.Error())
+ }
+ signal.Stop(c)
+ return nil
+}
+
+func CopyFile(srcFile string, destFile string) error {
+ _, err := ShellCommand(fmt.Sprintf("mkdir -p %s", filepath.Dir(destFile)))
+ if err != nil {
+ return err
+ }
+ if _, err := ShellCommand(fmt.Sprintf("cp -Rf %s %s", srcFile,
+ destFile)); err != nil {
+ return err
+ }
+ return nil
+}
+
+func CopyDir(srcDir, destDir string) error {
+ return CopyFile(srcDir, destDir)
+}
+
+// Reads each line from the specified text file into an array of strings. If a
+// line ends with a backslash, it is concatenated with the following line.
+func ReadLines(path string) ([]string, error) {
+ file, err := os.Open(path)
+ if err != nil {
+ return nil, NewNewtError(err.Error())
+ }
+ defer file.Close()
+
+ lines := []string{}
+ scanner := bufio.NewScanner(file)
+
+ for scanner.Scan() {
+ line := scanner.Text()
+ concatted := false
+
+ if len(lines) != 0 {
+ prevLine := lines[len(lines)-1]
+ if len(prevLine) > 0 && prevLine[len(prevLine)-1:] == "\\" {
+ prevLine = prevLine[:len(prevLine)-1]
+ prevLine += line
+ lines[len(lines)-1] = prevLine
+
+ concatted = true
+ }
+ }
+
+ if !concatted {
+ lines = append(lines, line)
+ }
+ }
+
+ if scanner.Err() != nil {
+ return lines, NewNewtError(scanner.Err().Error())
+ }
+
+ return lines, nil
+}
+
+// Removes all duplicate strings from the specified array, while preserving
+// order.
+func UniqueStrings(elems []string) []string {
+ set := make(map[string]bool)
+ result := make([]string, 0)
+
+ for _, elem := range elems {
+ if !set[elem] {
+ result = append(result, elem)
+ set[elem] = true
+ }
+ }
+
+ return result
+}
+
+// Sorts whitespace-delimited lists of strings.
+//
+// @param wsSepStrings A list of strings; each string contains one or
+// more whitespace-delimited tokens.
+//
+// @return A slice containing all the input tokens, sorted
+// alphabetically.
+func SortFields(wsSepStrings ...string) []string {
+ slice := []string{}
+
+ for _, s := range wsSepStrings {
+ slice = append(slice, strings.Fields(s)...)
+ }
+
+ slice = UniqueStrings(slice)
+ sort.Strings(slice)
+ return slice
+}
[35/50] incubator-mynewt-newt git commit: merge chris' last commit.
cleanup installation logic a bit. more to go
Posted by ma...@apache.org.
merge chris' last commit. cleanup installation logic a bit. more to go
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/88156134
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/88156134
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/88156134
Branch: refs/heads/develop
Commit: 88156134144fa3df30e5d098c83309f5c0baf89c
Parents: 37bd71f cc41f16
Author: Sterling Hughes <st...@apache.org>
Authored: Tue Mar 8 19:29:01 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Mar 8 19:29:01 2016 -0800
----------------------------------------------------------------------
newt/builder/build.go | 29 ++--
newt/builder/buildpackage.go | 2 +-
newt/builder/buildutil.go | 5 +
newt/builder/cmds.go | 2 +-
newt/builder/download.go | 5 +-
newt/builder/size.go | 3 +-
newt/cli/util.go | 283 -------------------------------------
newt/downloader/downloader.go | 5 +-
newt/image/cmds.go | 9 ++
newt/image/image.go | 24 ++--
newt/newt.go | 11 +-
newt/pkg/localpackage.go | 5 +-
newt/project/project.go | 44 +++---
newt/project/projectstate.go | 3 +-
newt/repo/repo.go | 15 +-
newt/target/cmds.go | 14 +-
newt/target/target.go | 3 +-
newt/target/vars.go | 5 +-
newt/toolchain/compiler.go | 59 ++++----
newt/toolchain/deps.go | 27 ++--
util/util.go | 272 ++++++++++++++++++++++++++++++++---
21 files changed, 397 insertions(+), 428 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/88156134/newt/project/project.go
----------------------------------------------------------------------
diff --cc newt/project/project.go
index 1967481,a7438cd..e5f21e6
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@@ -139,98 -138,82 +138,111 @@@ func (proj *Project) PackageSearchDirs(
return proj.packageSearchDirs
}
-func (proj *Project) Install(upgrade bool, force bool) error {
- repoList := proj.Repos()
- for rname, r := range repoList {
- // Ignore the local repo on install
- if rname == repo.REPO_NAME_LOCAL {
- continue
- }
- // Download repository description. Try and resolve this
- // repository out of the repo list (repodesc for each repo.)
- // If matching repository is found, then prompt for install and install
- // that repository.
- if err := r.DownloadDesc(); err != nil {
- return err
- }
+func (proj *Project) upgradeCheck(r *repo.Repo, vers *repo.Version,
+ upgrade bool, force bool) (bool, error) {
+ rdesc, err := r.GetRepoDesc()
+ if err != nil {
+ return false, err
+ }
- rdesc, err := r.ReadDesc()
- if err != nil {
- return err
+ if !upgrade {
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
++ util.StatusMessage(util.VERBOSITY_DEFAULT,
+ fmt.Sprintf("Installed repository %s has version %s, "+
+ "which meets project requirements. Moving on to next repository.\n",
+ r.Name(), vers))
+ return true, nil
+ } else {
+ _, newVers, _ := rdesc.Match(r)
+ if newVers == nil {
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
++ util.StatusMessage(util.VERBOSITY_DEFAULT,
+ "No matching version to upgrade to "+
+ "found for %s. Please check your project requirements, and use the "+
+ "project show-repo command to see available repository versions.",
+ r.Name())
+ return false, util.NewNewtError(fmt.Sprintf("Cannot find a "+
+ "version of repository %s that matches project requirements.",
+ r.Name()))
}
- vers := proj.projState.GetInstalledVersion(rname)
- if vers != nil {
- ok := rdesc.SatisfiesVersion(vers, r.VersionRequirements())
- if !ok && !upgrade {
- fmt.Printf("WARNING: Installed version %s of repository %s "+
- "does not match desired versions %s in project\n",
- vers, rname, r.VersionRequirementsString())
- continue
- }
-
- if !upgrade {
- util.StatusMessage(util.VERBOSITY_DEFAULT,
- fmt.Sprintf("Installed repository %s matches project requirements, "+
- "moving on to next repository.\n", r.Name()))
- continue
- } else {
- _, newVers, _ := rdesc.Match(r)
- if newVers == nil {
- return util.NewNewtError(fmt.Sprintf(
- "No matching version for repository %s\n", r.Name()))
+ // If the change between the old repository and the new repository would cause
+ // and upgrade. Then prompt for an upgrade response, unless the force option
+ // is present.
+ if vers.CompareVersions(newVers, vers) != 0 ||
+ vers.Stability() != newVers.Stability() {
+ if !force {
+ branch, newVers, _ := rdesc.Match(r)
+
+ str := ""
+ if newVers.Stability() != repo.VERSION_STABILITY_NONE {
+ str += "(" + branch + ")"
}
- if vers.CompareVersions(newVers, vers) != 0 ||
- vers.Stability() != newVers.Stability() {
- // Prompt for upgrade, unless force option present
- if !force {
- branch, newVers, _ := rdesc.Match(r)
-
- str := ""
- if newVers.Stability() != repo.VERSION_STABILITY_NONE {
- str += "(" + branch + ")"
- }
-
- fmt.Printf("Would you like to upgrade repository %s from %s to %s %s? [Yn] ",
- r.Name(), vers.String(), newVers.String(), str)
-
- line, more, err := bufio.NewReader(os.Stdin).ReadLine()
- if more || err != nil {
- return util.NewNewtError(fmt.Sprintf(
- "Couldn't read upgrade response: %s\n", err.Error()))
- }
- answer := strings.ToUpper(strings.Trim(string(line), " "))
- if answer == "N" || answer == "NO" {
- fmt.Printf("Users says don't upgrade, skipping upgrade of %s\n",
- r.Name())
- continue
- }
- }
+ fmt.Printf("Would you like to upgrade repository %s from %s to %s %s? [Yn] ",
+ r.Name(), vers.String(), newVers.String(), str)
+
- line, more, err := bufio.NewReader(os.Stdin).ReadLine()
- if more || err != nil {
- return false, util.NewNewtError(fmt.Sprintf(
- "Couldn't read upgrade response: %s\n", err.Error()))
- }
- // Anything but no means yes.
- answer := strings.ToUpper(strings.Trim(string(line), " "))
- if answer == "N" || answer == "NO" {
- fmt.Printf("Users says don't upgrade, skipping upgrade of %s\n",
- r.Name())
++ if !upgrade {
++ util.StatusMessage(util.VERBOSITY_DEFAULT,
++ fmt.Sprintf("Installed repository %s matches project requirements, "+
++ "moving on to next repository.\n", r.Name()))
+ return true, nil
+ } else {
- fmt.Printf("Repository %s doesn't need to be upgraded, latest "+
- "version installed.\n", r.Name())
- continue
++ _, newVers, _ := rdesc.Match(r)
++ if newVers == nil {
++ return true, util.NewNewtError(fmt.Sprintf(
++ "No matching version for repository %s\n", r.Name()))
++ }
++ line, more, err := bufio.NewReader(os.Stdin).ReadLine()
++ if more || err != nil {
++ return false, util.NewNewtError(fmt.Sprintf(
++ "Couldn't read upgrade response: %s\n", err.Error()))
++ }
++
++ // Anything but no means yes.
++ answer := strings.ToUpper(strings.Trim(string(line), " "))
++ if answer == "N" || answer == "NO" {
++ fmt.Printf("Users says don't upgrade, skipping upgrade of %s\n",
++ r.Name())
++ return true, nil
++ }
}
}
+ } else {
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
++ util.StatusMessage(util.VERBOSITY_DEFAULT,
+ "Repository %s doesn't need to be upgraded, latest "+
+ "version installed.\n", r.Name())
+ return true, nil
}
+ }
+
+ return false, nil
+}
+
+func (proj *Project) checkVersionRequirements(r *repo.Repo, upgrade bool, force bool) (bool, error) {
+ rdesc, err := r.GetRepoDesc()
+ if err != nil {
+ return false, err
+ }
+ rname := r.Name()
+
+ vers := proj.projState.GetInstalledVersion(rname)
+ if vers != nil {
+ ok := rdesc.SatisfiesVersion(vers, r.VersionRequirements())
+ if !ok && !upgrade {
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "WARNING: Installed"+
++ util.StatusMessage(util.VERBOSITY_DEFAULT, "WARNING: Installed"+
+ "version %s of repository %s does not match desired "+
+ "version %s in project file. You can fix this by either upgrading"+
+ " your repository, or modifying the project.yml file.\n",
+ vers, rname, r.VersionRequirementsString())
+ return true, err
+ } else {
+ skip, err := proj.upgradeCheck(r, vers, upgrade, force)
+ return skip, err
+ }
+ } else {
+ // Fallthrough and perform the installation.
+ // Check to make sure that this repository contains a version
+ // that can satisfy.
_, _, ok := rdesc.Match(r)
if !ok {
fmt.Printf("WARNING: No matching repository version found for repository "+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/88156134/newt/repo/repo.go
----------------------------------------------------------------------
diff --cc newt/repo/repo.go
index a41a0b7,eb8d596..4ae8865
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@@ -190,9 -179,9 +189,9 @@@ func (r *Repo) repoFilePath() string
".configs/" + r.name + "/"
}
-func (r *Repo) Install(rdesc *RepoDesc, force bool) (*Version, error) {
+func (r *Repo) Install(force bool) (*Version, error) {
// Copy the git repo into /repos/, error'ing out if the repo already exists
- if cli.NodeExist(r.Path()) {
+ if util.NodeExist(r.Path()) {
if force {
if err := os.RemoveAll(r.Path()); err != nil {
return nil, util.NewNewtError(err.Error())
[46/50] incubator-mynewt-newt git commit: "test all" command.
Posted by ma...@apache.org.
"test all" command.
Note: Some tests fail due to some sim/os issues which need to be
addressed.
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/e49f113f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/e49f113f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/e49f113f
Branch: refs/heads/develop
Commit: e49f113f3817867b8ee690ac4f7ec07ecf417cb7
Parents: d9b22a6
Author: ccollins at iori.nightmare.heaven <cc...@iori.nightmare-heaven.no-ip.biz>
Authored: Wed Mar 9 09:59:25 2016 -0800
Committer: ccollins at iori.nightmare.heaven <cc...@iori.nightmare-heaven.no-ip.biz>
Committed: Wed Mar 9 10:00:09 2016 -0800
----------------------------------------------------------------------
newt/builder/cmds.go | 71 +++++++++++++++++++++++++++----------------
newt/pkg/localpackage.go | 8 +++--
2 files changed, 50 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e49f113f/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index abcbd47..dcdb37c 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -99,40 +99,57 @@ func testRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, nil)
}
- t := target.ResolveTarget(TARGET_TEST_NAME)
- if t == nil {
- cli.NewtUsage(cmd, util.NewNewtError("can't find unit test target: "+
- TARGET_TEST_NAME))
- }
-
- b, err := NewBuilder(t)
- if err != nil {
- cli.NewtUsage(cmd, err)
- }
-
// Verify and resolve each specified package.
+ testAll := false
packs := []*pkg.LocalPackage{}
for _, pkgName := range args {
- dep, err := pkg.NewDependency(nil, pkgName)
- if err != nil {
- cli.NewtUsage(cmd, util.NewNewtError(fmt.Sprintf("invalid "+
- "package name: %s (%s)", pkgName, err.Error())))
- }
- if dep == nil {
- cli.NewtUsage(cmd, util.NewNewtError("invalid package name: "+
- pkgName))
- }
- pack := project.GetProject().ResolveDependency(dep)
- if pack == nil {
- cli.NewtUsage(cmd, util.NewNewtError("unknown package: "+
- pkgName))
- }
+ if pkgName == "all" {
+ testAll = true
+ } else {
+ dep, err := pkg.NewDependency(nil, pkgName)
+ if err != nil {
+ cli.NewtUsage(cmd, util.NewNewtError(fmt.Sprintf("invalid "+
+ "package name: %s (%s)", pkgName, err.Error())))
+ }
+ if dep == nil {
+ cli.NewtUsage(cmd, util.NewNewtError("invalid package name: "+
+ pkgName))
+ }
+ pack := project.GetProject().ResolveDependency(dep)
+ if pack == nil {
+ cli.NewtUsage(cmd, util.NewNewtError("unknown package: "+
+ pkgName))
+ }
+
+ packs = append(packs, pack.(*pkg.LocalPackage))
+ }
+ }
- packs = append(packs, pack.(*pkg.LocalPackage))
+ // Test each specified package.
+ t := target.ResolveTarget(TARGET_TEST_NAME)
+ if t == nil {
+ cli.NewtUsage(cmd, util.NewNewtError("Can't find unit test target: "+
+ TARGET_TEST_NAME))
}
- // Test each package.
+ if testAll {
+ packs = []*pkg.LocalPackage{}
+ for _,repoHash := range project.GetProject().PackageList() {
+ for _,pack := range *repoHash {
+ lclPack := pack.(*pkg.LocalPackage)
+ if lclPack.IsTestable() {
+ packs = append(packs, lclPack)
+ }
+ }
+ }
+ }
+
for _, pack := range packs {
+ b, err := NewBuilder(t)
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+
err = b.Test(pack)
if err != nil {
cli.NewtUsage(cmd, err)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e49f113f/newt/pkg/localpackage.go
----------------------------------------------------------------------
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index 089f7cf..52a7c77 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -200,8 +200,6 @@ func (pkg *LocalPackage) readDesc(v *viper.Viper) (*PackageDesc, error) {
return pdesc, nil
}
-// Load reads everything that isn't identity specific into the
-// package
func (pkg *LocalPackage) Init(repo *repo.Repo, pkgDir string) {
pkg.repo = repo
pkg.basePath = filepath.Clean(pkgDir) + "/"
@@ -240,6 +238,8 @@ func (pkg *LocalPackage) Save() error {
return nil
}
+// Load reads everything that isn't identity specific into the
+// package
func (pkg *LocalPackage) Load() error {
// Load configuration
log.Printf("[DEBUG] Loading configuration for package %s", pkg.basePath)
@@ -272,6 +272,10 @@ func (pkg *LocalPackage) Load() error {
return nil
}
+func (pkg *LocalPackage) IsTestable() bool {
+ return util.NodeExist(pkg.BasePath() + "/src/test")
+}
+
func LoadLocalPackage(repo *repo.Repo, pkgDir string) (*LocalPackage, error) {
pkg := &LocalPackage{}
pkg.Init(repo, pkgDir)
[16/50] incubator-mynewt-newt git commit: Escape strings in generated
yml files.
Posted by ma...@apache.org.
Escape strings in generated yml files.
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/9446bbca
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/9446bbca
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/9446bbca
Branch: refs/heads/develop
Commit: 9446bbca6740fd0222dc48bad259ff7627876dc7
Parents: 19fea21
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 14:32:31 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 14:32:31 2016 -0800
----------------------------------------------------------------------
newt/pkg/localpackage.go | 18 ++++++++++++------
newt/target/target.go | 3 ++-
yaml/misc.go | 32 ++++++++++++++++++++++++++++++++
3 files changed, 46 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9446bbca/newt/pkg/localpackage.go
----------------------------------------------------------------------
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index 876282c..0e1e17f 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -34,6 +34,7 @@ import (
"mynewt.apache.org/newt/newt/interfaces"
"mynewt.apache.org/newt/newt/repo"
"mynewt.apache.org/newt/util"
+ "mynewt.apache.org/newt/yaml"
)
var PackageHashIgnoreDirs = map[string]bool{
@@ -205,12 +206,17 @@ func (pkg *LocalPackage) Save() error {
file.WriteString("### Package: " + pkg.Name() + "\n\n")
- file.WriteString("pkg.name: " + pkg.Name() + "\n")
- file.WriteString("pkg.type: " + PackageTypeNames[pkg.Type()] + "\n")
- file.WriteString("pkg.description: " + pkg.Desc().Description + "\n")
- file.WriteString("pkg.author: " + pkg.Desc().Author + "\n")
- file.WriteString("pkg.homepage: " + pkg.Desc().Homepage + "\n")
- file.WriteString("pkg.repository: " + pkg.Repo().Name() + "\n")
+ file.WriteString("pkg.name: " + yaml.EscapeString(pkg.Name()) + "\n")
+ file.WriteString("pkg.type: " +
+ yaml.EscapeString(PackageTypeNames[pkg.Type()]) + "\n")
+ file.WriteString("pkg.description: " +
+ yaml.EscapeString(pkg.Desc().Description) + "\n")
+ file.WriteString("pkg.author: " +
+ yaml.EscapeString(pkg.Desc().Author) + "\n")
+ file.WriteString("pkg.homepage: " +
+ yaml.EscapeString(pkg.Desc().Homepage) + "\n")
+ file.WriteString("pkg.repository: " +
+ yaml.EscapeString(pkg.Repo().Name()) + "\n")
return nil
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9446bbca/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 99c8d1f..62b0b5f 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -31,6 +31,7 @@ import (
"mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/util"
+ "mynewt.apache.org/newt/yaml"
)
const TARGET_FILE_NAME string = "target.yml"
@@ -185,7 +186,7 @@ func (t *Target) Save() error {
sort.Strings(keys)
for _, k := range keys {
- file.WriteString(k + ": " + t.Vars[k] + "\n")
+ file.WriteString(k + ": " + yaml.EscapeString(t.Vars[k]) + "\n")
}
return nil
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9446bbca/yaml/misc.go
----------------------------------------------------------------------
diff --git a/yaml/misc.go b/yaml/misc.go
new file mode 100644
index 0000000..3b270fa
--- /dev/null
+++ b/yaml/misc.go
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package yaml
+
+import (
+ "strings"
+)
+
+func EscapeString(s string) string {
+ if s == "" {
+ return ""
+ } else {
+ return "\"" + strings.Replace(s, "\"", "\\\"", -1) + "\""
+ }
+}
[26/50] incubator-mynewt-newt git commit: Remove some debug printf
calls.
Posted by ma...@apache.org.
Remove some debug printf calls.
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/a54695c2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/a54695c2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/a54695c2
Branch: refs/heads/develop
Commit: a54695c232e496429591a28b8c6d46b9d56cbfad
Parents: aef3d39
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 15:28:03 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 17:32:44 2016 -0800
----------------------------------------------------------------------
newt/target/target.go | 4 ----
1 file changed, 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a54695c2/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 39714d4..2a4f781 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -20,7 +20,6 @@
package target
import (
- "fmt"
"io/ioutil"
"os"
"path/filepath"
@@ -117,14 +116,11 @@ func (target *Target) ShortName() string {
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)
return nil
}
[31/50] incubator-mynewt-newt git commit: pretty up the help a little
Posted by ma...@apache.org.
pretty up the help a little
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/35e2e6f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/35e2e6f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/35e2e6f1
Branch: refs/heads/develop
Commit: 35e2e6f1df459af70127b6b08010b186b039a270
Parents: f3842f0
Author: Sterling Hughes <st...@apache.org>
Authored: Tue Mar 8 17:39:06 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Mar 8 17:39:06 2016 -0800
----------------------------------------------------------------------
newt/project/cmds.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/35e2e6f1/newt/project/cmds.go
----------------------------------------------------------------------
diff --git a/newt/project/cmds.go b/newt/project/cmds.go
index eb08b2a..97e216c 100644
--- a/newt/project/cmds.go
+++ b/newt/project/cmds.go
@@ -56,7 +56,7 @@ func AddCommands(cmd *cobra.Command) {
installHelpEx := ""
installCmd := &cobra.Command{
Use: "install",
- Short: "Command to install project dependencies",
+ Short: "Install project dependencies",
Long: installHelpText,
Example: installHelpEx,
Run: installRunCmd,
@@ -71,7 +71,7 @@ func AddCommands(cmd *cobra.Command) {
upgradeHelpEx := ""
upgradeCmd := &cobra.Command{
Use: "upgrade",
- Short: "Command to upgrade project dependencies",
+ Short: "Upgrade project dependencies",
Long: upgradeHelpText,
Example: upgradeHelpEx,
Run: upgradeRunCmd,
[18/50] incubator-mynewt-newt git commit: Allow "naked" target name
in target create command.
Posted by ma...@apache.org.
Allow "naked" target name in target create command.
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/1be80b87
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/1be80b87
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/1be80b87
Branch: refs/heads/develop
Commit: 1be80b8763490978f4010188288852647cd3d7d1
Parents: 690cb84
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 14:45:42 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 14:45:42 2016 -0800
----------------------------------------------------------------------
newt/target/cmds.go | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1be80b87/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index 5049886..cba4dd7 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -107,10 +107,12 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
"(target-name & k=v) to set"))
}
- t := ResolveTargetName(args[0])
+ tName := args[0]
+ t := ResolveTargetName(tName)
if t == nil {
- cli.NewtUsage(cmd, util.NewNewtError("Unknown target"))
+ cli.NewtUsage(cmd, util.NewNewtError("Unknown target: "+tName))
}
+ tName = t.Name()
ar := strings.SplitN(args[1], "=", 2)
if !strings.HasPrefix(ar[0], "target.") {
@@ -139,30 +141,37 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
if ar[1] == "" {
cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Target %s successfully unset %s\n", args[0], ar[0])
+ "Target %s successfully unset %s\n", tName, ar[0])
} else {
cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Target %s successfully set %s to %s\n", args[0], ar[0], ar[1])
+ "Target %s successfully set %s to %s\n", tName, ar[0], ar[1])
}
}
}
func targetCreateCmd(cmd *cobra.Command, args []string) {
if len(args) != 1 {
- cli.NewtUsage(cmd, util.NewNewtError("Wrong number of args to create cmd."))
+ cli.NewtUsage(cmd, util.NewNewtError("Missing target name"))
}
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Creating target "+args[0]+"\n")
+ tName := args[0]
- t := ResolveTargetName(args[0])
+ // "Naked" target names go in the "targets/" directory.
+ if !strings.Contains(tName, "/") {
+ tName = "targets/" + tName
+ }
+
+ cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Creating target "+tName+"\n")
+
+ t := ResolveTargetName(tName)
if t != nil {
cli.NewtUsage(cmd, util.NewNewtError(
- "Target already exists, cannot create target with same name."))
+ "Target already exists; cannot create target with same name."))
}
repo := project.GetProject().LocalRepo()
- pack := pkg.NewLocalPackage(repo, repo.Path()+"/"+args[0])
- pack.SetName(args[0])
+ pack := pkg.NewLocalPackage(repo, repo.Path()+"/"+tName)
+ pack.SetName(tName)
pack.SetType(pkg.PACKAGE_TYPE_TARGET)
t = NewTarget(pack)
@@ -171,7 +180,7 @@ func targetCreateCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(nil, err)
} else {
cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Target %s successfully created!\n", args[0])
+ "Target %s successfully created!\n", tName)
}
}
[38/50] incubator-mynewt-newt git commit: target copy command.
Posted by ma...@apache.org.
target copy command.
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/1049e220
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/1049e220
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/1049e220
Branch: refs/heads/develop
Commit: 1049e220d5183335f89f0466274058347e9924ec
Parents: 7a3d691
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 19:38:40 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 19:39:09 2016 -0800
----------------------------------------------------------------------
newt/pkg/localpackage.go | 11 +++++
newt/target/cmds.go | 97 ++++++++++++++++++++++++++++++++++---------
2 files changed, 88 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1049e220/newt/pkg/localpackage.go
----------------------------------------------------------------------
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index f7ab295..089f7cf 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -108,6 +108,10 @@ func (pkg *LocalPackage) SetName(name string) {
pkg.name = name
}
+func (pkg *LocalPackage) SetBasePath(basePath string) {
+ pkg.basePath = basePath
+}
+
func (pkg *LocalPackage) SetType(packageType interfaces.PackageType) {
pkg.packageType = packageType
}
@@ -116,6 +120,10 @@ func (pkg *LocalPackage) SetDesc(desc *PackageDesc) {
pkg.desc = desc
}
+func (pkg *LocalPackage) SetRepo(r *repo.Repo) {
+ pkg.repo = r
+}
+
func (pkg *LocalPackage) Hash() (string, error) {
hash := sha1.New()
@@ -199,6 +207,9 @@ func (pkg *LocalPackage) Init(repo *repo.Repo, pkgDir string) {
pkg.basePath = filepath.Clean(pkgDir) + "/"
}
+// Saves the package's pkg.yml file.
+// NOTE: This does not save every field in the package. Only the fields
+// necessary for creating a new target get saved.
func (pkg *LocalPackage) Save() error {
dirpath := pkg.BasePath()
if err := os.MkdirAll(dirpath, 0755); err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1049e220/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index 98f0df6..17d61d9 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -42,6 +42,29 @@ func resolveTargetArg(arg string) (*Target, error) {
return t, nil
}
+func resolveNewTargetArg(arg string) (string, error) {
+ repoName, pkgName, err := cli.ParsePackageString(arg)
+ if err != nil {
+ return "", err
+ }
+
+ if repoName != "" {
+ return "", util.NewNewtError("Target name cannot contain repo; " +
+ "must be local")
+ }
+
+ // "Naked" target names go in the "targets/" directory.
+ if !strings.Contains(pkgName, "/") {
+ pkgName = "targets/" + pkgName
+ }
+
+ if GetTargets()[pkgName] != nil {
+ return "", util.NewNewtError("Target already exists: " + pkgName)
+ }
+
+ return pkgName, nil
+}
+
func targetShowCmd(cmd *cobra.Command, args []string) {
proj := project.GetProject()
err := proj.LoadPackageList()
@@ -169,29 +192,11 @@ func targetCreateCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, util.NewNewtError("Missing target name"))
}
- repoName, pkgName, err := cli.ParsePackageString(args[0])
+ pkgName, err := resolveNewTargetArg(args[0])
if err != nil {
cli.NewtUsage(cmd, err)
}
- if repoName != "" {
- cli.NewtUsage(cmd, util.NewNewtError("Target name cannot contain "+
- "repo; must be local"))
- }
-
- // "Naked" target names go in the "targets/" directory.
- if !strings.Contains(pkgName, "/") {
- pkgName = "targets/" + pkgName
- }
-
- util.StatusMessage(util.VERBOSITY_DEFAULT, "Creating target "+
- pkgName+"\n")
-
- if GetTargets()[pkgName] != nil {
- cli.NewtUsage(cmd, util.NewNewtError("Target already exists: "+
- pkgName))
- }
-
repo := project.GetProject().LocalRepo()
pack := pkg.NewLocalPackage(repo, repo.Path()+"/"+pkgName)
pack.SetName(pkgName)
@@ -203,7 +208,7 @@ func targetCreateCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(nil, err)
} else {
util.StatusMessage(util.VERBOSITY_DEFAULT,
- "Target %s successfully created!\n", pkgName)
+ "Target %s successfully created\n", pkgName)
}
}
@@ -255,6 +260,44 @@ func targetDelCmd(cmd *cobra.Command, args []string) {
}
}
+func targetCopyCmd(cmd *cobra.Command, args []string) {
+ if len(args) != 2 {
+ cli.NewtUsage(cmd, util.NewNewtError("Must specify exactly one "+
+ "source target and one destination target"))
+ }
+
+ srcTarget, err := resolveTargetArg(args[0])
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+
+ dstName, err := resolveNewTargetArg(args[1])
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+
+ // Copy the source target's base package and adjust the fields which need
+ // to change.
+ dstBasePkg := *srcTarget.basePkg
+ dstBasePkg.SetRepo(project.GetProject().LocalRepo())
+ dstBasePkg.SetName(dstName)
+ dstBasePkg.SetBasePath(dstName)
+
+ // Copy the source target.
+ dstTarget := *srcTarget
+ dstTarget.basePkg = &dstBasePkg
+
+ // Save the new target.
+ err = dstTarget.Save()
+ if err != nil {
+ cli.NewtUsage(nil, err)
+ } else {
+ util.StatusMessage(util.VERBOSITY_DEFAULT,
+ "Target successfully copied; %s --> %s\n",
+ srcTarget.FullName(), dstTarget.FullName())
+ }
+}
+
func AddCommands(cmd *cobra.Command) {
targetHelpText := ""
targetHelpEx := ""
@@ -329,4 +372,18 @@ func AddCommands(cmd *cobra.Command) {
}
targetCmd.AddCommand(delCmd)
+
+ copyHelpText := "Creates a new target by cloning <src-target>."
+ copyHelpEx := " newt target copy <src-target> <dst-target>\n"
+ copyHelpEx += " newt target copy blinky_sim my_target"
+
+ copyCmd := &cobra.Command{
+ Use: "copy",
+ Short: "Copy target",
+ Long: copyHelpText,
+ Example: copyHelpEx,
+ Run: targetCopyCmd,
+ }
+
+ targetCmd.AddCommand(copyCmd)
}
[12/50] incubator-mynewt-newt git commit: add upgrade command. next
step is cleanup & status messages.
Posted by ma...@apache.org.
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/develop
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
}
[08/50] incubator-mynewt-newt git commit: Move image creation under
target.
Posted by ma...@apache.org.
Move image creation under target.
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/b1c09ba2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/b1c09ba2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/b1c09ba2
Branch: refs/heads/develop
Commit: b1c09ba2b7e44cc93c9b97c08379997b655322bb
Parents: 88fe565
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Mar 8 08:03:05 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Mar 8 08:03:05 2016 -0800
----------------------------------------------------------------------
newt/image/cmds.go | 73 ----------
newt/image/image.go | 329 ----------------------------------------------
newt/newt.go | 2 -
newt/target/cmds.go | 41 ++++++
newt/target/image.go | 328 +++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 369 insertions(+), 404 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b1c09ba2/newt/image/cmds.go
----------------------------------------------------------------------
diff --git a/newt/image/cmds.go b/newt/image/cmds.go
deleted file mode 100644
index 3a10713..0000000
--- a/newt/image/cmds.go
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package image
-
-import (
- "fmt"
-
- "github.com/spf13/cobra"
- "mynewt.apache.org/newt/newt/cli"
- "mynewt.apache.org/newt/newt/target"
- "mynewt.apache.org/newt/util"
-)
-
-func createImageRunCmd(cmd *cobra.Command, args []string) {
- if len(args) < 2 {
- cli.NewtUsage(cmd, util.NewNewtError("Must specify target and version"))
- }
-
- targetName := args[0]
- t := target.GetTargets()[targetName]
- if t == nil {
- cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"))
- }
-
- image, err := NewImage(t)
- if err != nil {
- fmt.Println(err)
- }
- err = image.SetVersion(args[1])
- if err != nil {
- cli.NewtUsage(cmd, err)
- }
- err = image.Generate()
- if err != nil {
- fmt.Println(err)
- }
-}
-
-func AddCommands(cmd *cobra.Command) {
- createImageHelpText := "Create image by adding image header to created "+
- "binary file for <target-name>. Version number in the header is set "+
- "to be <version>."
- createImageHelpEx := " newt create-image <target-name> <version>\n"
- createImageHelpEx += " newt create-image my_target1 1.2.0\n"
- createImageHelpEx += " newt create-image my_target1 1.2.0.3\n"
-
- createImageCmd := &cobra.Command{
- Use: "create-image",
- Short: "Add image header to target binary",
- Long: createImageHelpText,
- Example: createImageHelpEx,
- Run: createImageRunCmd,
- }
- cmd.AddCommand(createImageCmd)
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b1c09ba2/newt/image/image.go
----------------------------------------------------------------------
diff --git a/newt/image/image.go b/newt/image/image.go
deleted file mode 100644
index edd3bfd..0000000
--- a/newt/image/image.go
+++ /dev/null
@@ -1,329 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package image
-
-import (
- "bytes"
- "crypto/sha256"
- "encoding/binary"
- "encoding/json"
- "fmt"
- "io"
- "log"
- "os"
- "path/filepath"
- "sort"
- "strconv"
- "strings"
- "time"
-
- "mynewt.apache.org/newt/newt/target"
- "mynewt.apache.org/newt/util"
-)
-
-type ImageVersion struct {
- Major uint8
- Minor uint8
- Rev uint16
- BuildNum uint32
-}
-
-type Image struct {
- target *target.Target
-
- sourceBin string
- targetImg string
- ManifestFile string
- version ImageVersion
-
- hash []byte
-}
-
-type ImageHdr struct {
- Magic uint32
- TlvSz uint32
- HdrSz uint32
- ImgSz uint32
- Flags uint32
- Vers ImageVersion
- Pad uint32
-}
-
-type ImageTrailerTlv struct {
- Type uint8
- Pad uint8
- Len uint16
-}
-
-const (
- IMAGE_MAGIC = 0x96f3b83c /* Image header magic */
-)
-
-const (
- IMAGE_HEADER_SIZE = 32
-)
-
-/*
- * Image header flags.
- */
-const (
- IMAGE_F_PIC = 0x00000001
- IMAGE_F_HAS_SHA256 = 0x00000002 /* Image contains hash TLV */
-)
-
-/*
- * Image trailer TLV types.
- */
-const (
- IMAGE_TLV_SHA256 = 1
-)
-
-/*
- * Data that's going to go to build manifest file
- */
-type ImageManifest struct {
- Date string `json:"build_time"`
- Version string `json:"build_version"`
- Hash string `json:"id"`
- Image string `json:"image"`
- Pkgs []*ImageManifestPkg `json:"pkgs"`
- TgtVars []string `json:"target"`
-}
-
-type ImageManifestPkg struct {
- Name string `json:"name"`
- Version string `json:"version,omitempty"`
- Hash string `json:"hash"`
-}
-
-func NewImage(t *target.Target) (*Image, error) {
- image := &Image{
- target: t,
- }
-
- image.sourceBin = t.ElfPath() + ".bin"
- image.targetImg = t.ImagePath()
- return image, nil
-}
-
-func (image *Image) SetVersion(versStr string) error {
- var err error
- var major uint64
- var minor uint64
- var rev uint64
- var buildNum uint64
-
- components := strings.Split(versStr, ".")
- major, err = strconv.ParseUint(components[0], 10, 8)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
- versStr))
- }
- if len(components) > 1 {
- minor, err = strconv.ParseUint(components[1], 10, 8)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
- versStr))
- }
- }
- if len(components) > 2 {
- rev, err = strconv.ParseUint(components[2], 10, 16)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
- versStr))
- }
- }
- if len(components) > 3 {
- buildNum, err = strconv.ParseUint(components[3], 10, 32)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
- versStr))
- }
- }
- image.version.Major = uint8(major)
- image.version.Minor = uint8(minor)
- image.version.Rev = uint16(rev)
- image.version.BuildNum = uint32(buildNum)
- log.Printf("[VERBOSE] Assigning version number %d.%d.%d.%d\n",
- image.version.Major, image.version.Minor,
- image.version.Rev, image.version.BuildNum)
-
- buf := new(bytes.Buffer)
- err = binary.Write(buf, binary.LittleEndian, image.version)
- if err != nil {
- fmt.Printf("Bombing out\n")
- return nil
- }
-
- return nil
-}
-
-func (image *Image) Generate() error {
- binFile, err := os.Open(image.sourceBin)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Can't open target binary %s: %s",
- image.sourceBin, err.Error()))
- }
- defer binFile.Close()
-
- binInfo, err := binFile.Stat()
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Can't stat target binary %s: %s",
- image.sourceBin, err.Error()))
- }
-
- imgFile, err := os.OpenFile(image.targetImg,
- os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Can't open target image %s: %s",
- image.targetImg, err.Error()))
- }
- defer imgFile.Close()
-
- /*
- * Compute hash while updating the file.
- */
- hash := sha256.New()
-
- /*
- * First the header
- */
- hdr := &ImageHdr{
- Magic: IMAGE_MAGIC,
- TlvSz: 4 + 32,
- HdrSz: IMAGE_HEADER_SIZE,
- ImgSz: uint32(binInfo.Size()),
- Flags: IMAGE_F_HAS_SHA256,
- Vers: image.version,
- Pad: 0,
- }
-
- err = binary.Write(imgFile, binary.LittleEndian, hdr)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Failed to serialize image hdr: %s",
- err.Error()))
- }
- err = binary.Write(hash, binary.LittleEndian, hdr)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Failed to hash data: %s",
- err.Error()))
- }
-
- /*
- * Followed by data.
- */
- dataBuf := make([]byte, 1024)
- for {
- cnt, err := binFile.Read(dataBuf)
- if err != nil && err != io.EOF {
- return util.NewNewtError(fmt.Sprintf("Failed to read from %s: %s",
- image.sourceBin, err.Error()))
- }
- if cnt == 0 {
- break
- }
- _, err = imgFile.Write(dataBuf[0:cnt])
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Failed to write to %s: %s",
- image.targetImg, err.Error()))
- }
- _, err = hash.Write(dataBuf[0:cnt])
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Failed to hash data: %s",
- err.Error()))
- }
- }
-
- image.hash = hash.Sum(nil)
-
- /*
- * Trailer with hash of the data
- */
- tlv := &ImageTrailerTlv{
- Type: IMAGE_TLV_SHA256,
- Pad: 0,
- Len: uint16(len(image.hash)),
- }
- err = binary.Write(imgFile, binary.LittleEndian, tlv)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Failed to serialize image "+
- "trailer: %s", err.Error()))
- }
- _, err = imgFile.Write(image.hash)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Failed to append hash: %s",
- err.Error()))
- }
-
- return nil
-}
-
-func (image *Image) CreateManifest() error {
- versionStr := fmt.Sprintf("%d.%d.%d.%d",
- image.version.Major, image.version.Minor,
- image.version.Rev, image.version.BuildNum)
- hashStr := fmt.Sprintf("%x", image.hash)
- timeStr := time.Now().Format(time.RFC3339)
-
- manifest := &ImageManifest{
- Version: versionStr,
- Hash: hashStr,
- Image: filepath.Base(image.targetImg),
- Date: timeStr,
- }
-/*
- for _, builtPkg := range BuiltPkgs {
- imgPkg := &ImageManifestPkg{
- Name: builtPkg.Name,
- Version: builtPkg.Version,
- Hash: builtPkg.Hash,
- }
- manifest.Pkgs = append(manifest.Pkgs, imgPkg)
- }
-*/
- vars := image.target.Vars
- var keys []string
- for k := range vars {
- keys = append(keys, k)
- }
- sort.Strings(keys)
- for _, k := range keys {
- manifest.TgtVars = append(manifest.TgtVars, k+"="+vars[k])
- }
- file, err := os.Create(image.ManifestFile)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Cannot create manifest file %s: %s",
- image.ManifestFile, err.Error()))
- }
- defer file.Close()
-
- buffer, err := json.MarshalIndent(manifest, "", " ")
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Cannot encode manifest: %s",
- err.Error()))
- }
- _, err = file.Write(buffer)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Cannot write manifest file: %s",
- err.Error()))
- }
-
- return nil
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b1c09ba2/newt/newt.go
----------------------------------------------------------------------
diff --git a/newt/newt.go b/newt/newt.go
index 9b05f55..4cb8ad6 100644
--- a/newt/newt.go
+++ b/newt/newt.go
@@ -25,7 +25,6 @@ import (
"mynewt.apache.org/newt/newt/builder"
"mynewt.apache.org/newt/newt/cli"
- "mynewt.apache.org/newt/newt/image"
"mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/newt/target"
@@ -92,7 +91,6 @@ func main() {
pkg.AddCommands(cmd)
target.AddCommands(cmd)
builder.AddCommands(cmd)
- image.AddCommands(cmd)
cmd.Execute()
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b1c09ba2/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index 9069574..00bdfae 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -208,6 +208,31 @@ func targetDelCmd(cmd *cobra.Command, args []string) {
"Target %s successfully removed\n", args[0])
}
+func createImageRunCmd(cmd *cobra.Command, args []string) {
+ if len(args) < 2 {
+ cli.NewtUsage(cmd, util.NewNewtError("Must specify target and version"))
+ }
+
+ targetName := args[0]
+ t := GetTargets()[targetName]
+ if t == nil {
+ cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"))
+ }
+
+ image, err := NewImage(t)
+ if err != nil {
+ fmt.Println(err)
+ }
+ err = image.SetVersion(args[1])
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+ err = image.Generate()
+ if err != nil {
+ fmt.Println(err)
+ }
+}
+
func AddCommands(cmd *cobra.Command) {
targetHelpText := ""
targetHelpEx := ""
@@ -282,4 +307,20 @@ func AddCommands(cmd *cobra.Command) {
}
targetCmd.AddCommand(delCmd)
+
+ createImageHelpText := "Create image by adding image header to created "+
+ "binary file for <target-name>. Version number in the header is set "+
+ "to be <version>."
+ createImageHelpEx := " newt create-image <target-name> <version>\n"
+ createImageHelpEx += " newt create-image my_target1 1.2.0\n"
+ createImageHelpEx += " newt create-image my_target1 1.2.0.3\n"
+
+ createImageCmd := &cobra.Command{
+ Use: "create-image",
+ Short: "Add image header to target binary",
+ Long: createImageHelpText,
+ Example: createImageHelpEx,
+ Run: createImageRunCmd,
+ }
+ cmd.AddCommand(createImageCmd)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b1c09ba2/newt/target/image.go
----------------------------------------------------------------------
diff --git a/newt/target/image.go b/newt/target/image.go
new file mode 100644
index 0000000..1964e5a
--- /dev/null
+++ b/newt/target/image.go
@@ -0,0 +1,328 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package target
+
+import (
+ "bytes"
+ "crypto/sha256"
+ "encoding/binary"
+ "encoding/json"
+ "fmt"
+ "io"
+ "log"
+ "os"
+ "path/filepath"
+ "sort"
+ "strconv"
+ "strings"
+ "time"
+
+ "mynewt.apache.org/newt/util"
+)
+
+type ImageVersion struct {
+ Major uint8
+ Minor uint8
+ Rev uint16
+ BuildNum uint32
+}
+
+type Image struct {
+ target *Target
+
+ sourceBin string
+ targetImg string
+ ManifestFile string
+ version ImageVersion
+
+ hash []byte
+}
+
+type ImageHdr struct {
+ Magic uint32
+ TlvSz uint32
+ HdrSz uint32
+ ImgSz uint32
+ Flags uint32
+ Vers ImageVersion
+ Pad uint32
+}
+
+type ImageTrailerTlv struct {
+ Type uint8
+ Pad uint8
+ Len uint16
+}
+
+const (
+ IMAGE_MAGIC = 0x96f3b83c /* Image header magic */
+)
+
+const (
+ IMAGE_HEADER_SIZE = 32
+)
+
+/*
+ * Image header flags.
+ */
+const (
+ IMAGE_F_PIC = 0x00000001
+ IMAGE_F_HAS_SHA256 = 0x00000002 /* Image contains hash TLV */
+)
+
+/*
+ * Image trailer TLV types.
+ */
+const (
+ IMAGE_TLV_SHA256 = 1
+)
+
+/*
+ * Data that's going to go to build manifest file
+ */
+type ImageManifest struct {
+ Date string `json:"build_time"`
+ Version string `json:"build_version"`
+ Hash string `json:"id"`
+ Image string `json:"image"`
+ Pkgs []*ImageManifestPkg `json:"pkgs"`
+ TgtVars []string `json:"target"`
+}
+
+type ImageManifestPkg struct {
+ Name string `json:"name"`
+ Version string `json:"version,omitempty"`
+ Hash string `json:"hash"`
+}
+
+func NewImage(t *Target) (*Image, error) {
+ image := &Image{
+ target: t,
+ }
+
+ image.sourceBin = t.ElfPath() + ".bin"
+ image.targetImg = t.ImagePath()
+ return image, nil
+}
+
+func (image *Image) SetVersion(versStr string) error {
+ var err error
+ var major uint64
+ var minor uint64
+ var rev uint64
+ var buildNum uint64
+
+ components := strings.Split(versStr, ".")
+ major, err = strconv.ParseUint(components[0], 10, 8)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
+ versStr))
+ }
+ if len(components) > 1 {
+ minor, err = strconv.ParseUint(components[1], 10, 8)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
+ versStr))
+ }
+ }
+ if len(components) > 2 {
+ rev, err = strconv.ParseUint(components[2], 10, 16)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
+ versStr))
+ }
+ }
+ if len(components) > 3 {
+ buildNum, err = strconv.ParseUint(components[3], 10, 32)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
+ versStr))
+ }
+ }
+ image.version.Major = uint8(major)
+ image.version.Minor = uint8(minor)
+ image.version.Rev = uint16(rev)
+ image.version.BuildNum = uint32(buildNum)
+ log.Printf("[VERBOSE] Assigning version number %d.%d.%d.%d\n",
+ image.version.Major, image.version.Minor,
+ image.version.Rev, image.version.BuildNum)
+
+ buf := new(bytes.Buffer)
+ err = binary.Write(buf, binary.LittleEndian, image.version)
+ if err != nil {
+ fmt.Printf("Bombing out\n")
+ return nil
+ }
+
+ return nil
+}
+
+func (image *Image) Generate() error {
+ binFile, err := os.Open(image.sourceBin)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Can't open target binary %s: %s",
+ image.sourceBin, err.Error()))
+ }
+ defer binFile.Close()
+
+ binInfo, err := binFile.Stat()
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Can't stat target binary %s: %s",
+ image.sourceBin, err.Error()))
+ }
+
+ imgFile, err := os.OpenFile(image.targetImg,
+ os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Can't open target image %s: %s",
+ image.targetImg, err.Error()))
+ }
+ defer imgFile.Close()
+
+ /*
+ * Compute hash while updating the file.
+ */
+ hash := sha256.New()
+
+ /*
+ * First the header
+ */
+ hdr := &ImageHdr{
+ Magic: IMAGE_MAGIC,
+ TlvSz: 4 + 32,
+ HdrSz: IMAGE_HEADER_SIZE,
+ ImgSz: uint32(binInfo.Size()),
+ Flags: IMAGE_F_HAS_SHA256,
+ Vers: image.version,
+ Pad: 0,
+ }
+
+ err = binary.Write(imgFile, binary.LittleEndian, hdr)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to serialize image hdr: %s",
+ err.Error()))
+ }
+ err = binary.Write(hash, binary.LittleEndian, hdr)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to hash data: %s",
+ err.Error()))
+ }
+
+ /*
+ * Followed by data.
+ */
+ dataBuf := make([]byte, 1024)
+ for {
+ cnt, err := binFile.Read(dataBuf)
+ if err != nil && err != io.EOF {
+ return util.NewNewtError(fmt.Sprintf("Failed to read from %s: %s",
+ image.sourceBin, err.Error()))
+ }
+ if cnt == 0 {
+ break
+ }
+ _, err = imgFile.Write(dataBuf[0:cnt])
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to write to %s: %s",
+ image.targetImg, err.Error()))
+ }
+ _, err = hash.Write(dataBuf[0:cnt])
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to hash data: %s",
+ err.Error()))
+ }
+ }
+
+ image.hash = hash.Sum(nil)
+
+ /*
+ * Trailer with hash of the data
+ */
+ tlv := &ImageTrailerTlv{
+ Type: IMAGE_TLV_SHA256,
+ Pad: 0,
+ Len: uint16(len(image.hash)),
+ }
+ err = binary.Write(imgFile, binary.LittleEndian, tlv)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to serialize image "+
+ "trailer: %s", err.Error()))
+ }
+ _, err = imgFile.Write(image.hash)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to append hash: %s",
+ err.Error()))
+ }
+
+ return nil
+}
+
+func (image *Image) CreateManifest() error {
+ versionStr := fmt.Sprintf("%d.%d.%d.%d",
+ image.version.Major, image.version.Minor,
+ image.version.Rev, image.version.BuildNum)
+ hashStr := fmt.Sprintf("%x", image.hash)
+ timeStr := time.Now().Format(time.RFC3339)
+
+ manifest := &ImageManifest{
+ Version: versionStr,
+ Hash: hashStr,
+ Image: filepath.Base(image.targetImg),
+ Date: timeStr,
+ }
+/*
+ for _, builtPkg := range BuiltPkgs {
+ imgPkg := &ImageManifestPkg{
+ Name: builtPkg.Name,
+ Version: builtPkg.Version,
+ Hash: builtPkg.Hash,
+ }
+ manifest.Pkgs = append(manifest.Pkgs, imgPkg)
+ }
+*/
+ vars := image.target.Vars
+ var keys []string
+ for k := range vars {
+ keys = append(keys, k)
+ }
+ sort.Strings(keys)
+ for _, k := range keys {
+ manifest.TgtVars = append(manifest.TgtVars, k+"="+vars[k])
+ }
+ file, err := os.Create(image.ManifestFile)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Cannot create manifest file %s: %s",
+ image.ManifestFile, err.Error()))
+ }
+ defer file.Close()
+
+ buffer, err := json.MarshalIndent(manifest, "", " ")
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Cannot encode manifest: %s",
+ err.Error()))
+ }
+ _, err = file.Write(buffer)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Cannot write manifest file: %s",
+ err.Error()))
+ }
+
+ return nil
+}
[25/50] incubator-mynewt-newt git commit: Allow multiple target vars
to be set at once.
Posted by ma...@apache.org.
Allow multiple target vars to be set at once.
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/d2d5ef1e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/d2d5ef1e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/d2d5ef1e
Branch: refs/heads/develop
Commit: d2d5ef1e9c9a5f32ba6a91e41849ddd82b88ba36
Parents: 9351ecf
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 14:58:44 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 17:31:54 2016 -0800
----------------------------------------------------------------------
newt/pkg/localpackage.go | 2 +-
newt/target/cmds.go | 58 +++++++++++++++++++++++++++----------------
newt/target/target.go | 2 +-
3 files changed, 38 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2d5ef1e/newt/pkg/localpackage.go
----------------------------------------------------------------------
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index 0e1e17f..1738b4c 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -204,7 +204,7 @@ func (pkg *LocalPackage) Save() error {
}
defer file.Close()
- file.WriteString("### Package: " + pkg.Name() + "\n\n")
+ file.WriteString("### Package: " + pkg.Name() + "\n")
file.WriteString("pkg.name: " + yaml.EscapeString(pkg.Name()) + "\n")
file.WriteString("pkg.type: " +
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2d5ef1e/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index cba4dd7..c55fd39 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -101,12 +101,13 @@ func showValidSettings(varName string) error {
}
func targetSetCmd(cmd *cobra.Command, args []string) {
- if len(args) != 2 {
+ if len(args) < 2 {
cli.NewtUsage(cmd,
- util.NewNewtError("Must specify two arguments "+
+ util.NewNewtError("Must specify at least two arguments "+
"(target-name & k=v) to set"))
}
+ // Parse target name.
tName := args[0]
t := ResolveTargetName(tName)
if t == nil {
@@ -114,37 +115,50 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
}
tName = t.Name()
- ar := strings.SplitN(args[1], "=", 2)
- if !strings.HasPrefix(ar[0], "target.") {
- ar[0] = "target." + ar[0]
- }
+ // Parse series of k=v pairs. If an argument doesn't contain a '='
+ // character, display the valid values for the variable and quit.
+ vars := [][]string{}
+ for i := 1; i < len(args); i++ {
+ kv := strings.SplitN(args[i], "=", 2)
+ if !strings.HasPrefix(kv[0], "target.") {
+ kv[0] = "target." + kv[0]
+ }
- if len(ar) == 1 {
- // User entered a variable name without a value. Display valid values
- // for the specified variable.
- err := showValidSettings(ar[0])
- if err != nil {
- cli.NewtUsage(cmd, err)
+ if len(kv) == 1 {
+ // User entered a variable name without a value. Display valid
+ // values for the specified variable.
+ err := showValidSettings(kv[0])
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+ return
}
- } else {
- if ar[1] == "" {
+
+ vars = append(vars, kv)
+ }
+
+ // Set each specified variable in the target.
+ for _, kv := range vars {
+ if kv[1] == "" {
// User specified empty value; delete variable.
- delete(t.Vars, ar[0])
+ delete(t.Vars, kv[0])
} else {
// Assign value to specified variable.
- t.Vars[ar[0]] = ar[1]
+ t.Vars[kv[0]] = kv[1]
}
+ }
- if err := t.Save(); err != nil {
- cli.NewtUsage(cmd, err)
- }
+ if err := t.Save(); err != nil {
+ cli.NewtUsage(cmd, err)
+ }
- if ar[1] == "" {
+ for _, kv := range vars {
+ if kv[1] == "" {
cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Target %s successfully unset %s\n", tName, ar[0])
+ "Target %s successfully unset %s\n", tName, kv[0])
} else {
cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Target %s successfully set %s to %s\n", tName, ar[0], ar[1])
+ "Target %s successfully set %s to %s\n", tName, kv[0], kv[1])
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2d5ef1e/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 643035e..39714d4 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -169,7 +169,7 @@ func (t *Target) Save() error {
}
defer file.Close()
- file.WriteString("### Target: " + t.basePkg.Name() + "\n\n")
+ file.WriteString("### Target: " + t.basePkg.Name() + "\n")
keys := []string{}
for k, _ := range t.Vars {
[19/50] incubator-mynewt-newt git commit: Get compiler package from
BSP's pkg.yml, instead of target variable.
Posted by ma...@apache.org.
Get compiler package from BSP's pkg.yml, instead of target variable.
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/9468c1bc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/9468c1bc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/9468c1bc
Branch: refs/heads/develop
Commit: 9468c1bc5219a5608eda5a28a46cb4ccabb45f15
Parents: 1be80b8
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Mar 8 15:05:18 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Mar 8 15:05:18 2016 -0800
----------------------------------------------------------------------
newt/builder/build.go | 7 +++----
newt/builder/buildutil.go | 10 ++++++++++
newt/pkg/bsp_package.go | 11 ++++++++---
newt/target/target.go | 7 -------
4 files changed, 21 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9468c1bc/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 185ec37..1f149af 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -20,7 +20,6 @@
package builder
import (
- "fmt"
"os"
"path/filepath"
@@ -274,7 +273,8 @@ func (b *Builder) PrepBuild() error {
return util.NewNewtError("bsp package not specified")
}
- compilerPkg := b.target.Compiler()
+ b.Bsp = pkg.NewBspPackage(bspPkg)
+ compilerPkg := b.resolveCompiler()
if compilerPkg == nil {
return util.NewNewtError("compiler package not specified")
}
@@ -352,7 +352,7 @@ func (b *Builder) PrepBuild() error {
// Read the BSP configuration. These settings are necessary for the link
// step.
- b.Bsp = pkg.NewBspPackage(bspPkg, b.Features())
+ b.Bsp.Reload(b.Features())
b.compilerPkg = compilerPkg
b.compilerInfo = baseCi
@@ -362,7 +362,6 @@ 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/9468c1bc/newt/builder/buildutil.go
----------------------------------------------------------------------
diff --git a/newt/builder/buildutil.go b/newt/builder/buildutil.go
index 1db97b2..83ed623 100644
--- a/newt/builder/buildutil.go
+++ b/newt/builder/buildutil.go
@@ -23,6 +23,7 @@ import (
"bytes"
"path/filepath"
+ "mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/util"
)
@@ -75,6 +76,15 @@ func (b *Builder) featureString() string {
return buffer.String()
}
+func (b *Builder) resolveCompiler() *pkg.LocalPackage {
+ if b.Bsp.CompilerName == "" {
+ return nil
+ }
+ dep, _ := pkg.NewDependency(b.Bsp.Repo(), b.Bsp.CompilerName)
+ mypkg := project.GetProject().ResolveDependency(dep).(*pkg.LocalPackage)
+ return mypkg
+}
+
// Makes sure all packages with required APIs have been augmented with a
// dependency that satisfies that requirement. If there are any unsatisfied
// requirements, an error is returned.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9468c1bc/newt/pkg/bsp_package.go
----------------------------------------------------------------------
diff --git a/newt/pkg/bsp_package.go b/newt/pkg/bsp_package.go
index ced518c..e744a74 100644
--- a/newt/pkg/bsp_package.go
+++ b/newt/pkg/bsp_package.go
@@ -25,12 +25,15 @@ import (
type BspPackage struct {
*LocalPackage
+ CompilerName string
LinkerScript string
DownloadScript string
DebugScript string
}
-func (bsp *BspPackage) load(features map[string]bool) {
+func (bsp *BspPackage) Reload(features map[string]bool) {
+ bsp.CompilerName = cli.GetStringFeatures(bsp.LocalPackage.Viper, features,
+ "pkg.compiler")
bsp.LinkerScript = cli.GetStringFeatures(bsp.LocalPackage.Viper, features,
"pkg.linkerscript")
bsp.DownloadScript = cli.GetStringFeatures(bsp.LocalPackage.Viper, features,
@@ -39,13 +42,15 @@ func (bsp *BspPackage) load(features map[string]bool) {
"pkg.debugscript")
}
-func NewBspPackage(lpkg *LocalPackage, features map[string]bool) *BspPackage {
+func NewBspPackage(lpkg *LocalPackage) *BspPackage {
bsp := &BspPackage{
+ CompilerName: "",
LinkerScript: "",
DownloadScript: "",
DebugScript: "",
}
+ lpkg.Load()
bsp.LocalPackage = lpkg
- bsp.load(features)
+ bsp.Reload(nil)
return bsp
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9468c1bc/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 62b0b5f..19e55ac 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -114,13 +114,6 @@ func (target *Target) ShortName() string {
return filepath.Base(target.Name())
}
-func (target *Target) Compiler() *pkg.LocalPackage {
- dep, _ := pkg.NewDependency(nil, target.CompilerName)
- mypkg := project.GetProject().ResolveDependency(dep).(*pkg.LocalPackage)
-
- return mypkg
-}
-
func (target *Target) App() *pkg.LocalPackage {
dep, err := pkg.NewDependency(nil, target.AppName)
if err != nil {
[44/50] incubator-mynewt-newt git commit: Rename ResolveTargetName[s]
-> ResolveTarget[s]
Posted by ma...@apache.org.
Rename ResolveTargetName[s] -> ResolveTarget[s]
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/59fef971
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/59fef971
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/59fef971
Branch: refs/heads/develop
Commit: 59fef9719ea48ff17cc4fe1983fc951a73147bee
Parents: 0442a0d
Author: ccollins at iori.nightmare.heaven <cc...@iori.nightmare-heaven.no-ip.biz>
Authored: Wed Mar 9 09:06:46 2016 -0800
Committer: ccollins at iori.nightmare.heaven <cc...@iori.nightmare-heaven.no-ip.biz>
Committed: Wed Mar 9 10:00:09 2016 -0800
----------------------------------------------------------------------
newt/builder/cmds.go | 12 ++++++------
newt/image/cmds.go | 2 +-
newt/run/cmds.go | 2 +-
newt/target/cmds.go | 2 +-
newt/target/target.go | 4 ++--
5 files changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/59fef971/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index 6298a92..b236bbf 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -37,7 +37,7 @@ func buildRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, nil)
}
- t := target.ResolveTargetName(args[0])
+ t := target.ResolveTarget(args[0])
if t == nil {
cli.NewtUsage(cmd, util.NewNewtError("invalid target name: "+args[0]))
}
@@ -60,7 +60,7 @@ func cleanRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, util.NewNewtError("Must specify target"))
}
- t := target.ResolveTargetName(args[0])
+ t := target.ResolveTarget(args[0])
if t == nil {
cli.NewtUsage(cmd, util.NewNewtError("invalid target name"+args[0]))
}
@@ -80,7 +80,7 @@ func testRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, nil)
}
- t := target.ResolveTargetName(TARGET_TEST_NAME)
+ t := target.ResolveTarget(TARGET_TEST_NAME)
if t == nil {
cli.NewtUsage(cmd, util.NewNewtError("can't find unit test target: "+
TARGET_TEST_NAME))
@@ -126,7 +126,7 @@ func downloadRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, util.NewNewtError("Must specify target"))
}
- t := target.ResolveTargetName(args[0])
+ t := target.ResolveTarget(args[0])
if t == nil {
cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"+args[0]))
}
@@ -147,7 +147,7 @@ func debugRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, util.NewNewtError("Must specify target"))
}
- t := target.ResolveTargetName(args[0])
+ t := target.ResolveTarget(args[0])
if t == nil {
cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"+args[0]))
}
@@ -168,7 +168,7 @@ func sizeRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, util.NewNewtError("Must specify target"))
}
- t := target.ResolveTargetName(args[0])
+ t := target.ResolveTarget(args[0])
if t == nil {
cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"+args[0]))
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/59fef971/newt/image/cmds.go
----------------------------------------------------------------------
diff --git a/newt/image/cmds.go b/newt/image/cmds.go
index 228b4b3..45926d7 100644
--- a/newt/image/cmds.go
+++ b/newt/image/cmds.go
@@ -33,7 +33,7 @@ func createImageRunCmd(cmd *cobra.Command, args []string) {
}
targetName := args[0]
- t := target.ResolveTargetName(targetName)
+ t := target.ResolveTarget(targetName)
if t == nil {
cli.NewtUsage(cmd, util.NewNewtError("Invalid target name: "+targetName))
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/59fef971/newt/run/cmds.go
----------------------------------------------------------------------
diff --git a/newt/run/cmds.go b/newt/run/cmds.go
index 4f133ef..bc6dbef 100644
--- a/newt/run/cmds.go
+++ b/newt/run/cmds.go
@@ -35,7 +35,7 @@ func runRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, util.NewNewtError("Must specify target"))
}
- t := target.ResolveTargetName(args[0])
+ t := target.ResolveTarget(args[0])
if t == nil {
cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"+args[0]))
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/59fef971/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index c639c31..1dabd1e 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -34,7 +34,7 @@ import (
)
func resolveExistingTargetArg(arg string) (*Target, error) {
- t := ResolveTargetName(arg)
+ t := ResolveTarget(arg)
if t == nil {
return nil, util.NewNewtError("Unknown target: " + arg)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/59fef971/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 661df43..4b64e57 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -239,7 +239,7 @@ func GetTargets() map[string]*Target {
return globalTargetMap
}
-func ResolveTargetName(name string) *Target {
+func ResolveTarget(name string) *Target {
targetMap := GetTargets()
// Check for fully-qualified name.
@@ -270,7 +270,7 @@ func ResolveTargetNames(names ...string) ([]*Target, error) {
targets := []*Target{}
for _, name := range names {
- t := ResolveTargetName(name)
+ t := ResolveTarget(name)
if t == nil {
return nil, util.NewNewtError("Could not resolve target name: " +
name)
[43/50] incubator-mynewt-newt git commit: flush status messages to
console,
ensuring they get displayed quickly. cleanup install & upgrade state logic,
this was a beast.
Posted by ma...@apache.org.
flush status messages to console, ensuring they get displayed quickly. cleanup install & upgrade state logic, this was a beast.
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/0442a0df
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/0442a0df
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/0442a0df
Branch: refs/heads/develop
Commit: 0442a0df7c8c79691e7afac1991938fed534670d
Parents: 1affb86
Author: Sterling Hughes <st...@apache.org>
Authored: Wed Mar 9 08:54:55 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Wed Mar 9 08:55:15 2016 -0800
----------------------------------------------------------------------
newt/project/project.go | 119 +++++++++++++++++++------------------------
util/util.go | 6 ++-
2 files changed, 56 insertions(+), 69 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0442a0df/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index e5f21e6..7292c7b 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -139,79 +139,56 @@ func (proj *Project) PackageSearchDirs() []string {
}
func (proj *Project) upgradeCheck(r *repo.Repo, vers *repo.Version,
- upgrade bool, force bool) (bool, error) {
+ force bool) (bool, error) {
rdesc, err := r.GetRepoDesc()
if err != nil {
return false, err
}
- if !upgrade {
+ branch, newVers, _ := rdesc.Match(r)
+ if newVers == nil {
util.StatusMessage(util.VERBOSITY_DEFAULT,
- fmt.Sprintf("Installed repository %s has version %s, "+
- "which meets project requirements. Moving on to next repository.\n",
- r.Name(), vers))
- return true, nil
- } else {
- _, newVers, _ := rdesc.Match(r)
- if newVers == nil {
- util.StatusMessage(util.VERBOSITY_DEFAULT,
- "No matching version to upgrade to "+
- "found for %s. Please check your project requirements, and use the "+
- "project show-repo command to see available repository versions.",
- r.Name())
- return false, util.NewNewtError(fmt.Sprintf("Cannot find a "+
- "version of repository %s that matches project requirements.",
- r.Name()))
- }
+ "No matching version to upgrade to "+
+ "found for %s. Please check your project requirements, and use the "+
+ "project show-repo command to see available repository versions.",
+ r.Name())
+ return false, util.NewNewtError(fmt.Sprintf("Cannot find a "+
+ "version of repository %s that matches project requirements.",
+ r.Name()))
+ }
- // If the change between the old repository and the new repository would cause
- // and upgrade. Then prompt for an upgrade response, unless the force option
- // is present.
- if vers.CompareVersions(newVers, vers) != 0 ||
- vers.Stability() != newVers.Stability() {
- if !force {
- branch, newVers, _ := rdesc.Match(r)
-
- str := ""
- if newVers.Stability() != repo.VERSION_STABILITY_NONE {
- str += "(" + branch + ")"
- }
-
- fmt.Printf("Would you like to upgrade repository %s from %s to %s %s? [Yn] ",
- r.Name(), vers.String(), newVers.String(), str)
-
- if !upgrade {
- util.StatusMessage(util.VERBOSITY_DEFAULT,
- fmt.Sprintf("Installed repository %s matches project requirements, "+
- "moving on to next repository.\n", r.Name()))
- return true, nil
- } else {
- _, newVers, _ := rdesc.Match(r)
- if newVers == nil {
- return true, util.NewNewtError(fmt.Sprintf(
- "No matching version for repository %s\n", r.Name()))
- }
- line, more, err := bufio.NewReader(os.Stdin).ReadLine()
- if more || err != nil {
- return false, util.NewNewtError(fmt.Sprintf(
- "Couldn't read upgrade response: %s\n", err.Error()))
- }
-
- // Anything but no means yes.
- answer := strings.ToUpper(strings.Trim(string(line), " "))
- if answer == "N" || answer == "NO" {
- fmt.Printf("Users says don't upgrade, skipping upgrade of %s\n",
- r.Name())
- return true, nil
- }
- }
+ // If the change between the old repository and the new repository would cause
+ // and upgrade. Then prompt for an upgrade response, unless the force option
+ // is present.
+ if vers.CompareVersions(newVers, vers) != 0 ||
+ vers.Stability() != newVers.Stability() {
+ if !force {
+ str := ""
+ if newVers.Stability() != repo.VERSION_STABILITY_NONE {
+ str += "(" + branch + ")"
+ }
+
+ fmt.Printf("Would you like to upgrade repository %s from %s to %s %s? [Yn] ",
+ r.Name(), vers.String(), newVers.String(), str)
+ line, more, err := bufio.NewReader(os.Stdin).ReadLine()
+ if more || err != nil {
+ return false, util.NewNewtError(fmt.Sprintf(
+ "Couldn't read upgrade response: %s\n", err.Error()))
+ }
+
+ // Anything but no means yes.
+ answer := strings.ToUpper(strings.Trim(string(line), " "))
+ if answer == "N" || answer == "NO" {
+ fmt.Printf("Users says don't upgrade, skipping upgrade of %s\n",
+ r.Name())
+ return true, nil
}
- } else {
- util.StatusMessage(util.VERBOSITY_DEFAULT,
- "Repository %s doesn't need to be upgraded, latest "+
- "version installed.\n", r.Name())
- return true, nil
}
+ } else {
+ util.StatusMessage(util.VERBOSITY_DEFAULT,
+ "Repository %s doesn't need to be upgraded, latest "+
+ "version installed.\n", r.Name())
+ return true, nil
}
return false, nil
@@ -229,15 +206,23 @@ func (proj *Project) checkVersionRequirements(r *repo.Repo, upgrade bool, force
if vers != nil {
ok := rdesc.SatisfiesVersion(vers, r.VersionRequirements())
if !ok && !upgrade {
- util.StatusMessage(util.VERBOSITY_DEFAULT, "WARNING: Installed"+
+ util.StatusMessage(util.VERBOSITY_DEFAULT, "WARNING: Installed "+
"version %s of repository %s does not match desired "+
"version %s in project file. You can fix this by either upgrading"+
" your repository, or modifying the project.yml file.\n",
vers, rname, r.VersionRequirementsString())
return true, err
} else {
- skip, err := proj.upgradeCheck(r, vers, upgrade, force)
- return skip, err
+ if !upgrade {
+ util.StatusMessage(util.VERBOSITY_DEFAULT,
+ fmt.Sprintf("Installed repository %s has version %s, "+
+ "which meets project requirements. Moving on to next repository.\n",
+ r.Name(), vers))
+ return true, nil
+ } else {
+ skip, err := proj.upgradeCheck(r, vers, force)
+ return skip, err
+ }
}
} else {
// Fallthrough and perform the installation.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0442a0df/util/util.go
----------------------------------------------------------------------
diff --git a/util/util.go b/util/util.go
index dc439ac..cd37c44 100644
--- a/util/util.go
+++ b/util/util.go
@@ -22,10 +22,8 @@ package util
import (
"bufio"
"fmt"
- "github.com/hashicorp/logutils"
"io/ioutil"
"log"
- "mynewt.apache.org/newt/viper"
"os"
"os/exec"
"os/signal"
@@ -36,6 +34,9 @@ import (
"strings"
"syscall"
"time"
+
+ "github.com/hashicorp/logutils"
+ "mynewt.apache.org/newt/viper"
)
var Logger *log.Logger
@@ -79,6 +80,7 @@ func StatusMessage(level int, message string, args ...interface{}) {
if Verbosity >= level {
fmt.Printf(message, args...)
}
+ os.Stdout.Sync()
}
// Print Silent, Quiet and Verbose aware status messages to stderr.
[42/50] incubator-mynewt-newt git commit: Use ResolveTargetName in
arg parsing.
Posted by ma...@apache.org.
Use ResolveTargetName in arg parsing.
For commands where an unqualified existing target name is allowed.
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/1affb86f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/1affb86f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/1affb86f
Branch: refs/heads/develop
Commit: 1affb86f0d308f151d5f902078fd224d22a22a0f
Parents: 057cef1
Author: ccollins at iori.nightmare.heaven <cc...@iori.nightmare-heaven.no-ip.biz>
Authored: Wed Mar 9 08:18:30 2016 -0800
Committer: ccollins at iori.nightmare.heaven <cc...@iori.nightmare-heaven.no-ip.biz>
Committed: Wed Mar 9 08:18:30 2016 -0800
----------------------------------------------------------------------
newt/image/cmds.go | 4 ++--
newt/target/cmds.go | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1affb86f/newt/image/cmds.go
----------------------------------------------------------------------
diff --git a/newt/image/cmds.go b/newt/image/cmds.go
index 75b6805..228b4b3 100644
--- a/newt/image/cmds.go
+++ b/newt/image/cmds.go
@@ -33,9 +33,9 @@ func createImageRunCmd(cmd *cobra.Command, args []string) {
}
targetName := args[0]
- t := target.GetTargets()[targetName]
+ t := target.ResolveTargetName(targetName)
if t == nil {
- cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"+targetName))
+ cli.NewtUsage(cmd, util.NewNewtError("Invalid target name: "+targetName))
}
b, err := builder.NewBuilder(t)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1affb86f/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index 17d61d9..c639c31 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -33,7 +33,7 @@ import (
"mynewt.apache.org/newt/util"
)
-func resolveTargetArg(arg string) (*Target, error) {
+func resolveExistingTargetArg(arg string) (*Target, error) {
t := ResolveTargetName(arg)
if t == nil {
return nil, util.NewNewtError("Unknown target: " + arg)
@@ -133,7 +133,7 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
}
// Parse target name.
- t, err := resolveTargetArg(args[0])
+ t, err := resolveExistingTargetArg(args[0])
if err != nil {
cli.NewtUsage(cmd, err)
}
@@ -266,7 +266,7 @@ func targetCopyCmd(cmd *cobra.Command, args []string) {
"source target and one destination target"))
}
- srcTarget, err := resolveTargetArg(args[0])
+ srcTarget, err := resolveExistingTargetArg(args[0])
if err != nil {
cli.NewtUsage(cmd, err)
}
[30/50] incubator-mynewt-newt git commit: Add silent/quiet/verbose
options.
Posted by ma...@apache.org.
Add silent/quiet/verbose options.
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/dc1e9475
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/dc1e9475
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/dc1e9475
Branch: refs/heads/develop
Commit: dc1e947524dce7b9b5f5bff27cb75245ae874171
Parents: 65b5bb3
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 16:09:37 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 17:35:02 2016 -0800
----------------------------------------------------------------------
newt/cli/util.go | 13 ++-----------
newt/newt.go | 21 ++++++++++++++++++++-
2 files changed, 22 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/dc1e9475/newt/cli/util.go
----------------------------------------------------------------------
diff --git a/newt/cli/util.go b/newt/cli/util.go
index fde67f3..a48de90 100644
--- a/newt/cli/util.go
+++ b/newt/cli/util.go
@@ -88,7 +88,7 @@ func FormatHelp(text string) string {
}
// Initialize the CLI module
-func Init(level string, silent bool, quiet bool, verbose bool) {
+func Init(level string, verbosity int) {
if level == "" {
level = "WARN"
}
@@ -101,16 +101,7 @@ func Init(level string, silent bool, quiet bool, verbose bool) {
}
log.SetOutput(filter)
-
- if silent {
- Verbosity = VERBOSITY_SILENT
- } else if quiet {
- Verbosity = VERBOSITY_QUIET
- } else if verbose {
- Verbosity = VERBOSITY_VERBOSE
- } else {
- Verbosity = VERBOSITY_DEFAULT
- }
+ Verbosity = verbosity
}
func CheckBoolMap(mapVar map[string]bool, item string) bool {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/dc1e9475/newt/newt.go
----------------------------------------------------------------------
diff --git a/newt/newt.go b/newt/newt.go
index 5e279c0..a18d507 100644
--- a/newt/newt.go
+++ b/newt/newt.go
@@ -35,6 +35,9 @@ import (
var NewtVersion string = "0.8.0"
var NewtLogLevel string = ""
+var newtSilent bool
+var newtQuiet bool
+var newtVerbose bool
func newtCmd() *cobra.Command {
newtHelpText := cli.FormatHelp(`Newt allows you to create your own embedded
@@ -59,13 +62,29 @@ func newtCmd() *cobra.Command {
Example: newtHelpEx,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
NewtLogLevel = strings.ToUpper(NewtLogLevel)
- cli.Init(NewtLogLevel, false, false, false)
+
+ verbosity := cli.VERBOSITY_DEFAULT
+ if newtSilent {
+ verbosity = cli.VERBOSITY_SILENT
+ } else if newtQuiet {
+ verbosity = cli.VERBOSITY_QUIET
+ } else if newtVerbose {
+ verbosity = cli.VERBOSITY_VERBOSE
+ }
+
+ cli.Init(NewtLogLevel, verbosity)
},
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}
+ newtCmd.PersistentFlags().BoolVarP(&newtVerbose, "verbose", "v", false,
+ "Enable verbose output when executing commands.")
+ newtCmd.PersistentFlags().BoolVarP(&newtQuiet, "quiet", "q", false,
+ "Be quiet; only display error output.")
+ newtCmd.PersistentFlags().BoolVarP(&newtSilent, "silent", "s", false,
+ "Be silent; don't output anything.")
newtCmd.PersistentFlags().StringVarP(&NewtLogLevel, "loglevel", "l",
"WARN", "Log level, defaults to WARN.")
[14/50] incubator-mynewt-newt git commit: Clean up some error
messages.
Posted by ma...@apache.org.
Clean up some error 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/77e2a2aa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/77e2a2aa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/77e2a2aa
Branch: refs/heads/develop
Commit: 77e2a2aa4ac0993c5d6c9999f6cf2d6bd5795a0a
Parents: 5aecc66
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 12:03:51 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 13:52:51 2016 -0800
----------------------------------------------------------------------
newt/builder/build.go | 3 ++-
newt/builder/buildutil.go | 20 ++++----------------
newt/builder/cmds.go | 8 +++++---
3 files changed, 11 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/77e2a2aa/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index ee265fb..0ff0bc0 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -123,7 +123,8 @@ func (b *Builder) loadDeps() error {
}
}
- b.logFeatures()
+ cli.StatusMessage(cli.VERBOSITY_VERBOSE, "Building with the following "+
+ "feature set: ["+b.featureString()+"]\n")
return nil
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/77e2a2aa/newt/builder/buildutil.go
----------------------------------------------------------------------
diff --git a/newt/builder/buildutil.go b/newt/builder/buildutil.go
index 2433efa..1db97b2 100644
--- a/newt/builder/buildutil.go
+++ b/newt/builder/buildutil.go
@@ -23,7 +23,6 @@ import (
"bytes"
"path/filepath"
- "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/util"
)
@@ -60,9 +59,8 @@ func (b *Builder) testExePath(pkgName string) string {
return b.pkgBinDir(pkgName) + "/test_" + filepath.Base(pkgName)
}
-func (b *Builder) logFeatures() {
+func (b *Builder) featureString() string {
var buffer bytes.Buffer
- buffer.WriteString("Building with the following feature set: [")
first := true
for feature, _ := range b.Features() {
@@ -74,21 +72,11 @@ func (b *Builder) logFeatures() {
buffer.WriteString(feature)
}
- buffer.WriteString("]\n")
-
- cli.StatusMessage(cli.VERBOSITY_VERBOSE, buffer.String())
-}
-
-func (b *Builder) featureString() string {
- featureString := ""
- for feature, _ := range b.features {
- featureString = featureString + " " + feature
- }
- return featureString
+ return buffer.String()
}
-// Makes sure all packages with required APIs have been augmented a dependency
-// which satisfies that requirement. If there are any unsatisfied
+// Makes sure all packages with required APIs have been augmented with a
+// dependency that satisfies that requirement. If there are any unsatisfied
// requirements, an error is returned.
func (b *Builder) verifyApisSatisfied() error {
unsatisfied := map[*BuildPackage][]string{}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/77e2a2aa/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index 1fea275..f2e8668 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -95,15 +95,17 @@ func testRunCmd(cmd *cobra.Command, args []string) {
for _, pkgName := range args {
dep, err := pkg.NewDependency(nil, pkgName)
if err != nil {
- cli.NewtUsage(cmd, err)
+ cli.NewtUsage(cmd, util.NewtErrorNoTrace(fmt.Sprintf("invalid "+
+ "package name: %s (%s)", pkgName, err.Error())))
}
if dep == nil {
- cli.NewtUsage(cmd, util.NewNewtError("invalid package name: "+
+ cli.NewtUsage(cmd, util.NewtErrorNoTrace("invalid package name: "+
pkgName))
}
pack := project.GetProject().ResolveDependency(dep)
if pack == nil {
- cli.NewtUsage(cmd, util.NewNewtError("unknown package: "+pkgName))
+ cli.NewtUsage(cmd, util.NewtErrorNoTrace("unknown package: "+
+ pkgName))
}
packs = append(packs, pack.(*pkg.LocalPackage))
[03/50] incubator-mynewt-newt git commit: Add create-image command.
Posted by ma...@apache.org.
Add create-image command.
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/ae87703f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/ae87703f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/ae87703f
Branch: refs/heads/develop
Commit: ae87703f9af329a652c842668605d4c7bc85befc
Parents: 0a68684
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Mar 7 18:02:48 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 7 18:04:06 2016 -0800
----------------------------------------------------------------------
newt/image/cmds.go | 73 ++++++++++
newt/image/image.go | 329 +++++++++++++++++++++++++++++++++++++++++++++
newt/newt.go | 2 +
newt/target/target.go | 20 +++
4 files changed, 424 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ae87703f/newt/image/cmds.go
----------------------------------------------------------------------
diff --git a/newt/image/cmds.go b/newt/image/cmds.go
new file mode 100644
index 0000000..3a10713
--- /dev/null
+++ b/newt/image/cmds.go
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package image
+
+import (
+ "fmt"
+
+ "github.com/spf13/cobra"
+ "mynewt.apache.org/newt/newt/cli"
+ "mynewt.apache.org/newt/newt/target"
+ "mynewt.apache.org/newt/util"
+)
+
+func createImageRunCmd(cmd *cobra.Command, args []string) {
+ if len(args) < 2 {
+ cli.NewtUsage(cmd, util.NewNewtError("Must specify target and version"))
+ }
+
+ targetName := args[0]
+ t := target.GetTargets()[targetName]
+ if t == nil {
+ cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"))
+ }
+
+ image, err := NewImage(t)
+ if err != nil {
+ fmt.Println(err)
+ }
+ err = image.SetVersion(args[1])
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+ err = image.Generate()
+ if err != nil {
+ fmt.Println(err)
+ }
+}
+
+func AddCommands(cmd *cobra.Command) {
+ createImageHelpText := "Create image by adding image header to created "+
+ "binary file for <target-name>. Version number in the header is set "+
+ "to be <version>."
+ createImageHelpEx := " newt create-image <target-name> <version>\n"
+ createImageHelpEx += " newt create-image my_target1 1.2.0\n"
+ createImageHelpEx += " newt create-image my_target1 1.2.0.3\n"
+
+ createImageCmd := &cobra.Command{
+ Use: "create-image",
+ Short: "Add image header to target binary",
+ Long: createImageHelpText,
+ Example: createImageHelpEx,
+ Run: createImageRunCmd,
+ }
+ cmd.AddCommand(createImageCmd)
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ae87703f/newt/image/image.go
----------------------------------------------------------------------
diff --git a/newt/image/image.go b/newt/image/image.go
new file mode 100644
index 0000000..edd3bfd
--- /dev/null
+++ b/newt/image/image.go
@@ -0,0 +1,329 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package image
+
+import (
+ "bytes"
+ "crypto/sha256"
+ "encoding/binary"
+ "encoding/json"
+ "fmt"
+ "io"
+ "log"
+ "os"
+ "path/filepath"
+ "sort"
+ "strconv"
+ "strings"
+ "time"
+
+ "mynewt.apache.org/newt/newt/target"
+ "mynewt.apache.org/newt/util"
+)
+
+type ImageVersion struct {
+ Major uint8
+ Minor uint8
+ Rev uint16
+ BuildNum uint32
+}
+
+type Image struct {
+ target *target.Target
+
+ sourceBin string
+ targetImg string
+ ManifestFile string
+ version ImageVersion
+
+ hash []byte
+}
+
+type ImageHdr struct {
+ Magic uint32
+ TlvSz uint32
+ HdrSz uint32
+ ImgSz uint32
+ Flags uint32
+ Vers ImageVersion
+ Pad uint32
+}
+
+type ImageTrailerTlv struct {
+ Type uint8
+ Pad uint8
+ Len uint16
+}
+
+const (
+ IMAGE_MAGIC = 0x96f3b83c /* Image header magic */
+)
+
+const (
+ IMAGE_HEADER_SIZE = 32
+)
+
+/*
+ * Image header flags.
+ */
+const (
+ IMAGE_F_PIC = 0x00000001
+ IMAGE_F_HAS_SHA256 = 0x00000002 /* Image contains hash TLV */
+)
+
+/*
+ * Image trailer TLV types.
+ */
+const (
+ IMAGE_TLV_SHA256 = 1
+)
+
+/*
+ * Data that's going to go to build manifest file
+ */
+type ImageManifest struct {
+ Date string `json:"build_time"`
+ Version string `json:"build_version"`
+ Hash string `json:"id"`
+ Image string `json:"image"`
+ Pkgs []*ImageManifestPkg `json:"pkgs"`
+ TgtVars []string `json:"target"`
+}
+
+type ImageManifestPkg struct {
+ Name string `json:"name"`
+ Version string `json:"version,omitempty"`
+ Hash string `json:"hash"`
+}
+
+func NewImage(t *target.Target) (*Image, error) {
+ image := &Image{
+ target: t,
+ }
+
+ image.sourceBin = t.ElfPath() + ".bin"
+ image.targetImg = t.ImagePath()
+ return image, nil
+}
+
+func (image *Image) SetVersion(versStr string) error {
+ var err error
+ var major uint64
+ var minor uint64
+ var rev uint64
+ var buildNum uint64
+
+ components := strings.Split(versStr, ".")
+ major, err = strconv.ParseUint(components[0], 10, 8)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
+ versStr))
+ }
+ if len(components) > 1 {
+ minor, err = strconv.ParseUint(components[1], 10, 8)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
+ versStr))
+ }
+ }
+ if len(components) > 2 {
+ rev, err = strconv.ParseUint(components[2], 10, 16)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
+ versStr))
+ }
+ }
+ if len(components) > 3 {
+ buildNum, err = strconv.ParseUint(components[3], 10, 32)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
+ versStr))
+ }
+ }
+ image.version.Major = uint8(major)
+ image.version.Minor = uint8(minor)
+ image.version.Rev = uint16(rev)
+ image.version.BuildNum = uint32(buildNum)
+ log.Printf("[VERBOSE] Assigning version number %d.%d.%d.%d\n",
+ image.version.Major, image.version.Minor,
+ image.version.Rev, image.version.BuildNum)
+
+ buf := new(bytes.Buffer)
+ err = binary.Write(buf, binary.LittleEndian, image.version)
+ if err != nil {
+ fmt.Printf("Bombing out\n")
+ return nil
+ }
+
+ return nil
+}
+
+func (image *Image) Generate() error {
+ binFile, err := os.Open(image.sourceBin)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Can't open target binary %s: %s",
+ image.sourceBin, err.Error()))
+ }
+ defer binFile.Close()
+
+ binInfo, err := binFile.Stat()
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Can't stat target binary %s: %s",
+ image.sourceBin, err.Error()))
+ }
+
+ imgFile, err := os.OpenFile(image.targetImg,
+ os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Can't open target image %s: %s",
+ image.targetImg, err.Error()))
+ }
+ defer imgFile.Close()
+
+ /*
+ * Compute hash while updating the file.
+ */
+ hash := sha256.New()
+
+ /*
+ * First the header
+ */
+ hdr := &ImageHdr{
+ Magic: IMAGE_MAGIC,
+ TlvSz: 4 + 32,
+ HdrSz: IMAGE_HEADER_SIZE,
+ ImgSz: uint32(binInfo.Size()),
+ Flags: IMAGE_F_HAS_SHA256,
+ Vers: image.version,
+ Pad: 0,
+ }
+
+ err = binary.Write(imgFile, binary.LittleEndian, hdr)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to serialize image hdr: %s",
+ err.Error()))
+ }
+ err = binary.Write(hash, binary.LittleEndian, hdr)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to hash data: %s",
+ err.Error()))
+ }
+
+ /*
+ * Followed by data.
+ */
+ dataBuf := make([]byte, 1024)
+ for {
+ cnt, err := binFile.Read(dataBuf)
+ if err != nil && err != io.EOF {
+ return util.NewNewtError(fmt.Sprintf("Failed to read from %s: %s",
+ image.sourceBin, err.Error()))
+ }
+ if cnt == 0 {
+ break
+ }
+ _, err = imgFile.Write(dataBuf[0:cnt])
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to write to %s: %s",
+ image.targetImg, err.Error()))
+ }
+ _, err = hash.Write(dataBuf[0:cnt])
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to hash data: %s",
+ err.Error()))
+ }
+ }
+
+ image.hash = hash.Sum(nil)
+
+ /*
+ * Trailer with hash of the data
+ */
+ tlv := &ImageTrailerTlv{
+ Type: IMAGE_TLV_SHA256,
+ Pad: 0,
+ Len: uint16(len(image.hash)),
+ }
+ err = binary.Write(imgFile, binary.LittleEndian, tlv)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to serialize image "+
+ "trailer: %s", err.Error()))
+ }
+ _, err = imgFile.Write(image.hash)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to append hash: %s",
+ err.Error()))
+ }
+
+ return nil
+}
+
+func (image *Image) CreateManifest() error {
+ versionStr := fmt.Sprintf("%d.%d.%d.%d",
+ image.version.Major, image.version.Minor,
+ image.version.Rev, image.version.BuildNum)
+ hashStr := fmt.Sprintf("%x", image.hash)
+ timeStr := time.Now().Format(time.RFC3339)
+
+ manifest := &ImageManifest{
+ Version: versionStr,
+ Hash: hashStr,
+ Image: filepath.Base(image.targetImg),
+ Date: timeStr,
+ }
+/*
+ for _, builtPkg := range BuiltPkgs {
+ imgPkg := &ImageManifestPkg{
+ Name: builtPkg.Name,
+ Version: builtPkg.Version,
+ Hash: builtPkg.Hash,
+ }
+ manifest.Pkgs = append(manifest.Pkgs, imgPkg)
+ }
+*/
+ vars := image.target.Vars
+ var keys []string
+ for k := range vars {
+ keys = append(keys, k)
+ }
+ sort.Strings(keys)
+ for _, k := range keys {
+ manifest.TgtVars = append(manifest.TgtVars, k+"="+vars[k])
+ }
+ file, err := os.Create(image.ManifestFile)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Cannot create manifest file %s: %s",
+ image.ManifestFile, err.Error()))
+ }
+ defer file.Close()
+
+ buffer, err := json.MarshalIndent(manifest, "", " ")
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Cannot encode manifest: %s",
+ err.Error()))
+ }
+ _, err = file.Write(buffer)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Cannot write manifest file: %s",
+ err.Error()))
+ }
+
+ return nil
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ae87703f/newt/newt.go
----------------------------------------------------------------------
diff --git a/newt/newt.go b/newt/newt.go
index 4cb8ad6..9b05f55 100644
--- a/newt/newt.go
+++ b/newt/newt.go
@@ -25,6 +25,7 @@ import (
"mynewt.apache.org/newt/newt/builder"
"mynewt.apache.org/newt/newt/cli"
+ "mynewt.apache.org/newt/newt/image"
"mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/newt/target"
@@ -91,6 +92,7 @@ func main() {
pkg.AddCommands(cmd)
target.AddCommands(cmd)
builder.AddCommands(cmd)
+ image.AddCommands(cmd)
cmd.Execute()
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ae87703f/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 3b6dfc6..67555ac 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -124,6 +124,26 @@ func (target *Target) Bsp() *pkg.LocalPackage {
return mypkg
}
+func (target *Target) ElfPath() string {
+ appPkg := target.App()
+ if appPkg == nil {
+ return ""
+ }
+
+ return appPkg.BasePath() + "/bin/" + target.Package().Name() + "/" +
+ appPkg.Name() + ".elf"
+}
+
+func (target *Target) ImagePath() string {
+ appPkg := target.App()
+ if appPkg == nil {
+ return ""
+ }
+
+ return appPkg.BasePath() + "/bin/" + target.Package().Name() + "/" +
+ appPkg.Name() + ".img"
+}
+
// Save the target's configuration elements
func (t *Target) Save() error {
if err := t.basePkg.Save(); err != nil {
[17/50] incubator-mynewt-newt git commit: Rename target var
"compiler_def" to "build_profile.
Posted by ma...@apache.org.
Rename target var "compiler_def" to "build_profile.
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/690cb84f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/690cb84f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/690cb84f
Branch: refs/heads/develop
Commit: 690cb84f3afc481b5caad5e66d188f9251db9d7c
Parents: 9446bbc
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 14:32:45 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 14:32:45 2016 -0800
----------------------------------------------------------------------
newt/toolchain/compiler.go | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/690cb84f/newt/toolchain/compiler.go
----------------------------------------------------------------------
diff --git a/newt/toolchain/compiler.go b/newt/toolchain/compiler.go
index 21c2ef1..34c2e51 100644
--- a/newt/toolchain/compiler.go
+++ b/newt/toolchain/compiler.go
@@ -81,7 +81,7 @@ func (ci *CompilerInfo) AddCompilerInfo(newCi *CompilerInfo) {
}
func NewCompiler(compilerDir string, dstDir string,
- cDef string) (*Compiler, error) {
+ buildProfile string) (*Compiler, error) {
c := &Compiler{
ObjPathList: map[string]bool{},
@@ -91,8 +91,8 @@ func NewCompiler(compilerDir string, dstDir string,
c.depTracker = NewDepTracker(c)
cli.StatusMessage(cli.VERBOSITY_VERBOSE,
- "Loading compiler %s, def %s\n", compilerDir, cDef)
- err := c.load(compilerDir, cDef)
+ "Loading compiler %s, def %s\n", compilerDir, buildProfile)
+ err := c.load(compilerDir, buildProfile)
if err != nil {
return nil, err
}
@@ -100,7 +100,7 @@ func NewCompiler(compilerDir string, dstDir string,
return c, nil
}
-func (c *Compiler) load(compilerDir string, cDef string) error {
+func (c *Compiler) load(compilerDir string, buildProfile string) error {
v, err := util.ReadConfig(compilerDir, "compiler")
if err != nil {
return err
@@ -113,7 +113,7 @@ func (c *Compiler) load(compilerDir string, cDef string) error {
c.osPath = v.GetString("compiler.path.objsize")
c.ocPath = v.GetString("compiler.path.objcopy")
- cflags := v.GetStringSlice("compiler.flags." + cDef)
+ cflags := v.GetStringSlice("compiler.flags." + buildProfile)
for _, flag := range cflags {
if strings.HasPrefix(flag, "compiler.flags") {
c.info.Cflags = append(c.info.Cflags,
[11/50] incubator-mynewt-newt git commit: Update to use new path to
generated binaries. Go formatting.
Posted by ma...@apache.org.
Update to use new path to generated binaries. Go formatting.
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/53ca8db6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/53ca8db6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/53ca8db6
Branch: refs/heads/develop
Commit: 53ca8db65a45c59b6bb44f90f0b25bec35a24f6c
Parents: d36820c
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Mar 8 12:33:28 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Mar 8 12:33:28 2016 -0800
----------------------------------------------------------------------
newt/builder/build.go | 8 +++----
newt/builder/buildutil.go | 12 +++++++++-
newt/builder/cmds.go | 46 +++++++++++++++++------------------
newt/builder/download.go | 48 ++++++++++++++++++-------------------
newt/image/cmds.go | 54 +++++++++++++++++++++++++++---------------
newt/image/image.go | 19 +++++++--------
6 files changed, 106 insertions(+), 81 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/53ca8db6/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index b256a53..890be8b 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -265,7 +265,7 @@ func (b *Builder) link(elfName string) error {
// Populates the builder with all the packages that need to be built, and
// configures each package's build settings. After this function executes,
// packages are ready to be built.
-func (b *Builder) prepBuild() error {
+func (b *Builder) PrepBuild() error {
// Collect the seed packages.
bspPkg := b.target.Bsp()
if bspPkg == nil {
@@ -360,7 +360,7 @@ func (b *Builder) Build() error {
// Populate the package and feature sets and calculate the base compiler
// flags.
- err := b.prepBuild()
+ err := b.PrepBuild()
if err != nil {
return err
}
@@ -375,7 +375,7 @@ func (b *Builder) Build() error {
}
}
- err = b.link(b.appElfPath())
+ err = b.link(b.AppElfPath())
if err != nil {
return err
}
@@ -396,7 +396,7 @@ func (b *Builder) Test(p *pkg.LocalPackage) error {
// Populate the package and feature sets and calculate the base compiler
// flags.
- err := b.prepBuild()
+ err := b.PrepBuild()
if err != nil {
return err
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/53ca8db6/newt/builder/buildutil.go
----------------------------------------------------------------------
diff --git a/newt/builder/buildutil.go b/newt/builder/buildutil.go
index 0091def..2433efa 100644
--- a/newt/builder/buildutil.go
+++ b/newt/builder/buildutil.go
@@ -41,11 +41,21 @@ func (b *Builder) archivePath(pkgName string) string {
return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".a"
}
-func (b *Builder) appElfPath() string {
+func (b *Builder) AppElfPath() string {
pkgName := b.target.App().Name()
return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".elf"
}
+func (b *Builder) AppImgPath() string {
+ pkgName := b.target.App().Name()
+ return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".img"
+}
+
+func (b *Builder) appBinBasePath() string {
+ pkgName := b.target.App().Name()
+ return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName)
+}
+
func (b *Builder) testExePath(pkgName string) string {
return b.pkgBinDir(pkgName) + "/test_" + filepath.Base(pkgName)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/53ca8db6/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index 472ae6d..1fea275 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -199,27 +199,27 @@ func AddCommands(cmd *cobra.Command) {
cmd.AddCommand(testCmd)
- downloadHelpText := "Download project image to target for <target-name>."
- downloadHelpEx := " newt download <target-name>\n"
-
- downloadCmd := &cobra.Command{
- Use: "download",
- Short: "Download built target to board",
- Long: downloadHelpText,
- Example: downloadHelpEx,
- Run: downloadRunCmd,
- }
- cmd.AddCommand(downloadCmd)
-
- debugHelpText := "Download project image to target for <target-name>.";
- debugHelpEx := " newt debug <target-name>\n"
-
- debugCmd := &cobra.Command{
- Use: "debug",
- Short: "Open debugger session to target",
- Long: debugHelpText,
- Example: debugHelpEx,
- Run: debugRunCmd,
- }
- cmd.AddCommand(debugCmd)
+ downloadHelpText := "Download project image to target for <target-name>."
+ downloadHelpEx := " newt download <target-name>\n"
+
+ downloadCmd := &cobra.Command{
+ Use: "download",
+ Short: "Download built target to board",
+ Long: downloadHelpText,
+ Example: downloadHelpEx,
+ Run: downloadRunCmd,
+ }
+ cmd.AddCommand(downloadCmd)
+
+ debugHelpText := "Download project image to target for <target-name>."
+ debugHelpEx := " newt debug <target-name>\n"
+
+ debugCmd := &cobra.Command{
+ Use: "debug",
+ Short: "Open debugger session to target",
+ Long: debugHelpText,
+ Example: debugHelpEx,
+ Run: debugRunCmd,
+ }
+ cmd.AddCommand(debugCmd)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/53ca8db6/newt/builder/download.go
----------------------------------------------------------------------
diff --git a/newt/builder/download.go b/newt/builder/download.go
index 0cbba72..32b4290 100644
--- a/newt/builder/download.go
+++ b/newt/builder/download.go
@@ -24,32 +24,32 @@ import (
"os"
"path/filepath"
- "mynewt.apache.org/newt/newt/cli"
- "mynewt.apache.org/newt/newt/project"
- "mynewt.apache.org/newt/util"
+ "mynewt.apache.org/newt/newt/cli"
+ "mynewt.apache.org/newt/newt/project"
+ "mynewt.apache.org/newt/util"
)
func (b *Builder) Download() error {
- if b.target.App() == nil {
- return util.NewNewtError("app package not specified")
- }
+ if b.target.App() == nil {
+ return util.NewNewtError("app package not specified")
+ }
- /*
- * Populate the package and feature sets.
+ /*
+ * Populate the package list and feature sets.
*/
- err := b.prepBuild()
- if err != nil {
- return err
- }
+ err := b.PrepBuild()
+ if err != nil {
+ return err
+ }
bspPath := b.Bsp.BasePath()
downloadScript := filepath.Join(bspPath, b.Bsp.DownloadScript)
- binBaseName := b.target.BinBasePath()
+ binBaseName := b.appBinBasePath()
featureString := b.featureString()
downloadCmd := fmt.Sprintf("%s %s %s %s",
downloadScript, bspPath, binBaseName, featureString)
-
+
rsp, err := cli.ShellCommand(downloadCmd)
fmt.Printf("%s", rsp)
@@ -57,21 +57,21 @@ func (b *Builder) Download() error {
}
func (b *Builder) Debug() error {
- if b.target.App() == nil {
- return util.NewNewtError("app package not specified")
- }
+ if b.target.App() == nil {
+ return util.NewNewtError("app package not specified")
+ }
- /*
- * Populate the package and feature sets.
+ /*
+ * Populate the package list and feature sets.
*/
- err := b.prepBuild()
- if err != nil {
- return err
- }
+ err := b.PrepBuild()
+ if err != nil {
+ return err
+ }
bspPath := b.Bsp.BasePath()
debugScript := filepath.Join(bspPath, b.Bsp.DebugScript)
- binBaseName := b.target.BinBasePath()
+ binBaseName := b.appBinBasePath()
featureString := b.featureString()
os.Chdir(project.GetProject().Path())
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/53ca8db6/newt/image/cmds.go
----------------------------------------------------------------------
diff --git a/newt/image/cmds.go b/newt/image/cmds.go
index d169b21..1ced272 100644
--- a/newt/image/cmds.go
+++ b/newt/image/cmds.go
@@ -20,12 +20,13 @@
package image
import (
- "fmt"
+ "fmt"
- "github.com/spf13/cobra"
- "mynewt.apache.org/newt/newt/cli"
- "mynewt.apache.org/newt/newt/target"
- "mynewt.apache.org/newt/util"
+ "github.com/spf13/cobra"
+ "mynewt.apache.org/newt/newt/builder"
+ "mynewt.apache.org/newt/newt/cli"
+ "mynewt.apache.org/newt/newt/target"
+ "mynewt.apache.org/newt/util"
)
func createImageRunCmd(cmd *cobra.Command, args []string) {
@@ -39,14 +40,29 @@ func createImageRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"))
}
- image, err := NewImage(t)
+ b, err := builder.NewBuilder(t)
if err != nil {
fmt.Println(err)
+ return
}
+
+ err = b.PrepBuild()
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+
+ image, err := NewImage(b)
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+
err = image.SetVersion(args[1])
if err != nil {
cli.NewtUsage(cmd, err)
}
+
err = image.Generate()
if err != nil {
fmt.Println(err)
@@ -54,19 +70,19 @@ func createImageRunCmd(cmd *cobra.Command, args []string) {
}
func AddCommands(cmd *cobra.Command) {
- createImageHelpText := "Create image by adding image header to created "+
- "binary file for <target-name>. Version number in the header is set "+
+ createImageHelpText := "Create image by adding image header to created " +
+ "binary file for <target-name>. Version number in the header is set " +
"to be <version>."
- createImageHelpEx := " newt create-image <target-name> <version>\n"
- createImageHelpEx += " newt create-image my_target1 1.2.0\n"
- createImageHelpEx += " newt create-image my_target1 1.2.0.3\n"
+ createImageHelpEx := " newt create-image <target-name> <version>\n"
+ createImageHelpEx += " newt create-image my_target1 1.2.0\n"
+ createImageHelpEx += " newt create-image my_target1 1.2.0.3\n"
- createImageCmd := &cobra.Command{
- Use: "create-image",
- Short: "Add image header to target binary",
- Long: createImageHelpText,
- Example: createImageHelpEx,
- Run: createImageRunCmd,
- }
- cmd.AddCommand(createImageCmd)
+ createImageCmd := &cobra.Command{
+ Use: "create-image",
+ Short: "Add image header to target binary",
+ Long: createImageHelpText,
+ Example: createImageHelpEx,
+ Run: createImageRunCmd,
+ }
+ cmd.AddCommand(createImageCmd)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/53ca8db6/newt/image/image.go
----------------------------------------------------------------------
diff --git a/newt/image/image.go b/newt/image/image.go
index edd3bfd..6c0dfdb 100644
--- a/newt/image/image.go
+++ b/newt/image/image.go
@@ -34,6 +34,7 @@ import (
"strings"
"time"
+ "mynewt.apache.org/newt/newt/builder"
"mynewt.apache.org/newt/newt/target"
"mynewt.apache.org/newt/util"
)
@@ -46,13 +47,13 @@ type ImageVersion struct {
}
type Image struct {
- target *target.Target
+ target *builder.Builder
+ builder *builder.Builder
sourceBin string
targetImg string
ManifestFile string
version ImageVersion
-
hash []byte
}
@@ -113,13 +114,11 @@ type ImageManifestPkg struct {
Hash string `json:"hash"`
}
-func NewImage(t *target.Target) (*Image, error) {
- image := &Image{
- target: t,
- }
+func NewImage(b *builder.Builder) (*Image, error) {
+ image := &Image{}
- image.sourceBin = t.ElfPath() + ".bin"
- image.targetImg = t.ImagePath()
+ image.sourceBin = b.AppElfPath() + ".bin"
+ image.targetImg = b.AppImgPath()
return image, nil
}
@@ -275,7 +274,7 @@ func (image *Image) Generate() error {
return nil
}
-func (image *Image) CreateManifest() error {
+func (image *Image) CreateManifest(t *target.Target) error {
versionStr := fmt.Sprintf("%d.%d.%d.%d",
image.version.Major, image.version.Minor,
image.version.Rev, image.version.BuildNum)
@@ -298,7 +297,7 @@ func (image *Image) CreateManifest() error {
manifest.Pkgs = append(manifest.Pkgs, imgPkg)
}
*/
- vars := image.target.Vars
+ vars := t.Vars
var keys []string
for k := range vars {
keys = append(keys, k)
[45/50] incubator-mynewt-newt git commit: "clean all" command.
Posted by ma...@apache.org.
"clean all" command.
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/d9b22a67
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/d9b22a67
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/d9b22a67
Branch: refs/heads/develop
Commit: d9b22a67f6eca6458e05d9a0ed648e08a7583e6f
Parents: 59fef97
Author: ccollins at iori.nightmare.heaven <cc...@iori.nightmare-heaven.no-ip.biz>
Authored: Wed Mar 9 09:32:05 2016 -0800
Committer: ccollins at iori.nightmare.heaven <cc...@iori.nightmare-heaven.no-ip.biz>
Committed: Wed Mar 9 10:00:09 2016 -0800
----------------------------------------------------------------------
newt/builder/build.go | 14 ++++++-------
newt/builder/buildutil.go | 32 +++++++++++++++++-------------
newt/builder/cmds.go | 45 ++++++++++++++++++++++++++++++------------
newt/builder/download.go | 8 ++++----
newt/target/cmds.go | 27 ++-----------------------
newt/target/target.go | 30 ++++++++++++++++++++++++++++
6 files changed, 93 insertions(+), 63 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d9b22a67/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 6f6ea75..d6ca89d 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -122,7 +122,7 @@ func (b *Builder) loadDeps() error {
}
util.StatusMessage(util.VERBOSITY_VERBOSE, "Building with the following "+
- "feature set: ["+b.featureString()+"]\n")
+ "feature set: ["+b.FeatureString()+"]\n")
return nil
}
@@ -193,7 +193,7 @@ func (b *Builder) buildPackage(bpkg *BuildPackage) error {
}
c, err := toolchain.NewCompiler(b.compilerPkg.BasePath(),
- b.pkgBinDir(bpkg.Name()), b.target.BuildProfile)
+ b.PkgBinDir(bpkg.Name()), b.target.BuildProfile)
if err != nil {
return err
}
@@ -228,7 +228,7 @@ func (b *Builder) buildPackage(bpkg *BuildPackage) error {
if err := os.Chdir(bpkg.BasePath() + "/"); err != nil {
return util.NewNewtError(err.Error())
}
- archiveFile := b.archivePath(bpkg.Name())
+ archiveFile := b.ArchivePath(bpkg.Name())
if err = c.CompileArchive(archiveFile); err != nil {
return err
}
@@ -238,14 +238,14 @@ func (b *Builder) buildPackage(bpkg *BuildPackage) error {
func (b *Builder) link(elfName string) error {
c, err := toolchain.NewCompiler(b.compilerPkg.BasePath(),
- b.pkgBinDir(elfName), b.target.BuildProfile)
+ b.PkgBinDir(elfName), b.target.BuildProfile)
if err != nil {
return err
}
pkgNames := []string{}
for _, bpkg := range b.Packages {
- archivePath := b.archivePath(bpkg.Name())
+ archivePath := b.ArchivePath(bpkg.Name())
if util.NodeExist(archivePath) {
pkgNames = append(pkgNames, archivePath)
}
@@ -445,7 +445,7 @@ func (b *Builder) Test(p *pkg.LocalPackage) error {
}
}
- testFilename := b.testExePath(p.Name())
+ testFilename := b.TestExePath(p.Name())
err = b.link(testFilename)
if err != nil {
return err
@@ -473,7 +473,7 @@ func (b *Builder) Test(p *pkg.LocalPackage) error {
}
func (b *Builder) Clean() error {
- path := b.binDir()
+ path := b.BinDir()
util.StatusMessage(util.VERBOSITY_VERBOSE, "Cleaning directory %s\n", path)
err := os.RemoveAll(path)
return err
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d9b22a67/newt/builder/buildutil.go
----------------------------------------------------------------------
diff --git a/newt/builder/buildutil.go b/newt/builder/buildutil.go
index 2654477..202149c 100644
--- a/newt/builder/buildutil.go
+++ b/newt/builder/buildutil.go
@@ -28,44 +28,48 @@ import (
"mynewt.apache.org/newt/util"
)
-func (b *Builder) binDir() string {
- return project.GetProject().Path() + "/bin/" + b.target.ShortName()
+func BinRoot() string {
+ return project.GetProject().Path() + "/bin"
}
-func (b *Builder) pkgBinDir(pkgName string) string {
- return b.binDir() + "/" + pkgName
+func (b *Builder) BinDir() string {
+ return BinRoot() + "/" + b.target.ShortName()
+}
+
+func (b *Builder) PkgBinDir(pkgName string) string {
+ return b.BinDir() + "/" + pkgName
}
// Generates the path+filename of the specified package's .a file.
-func (b *Builder) archivePath(pkgName string) string {
- return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".a"
+func (b *Builder) ArchivePath(pkgName string) string {
+ return b.PkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".a"
}
func (b *Builder) AppElfPath() string {
pkgName := b.target.App().Name()
- return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".elf"
+ return b.PkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".elf"
}
func (b *Builder) AppImgPath() string {
pkgName := b.target.App().Name()
- return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".img"
+ return b.PkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".img"
}
func (b *Builder) AppPath() string {
pkgName := b.target.App().Name()
- return b.pkgBinDir(pkgName) + "/"
+ return b.PkgBinDir(pkgName) + "/"
}
-func (b *Builder) appBinBasePath() string {
+func (b *Builder) AppBinBasePath() string {
pkgName := b.target.App().Name()
- return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName)
+ return b.PkgBinDir(pkgName) + "/" + filepath.Base(pkgName)
}
-func (b *Builder) testExePath(pkgName string) string {
- return b.pkgBinDir(pkgName) + "/test_" + filepath.Base(pkgName)
+func (b *Builder) TestExePath(pkgName string) string {
+ return b.PkgBinDir(pkgName) + "/test_" + filepath.Base(pkgName)
}
-func (b *Builder) featureString() string {
+func (b *Builder) FeatureString() string {
var buffer bytes.Buffer
first := true
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d9b22a67/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index b236bbf..abcbd47 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -21,6 +21,7 @@ package builder
import (
"fmt"
+ "os"
"github.com/spf13/cobra"
"mynewt.apache.org/newt/newt/cli"
@@ -60,19 +61,37 @@ func cleanRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, util.NewNewtError("Must specify target"))
}
- t := target.ResolveTarget(args[0])
- if t == nil {
- cli.NewtUsage(cmd, util.NewNewtError("invalid target name"+args[0]))
- }
-
- b, err := NewBuilder(t)
- if err != nil {
- cli.NewtUsage(cmd, err)
- }
- err = b.Clean()
- if err != nil {
- cli.NewtUsage(cmd, err)
- }
+ cleanAll := false
+ targets := []*target.Target{}
+ for _, arg := range args {
+ if arg == target.TARGET_KEYWORD_ALL {
+ cleanAll = true
+ } else {
+ t := target.ResolveTarget(arg)
+ if t == nil {
+ cli.NewtUsage(cmd, util.NewNewtError("invalid target name"+arg))
+ }
+ targets = append(targets, t)
+ }
+ }
+
+ if cleanAll {
+ err := os.RemoveAll(BinRoot())
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+ } else {
+ for _,t := range targets {
+ b, err := NewBuilder(t)
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+ err = b.Clean()
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+ }
+ }
}
func testRunCmd(cmd *cobra.Command, args []string) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d9b22a67/newt/builder/download.go
----------------------------------------------------------------------
diff --git a/newt/builder/download.go b/newt/builder/download.go
index cab02c8..0cb0258 100644
--- a/newt/builder/download.go
+++ b/newt/builder/download.go
@@ -50,8 +50,8 @@ func (b *Builder) Download() error {
bspPath := b.Bsp.BasePath()
downloadScript := filepath.Join(bspPath, b.Bsp.DownloadScript)
- binBaseName := b.appBinBasePath()
- featureString := b.featureString()
+ binBaseName := b.AppBinBasePath()
+ featureString := b.FeatureString()
downloadCmd := fmt.Sprintf("%s %s %s %s",
downloadScript, bspPath, binBaseName, featureString)
@@ -77,8 +77,8 @@ func (b *Builder) Debug() error {
bspPath := b.Bsp.BasePath()
debugScript := filepath.Join(bspPath, b.Bsp.DebugScript)
- binBaseName := b.appBinBasePath()
- featureString := b.featureString()
+ binBaseName := b.AppBinBasePath()
+ featureString := b.FeatureString()
os.Chdir(project.GetProject().Path())
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d9b22a67/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index 1dabd1e..e3aae87 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -42,29 +42,6 @@ func resolveExistingTargetArg(arg string) (*Target, error) {
return t, nil
}
-func resolveNewTargetArg(arg string) (string, error) {
- repoName, pkgName, err := cli.ParsePackageString(arg)
- if err != nil {
- return "", err
- }
-
- if repoName != "" {
- return "", util.NewNewtError("Target name cannot contain repo; " +
- "must be local")
- }
-
- // "Naked" target names go in the "targets/" directory.
- if !strings.Contains(pkgName, "/") {
- pkgName = "targets/" + pkgName
- }
-
- if GetTargets()[pkgName] != nil {
- return "", util.NewNewtError("Target already exists: " + pkgName)
- }
-
- return pkgName, nil
-}
-
func targetShowCmd(cmd *cobra.Command, args []string) {
proj := project.GetProject()
err := proj.LoadPackageList()
@@ -192,7 +169,7 @@ func targetCreateCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, util.NewNewtError("Missing target name"))
}
- pkgName, err := resolveNewTargetArg(args[0])
+ pkgName, err := ResolveNewTargetName(args[0])
if err != nil {
cli.NewtUsage(cmd, err)
}
@@ -271,7 +248,7 @@ func targetCopyCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, err)
}
- dstName, err := resolveNewTargetArg(args[1])
+ dstName, err := ResolveNewTargetName(args[1])
if err != nil {
cli.NewtUsage(cmd, err)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d9b22a67/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 4b64e57..32098f3 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -26,6 +26,7 @@ import (
"sort"
"strings"
+ "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/util"
@@ -34,6 +35,7 @@ import (
const TARGET_FILENAME string = "target.yml"
const TARGET_DEFAULT_DIR string = "targets"
+const TARGET_KEYWORD_ALL string = "all"
var globalTargetMap map[string]*Target
@@ -281,3 +283,31 @@ func ResolveTargetNames(names ...string) ([]*Target, error) {
return targets, nil
}
+
+func ResolveNewTargetName(name string) (string, error) {
+ repoName, pkgName, err := cli.ParsePackageString(name)
+ if err != nil {
+ return "", err
+ }
+
+ if repoName != "" {
+ return "", util.NewNewtError("Target name cannot contain repo; " +
+ "must be local")
+ }
+
+ if pkgName == TARGET_KEYWORD_ALL {
+ return "", util.NewNewtError("Target name " + TARGET_KEYWORD_ALL +
+ " is reserved")
+ }
+
+ // "Naked" target names translate to "targets/<name>".
+ if !strings.Contains(pkgName, "/") {
+ pkgName = TARGET_DEFAULT_DIR + "/" + pkgName
+ }
+
+ if GetTargets()[pkgName] != nil {
+ return "", util.NewNewtError("Target already exists: " + pkgName)
+ }
+
+ return pkgName, nil
+}
[10/50] incubator-mynewt-newt git commit: first cut of package
installation. very rough, but good checkpoint for others work.
Posted by ma...@apache.org.
first cut of package installation. very rough, but good checkpoint for others work.
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/d36820cf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/d36820cf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/d36820cf
Branch: refs/heads/develop
Commit: d36820cf372c45ff590fa38e0456445da551a6ae
Parents: 32463b4
Author: Sterling Hughes <st...@apache.org>
Authored: Tue Mar 8 11:43:28 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Mar 8 11:43:28 2016 -0800
----------------------------------------------------------------------
newt/downloader/downloader.go | 20 +++
newt/interfaces/interfaces.go | 3 +-
newt/newt.go | 8 +-
newt/pkg/dependency.go | 73 +----------
newt/pkg/localpackage.go | 18 ---
newt/pkg/package.go | 2 -
newt/pkg/version.go | 209 -------------------------------
newt/project/cmds.go | 22 ++--
newt/project/project.go | 96 ++++++++++++--
newt/project/projectstate.go | 110 ++++++++++++++++
newt/repo/repo.go | 191 +++++++++++++++++++++++++---
newt/repo/version.go | 249 +++++++++++++++++++++++++++++++++++++
newt/target/cmds.go | 1 -
13 files changed, 666 insertions(+), 336 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d36820cf/newt/downloader/downloader.go
----------------------------------------------------------------------
diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index a48f3d7..37ae4d3 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -27,6 +27,7 @@ import (
"net/http"
"os"
+ "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/util"
)
@@ -34,6 +35,7 @@ type Downloader interface {
FetchFile(name string, dest string) error
Branch() string
SetBranch(branch string)
+ DownloadRepo(branch string) (string, error)
}
type GenericDownloader struct {
@@ -83,6 +85,24 @@ func (gd *GithubDownloader) FetchFile(name string, dest string) error {
return nil
}
+func (gd *GithubDownloader) DownloadRepo(branch string) (string, error) {
+ // Get a temporary directory, and copy the repository into that directory.
+ tmpdir, err := ioutil.TempDir("", "newt-repo")
+ if err != nil {
+ return "", err
+ }
+
+ url := fmt.Sprintf("https://github.com/%s/%s.git", gd.User, gd.Repo)
+
+ _, err = cli.ShellCommand(fmt.Sprintf("git clone -b %s %s %s",
+ branch, url, tmpdir))
+ if err != nil {
+ return "", err
+ }
+
+ return tmpdir, nil
+}
+
func NewGithubDownloader() *GithubDownloader {
return &GithubDownloader{}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d36820cf/newt/interfaces/interfaces.go
----------------------------------------------------------------------
diff --git a/newt/interfaces/interfaces.go b/newt/interfaces/interfaces.go
index 8023292..16cd3c6 100644
--- a/newt/interfaces/interfaces.go
+++ b/newt/interfaces/interfaces.go
@@ -22,7 +22,6 @@ package interfaces
type PackageInterface interface {
Name() string
Repo() RepoInterface
- Vers() VersionInterface
Type() PackageType
}
@@ -35,6 +34,7 @@ type RepoInterface interface {
type VersionReqInterface interface {
CompareType() string
Version() VersionInterface
+ String() string
}
type VersionInterface interface {
@@ -43,6 +43,7 @@ type VersionInterface interface {
Major() int64
Minor() int64
Revision() int64
+ Stability() string
String() string
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d36820cf/newt/newt.go
----------------------------------------------------------------------
diff --git a/newt/newt.go b/newt/newt.go
index 9b05f55..5e279c0 100644
--- a/newt/newt.go
+++ b/newt/newt.go
@@ -57,6 +57,10 @@ func newtCmd() *cobra.Command {
Short: "Newt is a tool to help you compose and build your own OS",
Long: newtHelpText,
Example: newtHelpEx,
+ PersistentPreRun: func(cmd *cobra.Command, args []string) {
+ NewtLogLevel = strings.ToUpper(NewtLogLevel)
+ cli.Init(NewtLogLevel, false, false, false)
+ },
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
@@ -65,8 +69,6 @@ func newtCmd() *cobra.Command {
newtCmd.PersistentFlags().StringVarP(&NewtLogLevel, "loglevel", "l",
"WARN", "Log level, defaults to WARN.")
- NewtLogLevel = strings.ToUpper(NewtLogLevel)
-
versHelpText := cli.FormatHelp(`Display the Newt version number.`)
versHelpEx := " newt version"
versCmd := &cobra.Command{
@@ -85,8 +87,6 @@ func newtCmd() *cobra.Command {
}
func main() {
- cli.Init("ERROR", false, false, false)
-
cmd := newtCmd()
project.AddCommands(cmd)
pkg.AddCommands(cmd)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d36820cf/newt/pkg/dependency.go
----------------------------------------------------------------------
diff --git a/newt/pkg/dependency.go b/newt/pkg/dependency.go
index 58d33ea..ee57655 100644
--- a/newt/pkg/dependency.go
+++ b/newt/pkg/dependency.go
@@ -29,39 +29,12 @@ import (
)
type Dependency struct {
- Name string
- Repo string
- Stability string
- VersReqs []interfaces.VersionReqInterface
-}
-
-func (dep *Dependency) SetVersionReqs(versStr string) error {
- var err error
-
- dep.VersReqs, err = LoadVersionMatches(versStr)
- if err != nil {
- return err
- }
-
- return nil
-}
-
-func (dep *Dependency) GetVersionReqsString() string {
- if dep.VersReqs == nil {
- return "none"
- }
-
- str := ""
- for _, vreq := range dep.VersReqs {
- str += fmt.Sprintf("%s%s", vreq.CompareType(), vreq.Version())
- }
-
- return str
+ Name string
+ Repo string
}
func (dep *Dependency) String() string {
- str := fmt.Sprintf("$%s/%s@%s#%s", dep.Repo, dep.Name,
- dep.GetVersionReqsString(), dep.Stability)
+ str := fmt.Sprintf("@%s/%s", dep.Repo, dep.Name)
return str
}
@@ -74,10 +47,6 @@ func (dep *Dependency) SatisfiesDependency(pkg interfaces.PackageInterface) bool
return false
}
- if !pkg.Vers().SatisfiesVersion(dep.VersReqs) {
- return false
- }
-
return true
}
@@ -85,7 +54,7 @@ func (dep *Dependency) setRepoAndName(parentRepo interfaces.RepoInterface, str s
// First part is always repo/dependency name combination.
// If repo is present, string will always begin with a $ sign
// representing the repo name, followed by 'n' slashes.
- if strings.HasPrefix(str, "$") {
+ if strings.HasPrefix(str, "@") {
nameParts := strings.SplitN(str[1:], "/", 2)
if len(nameParts) == 1 {
return util.NewNewtError(fmt.Sprintf(
@@ -107,44 +76,14 @@ func (dep *Dependency) setRepoAndName(parentRepo interfaces.RepoInterface, str s
}
func (dep *Dependency) Init(parentRepo interfaces.RepoInterface, depStr string) error {
- // Split string into multiple parts
- // @ separates repo/name from version requirements
- // # separates repo/name or version requirements from stability level
- parts := strings.Split(depStr, "@")
- if len(parts) == 1 {
- // There is no @ sign, which means version requirements don't
- // exist. Now check for stability level
- parts = strings.Split(depStr, "#")
-
- if err := dep.setRepoAndName(parentRepo, parts[0]); err != nil {
- return err
- }
-
- if len(parts) > 1 {
- dep.Stability = parts[1]
- } else {
- dep.Stability = PACKAGE_STABILITY_STABLE
- }
- } else if len(parts) == 2 {
- if err := dep.setRepoAndName(parentRepo, parts[0]); err != nil {
- return err
- }
- verParts := strings.Split(parts[1], "#")
- if err := dep.SetVersionReqs(verParts[0]); err != nil {
- return err
- }
- if len(verParts) == 2 {
- dep.Stability = verParts[1]
- } else {
- dep.Stability = PACKAGE_STABILITY_STABLE
- }
+ if err := dep.setRepoAndName(parentRepo, depStr); err != nil {
+ return err
}
return nil
}
func NewDependency(parentRepo interfaces.RepoInterface, depStr string) (*Dependency, error) {
- // Allocate depedency
dep := &Dependency{}
if err := dep.Init(parentRepo, depStr); err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d36820cf/newt/pkg/localpackage.go
----------------------------------------------------------------------
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index 4e25b90..876282c 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -56,8 +56,6 @@ type LocalPackage struct {
// General information about the package
desc *PackageDesc
- // Version information about this package
- vers *Version
// Dependencies for this package
deps []*Dependency
// APIs that this package exports
@@ -72,7 +70,6 @@ type LocalPackage struct {
func NewLocalPackage(r *repo.Repo, pkgDir string) *LocalPackage {
pkg := &LocalPackage{
desc: &PackageDesc{},
- vers: &Version{},
}
pkg.Init(r, pkgDir)
return pkg
@@ -98,10 +95,6 @@ func (pkg *LocalPackage) Desc() *PackageDesc {
return pkg.desc
}
-func (pkg *LocalPackage) Vers() interfaces.VersionInterface {
- return pkg.vers
-}
-
func (pkg *LocalPackage) SetName(name string) {
pkg.name = name
}
@@ -114,10 +107,6 @@ func (pkg *LocalPackage) SetDesc(desc *PackageDesc) {
pkg.desc = desc
}
-func (pkg *LocalPackage) SetVers(vers *Version) {
- pkg.vers = vers
-}
-
func (pkg *LocalPackage) Hash() (string, error) {
hash := sha1.New()
@@ -217,7 +206,6 @@ func (pkg *LocalPackage) Save() error {
file.WriteString("### Package: " + pkg.Name() + "\n\n")
file.WriteString("pkg.name: " + pkg.Name() + "\n")
- file.WriteString("pkg.vers: " + pkg.Vers().String() + "\n")
file.WriteString("pkg.type: " + PackageTypeNames[pkg.Type()] + "\n")
file.WriteString("pkg.description: " + pkg.Desc().Description + "\n")
file.WriteString("pkg.author: " + pkg.Desc().Author + "\n")
@@ -250,12 +238,6 @@ func (pkg *LocalPackage) Load() error {
}
}
- // Get the package version
- pkg.vers, err = LoadVersion(v.GetString("pkg.vers"))
- if err != nil {
- return err
- }
-
// Read the package description from the file
pkg.desc, err = pkg.readDesc(v)
if err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d36820cf/newt/pkg/package.go
----------------------------------------------------------------------
diff --git a/newt/pkg/package.go b/newt/pkg/package.go
index 23601e7..38be9f4 100644
--- a/newt/pkg/package.go
+++ b/newt/pkg/package.go
@@ -65,8 +65,6 @@ type Package interface {
Hash() (string, error)
// Description of this package
Desc() *PackageDesc
- // Version of this package
- Vers() *Version
// Dependency list for this package
Deps() []*Dependency
// APIs exported by this package
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d36820cf/newt/pkg/version.go
----------------------------------------------------------------------
diff --git a/newt/pkg/version.go b/newt/pkg/version.go
deleted file mode 100644
index 359f17f..0000000
--- a/newt/pkg/version.go
+++ /dev/null
@@ -1,209 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package pkg
-
-import (
- "fmt"
- "regexp"
- "strconv"
- "strings"
-
- "mynewt.apache.org/newt/newt/interfaces"
- "mynewt.apache.org/newt/util"
-)
-
-const VERSION_FORMAT = "%d.%d.%d"
-
-type VersionMatch struct {
- compareType string
- Vers *Version
-}
-
-type Version struct {
- major int64
- minor int64
- revision int64
-}
-
-func (vm *VersionMatch) CompareType() string {
- return vm.compareType
-}
-
-func (vm *VersionMatch) Version() interfaces.VersionInterface {
- return vm.Vers
-}
-
-func (v *Version) Major() int64 {
- return v.major
-}
-
-func (v *Version) Minor() int64 {
- return v.minor
-}
-
-func (v *Version) Revision() int64 {
- return v.revision
-}
-
-func (v *Version) CompareVersions(vers1 interfaces.VersionInterface, vers2 interfaces.VersionInterface) int64 {
- if r := vers1.Major() - vers2.Major(); r != 0 {
- return r
- }
-
- if r := vers1.Minor() - vers2.Minor(); r != 0 {
- return r
- }
-
- if r := vers1.Revision() - vers2.Revision(); r != 0 {
- return r
- }
-
- return 0
-}
-
-func (v *Version) SatisfiesVersion(versMatches []interfaces.VersionReqInterface) bool {
- if versMatches == nil {
- return true
- }
-
- for _, match := range versMatches {
- r := v.CompareVersions(match.Version(), v)
- switch match.CompareType() {
- case "<":
- if r <= 0 {
- return false
- }
- case "<=":
- if r < 0 {
- return false
- }
- case ">":
- if r >= 0 {
- return false
- }
- case ">=":
- if r > 0 {
- return false
- }
- case "==":
- if r != 0 {
- return false
- }
- }
- }
-
- return true
-}
-
-func (vers *Version) String() string {
- return fmt.Sprintf(VERSION_FORMAT, vers.Major, vers.Minor, vers.Revision)
-}
-
-func LoadVersion(versStr string) (*Version, error) {
- var err error
-
- parts := strings.Split(versStr, ".")
- if len(parts) > 3 {
- return nil, util.NewNewtError(fmt.Sprintf("Invalid version string: %s", versStr))
- }
-
- if strings.Trim(parts[0], " ") == "" || strings.Trim(parts[0], " ") == "none" {
- return nil, nil
- }
-
- vers := &Version{}
-
- // convert first string to an int
- if vers.major, err = strconv.ParseInt(parts[0], 0, 64); err != nil {
- return nil, util.NewNewtError(err.Error())
- }
- if len(parts) >= 2 {
- if vers.minor, err = strconv.ParseInt(parts[1], 0, 64); err != nil {
- return nil, util.NewNewtError(err.Error())
- }
- }
- if len(parts) == 3 {
- if vers.revision, err = strconv.ParseInt(parts[2], 0, 64); err != nil {
- return nil, util.NewNewtError(err.Error())
- }
- }
-
- return vers, nil
-}
-
-func NewVersion(major int64, minor int64, rev int64) *Version {
- vers := &Version{}
-
- vers.major = major
- vers.minor = minor
- vers.revision = rev
-
- return vers
-}
-
-// Parse a set of version string constraints on a dependency.
-// This function
-// The version string contains a list of version constraints in the following format:
-// - <comparison><version>
-// Where <comparison> can be any one of the following comparison
-// operators: <=, <, >, >=, ==
-// And <version> is specified in the form: X.Y.Z where X, Y and Z are all
-// int64 types in decimal form
-func LoadVersionMatches(versStr string) ([]interfaces.VersionReqInterface, error) {
- var err error
-
- versMatches := []interfaces.VersionReqInterface{}
-
- re, err := regexp.Compile(`(<=|>=|==|>|<)([\d\.]+)`)
- if err != nil {
- return nil, err
- }
-
- matches := re.FindAllStringSubmatch(versStr, -1)
- if matches != nil {
- for _, match := range matches {
- vm := &VersionMatch{}
- vm.compareType = match[1]
- if vm.Vers, err = LoadVersion(match[2]); err != nil {
- return nil, err
- }
-
- if vm.Vers != nil {
- versMatches = append(versMatches, vm)
- }
- }
- } else {
- vm := &VersionMatch{}
- vm.compareType = "=="
- if vm.Vers, err = LoadVersion(versStr); err != nil {
- return nil, err
- }
-
- if vm.Vers != nil {
- versMatches = append(versMatches, vm)
- }
- }
-
- if len(versMatches) == 0 {
- versMatches = nil
- }
-
- return versMatches, nil
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d36820cf/newt/project/cmds.go
----------------------------------------------------------------------
diff --git a/newt/project/cmds.go b/newt/project/cmds.go
index 0d4d2a2..8e61f85 100644
--- a/newt/project/cmds.go
+++ b/newt/project/cmds.go
@@ -29,13 +29,15 @@ import (
"mynewt.apache.org/newt/util"
)
-func repoRunCmd(cmd *cobra.Command, args []string) {
+func installRunCmd(cmd *cobra.Command, args []string) {
proj := GetProject()
interfaces.SetProject(proj)
- r := proj.FindRepo("apache-mynewt-world")
- r.DownloadDesc()
+ if err := proj.Install(false); err != nil {
+ panic(err.Error())
+ }
+ fmt.Println("Repos successfully installed")
}
func projectRunCmd(cmd *cobra.Command, args []string) {
@@ -49,6 +51,7 @@ func projectRunCmd(cmd *cobra.Command, args []string) {
cli.NewtUsage(cmd, err)
}
proj.LoadPackageList()
+
for rName, list := range proj.PackageList() {
fmt.Printf("repository name: %s\n", rName)
for pkgName, _ := range *list {
@@ -71,11 +74,16 @@ func AddCommands(cmd *cobra.Command) {
Run: projectRunCmd,
}
- repoCmd := &cobra.Command{
- Use: "repo",
- Run: repoRunCmd,
+ installHelpText := ""
+ installHelpEx := ""
+ installCmd := &cobra.Command{
+ Use: "install",
+ Short: "Command to install project dependencies from project.yml",
+ Long: installHelpText,
+ Example: installHelpEx,
+ Run: installRunCmd,
}
- cmd.AddCommand(repoCmd)
+ cmd.AddCommand(installCmd)
cmd.AddCommand(projectCmd)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d36820cf/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index 80cf5ff..5194cd5 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -20,6 +20,7 @@
package project
import (
+ "fmt"
"log"
"os"
"path"
@@ -63,6 +64,8 @@ type Project struct {
packages interfaces.PackageList
+ projState *ProjectState
+
// Repositories configured on this project
repos map[string]*repo.Repo
@@ -135,25 +138,87 @@ func (proj *Project) PackageSearchDirs() []string {
return proj.packageSearchDirs
}
+func (proj *Project) Install(force bool) error {
+ repoList := proj.Repos()
+ for rname, r := range repoList {
+ // Ignore the local repo on install
+ if rname == repo.REPO_NAME_LOCAL {
+ continue
+ }
+ // Download repository description. Try and resolve this
+ // repository out of the repo list (repodesc for each repo.)
+ // If matching repository is found, then prompt for install and install
+ // that repository.
+ if err := r.DownloadDesc(); err != nil {
+ return err
+ }
+
+ rdesc, err := r.ReadDesc()
+ if err != nil {
+ return err
+ }
+
+ vers := proj.projState.GetInstalledVersion(rname)
+ if vers != nil {
+ // 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 {
+ 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
+ }
+
+ rvers, err := r.Install(rdesc, force)
+ if err != nil {
+ return err
+ }
+
+ if rvers != nil {
+ proj.projState.Add(rname, rvers)
+ }
+ }
+ }
+
+ if err := proj.projState.Save(); err != nil {
+ return err
+ }
+
+ return nil
+}
+
func (proj *Project) loadRepo(rname string, v *viper.Viper) error {
- //rType := v.GetString(rname + ".type")
- //if rType != "github" {
- //return util.NewNewtError(fmt.Sprintf("Unknown repo type %s, only github supported.", rType))
- //}
+ varName := fmt.Sprintf("repository.%s", rname)
- user := v.GetString(rname + ".user")
- gitRepo := v.GetString(rname + ".repo")
+ repoVars := v.GetStringMapString(varName)
+
+ if repoVars["type"] != "github" {
+ return util.NewNewtError("Only github repositories are currently supported.")
+ }
+ rversreq := repoVars["vers"]
dl := downloader.NewGithubDownloader()
- dl.User = user
- dl.Repo = gitRepo
+ dl.User = repoVars["user"]
+ dl.Repo = repoVars["repo"]
- r, err := repo.NewRepo(proj.Path(), rname, dl)
+ r, err := repo.NewRepo(rname, rversreq, dl)
if err != nil {
return err
}
- proj.repos[r.Name()] = r
+ log.Printf("[VERBOSE] Loaded repository %s (type: %s, user: %s, repo: %s)", rname,
+ repoVars["type"], repoVars["user"], repoVars["repo"])
+
+ proj.repos[r.Name()] = r
return nil
}
@@ -168,10 +233,15 @@ func (proj *Project) loadConfig() error {
// we need to process it later.
proj.v = v
+ proj.projState, err = LoadProjectState()
+ if err != nil {
+ return err
+ }
+
proj.name = v.GetString("project.name")
// Local repository always included in initialization
- r, err := repo.NewLocalRepo(proj.BasePath)
+ r, err := repo.NewLocalRepo()
if err != nil {
return err
}
@@ -196,6 +266,9 @@ func (proj *Project) loadConfig() error {
func (proj *Project) Init(dir string) error {
proj.BasePath = dir
+ // Only one project per system, when created, set it as the global project
+ interfaces.SetProject(proj)
+
proj.repos = map[string]*repo.Repo{}
proj.packageSearchDirs = PackageSearchDirs
@@ -269,5 +342,6 @@ func LoadProject(dir string) (*Project, error) {
}
proj, err := NewProject(projDir)
+
return proj, err
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d36820cf/newt/project/projectstate.go
----------------------------------------------------------------------
diff --git a/newt/project/projectstate.go b/newt/project/projectstate.go
new file mode 100644
index 0000000..9e07207
--- /dev/null
+++ b/newt/project/projectstate.go
@@ -0,0 +1,110 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package project
+
+import (
+ "bufio"
+ "fmt"
+ "os"
+ "strings"
+
+ "mynewt.apache.org/newt/newt/cli"
+ "mynewt.apache.org/newt/newt/interfaces"
+ "mynewt.apache.org/newt/newt/repo"
+ "mynewt.apache.org/newt/util"
+)
+
+const PROJECT_STATE_FILE = "project.state"
+
+type ProjectState struct {
+ installedRepos map[string]*repo.Version
+}
+
+func (ps *ProjectState) GetInstalledVersion(rname string) *repo.Version {
+ v, _ := ps.installedRepos[rname]
+ return v
+}
+
+func (ps *ProjectState) Add(rname string, rvers *repo.Version) {
+ ps.installedRepos[rname] = rvers
+}
+
+func (ps *ProjectState) StateFile() string {
+ return interfaces.GetProject().Path() + "/" + PROJECT_STATE_FILE
+}
+
+func (ps *ProjectState) Save() error {
+ file, err := os.Create(ps.StateFile())
+ if err != nil {
+ return util.NewNewtError(err.Error())
+ }
+ defer file.Close()
+
+ for k, v := range ps.installedRepos {
+ str := fmt.Sprintf("%s,%d.%d.%d\n", k, v.Major(), v.Minor(), v.Revision())
+ file.WriteString(str)
+ }
+
+ return nil
+}
+
+func (ps *ProjectState) Init() error {
+ ps.installedRepos = map[string]*repo.Version{}
+
+ path := ps.StateFile()
+
+ // Read project state file. If doesn't exist, it will be empty until somebody
+ // installs a repo
+ if cli.NodeNotExist(path) {
+ return nil
+ }
+
+ file, err := os.Open(path)
+ if err != nil {
+ return err
+ }
+ defer file.Close()
+
+ scanner := bufio.NewScanner(file)
+ for scanner.Scan() {
+ line := strings.Split(scanner.Text(), ",")
+ if len(line) != 2 {
+ return util.NewNewtError(fmt.Sprintf(
+ "Invalid format for line in project.state file: %s\n", line))
+ }
+
+ repoName := line[0]
+ repoVers, err := repo.LoadVersion(line[1])
+ if err != nil {
+ return err
+ }
+
+ ps.installedRepos[repoName] = repoVers
+ }
+ return nil
+}
+
+func LoadProjectState() (*ProjectState, error) {
+ ps := &ProjectState{}
+ if err := ps.Init(); err != nil {
+ return nil, err
+ }
+ return ps, nil
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d36820cf/newt/repo/repo.go
----------------------------------------------------------------------
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index ac6d90a..c67561a 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -20,23 +20,100 @@
package repo
import (
+ "fmt"
+ "log"
"os"
"path/filepath"
+ "strings"
"mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/newt/downloader"
+ "mynewt.apache.org/newt/newt/interfaces"
"mynewt.apache.org/newt/util"
)
const REPO_NAME_LOCAL = "local"
const REPO_DEFAULT_PERMS = 0755
+const REPO_FILE_NAME = "repository.yml"
const REPOS_DIR = "repos"
type Repo struct {
name string
downloader downloader.Downloader
localPath string
+ versreq []interfaces.VersionReqInterface
+ rdesc *RepoDesc
+}
+
+type RepoDesc struct {
+ name string
+ vers map[string]*Version
+}
+
+func (rd *RepoDesc) MatchVersion(searchVers *Version) (string, *Version, bool) {
+ for curBranch, vers := range rd.vers {
+ if vers.CompareVersions(vers, searchVers) == 0 {
+ return curBranch, vers, true
+ }
+ }
+ return "", nil, false
+}
+
+func (rd *RepoDesc) Match(r *Repo) (string, *Version, bool) {
+ for branch, vers := range rd.vers {
+ if vers.SatisfiesVersion(r.VersionRequirements()) {
+ log.Printf("[DEBUG] Found matching version %s for repo %s",
+ vers.String(), r.Name())
+ if vers.Stability() != "none" {
+ searchVers, err := LoadVersion(branch)
+ if err != nil {
+ return "", nil, false
+ }
+
+ var ok bool
+ branch, vers, ok = rd.MatchVersion(searchVers)
+ if !ok {
+ return "", nil, false
+ }
+ }
+
+ return branch, vers, true
+ }
+ }
+
+ return "", nil, false
+}
+
+func (rd *RepoDesc) Init(name string, versBranchMap map[string]string) error {
+ rd.name = name
+ rd.vers = map[string]*Version{}
+ for k, v := range versBranchMap {
+ log.Printf("[DEBUG] Printing version %s for remote repo %s", k, name)
+ vers, err := LoadVersion(k)
+ if err != nil {
+ return err
+ }
+
+ // store branch->version mapping
+ rd.vers[v] = vers
+ }
+
+ return nil
+}
+
+func (rd *RepoDesc) String() string {
+ return rd.name
+}
+
+func NewRepoDesc(name string, versBranchMap map[string]string) (*RepoDesc, error) {
+ rd := &RepoDesc{}
+
+ if err := rd.Init(name, versBranchMap); err != nil {
+ return nil, err
+ }
+
+ return rd, nil
}
func (r *Repo) Name() string {
@@ -47,54 +124,136 @@ func (r *Repo) Path() string {
return r.localPath
}
+func (r *Repo) VersionRequirements() []interfaces.VersionReqInterface {
+ return r.versreq
+}
+
+func (r *Repo) VersionRequirementsString() string {
+ str := ""
+ for _, vreq := range r.versreq {
+ str += vreq.String()
+ }
+
+ return str
+}
+
+func (r *Repo) repoFilePath() string {
+ return interfaces.GetProject().Path() + "/" + REPOS_DIR + "/" +
+ ".configs/" + r.name + "/"
+}
+
+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()))
+ }
+
+ branchName, vers, found := rdesc.Match(r)
+ if !found {
+ return nil, util.NewNewtError(fmt.Sprintf("No repository matching description %s found",
+ rdesc.String()))
+ }
+
+ dl := r.downloader
+
+ // Download the git repo, returns the git repo, checked out to that branch
+ tmpdir, err := dl.DownloadRepo(branchName)
+ if err != nil {
+ return nil, err
+ }
+
+ // Copy the Git repo into the the desired local path of the repo
+ if err := cli.CopyDir(tmpdir, r.Path()); err != nil {
+ // Cleanup any directory that might have been created if we error out
+ // here.
+ os.RemoveAll(r.Path())
+ return nil, err
+ }
+
+ return vers, nil
+}
+
// Download the repository description.
func (r *Repo) DownloadDesc() error {
dl := r.downloader
+ // Configuration path
+ cpath := r.repoFilePath()
+ if cli.NodeNotExist(cpath) {
+ if err := os.MkdirAll(cpath, REPO_DEFAULT_PERMS); err != nil {
+ return util.NewNewtError(err.Error())
+ }
+ }
+
dl.SetBranch("master")
if err := dl.FetchFile("repository.yml",
- r.localPath+"/"+"repository.yml"); err != nil {
+ cpath+"/"+"repository.yml"); err != nil {
return err
}
return nil
}
-func (r *Repo) Init(basePath string, repoName string,
- d downloader.Downloader) error {
+func (r *Repo) ReadDesc() (*RepoDesc, error) {
+ if cli.NodeNotExist(r.repoFilePath() + REPO_FILE_NAME) {
+ return nil,
+ util.NewNewtError("No configuration exists for repository " + r.name)
+ }
+
+ v, err := util.ReadConfig(r.repoFilePath(),
+ strings.TrimSuffix(REPO_FILE_NAME, ".yml"))
+ if err != nil {
+ return nil, err
+ }
+
+ name := v.GetString("repo.name")
+ versMap := v.GetStringMapString("repo.versions")
+
+ rdesc, err := NewRepoDesc(name, versMap)
+ if err != nil {
+ return nil, err
+ }
+ r.rdesc = rdesc
+
+ return rdesc, nil
+}
+
+func (r *Repo) Init(repoName string, rversreq string, d downloader.Downloader) error {
+ var err error
+
r.name = repoName
r.downloader = d
+ r.versreq, err = LoadVersionMatches(rversreq)
+ if err != nil {
+ return err
+ }
+
+ path := interfaces.GetProject().Path()
if r.name == REPO_NAME_LOCAL {
- r.localPath = filepath.Clean(basePath)
+ r.localPath = filepath.Clean(path)
} else {
- r.localPath = filepath.Clean(basePath + "/" + REPOS_DIR + "/" + r.name)
- }
-
- // If local path doesn't exist, create it.
- if cli.NodeNotExist(r.localPath) {
- if err := os.MkdirAll(r.localPath, REPO_DEFAULT_PERMS); err != nil {
- return util.NewNewtError(err.Error())
- }
+ r.localPath = filepath.Clean(path + "/" + REPOS_DIR + "/" + r.name)
}
return nil
}
-func NewRepo(basePath string, repoName string, d downloader.Downloader) (*Repo, error) {
+func NewRepo(repoName string, rversreq string, d downloader.Downloader) (*Repo, error) {
r := &Repo{}
- if err := r.Init(basePath, repoName, d); err != nil {
+ if err := r.Init(repoName, rversreq, d); err != nil {
return nil, err
}
return r, nil
}
-func NewLocalRepo(basePath string) (*Repo, error) {
+func NewLocalRepo() (*Repo, error) {
r := &Repo{}
- if err := r.Init(basePath, REPO_NAME_LOCAL, nil); err != nil {
+ if err := r.Init(REPO_NAME_LOCAL, "", nil); err != nil {
return nil, err
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d36820cf/newt/repo/version.go
----------------------------------------------------------------------
diff --git a/newt/repo/version.go b/newt/repo/version.go
new file mode 100644
index 0000000..fb0ae58
--- /dev/null
+++ b/newt/repo/version.go
@@ -0,0 +1,249 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package repo
+
+import (
+ "fmt"
+ "regexp"
+ "strconv"
+ "strings"
+
+ "mynewt.apache.org/newt/newt/interfaces"
+ "mynewt.apache.org/newt/util"
+)
+
+const VERSION_FORMAT = "%d.%d.%d-%s"
+
+const (
+ VERSION_STABILITY_NONE = "none"
+ VERSION_STABILITY_STABLE = "stable"
+ VERSION_STABILITY_DEV = "dev"
+ VERSION_STABILITY_LATEST = "latest"
+)
+
+type VersionMatch struct {
+ compareType string
+ Vers *Version
+}
+
+type Version struct {
+ major int64
+ minor int64
+ revision int64
+ stability string
+}
+
+func (vm *VersionMatch) CompareType() string {
+ return vm.compareType
+}
+
+func (vm *VersionMatch) Version() interfaces.VersionInterface {
+ return vm.Vers
+}
+
+func (vm *VersionMatch) String() string {
+ return vm.compareType + vm.Vers.String()
+}
+
+func (v *Version) Major() int64 {
+ return v.major
+}
+
+func (v *Version) Minor() int64 {
+ return v.minor
+}
+
+func (v *Version) Revision() int64 {
+ return v.revision
+}
+
+func (v *Version) Stability() string {
+ return v.stability
+}
+
+func (v *Version) CompareVersions(vers1 interfaces.VersionInterface,
+ vers2 interfaces.VersionInterface) int64 {
+ if r := vers1.Major() - vers2.Major(); r != 0 {
+ return r
+ }
+
+ if r := vers1.Minor() - vers2.Minor(); r != 0 {
+ return r
+ }
+
+ if r := vers1.Revision() - vers2.Revision(); r != 0 {
+ return r
+ }
+
+ return 0
+}
+
+func (v *Version) SatisfiesVersion(versMatches []interfaces.VersionReqInterface) bool {
+ if versMatches == nil {
+ return true
+ }
+
+ for _, match := range versMatches {
+ r := v.CompareVersions(match.Version(), v)
+ switch match.CompareType() {
+ case "<":
+ if r <= 0 {
+ return false
+ }
+ case "<=":
+ if r < 0 {
+ return false
+ }
+ case ">":
+ if r >= 0 {
+ return false
+ }
+ case ">=":
+ if r > 0 {
+ return false
+ }
+ case "==":
+ if r != 0 {
+ return false
+ }
+ }
+
+ if match.Version().Stability() != VERSION_STABILITY_NONE &&
+ match.Version().Stability() != v.Stability() {
+ return false
+ }
+ }
+
+ return true
+}
+
+func (vers *Version) String() string {
+ return fmt.Sprintf(VERSION_FORMAT, vers.Major(), vers.Minor(), vers.Revision(), vers.Stability())
+}
+
+func LoadVersion(versStr string) (*Version, error) {
+ var err error
+
+ // Split to get stability level first
+ sparts := strings.Split(versStr, "-")
+ stability := VERSION_STABILITY_NONE
+ if len(sparts) > 1 {
+ stability = strings.Trim(sparts[1], " ")
+ switch stability {
+ case VERSION_STABILITY_STABLE:
+ fallthrough
+ case VERSION_STABILITY_DEV:
+ fallthrough
+ case VERSION_STABILITY_LATEST:
+ default:
+ return nil, util.NewNewtError(
+ fmt.Sprintf("Unknown stability (%s) in version ", stability) + versStr)
+ }
+ }
+
+ parts := strings.Split(sparts[0], ".")
+ if len(parts) > 3 {
+ return nil, util.NewNewtError(fmt.Sprintf("Invalid version string: %s", versStr))
+ }
+
+ if strings.Trim(parts[0], " ") == "" || strings.Trim(parts[0], " ") == "none" {
+ return nil, nil
+ }
+
+ vers := &Version{}
+ vers.stability = stability
+
+ // convert first string to an int
+ if vers.major, err = strconv.ParseInt(parts[0], 10, 64); err != nil {
+ return nil, util.NewNewtError(err.Error())
+ }
+ if len(parts) >= 2 {
+ if vers.minor, err = strconv.ParseInt(parts[1], 10, 64); err != nil {
+ return nil, util.NewNewtError(err.Error())
+ }
+ }
+ if len(parts) == 3 {
+ if vers.revision, err = strconv.ParseInt(parts[2], 10, 64); err != nil {
+ return nil, util.NewNewtError(err.Error())
+ }
+ }
+
+ return vers, nil
+}
+
+func NewVersion(major int64, minor int64, rev int64) *Version {
+ vers := &Version{}
+
+ vers.major = major
+ vers.minor = minor
+ vers.revision = rev
+
+ return vers
+}
+
+// Parse a set of version string constraints on a dependency.
+// This function
+// The version string contains a list of version constraints in the following format:
+// - <comparison><version>
+// Where <comparison> can be any one of the following comparison
+// operators: <=, <, >, >=, ==
+// And <version> is specified in the form: X.Y.Z where X, Y and Z are all
+// int64 types in decimal form
+func LoadVersionMatches(versStr string) ([]interfaces.VersionReqInterface, error) {
+ var err error
+
+ versMatches := []interfaces.VersionReqInterface{}
+
+ re, err := regexp.Compile(`(<=|>=|==|>|<)([\d\.]+)`)
+ if err != nil {
+ return nil, err
+ }
+
+ matches := re.FindAllStringSubmatch(versStr, -1)
+ if matches != nil {
+ for _, match := range matches {
+ vm := &VersionMatch{}
+ vm.compareType = match[1]
+ if vm.Vers, err = LoadVersion(match[2]); err != nil {
+ return nil, err
+ }
+
+ if vm.Vers != nil {
+ versMatches = append(versMatches, vm)
+ }
+ }
+ } else {
+ vm := &VersionMatch{}
+ vm.compareType = "=="
+ if vm.Vers, err = LoadVersion(versStr); err != nil {
+ return nil, err
+ }
+
+ if vm.Vers != nil {
+ versMatches = append(versMatches, vm)
+ }
+ }
+
+ if len(versMatches) == 0 {
+ versMatches = nil
+ }
+
+ return versMatches, nil
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d36820cf/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index 9069574..4102740 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -156,7 +156,6 @@ func targetCreateCmd(cmd *cobra.Command, args []string) {
pack := pkg.NewLocalPackage(repo, repo.Path()+"/"+args[0])
pack.SetName(args[0])
pack.SetType(pkg.PACKAGE_TYPE_TARGET)
- pack.SetVers(pkg.NewVersion(0, 0, 1))
t = NewTarget(pack)
err := t.Save()
[50/50] incubator-mynewt-newt git commit: Add verbose status message
for "clean all"
Posted by ma...@apache.org.
Add verbose status message for "clean all"
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/2b15801b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/2b15801b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/2b15801b
Branch: refs/heads/develop
Commit: 2b15801bab1ebd81b5b53606df0351ab9474b841
Parents: bdf361d
Author: ccollins at iori.nightmare.heaven <cc...@iori.nightmare-heaven.no-ip.biz>
Authored: Wed Mar 9 10:04:47 2016 -0800
Committer: ccollins at iori.nightmare.heaven <cc...@iori.nightmare-heaven.no-ip.biz>
Committed: Wed Mar 9 10:05:30 2016 -0800
----------------------------------------------------------------------
newt/builder/cmds.go | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/2b15801b/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index dcdb37c..dc8af98 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -76,7 +76,11 @@ func cleanRunCmd(cmd *cobra.Command, args []string) {
}
if cleanAll {
- err := os.RemoveAll(BinRoot())
+ path := BinRoot()
+ util.StatusMessage(util.VERBOSITY_VERBOSE,
+ "Cleaning directory %s\n", path)
+
+ err := os.RemoveAll(path)
if err != nil {
cli.NewtUsage(cmd, err)
}
[05/50] incubator-mynewt-newt git commit: Test command
Posted by ma...@apache.org.
Test command
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/928e0344
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/928e0344
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/928e0344
Branch: refs/heads/develop
Commit: 928e0344dfc04f0dda96075b3f4ba0b70b0d2f73
Parents: 516dd1e
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Mar 7 19:18:30 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Mar 7 21:28:00 2016 -0800
----------------------------------------------------------------------
newt/builder/build.go | 298 ++++++++++++++++++++++++++++++----------
newt/builder/cmds.go | 51 +++++++
newt/pkg/dependency.go | 1 -
newt/target/target.go | 14 +-
newt/toolchain/compiler.go | 22 +--
5 files changed, 303 insertions(+), 83 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/928e0344/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 11221b6..46e8133 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -36,7 +36,10 @@ type Builder struct {
Packages map[*pkg.LocalPackage]*BuildPackage
features map[string]bool
apis map[string]*BuildPackage
- Bsp *pkg.BspPackage
+
+ Bsp *pkg.BspPackage
+ compilerPkg *pkg.LocalPackage
+ compilerInfo *toolchain.CompilerInfo
target *target.Target
}
@@ -49,13 +52,19 @@ func (b *Builder) AddFeature(feature string) {
b.features[feature] = true
}
-func (b *Builder) AddPackage(npkg *pkg.LocalPackage) {
+func (b *Builder) AddPackage(npkg *pkg.LocalPackage) *BuildPackage {
// Don't allow nil entries to the map
if npkg == nil {
panic("Cannot add nil package builder map")
}
- b.Packages[npkg] = NewBuildPackage(npkg)
+ bpkg := b.Packages[npkg]
+ if bpkg == nil {
+ bpkg = NewBuildPackage(npkg)
+ b.Packages[npkg] = bpkg
+ }
+
+ return bpkg
}
// @return bool true if this is a new API.
@@ -74,6 +83,25 @@ func (b *Builder) AddApi(apiString string, bpkg *BuildPackage) bool {
}
}
+func (b *Builder) logFeatures() {
+ var buffer bytes.Buffer
+ buffer.WriteString("Building with the following feature set: [")
+
+ first := true
+ for feature, _ := range b.Features() {
+ if !first {
+ buffer.WriteString(" ")
+ } else {
+ first = false
+ }
+
+ buffer.WriteString(feature)
+ }
+ buffer.WriteString("]\n")
+
+ cli.StatusMessage(cli.VERBOSITY_VERBOSE, buffer.String())
+}
+
func (b *Builder) loadDeps() error {
// Circularly resolve dependencies, identities, APIs, and required APIs
// until no new ones exist.
@@ -94,6 +122,9 @@ func (b *Builder) loadDeps() error {
break
}
}
+
+ b.logFeatures()
+
return nil
}
@@ -137,18 +168,19 @@ func (b *Builder) verifyApisSatisfied() error {
// Recursively compiles all the .c and .s files in the specified directory.
// Architecture-specific files are also compiled.
-func buildDir(srcDir string, c *toolchain.Compiler, t *target.Target,
+func buildDir(srcDir string, c *toolchain.Compiler, arch string,
ignDirs []string) error {
- var err error
+ // Quietly succeed if the source directory doesn't exist.
+ if cli.NodeNotExist(srcDir) {
+ return nil
+ }
cli.StatusMessage(util.VERBOSITY_VERBOSE,
"compiling src in base directory: %s\n", srcDir)
- // First change into the pkg src directory, and build all the objects
- // there
- err = os.Chdir(srcDir)
- if err != nil {
+ // Start from the source directory.
+ if err := os.Chdir(srcDir); err != nil {
return util.NewNewtError(err.Error())
}
@@ -157,16 +189,15 @@ func buildDir(srcDir string, c *toolchain.Compiler, t *target.Target,
ignDirs = append(ignDirs, "bin")
// Ignore architecture-specific source files for now. Use a temporary
- // string array here so that the "arch" directory is not ignored in the
+ // string slice here so that the "arch" directory is not ignored in the
// subsequent architecture-specific compile phase.
- baseIgnDirs := append(ignDirs, "arch")
+ if err := c.RecursiveCompile(toolchain.COMPILER_TYPE_C,
+ append(ignDirs, "arch")); err != nil {
- if err = c.RecursiveCompile(toolchain.COMPILER_TYPE_C,
- baseIgnDirs); err != nil {
return err
}
- archDir := srcDir + "/arch/" + t.Arch + "/"
+ archDir := srcDir + "/arch/" + arch + "/"
cli.StatusMessage(util.VERBOSITY_VERBOSE,
"compiling architecture specific src pkgs in directory: %s\n",
archDir)
@@ -177,12 +208,14 @@ func buildDir(srcDir string, c *toolchain.Compiler, t *target.Target,
}
if err := c.RecursiveCompile(toolchain.COMPILER_TYPE_C,
ignDirs); err != nil {
+
return err
}
// compile assembly sources in recursive compile as well
- if err = c.RecursiveCompile(toolchain.COMPILER_TYPE_ASM,
+ if err := c.RecursiveCompile(toolchain.COMPILER_TYPE_ASM,
ignDirs); err != nil {
+
return err
}
}
@@ -199,36 +232,33 @@ func (b *Builder) pkgBinDir(pkgName string) string {
}
// Generates the path+filename of the specified package's .a file.
-func (b *Builder) archivePath(bpkg *BuildPackage) string {
- return b.pkgBinDir(bpkg.Name()) + "/" + filepath.Base(bpkg.Name()) + ".a"
+func (b *Builder) archivePath(pkgName string) string {
+ return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".a"
}
-func (b *Builder) elfPath() string {
- appPkg := b.target.App()
- if appPkg == nil {
- return ""
- }
+func (b *Builder) appElfPath() string {
+ pkgName := b.target.App().Name()
+ return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".elf"
+}
- return b.pkgBinDir(appPkg.Name()) + "/" +
- filepath.Base(appPkg.Name()) + ".elf"
+func (b *Builder) testExePath(pkgName string) string {
+ return b.pkgBinDir(pkgName) + "/test_" + filepath.Base(pkgName)
}
// Compiles and archives a package.
-func (b *Builder) buildPackage(bpkg *BuildPackage,
- baseCi *toolchain.CompilerInfo, compilerPkg *pkg.LocalPackage) error {
-
+func (b *Builder) buildPackage(bpkg *BuildPackage) error {
srcDir := bpkg.BasePath() + "/src"
if cli.NodeNotExist(srcDir) {
// Nothing to compile.
return nil
}
- c, err := toolchain.NewCompiler(compilerPkg.BasePath(),
+ c, err := toolchain.NewCompiler(b.compilerPkg.BasePath(),
b.pkgBinDir(bpkg.Name()), "default") // XXX Use correct compiler def
if err != nil {
return err
}
- c.AddInfo(baseCi)
+ c.AddInfo(b.compilerInfo)
ci, err := bpkg.CompilerInfo(b)
if err != nil {
@@ -236,26 +266,30 @@ func (b *Builder) buildPackage(bpkg *BuildPackage,
}
c.AddInfo(ci)
- // For now, ignore test code. Tests get built later if the test
- // feature is in effect.
- ignDirs := []string{"test"}
-
- // Compile the source files.
- err = buildDir(srcDir, c, b.target, ignDirs)
- if err != nil {
+ // Build the package source in two phases:
+ // 1. Non-test code.
+ // 2. Test code (if the "test" feature is enabled).
+ //
+ // This is done in two passes because the structure of
+ // architecture-specific directories is different for normal code and test
+ // code, and not easy to generalize into a single operation:
+ // * src/arch/<target-arch>
+ // * src/test/arch/<target-arch>
+ if err = buildDir(srcDir, c, b.target.Arch, []string{"test"}); err != nil {
return err
}
-
- // Archive everything into a static library, which can be linked with a
- // main program
- if err := os.Chdir(bpkg.BasePath() + "/"); err != nil {
- return util.NewNewtError(err.Error())
+ if b.features["test"] {
+ testSrcDir := srcDir + "/test"
+ if err = buildDir(testSrcDir, c, b.target.Arch, nil); err != nil {
+ return err
+ }
}
- archiveFile := b.archivePath(bpkg)
- if err := os.MkdirAll(filepath.Dir(archiveFile), 0755); err != nil {
+ // Create a static library ("archive").
+ if err := os.Chdir(bpkg.BasePath() + "/"); err != nil {
return util.NewNewtError(err.Error())
}
+ archiveFile := b.archivePath(bpkg.Name())
if err = c.CompileArchive(archiveFile); err != nil {
return err
}
@@ -263,18 +297,16 @@ func (b *Builder) buildPackage(bpkg *BuildPackage,
return nil
}
-func (b *Builder) linkApp(baseCi *toolchain.CompilerInfo,
- compilerPkg *pkg.LocalPackage) error {
-
- c, err := toolchain.NewCompiler(compilerPkg.BasePath(),
- b.pkgBinDir(b.target.App().Name()), "default") // XXX
+func (b *Builder) link(elfName string) error {
+ c, err := toolchain.NewCompiler(b.compilerPkg.BasePath(),
+ b.pkgBinDir(elfName), "default") // XXX
if err != nil {
return err
}
pkgNames := []string{}
for _, bpkg := range b.Packages {
- archivePath := b.archivePath(bpkg)
+ archivePath := b.archivePath(bpkg.Name())
if cli.NodeExist(archivePath) {
pkgNames = append(pkgNames, archivePath)
}
@@ -283,7 +315,7 @@ func (b *Builder) linkApp(baseCi *toolchain.CompilerInfo,
if b.Bsp.LinkerScript != "" {
c.LinkerScript = b.Bsp.BasePath() + b.Bsp.LinkerScript
}
- err = c.CompileElf(b.elfPath(), pkgNames)
+ err = c.CompileElf(elfName, pkgNames)
if err != nil {
return err
}
@@ -291,62 +323,188 @@ func (b *Builder) linkApp(baseCi *toolchain.CompilerInfo,
return nil
}
-func (b *Builder) Build() error {
+// Populates the builder with all the packages that need to be built, and
+// configures each package's build settings. After this function executes,
+// packages are ready to be built.
+func (b *Builder) prepBuild() error {
+ // Collect the seed packages.
+ bspPkg := b.target.Bsp()
+ if bspPkg == nil {
+ return util.NewNewtError("bsp package not specified")
+ }
+
compilerPkg := b.target.Compiler()
if compilerPkg == nil {
- return util.NewNewtError("compiler package not found")
+ return util.NewNewtError("compiler package not specified")
+ }
+
+ // An app package is not required (e.g., unit tests).
+ appPkg := b.target.App()
+
+ // Seed the builder with the app (if present), bsp, compiler, and target
+ // packages.
+
+ var appBpkg *BuildPackage
+ if appPkg != nil {
+ appBpkg = b.Packages[appPkg]
+ if appBpkg == nil {
+ appBpkg = b.AddPackage(appPkg)
+ }
+ }
+
+ bspBpkg := b.Packages[bspPkg]
+ if bspBpkg == nil {
+ bspBpkg = b.AddPackage(bspPkg)
}
- b.AddPackage(b.target.Bsp())
- b.AddPackage(b.target.App())
- b.AddPackage(b.target.Compiler())
+ compilerBpkg := b.Packages[compilerPkg]
+ if compilerBpkg == nil {
+ compilerBpkg = b.AddPackage(compilerPkg)
+ }
+
+ targetBpkg := b.AddPackage(b.target.Package())
+ // Populate the full set of packages to be built and resolve the feature
+ // set.
if err := b.loadDeps(); err != nil {
return err
}
+ // Terminate if any package has an unmet API requirement.
if err := b.verifyApisSatisfied(); err != nil {
return err
}
- bspPackage := b.Packages[b.target.Bsp()]
- if bspPackage == nil {
- return util.NewNewtError("BSP package not found!")
+ // Populate the base set of compiler flags. Flags from the following
+ // packages get applied to every source file:
+ // * app (if present)
+ // * bsp
+ // * compiler
+ // * target
+
+ baseCi := toolchain.NewCompilerInfo()
+
+ if appBpkg != nil {
+ appCi, err := appBpkg.CompilerInfo(b)
+ if err != nil {
+ return err
+ }
+ baseCi.AddCompilerInfo(appCi)
+ }
+
+ bspCi, err := bspBpkg.CompilerInfo(b)
+ if err != nil {
+ return err
+ }
+ baseCi.AddCompilerInfo(bspCi)
+
+ targetCi, err := targetBpkg.CompilerInfo(b)
+ if err != nil {
+ return err
+ }
+ baseCi.AddCompilerInfo(targetCi)
+
+ // Read the BSP configuration. These settings are necessary for the link
+ // step.
+ b.Bsp = pkg.NewBspPackage(bspPkg, b.Features())
+
+ b.compilerPkg = compilerPkg
+ b.compilerInfo = baseCi
+
+ return nil
+}
+
+func (b *Builder) Build() error {
+ if b.target.App() == nil {
+ return util.NewNewtError("app package not specified")
}
- bspCi, err := bspPackage.CompilerInfo(b)
+ // Populate the package and feature sets and calculate the base compiler
+ // flags.
+ err := b.prepBuild()
if err != nil {
return err
}
- b.Bsp = pkg.NewBspPackage(bspPackage.LocalPackage, b.Features())
- appPackage := b.Packages[b.target.App()]
- if appPackage == nil {
- return util.NewNewtError("App package not found")
+ // XXX: If any yml files have changed, a full rebuild is required. We
+ // don't currently check this.
+
+ for _, bpkg := range b.Packages {
+ err = b.buildPackage(bpkg)
+ if err != nil {
+ return err
+ }
+ }
+
+ err = b.link(b.appElfPath())
+ if err != nil {
+ return err
}
- appCi, err := appPackage.CompilerInfo(b)
+
+ return nil
+}
+
+func (b *Builder) Test(p *pkg.LocalPackage) error {
+ // Seed the builder with the package under test.
+ testBpkg := b.AddPackage(p)
+
+ // A few features are automatically supported when the test command is
+ // used:
+ // * test: ensures that the test code gets compiled.
+ // * selftest: indicates that there is no app.
+ b.AddFeature("test")
+ b.AddFeature("selftest")
+
+ // Populate the package and feature sets and calculate the base compiler
+ // flags.
+ err := b.prepBuild()
if err != nil {
return err
}
- baseCi := toolchain.NewCompilerInfo()
- baseCi.AddCompilerInfo(bspCi)
- baseCi.AddCompilerInfo(appCi)
+ // Define the PKG_TEST symbol while the package under test is being
+ // compiled. This symbol enables the appropriate main function that
+ // usually comes from an app.
+ testPkgCi, err := testBpkg.CompilerInfo(b)
+ if err != nil {
+ return err
+ }
+ testPkgCi.Cflags = append(testPkgCi.Cflags, "-DPKG_TEST")
- // XXX: If any yml files have changed, a full rebuild is required.
+ // XXX: If any yml files have changed, a full rebuild is required. We
+ // don't currently check this.
for _, bpkg := range b.Packages {
- err = b.buildPackage(bpkg, baseCi, compilerPkg)
+ err = b.buildPackage(bpkg)
if err != nil {
return err
}
}
- err = b.linkApp(baseCi, compilerPkg)
+ testFilename := b.testExePath(p.Name())
+ err = b.link(testFilename)
if err != nil {
return err
}
+ // Run the tests.
+ cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Testing package %s\n", p.Name())
+
+ if err := os.Chdir(filepath.Dir(testFilename)); err != nil {
+ return err
+ }
+
+ o, err := cli.ShellCommand(testFilename)
+ if err != nil {
+ cli.StatusMessage(cli.VERBOSITY_DEFAULT, "%s", string(o))
+
+ // Always terminate on test failure since only one test is being run.
+ return util.NewtErrorNoTrace("Test failed: " + testFilename)
+ }
+
+ cli.StatusMessage(cli.VERBOSITY_VERBOSE, "%s", string(o))
+ cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Test %s ok!\n", testFilename)
+
return nil
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/928e0344/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index 484a487..5cb3889 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -24,10 +24,14 @@ import (
"github.com/spf13/cobra"
"mynewt.apache.org/newt/newt/cli"
+ "mynewt.apache.org/newt/newt/pkg"
+ "mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/newt/target"
"mynewt.apache.org/newt/util"
)
+const TARGET_TEST_NAME = "targets/unittest"
+
func buildRunCmd(cmd *cobra.Command, args []string) {
if len(args) < 1 {
cli.NewtUsage(cmd, nil)
@@ -70,6 +74,41 @@ func cleanRunCmd(cmd *cobra.Command, args []string) {
}
}
+func testRunCmd(cmd *cobra.Command, args []string) {
+ if len(args) < 1 {
+ cli.NewtUsage(cmd, nil)
+ }
+
+ t := target.GetTargets()[TARGET_TEST_NAME]
+ if t == nil {
+ cli.NewtUsage(cmd, util.NewNewtError("can't find unit test target: "+
+ TARGET_TEST_NAME))
+ }
+
+ b, err := NewBuilder(t)
+ if err != nil {
+ fmt.Println(err)
+ }
+
+ pkgString := args[0]
+ dep, err := pkg.NewDependency(nil, pkgString)
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+ if dep == nil {
+ cli.NewtUsage(cmd, util.NewNewtError("invalid package name"))
+ }
+ pack := project.GetProject().ResolveDependency(dep)
+ if pack == nil {
+ cli.NewtUsage(cmd, util.NewNewtError("invalid package name"))
+ }
+
+ err = b.Test(pack.(*pkg.LocalPackage))
+ if err != nil {
+ fmt.Println(err)
+ }
+}
+
func AddCommands(cmd *cobra.Command) {
buildHelpText := ""
buildHelpEx := ""
@@ -94,4 +133,16 @@ func AddCommands(cmd *cobra.Command) {
}
cmd.AddCommand(cleanCmd)
+
+ testHelpText := ""
+ testHelpEx := ""
+ testCmd := &cobra.Command{
+ Use: "test",
+ Short: "Executes unit tests for one or more packages",
+ Long: testHelpText,
+ Example: testHelpEx,
+ Run: testRunCmd,
+ }
+
+ cmd.AddCommand(testCmd)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/928e0344/newt/pkg/dependency.go
----------------------------------------------------------------------
diff --git a/newt/pkg/dependency.go b/newt/pkg/dependency.go
index c4d5741..58d33ea 100644
--- a/newt/pkg/dependency.go
+++ b/newt/pkg/dependency.go
@@ -130,7 +130,6 @@ func (dep *Dependency) Init(parentRepo interfaces.RepoInterface, depStr string)
return err
}
verParts := strings.Split(parts[1], "#")
-
if err := dep.SetVersionReqs(verParts[0]); err != nil {
return err
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/928e0344/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 67555ac..c48affe 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -113,9 +113,17 @@ func (target *Target) Compiler() *pkg.LocalPackage {
}
func (target *Target) App() *pkg.LocalPackage {
- dep, _ := pkg.NewDependency(nil, target.AppName)
- mypkg := project.GetProject().ResolveDependency(dep).(*pkg.LocalPackage)
- return mypkg
+ dep, err := pkg.NewDependency(nil, target.AppName)
+ if err != nil {
+ return nil
+ }
+
+ appPkg := project.GetProject().ResolveDependency(dep)
+ if appPkg == nil {
+ return nil
+ }
+
+ return appPkg.(*pkg.LocalPackage)
}
func (target *Target) Bsp() *pkg.LocalPackage {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/928e0344/newt/toolchain/compiler.go
----------------------------------------------------------------------
diff --git a/newt/toolchain/compiler.go b/newt/toolchain/compiler.go
index cb3017c..21c2ef1 100644
--- a/newt/toolchain/compiler.go
+++ b/newt/toolchain/compiler.go
@@ -30,7 +30,7 @@ import (
"time"
"mynewt.apache.org/newt/newt/cli"
- . "mynewt.apache.org/newt/util"
+ "mynewt.apache.org/newt/util"
)
const (
@@ -101,7 +101,7 @@ func NewCompiler(compilerDir string, dstDir string,
}
func (c *Compiler) load(compilerDir string, cDef string) error {
- v, err := ReadConfig(compilerDir, "compiler")
+ v, err := util.ReadConfig(compilerDir, "compiler")
if err != nil {
return err
}
@@ -205,7 +205,7 @@ func (c *Compiler) CompileFileCmd(file string,
case COMPILER_TYPE_ASM:
cmd = c.asPath
default:
- return "", NewNewtError("Unknown compiler type")
+ return "", util.NewNewtError("Unknown compiler type")
}
cmd += " -c " + "-o " + objPath + " " + file +
@@ -281,7 +281,7 @@ func (c *Compiler) CompileFile(file string, compilerType int) error {
case COMPILER_TYPE_ASM:
cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Assembling %s\n", file)
default:
- return NewNewtError("Unknown compiler type")
+ return util.NewNewtError("Unknown compiler type")
}
rsp, err := cli.ShellCommand(cmd)
@@ -389,13 +389,13 @@ func (c *Compiler) RecursiveCompile(cType int, ignDirs []string) error {
wd, err := os.Getwd()
if err != nil {
- return NewNewtError(err.Error())
+ return util.NewNewtError(err.Error())
}
wd = filepath.ToSlash(wd)
dirList, err := ioutil.ReadDir(wd)
if err != nil {
- return NewNewtError(err.Error())
+ return util.NewNewtError(err.Error())
}
for _, node := range dirList {
@@ -418,7 +418,7 @@ func (c *Compiler) RecursiveCompile(cType int, ignDirs []string) error {
case COMPILER_TYPE_ASM:
return c.CompileAs()
default:
- return NewNewtError("Wrong compiler type specified to RecursiveCompile")
+ return util.NewNewtError("Wrong compiler type specified to RecursiveCompile")
}
}
@@ -573,7 +573,7 @@ func (c *Compiler) CompileElf(binFile string, objFiles []string) error {
}
if linkRequired {
if err := os.MkdirAll(filepath.Dir(binFile), 0755); err != nil {
- return NewNewtError(err.Error())
+ return util.NewNewtError(err.Error())
}
err := c.CompileBinary(binFile, options, objFiles)
if err != nil {
@@ -618,6 +618,10 @@ func (c *Compiler) CompileArchive(archiveFile string) error {
return nil
}
+ if err := os.MkdirAll(filepath.Dir(archiveFile), 0755); err != nil {
+ return util.NewNewtError(err.Error())
+ }
+
cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Archiving %s\n",
path.Base(archiveFile))
objList := c.getObjFiles([]string{})
@@ -627,7 +631,7 @@ func (c *Compiler) CompileArchive(archiveFile string) error {
// Delete the old archive, if it exists.
err = os.Remove(archiveFile)
if err != nil && !os.IsNotExist(err) {
- return NewNewtError(err.Error())
+ return util.NewNewtError(err.Error())
}
cmd := c.CompileArchiveCmd(archiveFile, objFiles)
[13/50] incubator-mynewt-newt git commit: Don't require "target/"
prefix in arguments.
Posted by ma...@apache.org.
Don't require "target/" prefix in arguments.
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/a3d68ef2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/a3d68ef2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/a3d68ef2
Branch: refs/heads/develop
Commit: a3d68ef227c7de4a724df226dd2941973bc116cd
Parents: 77e2a2a
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 13:37:17 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 13:52:51 2016 -0800
----------------------------------------------------------------------
newt/builder/build.go | 9 +++++++--
newt/cli/util.go | 9 ++++++++-
newt/target/cmds.go | 46 +++++++++++++++++++++++++++-------------------
newt/target/target.go | 43 +++++++++++++++++++++++++++++++++++++++++--
4 files changed, 83 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a3d68ef2/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 0ff0bc0..185ec37 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -195,7 +195,7 @@ func (b *Builder) buildPackage(bpkg *BuildPackage) error {
}
c, err := toolchain.NewCompiler(b.compilerPkg.BasePath(),
- b.pkgBinDir(bpkg.Name()), "default") // XXX Use correct compiler def
+ b.pkgBinDir(bpkg.Name()), b.target.BuildProfile)
if err != nil {
return err
}
@@ -240,7 +240,7 @@ func (b *Builder) buildPackage(bpkg *BuildPackage) error {
func (b *Builder) link(elfName string) error {
c, err := toolchain.NewCompiler(b.compilerPkg.BasePath(),
- b.pkgBinDir(elfName), "default") // XXX
+ b.pkgBinDir(elfName), b.target.BuildProfile)
if err != nil {
return err
}
@@ -325,6 +325,7 @@ func (b *Builder) PrepBuild() error {
baseCi := toolchain.NewCompilerInfo()
+ // App flags.
if appBpkg != nil {
appCi, err := appBpkg.CompilerInfo(b)
if err != nil {
@@ -333,18 +334,22 @@ func (b *Builder) PrepBuild() error {
baseCi.AddCompilerInfo(appCi)
}
+ // Bsp flags.
bspCi, err := bspBpkg.CompilerInfo(b)
if err != nil {
return err
}
baseCi.AddCompilerInfo(bspCi)
+ // Target flags.
targetCi, err := targetBpkg.CompilerInfo(b)
if err != nil {
return err
}
baseCi.AddCompilerInfo(targetCi)
+ // Note: Compiler flags get added when compiler is created.
+
// Read the BSP configuration. These settings are necessary for the link
// step.
b.Bsp = pkg.NewBspPackage(bspPkg, b.Features())
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a3d68ef2/newt/cli/util.go
----------------------------------------------------------------------
diff --git a/newt/cli/util.go b/newt/cli/util.go
index 0b29f87..0794cc1 100644
--- a/newt/cli/util.go
+++ b/newt/cli/util.go
@@ -320,13 +320,20 @@ func CopyDir(srcDir, destDir string) error {
return CopyFile(srcDir, destDir)
}
-// Print Silent, Quiet and Verbose aware status messages
+// Print Silent, Quiet and Verbose aware status messages to stdout.
func StatusMessage(level int, message string, args ...interface{}) {
if Verbosity >= level {
fmt.Printf(message, args...)
}
}
+// Print Silent, Quiet and Verbose aware status messages to stderr.
+func ErrorMessage(level int, message string, args ...interface{}) {
+ if Verbosity >= level {
+ fmt.Fprintf(os.Stderr, message, args...)
+ }
+}
+
// Reads each line from the specified text file into an array of strings. If a
// line ends with a backslash, it is concatenated with the following line.
func ReadLines(path string) ([]string, error) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a3d68ef2/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index 4102740..018b713 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -42,34 +42,42 @@ func (a ByName) Less(i, j int) bool { return a[i].Package().Name() < a[j].Packag
func targetShowCmd(cmd *cobra.Command, args []string) {
proj := project.GetProject()
- proj.LoadPackageList()
-
- dispTarget := ""
- if len(args) == 1 {
- dispTarget = args[0]
+ err := proj.LoadPackageList()
+ if err != nil {
+ cli.NewtUsage(cmd, err)
}
targetNames := []string{}
- for name, _ := range GetTargets() {
- targetNames = append(targetNames, name)
+ if len(args) == 0 {
+ for name, _ := range GetTargets() {
+ targetNames = append(targetNames, name)
+ }
+ } else {
+ targetSlice, err := ResolveTargetNames(args...)
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+
+ for _, t := range targetSlice {
+ targetNames = append(targetNames, t.Name())
+ }
}
+
sort.Strings(targetNames)
for _, name := range targetNames {
- if dispTarget == "" || dispTarget == name {
- cli.StatusMessage(cli.VERBOSITY_QUIET, name+"\n")
+ cli.StatusMessage(cli.VERBOSITY_QUIET, name+"\n")
- target := GetTargets()[name]
- keys := []string{}
- for k, _ := range target.Vars {
- keys = append(keys, k)
- }
+ target := GetTargets()[name]
+ keys := []string{}
+ for k, _ := range target.Vars {
+ keys = append(keys, k)
+ }
- sort.Strings(keys)
- for _, k := range keys {
- cli.StatusMessage(cli.VERBOSITY_QUIET,
- " %s=%s\n", k, target.Vars[k])
- }
+ sort.Strings(keys)
+ for _, k := range keys {
+ cli.StatusMessage(cli.VERBOSITY_QUIET, " %s=%s\n", k,
+ target.Vars[k])
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a3d68ef2/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 128ea9b..99c8d1f 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -27,6 +27,7 @@ import (
"sort"
"strings"
+ "mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/util"
@@ -36,6 +37,10 @@ const TARGET_FILE_NAME string = "target.yml"
var globalTargetMap map[string]*Target
+var targetSearchDirs = []string{
+ "targets",
+}
+
type Target struct {
basePkg *pkg.LocalPackage
@@ -46,6 +51,7 @@ type Target struct {
BspName string
AppName string
Arch string
+ BuildProfile string
// target.yml configuration structure
Vars map[string]string
@@ -88,6 +94,7 @@ func (target *Target) Load(basePkg *pkg.LocalPackage) error {
target.BspName = target.Vars["target.bsp"]
target.AppName = target.Vars["target.app"]
target.Arch = target.Vars["target.arch"]
+ target.BuildProfile = target.Vars["target.build_profile"]
// XXX: Verify required fields set?
@@ -223,9 +230,13 @@ func buildTargetMap() error {
if pack.Type() == pkg.PACKAGE_TYPE_TARGET {
target, err := LoadTarget(pack.(*pkg.LocalPackage))
if err != nil {
- return err
+ nerr := err.(*util.NewtError)
+ cli.ErrorMessage(cli.VERBOSITY_QUIET,
+ "Warning: failed to load target \"%s\": %s\n", name,
+ nerr.Text)
+ } else {
+ globalTargetMap[name] = target
}
- globalTargetMap[name] = target
}
}
}
@@ -243,3 +254,31 @@ func GetTargets() map[string]*Target {
return globalTargetMap
}
+
+func ResolveTargetName(name string) *Target {
+ targetMap := GetTargets()
+
+ t := targetMap[name]
+ for i := 0; t == nil && i < len(targetSearchDirs); i++ {
+ guess := targetSearchDirs[i] + "/" + name
+ t = targetMap[guess]
+ }
+
+ return t
+}
+
+func ResolveTargetNames(names ...string) ([]*Target, error) {
+ targets := []*Target{}
+
+ for _, name := range names {
+ t := ResolveTargetName(name)
+ if t == nil {
+ return nil, util.NewNewtError("Could not resolve target name: " +
+ name)
+ }
+
+ targets = append(targets, t)
+ }
+
+ return targets, nil
+}
[09/50] incubator-mynewt-newt git commit: Add download/debug commands.
Posted by ma...@apache.org.
Add download/debug commands.
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/32463b45
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/32463b45
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/32463b45
Branch: refs/heads/develop
Commit: 32463b4559f4d5380074ba5b8cdca4656bfb84d3
Parents: b1c09ba
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Mar 8 11:11:17 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Mar 8 11:11:17 2016 -0800
----------------------------------------------------------------------
newt/builder/buildutil.go | 8 +
newt/builder/cmds.go | 68 +++++++++
newt/builder/download.go | 81 ++++++++++
newt/image/cmds.go | 72 +++++++++
newt/image/image.go | 329 +++++++++++++++++++++++++++++++++++++++++
newt/newt.go | 2 +
newt/target/cmds.go | 41 -----
newt/target/image.go | 328 ----------------------------------------
newt/target/target.go | 16 +-
9 files changed, 567 insertions(+), 378 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/32463b45/newt/builder/buildutil.go
----------------------------------------------------------------------
diff --git a/newt/builder/buildutil.go b/newt/builder/buildutil.go
index 06de849..0091def 100644
--- a/newt/builder/buildutil.go
+++ b/newt/builder/buildutil.go
@@ -69,6 +69,14 @@ func (b *Builder) logFeatures() {
cli.StatusMessage(cli.VERBOSITY_VERBOSE, buffer.String())
}
+func (b *Builder) featureString() string {
+ featureString := ""
+ for feature, _ := range b.features {
+ featureString = featureString + " " + feature
+ }
+ return featureString
+}
+
// Makes sure all packages with required APIs have been augmented a dependency
// which satisfies that requirement. If there are any unsatisfied
// requirements, an error is returned.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/32463b45/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index a6f2c89..472ae6d 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -118,6 +118,50 @@ func testRunCmd(cmd *cobra.Command, args []string) {
}
}
+func downloadRunCmd(cmd *cobra.Command, args []string) {
+ if len(args) < 1 {
+ cli.NewtUsage(cmd, util.NewNewtError("Must specify target"))
+ }
+
+ targetName := args[0]
+ t := target.GetTargets()[targetName]
+ if t == nil {
+ cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"))
+ }
+
+ b, err := NewBuilder(t)
+ if err != nil {
+ fmt.Println(err)
+ }
+
+ err = b.Download()
+ if err != nil {
+ fmt.Println(err)
+ }
+}
+
+func debugRunCmd(cmd *cobra.Command, args []string) {
+ if len(args) < 1 {
+ cli.NewtUsage(cmd, util.NewNewtError("Must specify target"))
+ }
+
+ targetName := args[0]
+ t := target.GetTargets()[targetName]
+ if t == nil {
+ cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"))
+ }
+
+ b, err := NewBuilder(t)
+ if err != nil {
+ fmt.Println(err)
+ }
+
+ err = b.Debug()
+ if err != nil {
+ fmt.Println(err)
+ }
+}
+
func AddCommands(cmd *cobra.Command) {
buildHelpText := ""
buildHelpEx := ""
@@ -154,4 +198,28 @@ func AddCommands(cmd *cobra.Command) {
}
cmd.AddCommand(testCmd)
+
+ downloadHelpText := "Download project image to target for <target-name>."
+ downloadHelpEx := " newt download <target-name>\n"
+
+ downloadCmd := &cobra.Command{
+ Use: "download",
+ Short: "Download built target to board",
+ Long: downloadHelpText,
+ Example: downloadHelpEx,
+ Run: downloadRunCmd,
+ }
+ cmd.AddCommand(downloadCmd)
+
+ debugHelpText := "Download project image to target for <target-name>.";
+ debugHelpEx := " newt debug <target-name>\n"
+
+ debugCmd := &cobra.Command{
+ Use: "debug",
+ Short: "Open debugger session to target",
+ Long: debugHelpText,
+ Example: debugHelpEx,
+ Run: debugRunCmd,
+ }
+ cmd.AddCommand(debugCmd)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/32463b45/newt/builder/download.go
----------------------------------------------------------------------
diff --git a/newt/builder/download.go b/newt/builder/download.go
new file mode 100644
index 0000000..0cbba72
--- /dev/null
+++ b/newt/builder/download.go
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package builder
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "mynewt.apache.org/newt/newt/cli"
+ "mynewt.apache.org/newt/newt/project"
+ "mynewt.apache.org/newt/util"
+)
+
+func (b *Builder) Download() error {
+ if b.target.App() == nil {
+ return util.NewNewtError("app package not specified")
+ }
+
+ /*
+ * Populate the package and feature sets.
+ */
+ err := b.prepBuild()
+ if err != nil {
+ return err
+ }
+
+ bspPath := b.Bsp.BasePath()
+ downloadScript := filepath.Join(bspPath, b.Bsp.DownloadScript)
+ binBaseName := b.target.BinBasePath()
+ featureString := b.featureString()
+
+ downloadCmd := fmt.Sprintf("%s %s %s %s",
+ downloadScript, bspPath, binBaseName, featureString)
+
+ rsp, err := cli.ShellCommand(downloadCmd)
+ fmt.Printf("%s", rsp)
+
+ return err
+}
+
+func (b *Builder) Debug() error {
+ if b.target.App() == nil {
+ return util.NewNewtError("app package not specified")
+ }
+
+ /*
+ * Populate the package and feature sets.
+ */
+ err := b.prepBuild()
+ if err != nil {
+ return err
+ }
+
+ bspPath := b.Bsp.BasePath()
+ debugScript := filepath.Join(bspPath, b.Bsp.DebugScript)
+ binBaseName := b.target.BinBasePath()
+ featureString := b.featureString()
+
+ os.Chdir(project.GetProject().Path())
+
+ cmdLine := []string{debugScript, bspPath, binBaseName, featureString}
+ return cli.ShellInteractiveCommand(cmdLine)
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/32463b45/newt/image/cmds.go
----------------------------------------------------------------------
diff --git a/newt/image/cmds.go b/newt/image/cmds.go
new file mode 100644
index 0000000..d169b21
--- /dev/null
+++ b/newt/image/cmds.go
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package image
+
+import (
+ "fmt"
+
+ "github.com/spf13/cobra"
+ "mynewt.apache.org/newt/newt/cli"
+ "mynewt.apache.org/newt/newt/target"
+ "mynewt.apache.org/newt/util"
+)
+
+func createImageRunCmd(cmd *cobra.Command, args []string) {
+ if len(args) < 2 {
+ cli.NewtUsage(cmd, util.NewNewtError("Must specify target and version"))
+ }
+
+ targetName := args[0]
+ t := target.GetTargets()[targetName]
+ if t == nil {
+ cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"))
+ }
+
+ image, err := NewImage(t)
+ if err != nil {
+ fmt.Println(err)
+ }
+ err = image.SetVersion(args[1])
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+ err = image.Generate()
+ if err != nil {
+ fmt.Println(err)
+ }
+}
+
+func AddCommands(cmd *cobra.Command) {
+ createImageHelpText := "Create image by adding image header to created "+
+ "binary file for <target-name>. Version number in the header is set "+
+ "to be <version>."
+ createImageHelpEx := " newt create-image <target-name> <version>\n"
+ createImageHelpEx += " newt create-image my_target1 1.2.0\n"
+ createImageHelpEx += " newt create-image my_target1 1.2.0.3\n"
+
+ createImageCmd := &cobra.Command{
+ Use: "create-image",
+ Short: "Add image header to target binary",
+ Long: createImageHelpText,
+ Example: createImageHelpEx,
+ Run: createImageRunCmd,
+ }
+ cmd.AddCommand(createImageCmd)
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/32463b45/newt/image/image.go
----------------------------------------------------------------------
diff --git a/newt/image/image.go b/newt/image/image.go
new file mode 100644
index 0000000..edd3bfd
--- /dev/null
+++ b/newt/image/image.go
@@ -0,0 +1,329 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package image
+
+import (
+ "bytes"
+ "crypto/sha256"
+ "encoding/binary"
+ "encoding/json"
+ "fmt"
+ "io"
+ "log"
+ "os"
+ "path/filepath"
+ "sort"
+ "strconv"
+ "strings"
+ "time"
+
+ "mynewt.apache.org/newt/newt/target"
+ "mynewt.apache.org/newt/util"
+)
+
+type ImageVersion struct {
+ Major uint8
+ Minor uint8
+ Rev uint16
+ BuildNum uint32
+}
+
+type Image struct {
+ target *target.Target
+
+ sourceBin string
+ targetImg string
+ ManifestFile string
+ version ImageVersion
+
+ hash []byte
+}
+
+type ImageHdr struct {
+ Magic uint32
+ TlvSz uint32
+ HdrSz uint32
+ ImgSz uint32
+ Flags uint32
+ Vers ImageVersion
+ Pad uint32
+}
+
+type ImageTrailerTlv struct {
+ Type uint8
+ Pad uint8
+ Len uint16
+}
+
+const (
+ IMAGE_MAGIC = 0x96f3b83c /* Image header magic */
+)
+
+const (
+ IMAGE_HEADER_SIZE = 32
+)
+
+/*
+ * Image header flags.
+ */
+const (
+ IMAGE_F_PIC = 0x00000001
+ IMAGE_F_HAS_SHA256 = 0x00000002 /* Image contains hash TLV */
+)
+
+/*
+ * Image trailer TLV types.
+ */
+const (
+ IMAGE_TLV_SHA256 = 1
+)
+
+/*
+ * Data that's going to go to build manifest file
+ */
+type ImageManifest struct {
+ Date string `json:"build_time"`
+ Version string `json:"build_version"`
+ Hash string `json:"id"`
+ Image string `json:"image"`
+ Pkgs []*ImageManifestPkg `json:"pkgs"`
+ TgtVars []string `json:"target"`
+}
+
+type ImageManifestPkg struct {
+ Name string `json:"name"`
+ Version string `json:"version,omitempty"`
+ Hash string `json:"hash"`
+}
+
+func NewImage(t *target.Target) (*Image, error) {
+ image := &Image{
+ target: t,
+ }
+
+ image.sourceBin = t.ElfPath() + ".bin"
+ image.targetImg = t.ImagePath()
+ return image, nil
+}
+
+func (image *Image) SetVersion(versStr string) error {
+ var err error
+ var major uint64
+ var minor uint64
+ var rev uint64
+ var buildNum uint64
+
+ components := strings.Split(versStr, ".")
+ major, err = strconv.ParseUint(components[0], 10, 8)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
+ versStr))
+ }
+ if len(components) > 1 {
+ minor, err = strconv.ParseUint(components[1], 10, 8)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
+ versStr))
+ }
+ }
+ if len(components) > 2 {
+ rev, err = strconv.ParseUint(components[2], 10, 16)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
+ versStr))
+ }
+ }
+ if len(components) > 3 {
+ buildNum, err = strconv.ParseUint(components[3], 10, 32)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
+ versStr))
+ }
+ }
+ image.version.Major = uint8(major)
+ image.version.Minor = uint8(minor)
+ image.version.Rev = uint16(rev)
+ image.version.BuildNum = uint32(buildNum)
+ log.Printf("[VERBOSE] Assigning version number %d.%d.%d.%d\n",
+ image.version.Major, image.version.Minor,
+ image.version.Rev, image.version.BuildNum)
+
+ buf := new(bytes.Buffer)
+ err = binary.Write(buf, binary.LittleEndian, image.version)
+ if err != nil {
+ fmt.Printf("Bombing out\n")
+ return nil
+ }
+
+ return nil
+}
+
+func (image *Image) Generate() error {
+ binFile, err := os.Open(image.sourceBin)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Can't open target binary %s: %s",
+ image.sourceBin, err.Error()))
+ }
+ defer binFile.Close()
+
+ binInfo, err := binFile.Stat()
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Can't stat target binary %s: %s",
+ image.sourceBin, err.Error()))
+ }
+
+ imgFile, err := os.OpenFile(image.targetImg,
+ os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Can't open target image %s: %s",
+ image.targetImg, err.Error()))
+ }
+ defer imgFile.Close()
+
+ /*
+ * Compute hash while updating the file.
+ */
+ hash := sha256.New()
+
+ /*
+ * First the header
+ */
+ hdr := &ImageHdr{
+ Magic: IMAGE_MAGIC,
+ TlvSz: 4 + 32,
+ HdrSz: IMAGE_HEADER_SIZE,
+ ImgSz: uint32(binInfo.Size()),
+ Flags: IMAGE_F_HAS_SHA256,
+ Vers: image.version,
+ Pad: 0,
+ }
+
+ err = binary.Write(imgFile, binary.LittleEndian, hdr)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to serialize image hdr: %s",
+ err.Error()))
+ }
+ err = binary.Write(hash, binary.LittleEndian, hdr)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to hash data: %s",
+ err.Error()))
+ }
+
+ /*
+ * Followed by data.
+ */
+ dataBuf := make([]byte, 1024)
+ for {
+ cnt, err := binFile.Read(dataBuf)
+ if err != nil && err != io.EOF {
+ return util.NewNewtError(fmt.Sprintf("Failed to read from %s: %s",
+ image.sourceBin, err.Error()))
+ }
+ if cnt == 0 {
+ break
+ }
+ _, err = imgFile.Write(dataBuf[0:cnt])
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to write to %s: %s",
+ image.targetImg, err.Error()))
+ }
+ _, err = hash.Write(dataBuf[0:cnt])
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to hash data: %s",
+ err.Error()))
+ }
+ }
+
+ image.hash = hash.Sum(nil)
+
+ /*
+ * Trailer with hash of the data
+ */
+ tlv := &ImageTrailerTlv{
+ Type: IMAGE_TLV_SHA256,
+ Pad: 0,
+ Len: uint16(len(image.hash)),
+ }
+ err = binary.Write(imgFile, binary.LittleEndian, tlv)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to serialize image "+
+ "trailer: %s", err.Error()))
+ }
+ _, err = imgFile.Write(image.hash)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Failed to append hash: %s",
+ err.Error()))
+ }
+
+ return nil
+}
+
+func (image *Image) CreateManifest() error {
+ versionStr := fmt.Sprintf("%d.%d.%d.%d",
+ image.version.Major, image.version.Minor,
+ image.version.Rev, image.version.BuildNum)
+ hashStr := fmt.Sprintf("%x", image.hash)
+ timeStr := time.Now().Format(time.RFC3339)
+
+ manifest := &ImageManifest{
+ Version: versionStr,
+ Hash: hashStr,
+ Image: filepath.Base(image.targetImg),
+ Date: timeStr,
+ }
+/*
+ for _, builtPkg := range BuiltPkgs {
+ imgPkg := &ImageManifestPkg{
+ Name: builtPkg.Name,
+ Version: builtPkg.Version,
+ Hash: builtPkg.Hash,
+ }
+ manifest.Pkgs = append(manifest.Pkgs, imgPkg)
+ }
+*/
+ vars := image.target.Vars
+ var keys []string
+ for k := range vars {
+ keys = append(keys, k)
+ }
+ sort.Strings(keys)
+ for _, k := range keys {
+ manifest.TgtVars = append(manifest.TgtVars, k+"="+vars[k])
+ }
+ file, err := os.Create(image.ManifestFile)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Cannot create manifest file %s: %s",
+ image.ManifestFile, err.Error()))
+ }
+ defer file.Close()
+
+ buffer, err := json.MarshalIndent(manifest, "", " ")
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Cannot encode manifest: %s",
+ err.Error()))
+ }
+ _, err = file.Write(buffer)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Cannot write manifest file: %s",
+ err.Error()))
+ }
+
+ return nil
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/32463b45/newt/newt.go
----------------------------------------------------------------------
diff --git a/newt/newt.go b/newt/newt.go
index 4cb8ad6..9b05f55 100644
--- a/newt/newt.go
+++ b/newt/newt.go
@@ -25,6 +25,7 @@ import (
"mynewt.apache.org/newt/newt/builder"
"mynewt.apache.org/newt/newt/cli"
+ "mynewt.apache.org/newt/newt/image"
"mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/newt/target"
@@ -91,6 +92,7 @@ func main() {
pkg.AddCommands(cmd)
target.AddCommands(cmd)
builder.AddCommands(cmd)
+ image.AddCommands(cmd)
cmd.Execute()
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/32463b45/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index 00bdfae..9069574 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -208,31 +208,6 @@ func targetDelCmd(cmd *cobra.Command, args []string) {
"Target %s successfully removed\n", args[0])
}
-func createImageRunCmd(cmd *cobra.Command, args []string) {
- if len(args) < 2 {
- cli.NewtUsage(cmd, util.NewNewtError("Must specify target and version"))
- }
-
- targetName := args[0]
- t := GetTargets()[targetName]
- if t == nil {
- cli.NewtUsage(cmd, util.NewNewtError("Invalid target name"))
- }
-
- image, err := NewImage(t)
- if err != nil {
- fmt.Println(err)
- }
- err = image.SetVersion(args[1])
- if err != nil {
- cli.NewtUsage(cmd, err)
- }
- err = image.Generate()
- if err != nil {
- fmt.Println(err)
- }
-}
-
func AddCommands(cmd *cobra.Command) {
targetHelpText := ""
targetHelpEx := ""
@@ -307,20 +282,4 @@ func AddCommands(cmd *cobra.Command) {
}
targetCmd.AddCommand(delCmd)
-
- createImageHelpText := "Create image by adding image header to created "+
- "binary file for <target-name>. Version number in the header is set "+
- "to be <version>."
- createImageHelpEx := " newt create-image <target-name> <version>\n"
- createImageHelpEx += " newt create-image my_target1 1.2.0\n"
- createImageHelpEx += " newt create-image my_target1 1.2.0.3\n"
-
- createImageCmd := &cobra.Command{
- Use: "create-image",
- Short: "Add image header to target binary",
- Long: createImageHelpText,
- Example: createImageHelpEx,
- Run: createImageRunCmd,
- }
- cmd.AddCommand(createImageCmd)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/32463b45/newt/target/image.go
----------------------------------------------------------------------
diff --git a/newt/target/image.go b/newt/target/image.go
deleted file mode 100644
index 1964e5a..0000000
--- a/newt/target/image.go
+++ /dev/null
@@ -1,328 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package target
-
-import (
- "bytes"
- "crypto/sha256"
- "encoding/binary"
- "encoding/json"
- "fmt"
- "io"
- "log"
- "os"
- "path/filepath"
- "sort"
- "strconv"
- "strings"
- "time"
-
- "mynewt.apache.org/newt/util"
-)
-
-type ImageVersion struct {
- Major uint8
- Minor uint8
- Rev uint16
- BuildNum uint32
-}
-
-type Image struct {
- target *Target
-
- sourceBin string
- targetImg string
- ManifestFile string
- version ImageVersion
-
- hash []byte
-}
-
-type ImageHdr struct {
- Magic uint32
- TlvSz uint32
- HdrSz uint32
- ImgSz uint32
- Flags uint32
- Vers ImageVersion
- Pad uint32
-}
-
-type ImageTrailerTlv struct {
- Type uint8
- Pad uint8
- Len uint16
-}
-
-const (
- IMAGE_MAGIC = 0x96f3b83c /* Image header magic */
-)
-
-const (
- IMAGE_HEADER_SIZE = 32
-)
-
-/*
- * Image header flags.
- */
-const (
- IMAGE_F_PIC = 0x00000001
- IMAGE_F_HAS_SHA256 = 0x00000002 /* Image contains hash TLV */
-)
-
-/*
- * Image trailer TLV types.
- */
-const (
- IMAGE_TLV_SHA256 = 1
-)
-
-/*
- * Data that's going to go to build manifest file
- */
-type ImageManifest struct {
- Date string `json:"build_time"`
- Version string `json:"build_version"`
- Hash string `json:"id"`
- Image string `json:"image"`
- Pkgs []*ImageManifestPkg `json:"pkgs"`
- TgtVars []string `json:"target"`
-}
-
-type ImageManifestPkg struct {
- Name string `json:"name"`
- Version string `json:"version,omitempty"`
- Hash string `json:"hash"`
-}
-
-func NewImage(t *Target) (*Image, error) {
- image := &Image{
- target: t,
- }
-
- image.sourceBin = t.ElfPath() + ".bin"
- image.targetImg = t.ImagePath()
- return image, nil
-}
-
-func (image *Image) SetVersion(versStr string) error {
- var err error
- var major uint64
- var minor uint64
- var rev uint64
- var buildNum uint64
-
- components := strings.Split(versStr, ".")
- major, err = strconv.ParseUint(components[0], 10, 8)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
- versStr))
- }
- if len(components) > 1 {
- minor, err = strconv.ParseUint(components[1], 10, 8)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
- versStr))
- }
- }
- if len(components) > 2 {
- rev, err = strconv.ParseUint(components[2], 10, 16)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
- versStr))
- }
- }
- if len(components) > 3 {
- buildNum, err = strconv.ParseUint(components[3], 10, 32)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Invalid version string %s",
- versStr))
- }
- }
- image.version.Major = uint8(major)
- image.version.Minor = uint8(minor)
- image.version.Rev = uint16(rev)
- image.version.BuildNum = uint32(buildNum)
- log.Printf("[VERBOSE] Assigning version number %d.%d.%d.%d\n",
- image.version.Major, image.version.Minor,
- image.version.Rev, image.version.BuildNum)
-
- buf := new(bytes.Buffer)
- err = binary.Write(buf, binary.LittleEndian, image.version)
- if err != nil {
- fmt.Printf("Bombing out\n")
- return nil
- }
-
- return nil
-}
-
-func (image *Image) Generate() error {
- binFile, err := os.Open(image.sourceBin)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Can't open target binary %s: %s",
- image.sourceBin, err.Error()))
- }
- defer binFile.Close()
-
- binInfo, err := binFile.Stat()
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Can't stat target binary %s: %s",
- image.sourceBin, err.Error()))
- }
-
- imgFile, err := os.OpenFile(image.targetImg,
- os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Can't open target image %s: %s",
- image.targetImg, err.Error()))
- }
- defer imgFile.Close()
-
- /*
- * Compute hash while updating the file.
- */
- hash := sha256.New()
-
- /*
- * First the header
- */
- hdr := &ImageHdr{
- Magic: IMAGE_MAGIC,
- TlvSz: 4 + 32,
- HdrSz: IMAGE_HEADER_SIZE,
- ImgSz: uint32(binInfo.Size()),
- Flags: IMAGE_F_HAS_SHA256,
- Vers: image.version,
- Pad: 0,
- }
-
- err = binary.Write(imgFile, binary.LittleEndian, hdr)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Failed to serialize image hdr: %s",
- err.Error()))
- }
- err = binary.Write(hash, binary.LittleEndian, hdr)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Failed to hash data: %s",
- err.Error()))
- }
-
- /*
- * Followed by data.
- */
- dataBuf := make([]byte, 1024)
- for {
- cnt, err := binFile.Read(dataBuf)
- if err != nil && err != io.EOF {
- return util.NewNewtError(fmt.Sprintf("Failed to read from %s: %s",
- image.sourceBin, err.Error()))
- }
- if cnt == 0 {
- break
- }
- _, err = imgFile.Write(dataBuf[0:cnt])
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Failed to write to %s: %s",
- image.targetImg, err.Error()))
- }
- _, err = hash.Write(dataBuf[0:cnt])
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Failed to hash data: %s",
- err.Error()))
- }
- }
-
- image.hash = hash.Sum(nil)
-
- /*
- * Trailer with hash of the data
- */
- tlv := &ImageTrailerTlv{
- Type: IMAGE_TLV_SHA256,
- Pad: 0,
- Len: uint16(len(image.hash)),
- }
- err = binary.Write(imgFile, binary.LittleEndian, tlv)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Failed to serialize image "+
- "trailer: %s", err.Error()))
- }
- _, err = imgFile.Write(image.hash)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Failed to append hash: %s",
- err.Error()))
- }
-
- return nil
-}
-
-func (image *Image) CreateManifest() error {
- versionStr := fmt.Sprintf("%d.%d.%d.%d",
- image.version.Major, image.version.Minor,
- image.version.Rev, image.version.BuildNum)
- hashStr := fmt.Sprintf("%x", image.hash)
- timeStr := time.Now().Format(time.RFC3339)
-
- manifest := &ImageManifest{
- Version: versionStr,
- Hash: hashStr,
- Image: filepath.Base(image.targetImg),
- Date: timeStr,
- }
-/*
- for _, builtPkg := range BuiltPkgs {
- imgPkg := &ImageManifestPkg{
- Name: builtPkg.Name,
- Version: builtPkg.Version,
- Hash: builtPkg.Hash,
- }
- manifest.Pkgs = append(manifest.Pkgs, imgPkg)
- }
-*/
- vars := image.target.Vars
- var keys []string
- for k := range vars {
- keys = append(keys, k)
- }
- sort.Strings(keys)
- for _, k := range keys {
- manifest.TgtVars = append(manifest.TgtVars, k+"="+vars[k])
- }
- file, err := os.Create(image.ManifestFile)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Cannot create manifest file %s: %s",
- image.ManifestFile, err.Error()))
- }
- defer file.Close()
-
- buffer, err := json.MarshalIndent(manifest, "", " ")
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Cannot encode manifest: %s",
- err.Error()))
- }
- _, err = file.Write(buffer)
- if err != nil {
- return util.NewNewtError(fmt.Sprintf("Cannot write manifest file: %s",
- err.Error()))
- }
-
- return nil
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/32463b45/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index c48affe..32727f5 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -132,24 +132,22 @@ func (target *Target) Bsp() *pkg.LocalPackage {
return mypkg
}
-func (target *Target) ElfPath() string {
+func (target *Target) BinBasePath() string {
appPkg := target.App()
if appPkg == nil {
return ""
}
return appPkg.BasePath() + "/bin/" + target.Package().Name() + "/" +
- appPkg.Name() + ".elf"
+ appPkg.Name()
}
-func (target *Target) ImagePath() string {
- appPkg := target.App()
- if appPkg == nil {
- return ""
- }
+func (target *Target) ElfPath() string {
+ return target.BinBasePath() + ".elf"
+}
- return appPkg.BasePath() + "/bin/" + target.Package().Name() + "/" +
- appPkg.Name() + ".img"
+func (target *Target) ImagePath() string {
+ return target.BinBasePath() + ".img"
}
// Save the target's configuration elements
[22/50] incubator-mynewt-newt git commit: remove empty project and
package commands
Posted by ma...@apache.org.
remove empty project and package commands
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/ec236857
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/ec236857
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/ec236857
Branch: refs/heads/develop
Commit: ec236857976e5c02b07b9f870443738b9b129b88
Parents: 4542bb4
Author: Sterling Hughes <st...@apache.org>
Authored: Tue Mar 8 16:37:01 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Mar 8 16:37:01 2016 -0800
----------------------------------------------------------------------
newt/pkg/cmds.go | 14 --------------
newt/project/cmds.go | 36 ------------------------------------
2 files changed, 50 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ec236857/newt/pkg/cmds.go
----------------------------------------------------------------------
diff --git a/newt/pkg/cmds.go b/newt/pkg/cmds.go
index 9eaf27e..53c4559 100644
--- a/newt/pkg/cmds.go
+++ b/newt/pkg/cmds.go
@@ -21,19 +21,5 @@ package pkg
import "github.com/spf13/cobra"
-func pkgRunCmd(cmd *cobra.Command, args []string) {
-}
-
func AddCommands(cmd *cobra.Command) {
- pkgHelpText := ""
- pkgHelpEx := ""
- pkgCmd := &cobra.Command{
- Use: "package",
- Short: "Commands for manipulating packages",
- Long: pkgHelpText,
- Example: pkgHelpEx,
- Run: pkgRunCmd,
- }
-
- cmd.AddCommand(pkgCmd)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ec236857/newt/project/cmds.go
----------------------------------------------------------------------
diff --git a/newt/project/cmds.go b/newt/project/cmds.go
index 44f56be..eb08b2a 100644
--- a/newt/project/cmds.go
+++ b/newt/project/cmds.go
@@ -21,12 +21,10 @@ package project
import (
"fmt"
- "os"
"github.com/spf13/cobra"
"mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/newt/interfaces"
- "mynewt.apache.org/newt/util"
)
var Force bool = false
@@ -53,41 +51,7 @@ func upgradeRunCmd(cmd *cobra.Command, args []string) {
fmt.Println("Repos successfully upgrade")
}
-func projectRunCmd(cmd *cobra.Command, args []string) {
- wd, err := os.Getwd()
- if err != nil {
- cli.NewtUsage(cmd, util.NewNewtError(err.Error()))
- }
-
- proj, err := LoadProject(wd)
- if err != nil {
- cli.NewtUsage(cmd, err)
- }
- proj.LoadPackageList()
-
- for rName, list := range proj.PackageList() {
- fmt.Printf("repository name: %s\n", rName)
- for pkgName, _ := range *list {
- fmt.Printf(" %s\n", pkgName)
- }
- }
-
- fmt.Printf("Project %s\n", proj.Name)
- fmt.Printf(" BasePath: %s\n", proj.BasePath)
-}
-
func AddCommands(cmd *cobra.Command) {
- projectHelpText := ""
- projectHelpEx := ""
- projectCmd := &cobra.Command{
- Use: "project",
- Short: "Command for manipulating projects",
- Long: projectHelpText,
- Example: projectHelpEx,
- Run: projectRunCmd,
- }
- cmd.AddCommand(projectCmd)
-
installHelpText := ""
installHelpEx := ""
installCmd := &cobra.Command{
[48/50] incubator-mynewt-newt git commit: Fix returned error type in
case of file not existing.
Posted by ma...@apache.org.
Fix returned error type in case of file not existing.
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/e5eaa6a7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/e5eaa6a7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/e5eaa6a7
Branch: refs/heads/develop
Commit: e5eaa6a77fc973e728cbbb0f3874639311d7833c
Parents: e49f113
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Mar 9 09:58:53 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Mar 9 10:02:33 2016 -0800
----------------------------------------------------------------------
newt/builder/size.go | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e5eaa6a7/newt/builder/size.go
----------------------------------------------------------------------
diff --git a/newt/builder/size.go b/newt/builder/size.go
index 769dba4..624f6a9 100644
--- a/newt/builder/size.go
+++ b/newt/builder/size.go
@@ -112,7 +112,8 @@ func ParseMapFileSizes(fileName string) (map[string]*PkgSize, map[string]*MemSec
file, err := os.Open(fileName)
if err != nil {
- return nil, nil, err
+ return nil, nil,
+ util.NewNewtError("Mapfile failed: "+ err.Error())
}
memSections := make(map[string]*MemSection)
[21/50] incubator-mynewt-newt git commit: improve status message and
behavior for install & upgrade
Posted by ma...@apache.org.
improve status message and behavior for install & upgrade
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/4542bb46
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/4542bb46
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/4542bb46
Branch: refs/heads/develop
Commit: 4542bb468570b2a60d9380b3416f87f6cae60b35
Parents: 91fac93
Author: Sterling Hughes <st...@apache.org>
Authored: Tue Mar 8 16:30:07 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Mar 8 16:30:07 2016 -0800
----------------------------------------------------------------------
newt/downloader/downloader.go | 23 ++++++++++++--
newt/project/cmds.go | 8 ++---
newt/project/project.go | 43 +++++++++++++++++++++++----
newt/repo/repo.go | 61 +++++++++++++++++++++++++++++++-------
4 files changed, 112 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4542bb46/newt/downloader/downloader.go
----------------------------------------------------------------------
diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index 37ae4d3..ee396bb 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -26,6 +26,7 @@ import (
"log"
"net/http"
"os"
+ "os/exec"
"mynewt.apache.org/newt/newt/cli"
"mynewt.apache.org/newt/util"
@@ -62,7 +63,6 @@ func (gd *GenericDownloader) TempDir() (string, error) {
}
func (gd *GithubDownloader) FetchFile(name string, dest string) error {
-
fmtStr := "https://raw.githubusercontent.com/%s/%s/%s/%s"
url := fmt.Sprintf(fmtStr, gd.User, gd.Repo, gd.Branch(), name)
@@ -93,10 +93,27 @@ func (gd *GithubDownloader) DownloadRepo(branch string) (string, error) {
}
url := fmt.Sprintf("https://github.com/%s/%s.git", gd.User, gd.Repo)
+ cli.StatusMessage(cli.VERBOSITY_DEFAULT, fmt.Sprintf("Downloading "+
+ "repository %s (branch: %s) at %s\n", gd.Repo, branch, url))
- _, err = cli.ShellCommand(fmt.Sprintf("git clone -b %s %s %s",
- branch, url, tmpdir))
+ gitPath, err := exec.LookPath("git")
if err != nil {
+ os.RemoveAll(tmpdir)
+ return "", util.NewNewtError(fmt.Sprintf("Can't find git binary: %s\n",
+ err.Error()))
+ }
+
+ cmds := []string{
+ gitPath,
+ "clone",
+ "-b",
+ branch,
+ url,
+ tmpdir,
+ }
+
+ if err := cli.ShellInteractiveCommand(cmds); err != nil {
+ os.RemoveAll(tmpdir)
return "", err
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4542bb46/newt/project/cmds.go
----------------------------------------------------------------------
diff --git a/newt/project/cmds.go b/newt/project/cmds.go
index b9a8923..44f56be 100644
--- a/newt/project/cmds.go
+++ b/newt/project/cmds.go
@@ -36,7 +36,7 @@ func installRunCmd(cmd *cobra.Command, args []string) {
interfaces.SetProject(proj)
if err := proj.Install(false, Force); err != nil {
- panic(err.Error())
+ cli.NewtUsage(cmd, err)
}
fmt.Println("Repos successfully installed")
@@ -47,7 +47,7 @@ func upgradeRunCmd(cmd *cobra.Command, args []string) {
interfaces.SetProject(proj)
if err := proj.Upgrade(Force); err != nil {
- panic(err.Error())
+ cli.NewtUsage(cmd, err)
}
fmt.Println("Repos successfully upgrade")
@@ -92,7 +92,7 @@ func AddCommands(cmd *cobra.Command) {
installHelpEx := ""
installCmd := &cobra.Command{
Use: "install",
- Short: "Command to install project dependencies from project.yml",
+ Short: "Command to install project dependencies",
Long: installHelpText,
Example: installHelpEx,
Run: installRunCmd,
@@ -107,7 +107,7 @@ func AddCommands(cmd *cobra.Command) {
upgradeHelpEx := ""
upgradeCmd := &cobra.Command{
Use: "upgrade",
- Short: "Command to upgrade project dependencies from project.yml",
+ Short: "Command to upgrade project dependencies",
Long: upgradeHelpText,
Example: upgradeHelpEx,
Run: upgradeRunCmd,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4542bb46/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index 5c79d2e..7e3e5e1 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -160,21 +160,52 @@ func (proj *Project) Install(upgrade bool, force bool) error {
vers := proj.projState.GetInstalledVersion(rname)
if vers != nil {
- // 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 := vers.SatisfiesVersion(r.VersionRequirements())
+ ok := rdesc.SatisfiesVersion(vers, r.VersionRequirements())
if !ok && !upgrade {
fmt.Printf("WARNING: Installed version %s of repository %s "+
- "does not match desired versions %s in project.yml\n",
+ "does not match desired versions %s in project\n",
vers, rname, r.VersionRequirementsString())
continue
}
+
+ if !upgrade {
+ cli.StatusMessage(cli.VERBOSITY_DEFAULT,
+ fmt.Sprintf("Installed repository %s matches project requirements, "+
+ "moving on to next repository.\n", r.Name()))
+ continue
+ } else {
+ _, newVers, _ := rdesc.Match(r)
+ if newVers == nil {
+ return util.NewNewtError(fmt.Sprintf(
+ "No matching version for repository %s\n", r.Name()))
+ }
+ if vers.CompareVersions(newVers, vers) != 0 ||
+ vers.Stability() != newVers.Stability() {
+ // Prompt for upgrade, unless force option present
+ if !force {
+ branch, newVers, _ := rdesc.Match(r)
+
+ str := ""
+ if newVers.Stability() != repo.VERSION_STABILITY_NONE {
+ str += "(" + branch + ")"
+ }
+
+ fmt.Printf("Would you like to upgrade repository %s from %s to %s %s",
+ r.Name(), vers.String(), newVers.String(), str)
+
+ }
+ } else {
+ fmt.Printf("Repository %s doesn't need to be upgraded, latest "+
+ "version installed.\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())
+ "%s specified in project, skipping...\n", r.Name())
continue
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4542bb46/newt/repo/repo.go
----------------------------------------------------------------------
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index 5f78314..35f7507 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -48,11 +48,11 @@ type Repo struct {
type RepoDesc struct {
name string
- vers map[string]*Version
+ vers map[*Version]string
}
func (rd *RepoDesc) MatchVersion(searchVers *Version) (string, *Version, bool) {
- for curBranch, vers := range rd.vers {
+ for vers, curBranch := range rd.vers {
if vers.CompareVersions(vers, searchVers) == 0 {
return curBranch, vers, true
}
@@ -61,7 +61,7 @@ func (rd *RepoDesc) MatchVersion(searchVers *Version) (string, *Version, bool) {
}
func (rd *RepoDesc) Match(r *Repo) (string, *Version, bool) {
- for branch, vers := range rd.vers {
+ for vers, branch := range rd.vers {
if vers.SatisfiesVersion(r.VersionRequirements()) {
log.Printf("[DEBUG] Found matching version %s for repo %s",
vers.String(), r.Name())
@@ -85,25 +85,59 @@ func (rd *RepoDesc) Match(r *Repo) (string, *Version, bool) {
return "", nil, false
}
+func (rd *RepoDesc) SatisfiesVersion(vers *Version, versReqs []interfaces.VersionReqInterface) bool {
+ var err error
+ versMatches := []interfaces.VersionReqInterface{}
+ for _, versReq := range versReqs {
+ versMatch := &VersionMatch{}
+ versMatch.compareType = versReq.CompareType()
+
+ if versReq.Version().Stability() != VERSION_STABILITY_NONE {
+ // Look up this item in the RepoDescription, and get a version
+ searchVers := versReq.Version().(*Version)
+ branch, _, ok := rd.MatchVersion(searchVers)
+ if !ok {
+ return false
+ }
+ versMatch.Vers, err = LoadVersion(branch)
+ if err != nil {
+ return false
+ }
+ } else {
+ versMatch.Vers = versReq.Version().(*Version)
+ }
+
+ versMatches = append(versMatches, versMatch)
+ }
+
+ return vers.SatisfiesVersion(versMatches)
+}
+
func (rd *RepoDesc) Init(name string, versBranchMap map[string]string) error {
rd.name = name
- rd.vers = map[string]*Version{}
- for k, v := range versBranchMap {
- log.Printf("[DEBUG] Printing version %s for remote repo %s", k, name)
- vers, err := LoadVersion(k)
+ rd.vers = map[*Version]string{}
+ for versStr, branch := range versBranchMap {
+ log.Printf("[DEBUG] Printing version %s for remote repo %s", versStr, name)
+ vers, err := LoadVersion(versStr)
if err != nil {
return err
}
// store branch->version mapping
- rd.vers[v] = vers
+ rd.vers[vers] = branch
}
return nil
}
func (rd *RepoDesc) String() string {
- return rd.name
+ name := rd.name + "@"
+ for k, v := range rd.vers {
+ name += fmt.Sprintf("%s=%s", k.String(), v)
+ name += "#"
+ }
+
+ return name
}
func NewRepoDesc(name string, versBranchMap map[string]string) (*RepoDesc, error) {
@@ -166,7 +200,8 @@ func (r *Repo) Install(rdesc *RepoDesc, force bool) (*Version, error) {
// Download the git repo, returns the git repo, checked out to that branch
tmpdir, err := dl.DownloadRepo(branchName)
if err != nil {
- return nil, err
+ return nil, util.NewNewtError(fmt.Sprintf("Error download repository %s, : %s",
+ r.Name(), err.Error()))
}
// Copy the Git repo into the the desired local path of the repo
@@ -184,6 +219,9 @@ func (r *Repo) Install(rdesc *RepoDesc, force bool) (*Version, error) {
func (r *Repo) DownloadDesc() error {
dl := r.downloader
+ cli.StatusMessage(cli.VERBOSITY_DEFAULT, fmt.Sprintf("Downloading "+
+ "repository description for %s...", r.Name()))
+
// Configuration path
cpath := r.repoFilePath()
if cli.NodeNotExist(cpath) {
@@ -195,9 +233,12 @@ func (r *Repo) DownloadDesc() error {
dl.SetBranch("master")
if err := dl.FetchFile("repository.yml",
cpath+"/"+"repository.yml"); err != nil {
+ cli.StatusMessage(cli.VERBOSITY_DEFAULT, " failed\n")
return err
}
+ cli.StatusMessage(cli.VERBOSITY_DEFAULT, " success!\n")
+
return nil
}