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:26 UTC
[11/50] incubator-mynewt-newt git commit: Update to use new path to
generated binaries. Go formatting.
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)